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