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 not equal to 'foo'", v:errors[0]) 36 call remove(v:errors, 0) 37endfunc 38 39func Test_assert_report() 40 call assert_report('something is wrong') 41 call assert_match('something is wrong', v:errors[0]) 42 call remove(v:errors, 0) 43endfunc 44 45func Test_assert_exception() 46 try 47 nocommand 48 catch 49 call assert_exception('E492:') 50 endtry 51 52 try 53 nocommand 54 catch 55 try 56 " illegal argument, get NULL for error 57 call assert_exception([]) 58 catch 59 call assert_exception('E730:') 60 endtry 61 endtry 62endfunc 63 64func Test_wrong_error_type() 65 let save_verrors = v:errors 66 let v:['errors'] = {'foo': 3} 67 call assert_equal('yes', 'no') 68 let verrors = v:errors 69 let v:errors = save_verrors 70 call assert_equal(type([]), type(verrors)) 71endfunc 72 73func Test_compare_fail() 74 let s:v = {} 75 let s:x = {"a": s:v} 76 let s:v["b"] = s:x 77 let s:w = {"c": s:x, "d": ''} 78 try 79 call assert_equal(s:w, '') 80 catch 81 call assert_exception('E724:') 82 call assert_match("Expected NULL but got ''", v:errors[0]) 83 call remove(v:errors, 0) 84 endtry 85endfunc 86 87func Test_match() 88 call assert_match('^f.*b.*r$', 'foobar') 89 90 call assert_match('bar.*foo', 'foobar') 91 call assert_match("Pattern 'bar.*foo' does not match 'foobar'", v:errors[0]) 92 call remove(v:errors, 0) 93 94 call assert_match('bar.*foo', 'foobar', 'wrong') 95 call assert_match('wrong', v:errors[0]) 96 call remove(v:errors, 0) 97endfunc 98 99func Test_notmatch() 100 call assert_notmatch('foo', 'bar') 101 call assert_notmatch('^foobar$', 'foobars') 102 103 call assert_notmatch('foo', 'foobar') 104 call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0]) 105 call remove(v:errors, 0) 106endfunc 107 108func Test_assert_fail_fails() 109 call assert_fails('xxx', {}) 110 call assert_match("Expected {} but got 'E731:", v:errors[0]) 111 call remove(v:errors, 0) 112endfunc 113 114func Test_assert_inrange() 115 call assert_inrange(7, 7, 7) 116 call assert_inrange(5, 7, 5) 117 call assert_inrange(5, 7, 6) 118 call assert_inrange(5, 7, 7) 119 120 call assert_inrange(5, 7, 4) 121 call assert_match("Expected range 5 - 7, but got 4", v:errors[0]) 122 call remove(v:errors, 0) 123 call assert_inrange(5, 7, 8) 124 call assert_match("Expected range 5 - 7, but got 8", v:errors[0]) 125 call remove(v:errors, 0) 126 127 call assert_fails('call assert_inrange(1, 1)', 'E119:') 128endfunc 129 130func Test_assert_with_msg() 131 call assert_equal('foo', 'bar', 'testing') 132 call assert_match("testing: Expected 'foo' but got 'bar'", v:errors[0]) 133 call remove(v:errors, 0) 134endfunc 135 136func Test_override() 137 call test_override('char_avail', 1) 138 call test_override('redraw', 1) 139 call test_override('ALL', 0) 140 call assert_fails("call test_override('xxx', 1)", 'E475') 141 call assert_fails("call test_override('redraw', 'yes')", 'E474') 142endfunc 143 144func Test_user_is_happy() 145 smile 146 sleep 300m 147endfunc 148