2016-05-19 15:05:37 -07:00
|
|
|
" Tests for :unlet
|
|
|
|
|
|
|
|
func Test_read_only()
|
2022-10-25 22:40:04 -07:00
|
|
|
" these caused a crash
|
|
|
|
call assert_fails('unlet v:count', 'E795:')
|
|
|
|
call assert_fails('unlet v:errmsg', 'E795:')
|
2016-05-19 15:05:37 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_existing()
|
|
|
|
let does_exist = 1
|
|
|
|
call assert_true(exists('does_exist'))
|
|
|
|
unlet does_exist
|
|
|
|
call assert_false(exists('does_exist'))
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_not_existing()
|
|
|
|
unlet! does_not_exist
|
2022-10-25 22:40:04 -07:00
|
|
|
call assert_fails('unlet does_not_exist', 'E108:')
|
2016-05-19 15:05:37 -07:00
|
|
|
endfunc
|
2018-03-17 01:49:06 -07:00
|
|
|
|
|
|
|
func Test_unlet_fails()
|
|
|
|
call assert_fails('unlet v:["count"]', 'E46:')
|
2022-10-25 22:05:33 -07:00
|
|
|
call assert_fails('unlet $', 'E475:')
|
2022-10-25 22:41:43 -07:00
|
|
|
let v = {}
|
|
|
|
call assert_fails('unlet v[:]', 'E719:')
|
|
|
|
let l = []
|
|
|
|
call assert_fails("unlet l['k'", 'E111:')
|
|
|
|
let d = {'k' : 1}
|
|
|
|
call assert_fails("unlet d.k2", 'E716:')
|
2022-10-26 04:53:54 -07:00
|
|
|
call assert_fails("unlet {a};", 'E488:')
|
2018-03-17 01:49:06 -07:00
|
|
|
endfunc
|
2018-10-01 19:57:49 -07:00
|
|
|
|
|
|
|
func Test_unlet_env()
|
|
|
|
let envcmd = has('win32') ? 'set' : 'env'
|
|
|
|
|
|
|
|
let $FOOBAR = 'test'
|
|
|
|
let found = 0
|
|
|
|
for kv in split(system(envcmd), "\r*\n")
|
|
|
|
if kv == 'FOOBAR=test'
|
|
|
|
let found = 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
call assert_equal(1, found)
|
|
|
|
|
|
|
|
unlet $FOOBAR
|
|
|
|
let found = 0
|
|
|
|
for kv in split(system(envcmd), "\r*\n")
|
|
|
|
if kv == 'FOOBAR=test'
|
|
|
|
let found = 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
call assert_equal(0, found)
|
|
|
|
|
|
|
|
unlet $MUST_NOT_BE_AN_ERROR
|
|
|
|
endfunc
|
2018-10-02 19:10:47 -07:00
|
|
|
|
|
|
|
func Test_unlet_complete()
|
|
|
|
let g:FOOBAR = 1
|
|
|
|
call feedkeys(":unlet g:FOO\t\n", 'tx')
|
|
|
|
call assert_true(!exists('g:FOOBAR'))
|
|
|
|
|
|
|
|
let $FOOBAR = 1
|
|
|
|
call feedkeys(":unlet $FOO\t\n", 'tx')
|
|
|
|
call assert_true(!exists('$FOOBAR') || empty($FOOBAR))
|
|
|
|
endfunc
|
2022-10-25 22:05:33 -07:00
|
|
|
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|