blob: 0a9f3c61b10ddc34e987e0bec17711f7a8248640 [file] [log] [blame]
Bram Moolenaaraf8af8b2016-01-04 22:05:24 +01001" Tests for :unlet
2
3func Test_read_only()
Bram Moolenaar065ee9a2016-01-15 20:53:38 +01004 " these caused a crash
5 call assert_fails('unlet count', 'E795:')
6 call assert_fails('unlet errmsg', 'E795:')
Bram Moolenaaraf8af8b2016-01-04 22:05:24 +01007endfunc
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
Bram Moolenaar065ee9a2016-01-15 20:53:38 +010018 call assert_fails('unlet does_not_exist', 'E108:')
Bram Moolenaaraf8af8b2016-01-04 22:05:24 +010019endfunc
Bram Moolenaar49439c42017-02-20 23:07:05 +010020
21func Test_unlet_fails()
22 call assert_fails('unlet v:["count"]', 'E46:')
23endfunc
Bram Moolenaar137374f2018-05-13 15:59:50 +020024
25func Test_unlet_env()
26 let envcmd = has('win32') ? 'set' : 'env'
27
28 let $FOOBAR = 'test'
29 let found = 0
30 for kv in split(system(envcmd), "\r*\n")
31 if kv == 'FOOBAR=test'
32 let found = 1
33 endif
34 endfor
35 call assert_equal(1, found)
36
37 unlet $FOOBAR
38 let found = 0
39 for kv in split(system(envcmd), "\r*\n")
40 if kv == 'FOOBAR=test'
41 let found = 1
42 endif
43 endfor
44 call assert_equal(0, found)
45
46 unlet $MUST_NOT_BE_AN_ERROR
47endfunc
Bram Moolenaar19834012018-06-12 17:03:39 +020048
49func Test_unlet_complete()
50 let g:FOOBAR = 1
51 call feedkeys(":unlet g:FOO\t\n", 'tx')
52 call assert_true(!exists('g:FOOBAR'))
53
54 let $FOOBAR = 1
55 call feedkeys(":unlet $FOO\t\n", 'tx')
56 call assert_true(!exists('$FOOBAR') || empty($FOOBAR))
57endfunc