comparison src/testdir/test_assert.vim @ 17728:68ea27d26d5b v8.1.1861

patch 8.1.1861: only some assert functions can be used as a method commit https://github.com/vim/vim/commit/24278d2407dfbc8d93eb36593cdd006ff5d86f94 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 16 21:49:22 2019 +0200 patch 8.1.1861: only some assert functions can be used as a method Problem: Only some assert functions can be used as a method. Solution: Allow using most assert functions as a method.
author Bram Moolenaar <Bram@vim.org>
date Fri, 16 Aug 2019 22:00:04 +0200
parents ccd21c8f916b
children ce993ba17adb
comparison
equal deleted inserted replaced
17727:145b465ffd33 17728:68ea27d26d5b
1 " Test that the methods used for testing work. 1 " Test that the methods used for testing work.
2 2
3 func Test_assert_false() 3 func Test_assert_false()
4 call assert_equal(0, assert_false(0)) 4 call assert_equal(0, assert_false(0))
5 call assert_equal(0, assert_false(v:false)) 5 call assert_equal(0, assert_false(v:false))
6 call assert_equal(0, v:false->assert_false())
6 7
7 call assert_equal(1, assert_false(123)) 8 call assert_equal(1, assert_false(123))
9 call assert_match("Expected False but got 123", v:errors[0])
10 call remove(v:errors, 0)
11
12 call assert_equal(1, 123->assert_false())
8 call assert_match("Expected False but got 123", v:errors[0]) 13 call assert_match("Expected False but got 123", v:errors[0])
9 call remove(v:errors, 0) 14 call remove(v:errors, 0)
10 endfunc 15 endfunc
11 16
12 func Test_assert_true() 17 func Test_assert_true()
13 call assert_equal(0, assert_true(1)) 18 call assert_equal(0, assert_true(1))
14 call assert_equal(0, assert_true(123)) 19 call assert_equal(0, assert_true(123))
15 call assert_equal(0, assert_true(v:true)) 20 call assert_equal(0, assert_true(v:true))
21 call assert_equal(0, v:true->assert_true())
16 22
17 call assert_equal(1, assert_true(0)) 23 call assert_equal(1, assert_true(0))
24 call assert_match("Expected True but got 0", v:errors[0])
25 call remove(v:errors, 0)
26
27 call assert_equal(1, 0->assert_true())
18 call assert_match("Expected True but got 0", v:errors[0]) 28 call assert_match("Expected True but got 0", v:errors[0])
19 call remove(v:errors, 0) 29 call remove(v:errors, 0)
20 endfunc 30 endfunc
21 31
22 func Test_assert_equal() 32 func Test_assert_equal()
139 call remove(v:errors, 0) 149 call remove(v:errors, 0)
140 150
141 call assert_equal(1, assert_match('bar.*foo', 'foobar', 'wrong')) 151 call assert_equal(1, assert_match('bar.*foo', 'foobar', 'wrong'))
142 call assert_match('wrong', v:errors[0]) 152 call assert_match('wrong', v:errors[0])
143 call remove(v:errors, 0) 153 call remove(v:errors, 0)
154
155 call assert_equal(1, 'foobar'->assert_match('bar.*foo', 'wrong'))
156 call assert_match('wrong', v:errors[0])
157 call remove(v:errors, 0)
144 endfunc 158 endfunc
145 159
146 func Test_notmatch() 160 func Test_notmatch()
147 call assert_equal(0, assert_notmatch('foo', 'bar')) 161 call assert_equal(0, assert_notmatch('foo', 'bar'))
148 call assert_equal(0, assert_notmatch('^foobar$', 'foobars')) 162 call assert_equal(0, assert_notmatch('^foobar$', 'foobars'))
149 163
150 call assert_equal(1, assert_notmatch('foo', 'foobar')) 164 call assert_equal(1, assert_notmatch('foo', 'foobar'))
151 call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0]) 165 call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0])
152 call remove(v:errors, 0) 166 call remove(v:errors, 0)
167
168 call assert_equal(1, 'foobar'->assert_notmatch('foo'))
169 call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0])
170 call remove(v:errors, 0)
153 endfunc 171 endfunc
154 172
155 func Test_assert_fail_fails() 173 func Test_assert_fail_fails()
156 call assert_equal(1, assert_fails('xxx', {})) 174 call assert_equal(1, assert_fails('xxx', {}))
157 call assert_match("Expected {} but got 'E731:", v:errors[0]) 175 call assert_match("Expected {} but got 'E731:", v:errors[0])
162 call remove(v:errors, 0) 180 call remove(v:errors, 0)
163 181
164 call assert_equal(1, assert_fails('echo', '', 'echo command')) 182 call assert_equal(1, assert_fails('echo', '', 'echo command'))
165 call assert_match("command did not fail: echo command", v:errors[0]) 183 call assert_match("command did not fail: echo command", v:errors[0])
166 call remove(v:errors, 0) 184 call remove(v:errors, 0)
185
186 call assert_equal(1, 'echo'->assert_fails('', 'echo command'))
187 call assert_match("command did not fail: echo command", v:errors[0])
188 call remove(v:errors, 0)
167 endfunc 189 endfunc
168 190
169 func Test_assert_fails_in_try_block() 191 func Test_assert_fails_in_try_block()
170 try 192 try
171 call assert_equal(0, assert_fails('throw "error"')) 193 call assert_equal(0, assert_fails('throw "error"'))
177 call assert_equal(0, assert_beeps('normal h')) 199 call assert_equal(0, assert_beeps('normal h'))
178 200
179 call assert_equal(1, assert_beeps('normal 0')) 201 call assert_equal(1, assert_beeps('normal 0'))
180 call assert_match("command did not beep: normal 0", v:errors[0]) 202 call assert_match("command did not beep: normal 0", v:errors[0])
181 call remove(v:errors, 0) 203 call remove(v:errors, 0)
204
205 call assert_equal(0, 'normal h'->assert_beeps())
206 call assert_equal(1, 'normal 0'->assert_beeps())
207 call assert_match("command did not beep: normal 0", v:errors[0])
208 call remove(v:errors, 0)
209
182 bwipe 210 bwipe
183 endfunc 211 endfunc
184 212
185 func Test_assert_inrange() 213 func Test_assert_inrange()
186 call assert_equal(0, assert_inrange(7, 7, 7)) 214 call assert_equal(0, assert_inrange(7, 7, 7))
190 218
191 call assert_equal(1, assert_inrange(5, 7, 4)) 219 call assert_equal(1, assert_inrange(5, 7, 4))
192 call assert_match("Expected range 5 - 7, but got 4", v:errors[0]) 220 call assert_match("Expected range 5 - 7, but got 4", v:errors[0])
193 call remove(v:errors, 0) 221 call remove(v:errors, 0)
194 call assert_equal(1, assert_inrange(5, 7, 8)) 222 call assert_equal(1, assert_inrange(5, 7, 8))
223 call assert_match("Expected range 5 - 7, but got 8", v:errors[0])
224 call remove(v:errors, 0)
225
226 call assert_equal(0, 5->assert_inrange(5, 7))
227 call assert_equal(0, 7->assert_inrange(5, 7))
228 call assert_equal(1, 8->assert_inrange(5, 7))
195 call assert_match("Expected range 5 - 7, but got 8", v:errors[0]) 229 call assert_match("Expected range 5 - 7, but got 8", v:errors[0])
196 call remove(v:errors, 0) 230 call remove(v:errors, 0)
197 231
198 call assert_fails('call assert_inrange(1, 1)', 'E119:') 232 call assert_fails('call assert_inrange(1, 1)', 'E119:')
199 233