test_unlet.vim (1774B)
1 " Tests for :unlet 2 3 func Test_read_only() 4 " these caused a crash 5 call assert_fails('unlet v:count', 'E795:') 6 call assert_fails('unlet v:errmsg', 'E795:') 7 endfunc 8 9 func Test_existing() 10 let does_exist = 1 11 call assert_true(exists('does_exist')) 12 unlet does_exist 13 call assert_false(exists('does_exist')) 14 endfunc 15 16 func Test_not_existing() 17 unlet! does_not_exist 18 call assert_fails('unlet does_not_exist', 'E108:') 19 endfunc 20 21 func Test_unlet_fails() 22 call assert_fails('unlet v:["count"]', 'E46:') 23 call assert_fails('unlet $', 'E475:') 24 let v = {} 25 call assert_fails('unlet v[:]', 'E719:') 26 let l = [] 27 call assert_fails("unlet l['k'", 'E111:') 28 let d = {'k' : 1} 29 call assert_fails("unlet d.k2", 'E716:') 30 call assert_fails("unlet {a};", 'E488:') 31 endfunc 32 33 func Test_unlet_env() 34 let envcmd = has('win32') ? 'set' : 'env' 35 36 let $FOOBAR = 'test' 37 let found = 0 38 for kv in split(system(envcmd), "\r*\n") 39 if kv == 'FOOBAR=test' 40 let found = 1 41 endif 42 endfor 43 call assert_equal(1, found) 44 45 unlet $FOOBAR 46 let found = 0 47 for kv in split(system(envcmd), "\r*\n") 48 if kv == 'FOOBAR=test' 49 let found = 1 50 endif 51 endfor 52 call assert_equal(0, found) 53 54 unlet $MUST_NOT_BE_AN_ERROR 55 endfunc 56 57 func Test_unlet_complete() 58 let g:FOOBAR = 1 59 call feedkeys(":unlet g:FOO\t\n", 'tx') 60 call assert_true(!exists('g:FOOBAR')) 61 62 let $FOOBAR = 1 63 call feedkeys(":unlet $FOO\t\n", 'tx') 64 call assert_true(!exists('$FOOBAR') || empty($FOOBAR)) 65 endfunc 66 67 func Test_unlet_nonexisting_key() 68 let g:base = {} 69 call assert_fails(':unlet g:base["foobar"]', 'E716:') 70 71 try 72 unlet! g:base["foobar"] 73 catch 74 call assert_report("error when unletting non-existing dict key") 75 endtry 76 unlet g:base 77 endfunc 78 79 " vim: shiftwidth=2 sts=2 expandtab