xref: /vim-8.2.3635/src/testdir/test_unlet.vim (revision 81ea1dfb)
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:')
30endfunc
31
32func Test_unlet_env()
33  let envcmd = has('win32') ? 'set' : 'env'
34
35  let $FOOBAR = 'test'
36  let found = 0
37  for kv in split(system(envcmd), "\r*\n")
38    if kv == 'FOOBAR=test'
39      let found = 1
40    endif
41  endfor
42  call assert_equal(1, found)
43
44  unlet $FOOBAR
45  let found = 0
46  for kv in split(system(envcmd), "\r*\n")
47    if kv == 'FOOBAR=test'
48      let found = 1
49    endif
50  endfor
51  call assert_equal(0, found)
52
53  unlet $MUST_NOT_BE_AN_ERROR
54endfunc
55
56func Test_unlet_complete()
57  let g:FOOBAR = 1
58  call feedkeys(":unlet g:FOO\t\n", 'tx')
59  call assert_true(!exists('g:FOOBAR'))
60
61  let $FOOBAR = 1
62  call feedkeys(":unlet $FOO\t\n", 'tx')
63  call assert_true(!exists('$FOOBAR') || empty($FOOBAR))
64endfunc
65
66" vim: shiftwidth=2 sts=2 expandtab
67