-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester_test.vim
180 lines (135 loc) · 5.94 KB
/
tester_test.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
so tester.vim
" XXX: not easy enough
let s:script_id = "47"
function! s:DecorateFunctionName(func_name)
let new_prefix = "<SNR>".s:script_id."_"
return substitute(a:func_name, "^s:", new_prefix, "")
endfunction
function! s:CallFunctionName(func_str)
let decorated_function_str = s:DecorateFunctionName(a:func_str)
let result = eval(decorated_function_str)
return result
endfunction
" -----------------------------------------------------------------------------
UTSuite "[tester] command"
function! s:TestCommand_T_calls_s:TestFile()
" 2 for full match
Assert exists(":T") == 2
endfunction
" -----------------------------------------------------------------------------
UTSuite "[tester] decorating filename into test"
function! s:TestSplittingFilenameIntoNameAndExtension()
let filename = "somefile.ext"
Assert <SNR>47_SplitFilename(filename) == ['somefile', 'ext']
endfunction
function! s:TestConvertFilenameIntoTestFilename()
let filename = "somefile.ext"
Assert <SNR>47_ConvertFilename2TestFilename(filename) == "somefile_test.ext"
endfunction
function! s:TestConvertFilenameIntoTestFilenameEvenItAlreadyHasTest()
let filename = "somefile_test.ext"
Assert <SNR>47_ConvertFilename2TestFilename(filename) == "somefile_test_test.ext"
endfunction
function! s:TestTestFilenameIntoFilename()
let filename = "somefile_test.ext"
Assert <SNR>47_ConvertTestFilename2Filename(filename) == "somefile.ext"
endfunction
UTSuite "[tester] changing path to test path and vice versa"
function! s:TestConvertPathIntoTestPath()
let path='/some/path/'
Assert <SNR>47_ConvertPath2TestPath(path) == "/some/path/test/"
endfunction
function! s:TestConvertPathIntoTestPathRemovesDuplicateSlashes()
let path='/some/path//'
Assert <SNR>47_ConvertPath2TestPath(path) == "/some/path/test/"
endfunction
function! s:TestConvertPathIntoTestPathConvertsToAbsPathIfRelative()
" let's say you are currently at /some/path
let cwd=substitute(getcwd(), '/$', '', "")
let path=''
Assert <SNR>47_ConvertPath2TestPath(path) == cwd ."/test/"
endfunction
function! s:TestConvertTestPathIntoPathRemoves_test_AtEnd()
let path='/some/path/test'
Assert <SNR>47_ConvertTestPath2Path(path) == "/some/path/"
endfunction
function! s:TestConvertTestPathIntoPathWorksRegardlessOfSlashAtEnd()
let path='/some/path/test/'
Assert <SNR>47_ConvertTestPath2Path(path) == "/some/path/"
endfunction
function! s:TestConvertTestPathIntoPathOnlyRemovesFinal_test()
let path='/some/path/test/final/test/'
Assert <SNR>47_ConvertTestPath2Path(path) == "/some/path/test/final/"
endfunction
function! s:TestConvertTestPathIntoPathCanReadSimplifyPath()
let path='/some/path/test/dir/..'
Assert <SNR>47_ConvertTestPath2Path(path) == "/some/path/"
endfunction
function! s:TestConvertTestPathIntoPathCanApplyRelativePath()
let path='relative/path'
endfunction
UTSuite "[tester] /prog/test/prog_test.ext -> /prog/prog.ext"
function! s:TestConvertingBothPathAndFilename()
let fullname = "/some/program/test/program_test.py"
Assert <SNR>47_ConvertFullTestFilename2FullFilename(fullname) == "/some/program/program.py"
endfunction
UTSuite "[tester] /prog/prog.ext -> /prog/test/prog_test.ext"
function! s:TestConvertingBothPathAndFilename()
let fullname = "/some/program/program.py"
echo "> ". <SNR>47_ConvertFullFilename2FullTestFilename(fullname)
Assert <SNR>47_ConvertFullFilename2FullTestFilename(fullname) == "/some/program/test/program_test.py"
endfunction
" -----------------------------------------------------------------------------
UTSuite "[tester] HasWordTest"
function! s:TestReturn_1_IfHasWordTest()
let with_test = 'somecode_test.vim'
Assert <SNR>47_HasWordTest(with_test) == 1
endfunction
function! s:TestReturn_0_IfDoNotHaveWordTest()
let without_test = 'somecode.vim'
Assert <SNR>47_HasWordTest(without_test) == 0
endfunction
function! s:TestHavingAWordTestIgnoringCase()
let with_test_ic = 'somecode_tEsT.vim'
Assert <SNR>47_HasWordTest(with_test_ic) == 1
endfunction
function! s:TestIsTestFile()
let with_test = 'somecode_test.vim'
Assert <SNR>47_IsTestFile(with_test) == 1
endfunction
UTSuite "[tester] IsTestCase"
function! s:TestsIfClassLineIsInString()
let str = "class TestCase(unittest.TestCase):"
Assert <SNR>47_IsTestCaseClassLine(str) == 1
endfunction
function! s:TestsIfSpacedClassLineIsInString()
let str = " class TestCase(unittest.TestCase):"
Assert <SNR>47_IsTestCaseClassLine(str) == 1
endfunction
function! s:TestsIfTabbedClassLineIsInString()
let str = " class TestCase(unittest.TestCase):"
Assert <SNR>47_IsTestCaseClassLine(str) == 1
endfunction
" XXX
"function! s:TestSubclassOfTestCase()
" let str = " class TestCase(SomeOtherSubClassOfTestCase):"
" Assert <SNR>47_IsTestCaseClass(str) == 1
"endfunction
UTSuite "[tester] IsSingleTestMethod"
function! s:TestMethodStartingWith_test()
let str = " def testSomething(self):"
Assert <SNR>47_IsSingleTestMethodLine(str) == 1
endfunction
function! s:TestNeeds_self()
let str = " def testSomething():"
Assert <SNR>47_IsSingleTestMethodLine(str) == 0
endfunction
function! s:TestCodeStartsWithComment()
let str = "# def testSomething(self):"
Assert <SNR>47_IsSingleTestMethodLine(str) == 0
endfunction
" XXX
"function! s:TestMethodThatDoesNotStartWith_test()
" let str = " def another_test_prefix_MethodName():"
" Assert <SNR>47_IsSingleTestMethod(str) == 1
"endfunction