blob: 81c20dffaaa4d6ae1a3893f7190ff93af188e8b0 [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:')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +010023 call assert_fails('unlet $', 'E475:')
Bram Moolenaar49439c42017-02-20 23:07:05 +010024endfunc
Bram Moolenaar137374f2018-05-13 15:59:50 +020025
26func Test_unlet_env()
27 let envcmd = has('win32') ? 'set' : 'env'
28
29 let $FOOBAR = 'test'
30 let found = 0
31 for kv in split(system(envcmd), "\r*\n")
32 if kv == 'FOOBAR=test'
33 let found = 1
34 endif
35 endfor
36 call assert_equal(1, found)
37
38 unlet $FOOBAR
39 let found = 0
40 for kv in split(system(envcmd), "\r*\n")
41 if kv == 'FOOBAR=test'
42 let found = 1
43 endif
44 endfor
45 call assert_equal(0, found)
46
47 unlet $MUST_NOT_BE_AN_ERROR
48endfunc
Bram Moolenaar19834012018-06-12 17:03:39 +020049
50func Test_unlet_complete()
51 let g:FOOBAR = 1
52 call feedkeys(":unlet g:FOO\t\n", 'tx')
53 call assert_true(!exists('g:FOOBAR'))
54
55 let $FOOBAR = 1
56 call feedkeys(":unlet $FOO\t\n", 'tx')
57 call assert_true(!exists('$FOOBAR') || empty($FOOBAR))
58endfunc
Bram Moolenaar8dfcce32020-03-18 19:32:26 +010059
60" vim: shiftwidth=2 sts=2 expandtab