1" Tests for expressions. 2 3func Test_equal() 4 let base = {} 5 func base.method() 6 return 1 7 endfunc 8 func base.other() dict 9 return 1 10 endfunc 11 let instance = copy(base) 12 call assert_true(base.method == instance.method) 13 call assert_true([base.method] == [instance.method]) 14 call assert_true(base.other == instance.other) 15 call assert_true([base.other] == [instance.other]) 16 17 call assert_false(base.method == base.other) 18 call assert_false([base.method] == [base.other]) 19 call assert_false(base.method == instance.other) 20 call assert_false([base.method] == [instance.other]) 21 22 call assert_fails('echo base.method > instance.method') 23endfunc 24 25func Test_version() 26 call assert_true(has('patch-7.4.001')) 27 call assert_true(has('patch-7.4.01')) 28 call assert_true(has('patch-7.4.1')) 29 call assert_true(has('patch-6.9.999')) 30 call assert_true(has('patch-7.1.999')) 31 call assert_true(has('patch-7.4.123')) 32 33 call assert_false(has('patch-7')) 34 call assert_false(has('patch-7.4')) 35 call assert_false(has('patch-7.4.')) 36 call assert_false(has('patch-9.1.0')) 37 call assert_false(has('patch-9.9.1')) 38endfunc 39 40func Test_dict() 41 let d = {'': 'empty', 'a': 'a', 0: 'zero'} 42 call assert_equal('empty', d['']) 43 call assert_equal('a', d['a']) 44 call assert_equal('zero', d[0]) 45 call assert_true(has_key(d, '')) 46 call assert_true(has_key(d, 'a')) 47 48 let d[''] = 'none' 49 let d['a'] = 'aaa' 50 call assert_equal('none', d['']) 51 call assert_equal('aaa', d['a']) 52endfunc 53 54func Test_strgetchar() 55 call assert_equal(char2nr('a'), strgetchar('axb', 0)) 56 call assert_equal(char2nr('x'), strgetchar('axb', 1)) 57 call assert_equal(char2nr('b'), strgetchar('axb', 2)) 58 59 call assert_equal(-1, strgetchar('axb', -1)) 60 call assert_equal(-1, strgetchar('axb', 3)) 61 call assert_equal(-1, strgetchar('', 0)) 62endfunc 63 64func Test_strcharpart() 65 call assert_equal('a', strcharpart('axb', 0, 1)) 66 call assert_equal('x', strcharpart('axb', 1, 1)) 67 call assert_equal('b', strcharpart('axb', 2, 1)) 68 call assert_equal('xb', strcharpart('axb', 1)) 69 70 call assert_equal('', strcharpart('axb', 1, 0)) 71 call assert_equal('', strcharpart('axb', 1, -1)) 72 call assert_equal('', strcharpart('axb', -1, 1)) 73 call assert_equal('', strcharpart('axb', -2, 2)) 74 75 call assert_equal('a', strcharpart('axb', -1, 2)) 76endfunc 77 78func Test_getreg_empty_list() 79 call assert_equal('', getreg('x')) 80 call assert_equal([], getreg('x', 1, 1)) 81 let x = getreg('x', 1, 1) 82 let y = x 83 call add(x, 'foo') 84 call assert_equal(['foo'], y) 85endfunc 86 87func Test_loop_over_null_list() 88 let null_list = test_null_list() 89 for i in null_list 90 call assert_true(0, 'should not get here') 91 endfor 92endfunc 93 94func Test_compare_null_dict() 95 call assert_fails('let x = test_null_dict()[10]') 96 call assert_equal({}, {}) 97 call assert_equal(test_null_dict(), test_null_dict()) 98 call assert_notequal({}, test_null_dict()) 99endfunc 100 101func Test_set_reg_null_list() 102 call setreg('x', test_null_list()) 103endfunc 104 105func Test_special_char() 106 " The failure is only visible using valgrind. 107 call assert_fails('echo "\<C-">') 108endfunc 109 110func Test_option_value() 111 " boolean 112 set bri 113 call assert_equal(1, &bri) 114 set nobri 115 call assert_equal(0, &bri) 116 117 " number 118 set ts=1 119 call assert_equal(1, &ts) 120 set ts=8 121 call assert_equal(8, &ts) 122 123 " string 124 exe "set cedit=\<Esc>" 125 call assert_equal("\<Esc>", &cedit) 126 set cpo= 127 call assert_equal("", &cpo) 128 set cpo=abcdefgi 129 call assert_equal("abcdefgi", &cpo) 130 set cpo&vim 131endfunc 132 133function Test_printf_64bit() 134 if has('num64') 135 call assert_equal("123456789012345", printf('%d', 123456789012345)) 136 endif 137endfunc 138