xref: /vim-8.2.3635/src/testdir/test_unlet.vim (revision ea04a6e8)
1" Tests for :unlet
2
3func Test_read_only()
4  " these caused a crash
5  call assert_fails('unlet count', 'E795:')
6  call assert_fails('unlet errmsg', 'E795:')
7endfunc
8
9func 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'))
14endfunc
15
16func Test_not_existing()
17  unlet! does_not_exist
18  call assert_fails('unlet does_not_exist', 'E108:')
19endfunc
20
21func 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:')
31endfunc
32
33func 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
55endfunc
56
57func 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))
65endfunc
66
67" vim: shiftwidth=2 sts=2 expandtab
68