robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.1.1913: Error message with :unlet! and non-existing dictionary item (#36549)16e9c21d8d

master
1.7 KiB79 linesraw
1" Tests for :unlet
2
3func Test_read_only()
4  " these caused a crash
5  call assert_fails('unlet v:count', 'E795:')
6  call assert_fails('unlet v: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
67func Test_unlet_nonexisting_key()
68  let g:base = {}
69  call assert_fails(':unlet g:base["foobar"]', 'E716:')
70
71  try
72    unlet! g:base["foobar"]
73  catch
74    call assert_report("error when unletting non-existing dict key")
75  endtry
76  unlet g:base
77endfunc
78
79" vim: shiftwidth=2 sts=2 expandtab