1" Test that the methods used for testing work. 2 3func Test_assert_false() 4 call assert_false(0) 5 call assert_false(v:false) 6endfunc 7 8func Test_assert_true() 9 call assert_true(1) 10 call assert_true(123) 11 call assert_true(v:true) 12endfunc 13 14func Test_assert_equal() 15 let s = 'foo' 16 call assert_equal('foo', s) 17 let n = 4 18 call assert_equal(4, n) 19 let l = [1, 2, 3] 20 call assert_equal([1, 2, 3], l) 21 22 let s = 'foo' 23 call assert_equal('bar', s) 24 call assert_match("Expected 'bar' but got 'foo'", v:errors[0]) 25 call remove(v:errors, 0) 26endfunc 27 28func Test_assert_notequal() 29 let n = 4 30 call assert_notequal('foo', n) 31 let s = 'foo' 32 call assert_notequal([1, 2, 3], s) 33 34 call assert_notequal('foo', s) 35 call assert_match("Expected 'foo' differs from 'foo'", v:errors[0]) 36 call remove(v:errors, 0) 37endfunc 38 39func Test_assert_exception() 40 try 41 nocommand 42 catch 43 call assert_exception('E492:') 44 endtry 45 46 try 47 nocommand 48 catch 49 try 50 " illegal argument, get NULL for error 51 call assert_exception([]) 52 catch 53 call assert_exception('E730:') 54 endtry 55 endtry 56endfunc 57 58func Test_wrong_error_type() 59 let save_verrors = v:errors 60 let v:['errors'] = {'foo': 3} 61 call assert_equal('yes', 'no') 62 let verrors = v:errors 63 let v:errors = save_verrors 64 call assert_equal(type([]), type(verrors)) 65endfunc 66 67func Test_compare_fail() 68 let s:v = {} 69 let s:x = {"a": s:v} 70 let s:v["b"] = s:x 71 let s:w = {"c": s:x, "d": ''} 72 try 73 call assert_equal(s:w, '') 74 catch 75 call assert_exception('E724:') 76 call assert_match("Expected NULL but got ''", v:errors[0]) 77 call remove(v:errors, 0) 78 endtry 79endfunc 80 81func Test_match() 82 call assert_match('^f.*b.*r$', 'foobar') 83 84 call assert_match('bar.*foo', 'foobar') 85 call assert_match("Pattern 'bar.*foo' does not match 'foobar'", v:errors[0]) 86 call remove(v:errors, 0) 87 88 call assert_match('bar.*foo', 'foobar', 'wrong') 89 call assert_match('wrong', v:errors[0]) 90 call remove(v:errors, 0) 91endfunc 92 93func Test_notmatch() 94 call assert_notmatch('foo', 'bar') 95 call assert_notmatch('^foobar$', 'foobars') 96 97 call assert_notmatch('foo', 'foobar') 98 call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0]) 99 call remove(v:errors, 0) 100endfunc 101 102func Test_assert_fail_fails() 103 call assert_fails('xxx', {}) 104 call assert_match("Expected {} but got 'E731:", v:errors[0]) 105 call remove(v:errors, 0) 106endfunc 107 108func Test_assert_inrange() 109 call assert_inrange(7, 7, 7) 110 call assert_inrange(5, 7, 5) 111 call assert_inrange(5, 7, 6) 112 call assert_inrange(5, 7, 7) 113 114 call assert_inrange(5, 7, 4) 115 call assert_match("Expected range 5 - 7, but got 4", v:errors[0]) 116 call remove(v:errors, 0) 117 call assert_inrange(5, 7, 8) 118 call assert_match("Expected range 5 - 7, but got 8", v:errors[0]) 119 call remove(v:errors, 0) 120 121 call assert_fails('call assert_inrange(1, 1)', 'E119:') 122endfunc 123 124func Test_user_is_happy() 125 smile 126 sleep 300m 127endfunc 128