From 3734052a76e8d5e9695b28ac83ecd9535fdf50e2 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Wed, 10 Feb 2016 13:34:52 +0100 Subject: tests: Migrate legacy test 55. --- test/functional/legacy/055_spec.lua | 813 ++++++++++++++++++++++++++++++++++++ 1 file changed, 813 insertions(+) create mode 100644 test/functional/legacy/055_spec.lua (limited to 'test') diff --git a/test/functional/legacy/055_spec.lua b/test/functional/legacy/055_spec.lua new file mode 100644 index 0000000000..194da288fc --- /dev/null +++ b/test/functional/legacy/055_spec.lua @@ -0,0 +1,813 @@ +-- Tests for List and Dictionary types. + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe('55', function() + setup(clear) + + it('is working', function() + insert([[ + start:]]) + + execute('fun Test(...)') + execute('lang C') + -- Creating List directly with different types. + execute([=[let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]]=]) + execute('$put =string(l)') + execute('$put =string(l[-1])') + execute('$put =string(l[-4])') + execute('try') + execute(' $put =string(l[-5])') + execute('catch') + execute(' $put =v:exception[:14]') + execute('endtry') + -- List slices. + execute('$put =string(l[:])') + execute('$put =string(l[1:])') + execute('$put =string(l[:-2])') + execute('$put =string(l[0:8])') + execute('$put =string(l[8:-1])') + + -- List identity. + execute('let ll = l') + execute('let lx = copy(l)') + execute('try') + execute(' $put =(l == ll) . (l isnot ll) . (l is ll) . (l == lx) . (l is lx) . (l isnot lx)') + execute('catch') + execute(' $put =v:exception') + execute('endtry') + + -- Creating Dictionary directly with different types. + execute([=[let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}]=]) + execute('$put =string(d) . d.1') + execute('$put =string(sort(keys(d)))') + execute('$put =string (values(d))') + execute('for [key, val] in items(d)') + execute([[ $put =key . ':' . string(val)]]) + execute(' unlet key val') + execute('endfor') + execute('call extend (d, {3:33, 1:99})') + execute([[call extend(d, {'b':'bbb', 'c':'ccc'}, "keep")]]) + execute('try') + execute(' call extend(d, {3:333,4:444}, "error")') + execute('catch') + execute(' $put =v:exception[:15] . v:exception[-1:-1]') + execute('endtry') + execute('$put =string(d)') + execute([=[call filter(d, 'v:key =~ ''[ac391]''')]=]) + execute('$put =string(d)') + + -- Dictionary identity. + execute('let dd = d') + execute('let dx = copy(d)') + execute('try') + execute(' $put =(d == dd) . (d isnot dd) . (d is dd) . (d == dx) . (d is dx) . (d isnot dx)') + execute('catch') + execute(' $put =v:exception') + execute('endtry') + + -- Changing var type should fail. + execute('try') + execute(' let d = []') + execute('catch') + execute(' $put =v:exception[:14] . v:exception[-1:-1]') + execute('endtry') + execute('try') + execute(' let l = {}') + execute('catch') + execute(' $put =v:exception[:14] . v:exception[-1:-1]') + execute('endtry') + + -- Removing items with :unlet. + execute('unlet l[2]') + execute('$put =string(l)') + execute('let l = range(8)') + execute('try') + execute('unlet l[:3]') + execute('unlet l[1:]') + execute('catch') + execute('$put =v:exception') + execute('endtry') + execute('$put =string(l)') + + execute('unlet d.c') + execute('unlet d[-1]') + execute('$put =string(d)') + + -- Removing items out of range: silently skip items that don't exist. + feed('let l = [0, 1, 2, 3]') + execute('unlet l[2:1]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[2:2]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[2:3]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[2:4]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[2:5]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[-1:2]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[-2:2]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[-3:2]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[-4:2]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[-5:2]') + execute('$put =string(l)') + feed('let l = [0, 1, 2, 3]') + execute('unlet l[-6:2]') + execute('$put =string(l)') + + -- Assignment to a list. + execute('let l = [0, 1, 2, 3]') + execute('let [va, vb] = l[2:3]') + execute('$put =va') + execute('$put =vb') + execute('try') + execute(' let [va, vb] = l') + execute('catch') + execute(' $put =v:exception[:14]') + execute('endtry') + execute('try') + execute(' let [va, vb] = l[1:1]') + execute('catch') + execute(' $put =v:exception[:14]') + execute('endtry') + + -- Manipulating a big Dictionary (hashtable.c has a border of 1000 entries). + execute('let d = {}') + execute('for i in range(1500)') + execute(' let d[i] = 3000 - i') + execute('endfor') + execute([=[$put =d[0] . ' ' . d[100] . ' ' . d[999] . ' ' . d[1400] . ' ' . d[1499]]=]) + execute('try') + execute(' let n = d[1500]') + execute('catch') + execute([[ $put =substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '')]]) + execute('endtry') + -- Lookup each items. + execute('for i in range(1500)') + execute(' if d[i] != 3000 - i') + execute(' $put =d[i]') + execute(' endif') + execute('endfor') + execute(' let i += 1') + -- Delete even items. + execute('while i >= 2') + execute(' let i -= 2') + execute(' unlet d[i]') + execute('endwhile') + execute([=[$put =get(d, 1500 - 100, 'NONE') . ' ' . d[1]]=]) + -- Delete odd items, checking value, one intentionally wrong. + execute('let d[33] = 999') + execute('let i = 1') + execute('while i < 1500') + execute(' if d[i] != 3000 - i') + execute([=[ $put =i . '=' . d[i]]=]) + execute(' else') + execute(' unlet d[i]') + execute(' endif') + execute(' let i += 2') + execute('endwhile') + -- Must be almost empty now. + execute('$put =string(d)') + execute('unlet d') + + -- Dictionary function. + execute('let dict = {}') + execute('func dict.func(a) dict') + execute(' $put =a:a . len(self.data)') + execute('endfunc') + execute('let dict.data = [1,2,3]') + execute('call dict.func("len: ")') + execute('let x = dict.func("again: ")') + execute('try') + execute(' let Fn = dict.func') + execute([[ call Fn('xxx')]]) + execute('catch') + execute(' $put =v:exception[:15]') + execute('endtry') + + -- Function in script-local List or Dict. + execute('let g:dict = {}') + execute('function g:dict.func() dict') + execute([=[ $put ='g:dict.func'.self.foo[1].self.foo[0]('asdf')]=]) + execute('endfunc') + execute([=[let g:dict.foo = ['-', 2, 3]]=]) + execute([[call insert(g:dict.foo, function('strlen'))]]) + execute('call g:dict.func()') + + -- Nasty: remove func from Dict that's being called (works). + execute('let d = {1:1}') + execute('func d.func(a)') + execute(' return "a:". a:a') + execute('endfunc') + execute([[$put =d.func(string(remove(d, 'func')))]]) + + -- Nasty: deepcopy() dict that refers to itself (fails when noref used). + execute('let d = {1:1, 2:2}') + execute('let l = [4, d, 6]') + execute('let d[3] = l') + execute('let dc = deepcopy(d)') + execute('try') + execute(' let dc = deepcopy(d, 1)') + execute('catch') + execute(' $put =v:exception[:14]') + execute('endtry') + execute('let l2 = [0, l, l, 3]') + execute('let l[1] = l2') + execute('let l3 = deepcopy(l2)') + execute([=[$put ='same list: ' . (l3[1] is l3[2])]=]) + + -- Locked variables. + execute('for depth in range(5)') + execute([[ $put ='depth is ' . depth]]) + execute(' for u in range(3)') + execute(' unlet l') + execute(' let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]') + execute(' exe "lockvar " . depth . " l"') + execute(' if u == 1') + execute(' exe "unlockvar l"') + execute(' elseif u == 2') + execute(' exe "unlockvar " . depth . " l"') + execute(' endif') + execute([=[ let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]")]=]) + execute(' $put =ps') + execute([[ let ps = '']]) + execute(' try') + execute(' let l[1][1][0] = 99') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' let l[1][1] = [99]') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' let l[1] = [99]') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute([=[ let l[2]['6'][7] = 99]=]) + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' let l[2][6] = {99: 99}') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' let l[2] = {99: 99}') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' let l = [99]') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' $put =ps') + execute(' endfor') + execute('endfor') + + -- Unletting locked variables. + execute([[$put ='Unletting:']]) + execute('for depth in range(5)') + execute([[ $put ='depth is ' . depth]]) + execute(' for u in range(3)') + execute(' unlet l') + execute(' let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]') + execute(' exe "lockvar " . depth . " l"') + execute(' if u == 1') + execute(' exe "unlockvar l"') + execute(' elseif u == 2') + execute(' exe "unlockvar " . depth . " l"') + execute(' endif') + execute([=[ let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]")]=]) + execute(' $put =ps') + execute([[ let ps = '']]) + execute(' try') + execute([=[ unlet l[2]['6'][7]]=]) + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' unlet l[2][6]') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' unlet l[2]') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' unlet l[1][1][0]') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' unlet l[1][1]') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' unlet l[1]') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' try') + execute(' unlet l') + execute([[ let ps .= 'p']]) + execute(' catch') + execute([[ let ps .= 'F']]) + execute(' endtry') + execute(' $put =ps') + execute(' endfor') + execute('endfor') + + -- Locked variables and :unlet or list / dict functions. + execute([[$put ='Locks and commands or functions:']]) + + execute([[$put ='No :unlet after lock on dict:']]) + execute('unlet! d') + execute([[let d = {'a': 99, 'b': 100}]]) + execute('lockvar 1 d') + execute('try') + execute(' unlet d.a') + execute([[ $put ='did :unlet']]) + execute('catch') + execute(' $put =v:exception[:16]') + execute('endtry') + execute('$put =string(d)') + + execute([[$put =':unlet after lock on dict item:']]) + execute('unlet! d') + execute([[let d = {'a': 99, 'b': 100}]]) + execute('lockvar d.a') + execute('try') + execute(' unlet d.a') + execute([[ $put ='did :unlet']]) + execute('catch') + execute(' $put =v:exception[:16]') + execute('endtry') + execute('$put =string(d)') + + execute([[$put ='filter() after lock on dict item:']]) + execute('unlet! d') + execute([[let d = {'a': 99, 'b': 100}]]) + execute('lockvar d.a') + execute('try') + execute([[ call filter(d, 'v:key != "a"')]]) + execute([[ $put ='did filter()']]) + execute('catch') + execute(' $put =v:exception[:16]') + execute('endtry') + execute('$put =string(d)') + + execute([[$put ='map() after lock on dict:']]) + execute('unlet! d') + execute([[let d = {'a': 99, 'b': 100}]]) + execute('lockvar 1 d') + execute('try') + execute([[ call map(d, 'v:val + 200')]]) + execute([[ $put ='did map()']]) + execute('catch') + execute(' $put =v:exception[:16]') + execute('endtry') + execute('$put =string(d)') + + execute([[$put ='No extend() after lock on dict item:']]) + execute('unlet! d') + execute([[let d = {'a': 99, 'b': 100}]]) + execute('lockvar d.a') + execute('try') + execute([[ $put =string(extend(d, {'a': 123}))]]) + execute([[ $put ='did extend()']]) + execute('catch') + execute(' $put =v:exception[:14]') + execute('endtry') + execute('$put =string(d)') + + execute([[$put ='No remove() of write-protected scope-level variable:']]) + execute('fun! Tfunc(this_is_a_loooooooooong_parameter_name)') + execute(' try') + execute([[ $put =string(remove(a:, 'this_is_a_loooooooooong_parameter_name'))]]) + execute([[ $put ='did remove()']]) + execute(' catch') + execute(' $put =v:exception[:14]') + execute(' endtry') + execute('endfun') + execute([[call Tfunc('testval')]]) + + execute([[$put ='No extend() of write-protected scope-level variable:']]) + execute('fun! Tfunc(this_is_a_loooooooooong_parameter_name)') + execute(' try') + execute([[ $put =string(extend(a:, {'this_is_a_loooooooooong_parameter_name': 1234}))]]) + execute([[ $put ='did extend()']]) + execute(' catch') + execute(' $put =v:exception[:14]') + execute(' endtry') + execute('endfun') + execute([[call Tfunc('testval')]]) + + execute([[$put ='No :unlet of variable in locked scope:']]) + execute('let b:testvar = 123') + execute('lockvar 1 b:') + execute('try') + execute(' unlet b:testvar') + execute([[ $put ='b:testvar was :unlet: '. (!exists('b:testvar'))]]) + execute('catch') + execute(' $put =v:exception[:16]') + execute('endtry') + execute('unlockvar 1 b:') + execute('unlet! b:testvar') + + execute([[$put ='No :let += of locked list variable:']]) + execute([=[let l = ['a', 'b', 3]]=]) + execute('lockvar 1 l') + execute('try') + execute([=[ let l += ['x']]=]) + execute([[ $put ='did :let +=']]) + execute('catch') + execute(' $put =v:exception[:14]') + execute('endtry') + execute('$put =string(l)') + + execute('unlet l') + execute('let l = [1, 2, 3, 4]') + execute('lockvar! l') + execute('$put =string(l)') + execute('unlockvar l[1]') + execute('unlet l[0:1]') + execute('$put =string(l)') + execute('unlet l[1:2]') + execute('$put =string(l)') + execute('unlockvar l[1]') + execute('let l[0:1] = [0, 1]') + execute('$put =string(l)') + execute('let l[1:2] = [0, 1]') + execute('$put =string(l)') + execute('unlet l') + -- :lockvar/islocked() triggering script autoloading. + execute('set rtp+=./sautest') + execute('lockvar g:footest#x') + execute('unlockvar g:footest#x') + execute([[$put ='locked g:footest#x:'.islocked('g:footest#x')]]) + execute([[$put ='exists g:footest#x:'.exists('g:footest#x')]]) + execute([[$put ='g:footest#x: '.g:footest#x]]) + + -- A:000 function argument. + -- First the tests that should fail. + execute('try') + execute(' let a:000 = [1, 2]') + execute('catch') + execute([[ $put ='caught a:000']]) + execute('endtry') + execute('try') + execute(' let a:000[0] = 9') + execute('catch') + execute([=[ $put ='caught a:000[0]']=]) + execute('endtry') + execute('try') + execute(' let a:000[2] = [9, 10]') + execute('catch') + execute([=[ $put ='caught a:000[2]']=]) + execute('endtry') + execute('try') + execute(' let a:000[3] = {9: 10}') + execute('catch') + execute([=[ $put ='caught a:000[3]']=]) + execute('endtry') + -- Now the tests that should pass. + execute('try') + execute(' let a:000[2][1] = 9') + execute(' call extend(a:000[2], [5, 6])') + execute(' let a:000[3][5] = 8') + execute([=[ let a:000[3]['a'] = 12]=]) + execute(' $put =string(a:000)') + execute('catch') + execute([[ $put ='caught ' . v:exception]]) + execute('endtry') + + -- Reverse(), sort(), uniq(). + execute([=[let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5]]=]) + execute('$put =string(uniq(copy(l)))') + execute('$put =string(reverse(l))') + execute('$put =string(reverse(reverse(l)))') + execute('$put =string(sort(l))') + execute('$put =string(reverse(sort(l)))') + execute('$put =string(sort(reverse(sort(l))))') + execute('$put =string(uniq(sort(l)))') + execute([=[let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, 0.22, 'four']]=]) + execute([[$put =string(sort(copy(l), 'n'))]]) + execute([=[let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]]=]) + execute('$put =string(sort(copy(l), 1))') + execute([[$put =string(sort(copy(l), 'i'))]]) + execute('$put =string(sort(copy(l)))') + + -- Splitting a string to a List. + execute([[$put =string(split(' aa bb '))]]) + execute([[$put =string(split(' aa bb ', '\W\+', 0))]]) + execute([[$put =string(split(' aa bb ', '\W\+', 1))]]) + execute([[$put =string(split(' aa bb ', '\W', 1))]]) + execute([[$put =string(split(':aa::bb:', ':', 0))]]) + execute([[$put =string(split(':aa::bb:', ':', 1))]]) + execute([[$put =string(split('aa,,bb, cc,', ',\s*', 1))]]) + execute([[$put =string(split('abc', '\zs'))]]) + execute([[$put =string(split('abc', '\zs', 1))]]) + + -- Compare recursively linked list and dict. + execute('let l = [1, 2, 3, 4]') + execute([[let d = {'1': 1, '2': l, '3': 3}]]) + execute('let l[1] = d') + execute('$put =(l == l)') + execute('$put =(d == d)') + execute('$put =(l != deepcopy(l))') + execute('$put =(d != deepcopy(d))') + + -- Compare complex recursively linked list and dict. + execute('let l = []') + execute('call add(l, l)') + execute('let dict4 = {"l": l}') + execute('call add(dict4.l, dict4)') + execute('let lcopy = deepcopy(l)') + execute('let dict4copy = deepcopy(dict4)') + execute('$put =(l == lcopy)') + execute('$put =(dict4 == dict4copy)') + + -- Pass the same List to extend(). + execute('let l = [1, 2, 3, 4, 5]') + execute('call extend(l, l)') + execute('$put =string(l)') + + -- Pass the same Dict to extend(). + execute([[let d = { 'a': {'b': 'B'}}]]) + execute('call extend(d, d)') + execute('$put =string(d)') + + -- Pass the same Dict to extend() with "error". + execute('try') + execute(' call extend(d, d, "error")') + execute('catch') + execute(' $put =v:exception[:15] . v:exception[-1:-1]') + execute('endtry') + execute('$put =string(d)') + + -- Test for range assign. + execute('let l = [0]') + execute('let l[:] = [1, 2]') + execute('$put =string(l)') + execute('endfun') + + -- This may take a while. + execute('call Test(1, 2, [3, 4], {5: 6})') + + execute('delfunc Test') + execute('unlet dict') + execute('call garbagecollect(1)') + + -- Test for patch 7.3.637. + execute([[let a = 'No error caught']]) + execute([=[try|foldopen|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry]=]) + + feed('o=a') + execute('lang C') + execute('redir => a') + execute([=[try|foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry]=]) + execute('redir END') + + feed('o=a:') + + -- Assert buffer contents. + expect([=[ + start: + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + {'a': 1} + 1 + Vim(put):E684: + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + ['as''d', [1, 2, function('strlen')], {'a': 1}] + [1, 'as''d', [1, 2, function('strlen')]] + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + [] + 101101 + {'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}asd + ['-1', '1', 'b'] + ['asd', [1, 2, function('strlen')], {'a': 1}] + 1:'asd' + b:[1, 2, function('strlen')] + -1:{'a': 1} + Vim(call):E737: 3 + {'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}} + {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} + 101101 + Vim(let):E706: d + Vim(let):E706: l + [1, 'as''d', {'a': 1}] + [4] + {'1': 99, '3': 33} + [0, 1, 2, 3] + [0, 1, 3] + [0, 1] + [0, 1] + [0, 1] + [0, 1, 2, 3] + [0, 1, 3] + [0, 3] + [3] + [3] + [3] + 2 + 3 + Vim(let):E687: + Vim(let):E688: + 3000 2900 2001 1600 1501 + Vim(let):E716: 1500 + NONE 2999 + 33=999 + {'33': 999} + len: 3 + again: 3 + Vim(call):E725: + g:dict.func-4 + a:function('3') + Vim(let):E698: + same list: 1 + depth is 0 + 0000-000 + ppppppp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 1 + 1000-000 + ppppppF + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 2 + 1100-100 + ppFppFF + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 3 + 1110-110 + pFFpFFF + 0010-010 + pFppFpp + 0000-000 + ppppppp + depth is 4 + 1111-111 + FFFFFFF + 0011-011 + FFpFFpp + 0000-000 + ppppppp + Unletting: + depth is 0 + 0000-000 + ppppppp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 1 + 1000-000 + ppFppFp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 2 + 1100-100 + pFFpFFp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 3 + 1110-110 + FFFFFFp + 0010-010 + FppFppp + 0000-000 + ppppppp + depth is 4 + 1111-111 + FFFFFFp + 0011-011 + FppFppp + 0000-000 + ppppppp + Locks and commands or functions: + No :unlet after lock on dict: + Vim(unlet):E741: + {'a': 99, 'b': 100} + :unlet after lock on dict item: + did :unlet + {'b': 100} + filter() after lock on dict item: + did filter() + {'b': 100} + map() after lock on dict: + did map() + {'a': 299, 'b': 300} + No extend() after lock on dict item: + Vim(put):E741: + {'a': 99, 'b': 100} + No remove() of write-protected scope-level variable: + Vim(put):E795: + No extend() of write-protected scope-level variable: + Vim(put):E742: + No :unlet of variable in locked scope: + Vim(unlet):E741: + No :let += of locked list variable: + Vim(let):E741: + ['a', 'b', 3] + [1, 2, 3, 4] + [1, 2, 3, 4] + [1, 2, 3, 4] + [1, 2, 3, 4] + [1, 2, 3, 4] + locked g:footest#x:-1 + exists g:footest#x:0 + g:footest#x: 1 + caught a:000 + caught a:000[0] + caught a:000[2] + caught a:000[3] + [1, 2, [3, 9, 5, 6], {'a': 12, '5': 8}] + ['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5] + [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] + [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] + ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]] + [[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'] + ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]] + ['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]] + [-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255] + ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] + ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] + ['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] + ['aa', 'bb'] + ['aa', 'bb'] + ['', 'aa', 'bb', ''] + ['', '', 'aa', '', 'bb', '', ''] + ['aa', '', 'bb'] + ['', 'aa', '', 'bb', ''] + ['aa', '', 'bb', 'cc', ''] + ['a', 'b', 'c'] + ['', 'a', '', 'b', '', 'c', ''] + 1 + 1 + 0 + 0 + 1 + 1 + [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] + {'a': {'b': 'B'}} + Vim(call):E737: a + {'a': {'b': 'B'}} + [1, 2] + Vim(foldopen):E490: + + + Error detected while processing : + E492: Not an editor command: foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry + ]=]) + end) +end) -- cgit From 726a6abfb7778412a293f01b564da14f469d1c8b Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Wed, 10 Feb 2016 14:08:54 +0100 Subject: test: Split migrated legacy test 55. The test is split into several it() blocks to find the part of the test that is making trouble. --- test/functional/legacy/055_spec.lua | 1363 +++++++++++++++++++---------------- 1 file changed, 750 insertions(+), 613 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/055_spec.lua b/test/functional/legacy/055_spec.lua index 194da288fc..8316fe15ce 100644 --- a/test/functional/legacy/055_spec.lua +++ b/test/functional/legacy/055_spec.lua @@ -5,296 +5,468 @@ local feed, insert, source = helpers.feed, helpers.insert, helpers.source local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect describe('55', function() - setup(clear) - - it('is working', function() - insert([[ - start:]]) + before_each(clear) + + it('creating list directly with different types', function() + source([[ + lang C + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + $put =string(l) + $put =string(l[-1]) + $put =string(l[-4]) + try + $put =string(l[-5]) + catch + $put =v:exception[:14] + endtry]]) + expect([[ + + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + {'a': 1} + 1 + Vim(put):E684: ]]) + end) - execute('fun Test(...)') - execute('lang C') - -- Creating List directly with different types. - execute([=[let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]]=]) - execute('$put =string(l)') - execute('$put =string(l[-1])') - execute('$put =string(l[-4])') - execute('try') - execute(' $put =string(l[-5])') - execute('catch') - execute(' $put =v:exception[:14]') - execute('endtry') - -- List slices. - execute('$put =string(l[:])') - execute('$put =string(l[1:])') - execute('$put =string(l[:-2])') - execute('$put =string(l[0:8])') - execute('$put =string(l[8:-1])') - - -- List identity. - execute('let ll = l') - execute('let lx = copy(l)') - execute('try') - execute(' $put =(l == ll) . (l isnot ll) . (l is ll) . (l == lx) . (l is lx) . (l isnot lx)') - execute('catch') - execute(' $put =v:exception') - execute('endtry') + it('list slices', function() + source([[ + lang C + " The list from the first test repeated after splitting the tests. + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + $put =string(l[:]) + $put =string(l[1:]) + $put =string(l[:-2]) + $put =string(l[0:8]) + $put =string(l[8:-1])]]) + expect([=[ + + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + ['as''d', [1, 2, function('strlen')], {'a': 1}] + [1, 'as''d', [1, 2, function('strlen')]] + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + []]=]) + end) - -- Creating Dictionary directly with different types. - execute([=[let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}]=]) - execute('$put =string(d) . d.1') - execute('$put =string(sort(keys(d)))') - execute('$put =string (values(d))') - execute('for [key, val] in items(d)') - execute([[ $put =key . ':' . string(val)]]) - execute(' unlet key val') - execute('endfor') - execute('call extend (d, {3:33, 1:99})') - execute([[call extend(d, {'b':'bbb', 'c':'ccc'}, "keep")]]) - execute('try') - execute(' call extend(d, {3:333,4:444}, "error")') - execute('catch') - execute(' $put =v:exception[:15] . v:exception[-1:-1]') - execute('endtry') - execute('$put =string(d)') - execute([=[call filter(d, 'v:key =~ ''[ac391]''')]=]) - execute('$put =string(d)') + it('list identity', function() + source([[ + lang C + " The list from the first test repeated after splitting the tests. + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + let ll = l + let lx = copy(l) + try + $put =(l == ll) . (l isnot ll) . (l is ll) . (l == lx) . + \ (l is lx) . (l isnot lx) + catch + $put =v:exception + endtry]]) + expect('\n101101') + end) - -- Dictionary identity. - execute('let dd = d') - execute('let dx = copy(d)') - execute('try') - execute(' $put =(d == dd) . (d isnot dd) . (d is dd) . (d == dx) . (d is dx) . (d isnot dx)') - execute('catch') - execute(' $put =v:exception') - execute('endtry') + it('creating dictionary directly with different types', function() + source([[ + lang C + let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} + $put =string(d) . d.1 + $put =string(sort(keys(d))) + $put =string (values(d)) + for [key, val] in items(d) + $put =key . ':' . string(val) + unlet key val + endfor + call extend (d, {3:33, 1:99}) + call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") + try + call extend(d, {3:333,4:444}, "error") + catch + $put =v:exception[:15] . v:exception[-1:-1] + endtry + $put =string(d) + call filter(d, 'v:key =~ ''[ac391]''') + $put =string(d)]]) + expect([[ + + {'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}asd + ['-1', '1', 'b'] + ['asd', [1, 2, function('strlen')], {'a': 1}] + 1:'asd' + b:[1, 2, function('strlen')] + -1:{'a': 1} + Vim(call):E737: 3 + {'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}} + {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}]]) + end) - -- Changing var type should fail. - execute('try') - execute(' let d = []') - execute('catch') - execute(' $put =v:exception[:14] . v:exception[-1:-1]') - execute('endtry') - execute('try') - execute(' let l = {}') - execute('catch') - execute(' $put =v:exception[:14] . v:exception[-1:-1]') - execute('endtry') + it('dictionary identity', function() + source([[ + lang C + " The dict from the first test repeated after splitting the tests. + let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} + let dd = d + let dx = copy(d) + try + $put =(d == dd) . (d isnot dd) . (d is dd) . (d == dx) . (d is dx) . + \ (d isnot dx) + catch + $put =v:exception + endtry]]) + expect('\n101101') + end) - -- Removing items with :unlet. - execute('unlet l[2]') - execute('$put =string(l)') - execute('let l = range(8)') - execute('try') - execute('unlet l[:3]') - execute('unlet l[1:]') - execute('catch') - execute('$put =v:exception') - execute('endtry') - execute('$put =string(l)') + it('changing var type should fail', function() + source([[ + lang C + " The list from the first test repeated after splitting the tests. + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + " The dict from the first test repeated after splitting the tests. + let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} + try + let d = [] + catch + $put =v:exception[:14] . v:exception[-1:-1] + endtry + try + let l = {} + catch + $put =v:exception[:14] . v:exception[-1:-1] + endtry]]) + expect([[ + + Vim(let):E706: d + Vim(let):E706: l]]) + end) - execute('unlet d.c') - execute('unlet d[-1]') - execute('$put =string(d)') + it('removing items with :unlet', function() + source([[ + lang C + " The list from the first test repeated after splitting the tests. + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + " The dict from the first test repeated after splitting the tests. + let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} + unlet l[2] + $put =string(l) + let l = range(8) + try + unlet l[:3] + unlet l[1:] + catch + $put =v:exception + endtry + $put =string(l) + + unlet d.c + unlet d[-1] + $put =string(d)]]) + expect([[ + + [1, 'as''d', {'a': 1}] + [4] + {'1': 99, '3': 33}]]) + end) - -- Removing items out of range: silently skip items that don't exist. - feed('let l = [0, 1, 2, 3]') + it("removing items out of range: silently skip items that don't exist", function() + -- We can not use source() here as we want to ignore all errors. + execute('lang C') + execute('let l = [0, 1, 2, 3]') execute('unlet l[2:1]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[2:2]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[2:3]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[2:4]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[2:5]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[-1:2]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[-2:2]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[-3:2]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[-4:2]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[-5:2]') execute('$put =string(l)') - feed('let l = [0, 1, 2, 3]') + execute('let l = [0, 1, 2, 3]') execute('unlet l[-6:2]') execute('$put =string(l)') + expect([=[ + + [0, 1, 2, 3] + [0, 1, 3] + [0, 1] + [0, 1] + [0, 1] + [0, 1, 2, 3] + [0, 1, 3] + [0, 3] + [3] + [3] + [3]]=]) + end) - -- Assignment to a list. - execute('let l = [0, 1, 2, 3]') - execute('let [va, vb] = l[2:3]') - execute('$put =va') - execute('$put =vb') - execute('try') - execute(' let [va, vb] = l') - execute('catch') - execute(' $put =v:exception[:14]') - execute('endtry') - execute('try') - execute(' let [va, vb] = l[1:1]') - execute('catch') - execute(' $put =v:exception[:14]') - execute('endtry') + it('assignment to a list', function() + source([[ + let l = [0, 1, 2, 3] + let [va, vb] = l[2:3] + $put =va + $put =vb + try + let [va, vb] = l + catch + $put =v:exception[:14] + endtry + try + let [va, vb] = l[1:1] + catch + $put =v:exception[:14] + endtry]]) + expect([[ + + 2 + 3 + Vim(let):E687: + Vim(let):E688: ]]) + end) - -- Manipulating a big Dictionary (hashtable.c has a border of 1000 entries). - execute('let d = {}') - execute('for i in range(1500)') - execute(' let d[i] = 3000 - i') - execute('endfor') - execute([=[$put =d[0] . ' ' . d[100] . ' ' . d[999] . ' ' . d[1400] . ' ' . d[1499]]=]) - execute('try') - execute(' let n = d[1500]') - execute('catch') - execute([[ $put =substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '')]]) - execute('endtry') - -- Lookup each items. - execute('for i in range(1500)') - execute(' if d[i] != 3000 - i') - execute(' $put =d[i]') - execute(' endif') - execute('endfor') - execute(' let i += 1') - -- Delete even items. - execute('while i >= 2') - execute(' let i -= 2') - execute(' unlet d[i]') - execute('endwhile') - execute([=[$put =get(d, 1500 - 100, 'NONE') . ' ' . d[1]]=]) - -- Delete odd items, checking value, one intentionally wrong. - execute('let d[33] = 999') - execute('let i = 1') - execute('while i < 1500') - execute(' if d[i] != 3000 - i') - execute([=[ $put =i . '=' . d[i]]=]) - execute(' else') - execute(' unlet d[i]') - execute(' endif') - execute(' let i += 2') - execute('endwhile') - -- Must be almost empty now. - execute('$put =string(d)') - execute('unlet d') - - -- Dictionary function. - execute('let dict = {}') - execute('func dict.func(a) dict') - execute(' $put =a:a . len(self.data)') - execute('endfunc') - execute('let dict.data = [1,2,3]') - execute('call dict.func("len: ")') - execute('let x = dict.func("again: ")') - execute('try') - execute(' let Fn = dict.func') - execute([[ call Fn('xxx')]]) - execute('catch') - execute(' $put =v:exception[:15]') - execute('endtry') + it('manipulating a big dictionary', function() + -- Manipulating a big Dictionary (hashtable.c has a border of 1000 + -- entries). + source([[ + let d = {} + for i in range(1500) + let d[i] = 3000 - i + endfor + $put =d[0] . ' ' . d[100] . ' ' . d[999] . ' ' . d[1400] . ' ' . + \ d[1499] + try + let n = d[1500] + catch + $put =substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '') + endtry + " Lookup each items. + for i in range(1500) + if d[i] != 3000 - i + $put =d[i] + endif + endfor + let i += 1 + " Delete even items. + while i >= 2 + let i -= 2 + unlet d[i] + endwhile + $put =get(d, 1500 - 100, 'NONE') . ' ' . d[1] + " Delete odd items, checking value, one intentionally wrong. + let d[33] = 999 + let i = 1 + while i < 1500 + if d[i] != 3000 - i + $put =i . '=' . d[i] + else + unlet d[i] + endif + let i += 2 + endwhile + " Must be almost empty now. + $put =string(d)]]) + expect([[ + + 3000 2900 2001 1600 1501 + Vim(let):E716: 1500 + NONE 2999 + 33=999 + {'33': 999}]]) + end) - -- Function in script-local List or Dict. - execute('let g:dict = {}') - execute('function g:dict.func() dict') - execute([=[ $put ='g:dict.func'.self.foo[1].self.foo[0]('asdf')]=]) - execute('endfunc') - execute([=[let g:dict.foo = ['-', 2, 3]]=]) - execute([[call insert(g:dict.foo, function('strlen'))]]) - execute('call g:dict.func()') - - -- Nasty: remove func from Dict that's being called (works). - execute('let d = {1:1}') - execute('func d.func(a)') - execute(' return "a:". a:a') - execute('endfunc') - execute([[$put =d.func(string(remove(d, 'func')))]]) + it('dictionary function', function() + source([[ + let dict = {} + func dict.func(a) dict + $put =a:a . len(self.data) + endfunc + let dict.data = [1,2,3] + call dict.func("len: ") + let x = dict.func("again: ") + try + let Fn = dict.func + call Fn('xxx') + catch + $put =v:exception[:15] + endtry]]) + expect([[ + + len: 3 + again: 3 + Vim(call):E725: ]]) + end) + + it('Function in script-local List or Dict', function() + source([[ + let g:dict = {} + function g:dict.func() dict + $put ='g:dict.func'.self.foo[1].self.foo[0]('asdf') + endfunc + let g:dict.foo = ['-', 2, 3] + call insert(g:dict.foo, function('strlen')) + call g:dict.func()]]) + expect('\ng:dict.func-4') + end) + it("remove func from dict that's being called (works)", function() + source([[ + let d = {1:1} + func d.func(a) + return "a:". a:a + endfunc + $put =d.func(string(remove(d, 'func')))]]) + -- The function number changed from 3 to 1 because we split the test. + -- There were two other functions in the old test before this. + expect("\na:function('1')") + end) + + it('deepcopy() dict that refers to itself', function() -- Nasty: deepcopy() dict that refers to itself (fails when noref used). - execute('let d = {1:1, 2:2}') - execute('let l = [4, d, 6]') - execute('let d[3] = l') - execute('let dc = deepcopy(d)') - execute('try') - execute(' let dc = deepcopy(d, 1)') - execute('catch') - execute(' $put =v:exception[:14]') - execute('endtry') - execute('let l2 = [0, l, l, 3]') - execute('let l[1] = l2') - execute('let l3 = deepcopy(l2)') - execute([=[$put ='same list: ' . (l3[1] is l3[2])]=]) + source([[ + let d = {1:1, 2:2} + let l = [4, d, 6] + let d[3] = l + let dc = deepcopy(d) + try + let dc = deepcopy(d, 1) + catch + $put =v:exception[:14] + endtry + let l2 = [0, l, l, 3] + let l[1] = l2 + let l3 = deepcopy(l2) + $put ='same list: ' . (l3[1] is l3[2])]]) + expect([[ + + Vim(let):E698: + same list: 1]]) + end) - -- Locked variables. - execute('for depth in range(5)') - execute([[ $put ='depth is ' . depth]]) - execute(' for u in range(3)') - execute(' unlet l') - execute(' let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]') - execute(' exe "lockvar " . depth . " l"') - execute(' if u == 1') - execute(' exe "unlockvar l"') - execute(' elseif u == 2') - execute(' exe "unlockvar " . depth . " l"') - execute(' endif') - execute([=[ let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]")]=]) - execute(' $put =ps') - execute([[ let ps = '']]) - execute(' try') - execute(' let l[1][1][0] = 99') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' let l[1][1] = [99]') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' let l[1] = [99]') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute([=[ let l[2]['6'][7] = 99]=]) - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' let l[2][6] = {99: 99}') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' let l[2] = {99: 99}') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' let l = [99]') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' $put =ps') - execute(' endfor') - execute('endfor') + -- TODO + it('locked variables (part 1)', function() + --execute([[function Test(...)]]) + execute([=[ let l = []]=]) + execute([[ for depth in range(5)]]) + execute([[ $put ='depth is ' . depth]]) + execute([[ for u in range(3)]]) + execute([[ unlet l]]) + execute([=[ let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]]=]) + execute([[ exe "lockvar " . depth . " l"]]) + execute([[ if u == 1]]) + execute([[ exe "unlockvar l"]]) + execute([[ elseif u == 2]]) + execute([[ exe "unlockvar " . depth . " l"]]) + execute([[ endif]]) + execute([[ let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . ]]) + execute([[ \ islocked("l[1][1][0]") . '-' . islocked("l[2]") .]]) + execute([[ \ islocked("l[2]['6']") . islocked("l[2]['6'][7]")]]) + execute([[ $put =ps]]) + execute([[ let ps = '']]) + execute([[ try]]) + execute([[ let l[1][1][0] = 99]]) + execute([[ let ps .= 'p']]) + execute([[ catch]]) + execute([[ let ps .= 'F']]) + execute([[ endtry]]) + execute([[ try]]) + execute([=[ let l[1][1] = [99]]=]) + execute([[ let ps .= 'p']]) + execute([[ catch]]) + execute([[ let ps .= 'F']]) + execute([[ endtry]]) + execute([[ try]]) + execute([=[ let l[1] = [99]]=]) + execute([[ let ps .= 'p']]) + execute([[ catch]]) + execute([[ let ps .= 'F']]) + execute([[ endtry]]) + execute([[ try]]) + execute([[ let l[2]['6'][7] = 99]]) + execute([[ let ps .= 'p']]) + execute([[ catch]]) + execute([[ let ps .= 'F']]) + execute([[ endtry]]) + execute([[ try]]) + execute([[ let l[2][6] = {99: 99}]]) + execute([[ let ps .= 'p']]) + execute([[ catch]]) + execute([[ let ps .= 'F']]) + execute([[ endtry]]) + execute([[ try]]) + execute([[ let l[2] = {99: 99}]]) + execute([[ let ps .= 'p']]) + execute([[ catch]]) + execute([[ let ps .= 'F']]) + execute([[ endtry]]) + execute([[ try]]) + execute([=[ let l = [99]]=]) + execute([[ let ps .= 'p']]) + execute([[ catch]]) + execute([[ let ps .= 'F']]) + execute([[ endtry]]) + execute([[ $put =ps]]) + execute([[ endfor]]) + execute([[ endfor]]) + execute([[ unlet l]]) + execute([[endfunction]]) + --execute('Test()') + --execute('call Test(1, 2, [3, 4], {5: 6})') + expect([[ + + depth is 0 + 0000-000 + ppppppp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 1 + 1000-000 + ppppppF + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 2 + 1100-100 + ppFppFF + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 3 + 1110-110 + pFFpFFF + 0010-010 + pFppFpp + 0000-000 + ppppppp + depth is 4 + 1111-111 + FFFFFFF + 0011-011 + FFpFFpp + 0000-000 + ppppppp]]) + end) - -- Unletting locked variables. - execute([[$put ='Unletting:']]) + + it('unletting locked variables', function() + --execute(' let l = []') execute('for depth in range(5)') execute([[ $put ='depth is ' . depth]]) execute(' for u in range(3)') @@ -354,351 +526,8 @@ describe('55', function() execute(' $put =ps') execute(' endfor') execute('endfor') - - -- Locked variables and :unlet or list / dict functions. - execute([[$put ='Locks and commands or functions:']]) - - execute([[$put ='No :unlet after lock on dict:']]) - execute('unlet! d') - execute([[let d = {'a': 99, 'b': 100}]]) - execute('lockvar 1 d') - execute('try') - execute(' unlet d.a') - execute([[ $put ='did :unlet']]) - execute('catch') - execute(' $put =v:exception[:16]') - execute('endtry') - execute('$put =string(d)') - - execute([[$put =':unlet after lock on dict item:']]) - execute('unlet! d') - execute([[let d = {'a': 99, 'b': 100}]]) - execute('lockvar d.a') - execute('try') - execute(' unlet d.a') - execute([[ $put ='did :unlet']]) - execute('catch') - execute(' $put =v:exception[:16]') - execute('endtry') - execute('$put =string(d)') - - execute([[$put ='filter() after lock on dict item:']]) - execute('unlet! d') - execute([[let d = {'a': 99, 'b': 100}]]) - execute('lockvar d.a') - execute('try') - execute([[ call filter(d, 'v:key != "a"')]]) - execute([[ $put ='did filter()']]) - execute('catch') - execute(' $put =v:exception[:16]') - execute('endtry') - execute('$put =string(d)') - - execute([[$put ='map() after lock on dict:']]) - execute('unlet! d') - execute([[let d = {'a': 99, 'b': 100}]]) - execute('lockvar 1 d') - execute('try') - execute([[ call map(d, 'v:val + 200')]]) - execute([[ $put ='did map()']]) - execute('catch') - execute(' $put =v:exception[:16]') - execute('endtry') - execute('$put =string(d)') - - execute([[$put ='No extend() after lock on dict item:']]) - execute('unlet! d') - execute([[let d = {'a': 99, 'b': 100}]]) - execute('lockvar d.a') - execute('try') - execute([[ $put =string(extend(d, {'a': 123}))]]) - execute([[ $put ='did extend()']]) - execute('catch') - execute(' $put =v:exception[:14]') - execute('endtry') - execute('$put =string(d)') - - execute([[$put ='No remove() of write-protected scope-level variable:']]) - execute('fun! Tfunc(this_is_a_loooooooooong_parameter_name)') - execute(' try') - execute([[ $put =string(remove(a:, 'this_is_a_loooooooooong_parameter_name'))]]) - execute([[ $put ='did remove()']]) - execute(' catch') - execute(' $put =v:exception[:14]') - execute(' endtry') - execute('endfun') - execute([[call Tfunc('testval')]]) - - execute([[$put ='No extend() of write-protected scope-level variable:']]) - execute('fun! Tfunc(this_is_a_loooooooooong_parameter_name)') - execute(' try') - execute([[ $put =string(extend(a:, {'this_is_a_loooooooooong_parameter_name': 1234}))]]) - execute([[ $put ='did extend()']]) - execute(' catch') - execute(' $put =v:exception[:14]') - execute(' endtry') - execute('endfun') - execute([[call Tfunc('testval')]]) - - execute([[$put ='No :unlet of variable in locked scope:']]) - execute('let b:testvar = 123') - execute('lockvar 1 b:') - execute('try') - execute(' unlet b:testvar') - execute([[ $put ='b:testvar was :unlet: '. (!exists('b:testvar'))]]) - execute('catch') - execute(' $put =v:exception[:16]') - execute('endtry') - execute('unlockvar 1 b:') - execute('unlet! b:testvar') - - execute([[$put ='No :let += of locked list variable:']]) - execute([=[let l = ['a', 'b', 3]]=]) - execute('lockvar 1 l') - execute('try') - execute([=[ let l += ['x']]=]) - execute([[ $put ='did :let +=']]) - execute('catch') - execute(' $put =v:exception[:14]') - execute('endtry') - execute('$put =string(l)') - - execute('unlet l') - execute('let l = [1, 2, 3, 4]') - execute('lockvar! l') - execute('$put =string(l)') - execute('unlockvar l[1]') - execute('unlet l[0:1]') - execute('$put =string(l)') - execute('unlet l[1:2]') - execute('$put =string(l)') - execute('unlockvar l[1]') - execute('let l[0:1] = [0, 1]') - execute('$put =string(l)') - execute('let l[1:2] = [0, 1]') - execute('$put =string(l)') - execute('unlet l') - -- :lockvar/islocked() triggering script autoloading. - execute('set rtp+=./sautest') - execute('lockvar g:footest#x') - execute('unlockvar g:footest#x') - execute([[$put ='locked g:footest#x:'.islocked('g:footest#x')]]) - execute([[$put ='exists g:footest#x:'.exists('g:footest#x')]]) - execute([[$put ='g:footest#x: '.g:footest#x]]) - - -- A:000 function argument. - -- First the tests that should fail. - execute('try') - execute(' let a:000 = [1, 2]') - execute('catch') - execute([[ $put ='caught a:000']]) - execute('endtry') - execute('try') - execute(' let a:000[0] = 9') - execute('catch') - execute([=[ $put ='caught a:000[0]']=]) - execute('endtry') - execute('try') - execute(' let a:000[2] = [9, 10]') - execute('catch') - execute([=[ $put ='caught a:000[2]']=]) - execute('endtry') - execute('try') - execute(' let a:000[3] = {9: 10}') - execute('catch') - execute([=[ $put ='caught a:000[3]']=]) - execute('endtry') - -- Now the tests that should pass. - execute('try') - execute(' let a:000[2][1] = 9') - execute(' call extend(a:000[2], [5, 6])') - execute(' let a:000[3][5] = 8') - execute([=[ let a:000[3]['a'] = 12]=]) - execute(' $put =string(a:000)') - execute('catch') - execute([[ $put ='caught ' . v:exception]]) - execute('endtry') - - -- Reverse(), sort(), uniq(). - execute([=[let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5]]=]) - execute('$put =string(uniq(copy(l)))') - execute('$put =string(reverse(l))') - execute('$put =string(reverse(reverse(l)))') - execute('$put =string(sort(l))') - execute('$put =string(reverse(sort(l)))') - execute('$put =string(sort(reverse(sort(l))))') - execute('$put =string(uniq(sort(l)))') - execute([=[let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, 0.22, 'four']]=]) - execute([[$put =string(sort(copy(l), 'n'))]]) - execute([=[let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []]]=]) - execute('$put =string(sort(copy(l), 1))') - execute([[$put =string(sort(copy(l), 'i'))]]) - execute('$put =string(sort(copy(l)))') - - -- Splitting a string to a List. - execute([[$put =string(split(' aa bb '))]]) - execute([[$put =string(split(' aa bb ', '\W\+', 0))]]) - execute([[$put =string(split(' aa bb ', '\W\+', 1))]]) - execute([[$put =string(split(' aa bb ', '\W', 1))]]) - execute([[$put =string(split(':aa::bb:', ':', 0))]]) - execute([[$put =string(split(':aa::bb:', ':', 1))]]) - execute([[$put =string(split('aa,,bb, cc,', ',\s*', 1))]]) - execute([[$put =string(split('abc', '\zs'))]]) - execute([[$put =string(split('abc', '\zs', 1))]]) - - -- Compare recursively linked list and dict. - execute('let l = [1, 2, 3, 4]') - execute([[let d = {'1': 1, '2': l, '3': 3}]]) - execute('let l[1] = d') - execute('$put =(l == l)') - execute('$put =(d == d)') - execute('$put =(l != deepcopy(l))') - execute('$put =(d != deepcopy(d))') - - -- Compare complex recursively linked list and dict. - execute('let l = []') - execute('call add(l, l)') - execute('let dict4 = {"l": l}') - execute('call add(dict4.l, dict4)') - execute('let lcopy = deepcopy(l)') - execute('let dict4copy = deepcopy(dict4)') - execute('$put =(l == lcopy)') - execute('$put =(dict4 == dict4copy)') - - -- Pass the same List to extend(). - execute('let l = [1, 2, 3, 4, 5]') - execute('call extend(l, l)') - execute('$put =string(l)') - - -- Pass the same Dict to extend(). - execute([[let d = { 'a': {'b': 'B'}}]]) - execute('call extend(d, d)') - execute('$put =string(d)') - - -- Pass the same Dict to extend() with "error". - execute('try') - execute(' call extend(d, d, "error")') - execute('catch') - execute(' $put =v:exception[:15] . v:exception[-1:-1]') - execute('endtry') - execute('$put =string(d)') - - -- Test for range assign. - execute('let l = [0]') - execute('let l[:] = [1, 2]') - execute('$put =string(l)') - execute('endfun') - - -- This may take a while. - execute('call Test(1, 2, [3, 4], {5: 6})') - - execute('delfunc Test') - execute('unlet dict') - execute('call garbagecollect(1)') - - -- Test for patch 7.3.637. - execute([[let a = 'No error caught']]) - execute([=[try|foldopen|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry]=]) - - feed('o=a') - execute('lang C') - execute('redir => a') - execute([=[try|foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry]=]) - execute('redir END') - - feed('o=a:') - - -- Assert buffer contents. - expect([=[ - start: - [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] - {'a': 1} - 1 - Vim(put):E684: - [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] - ['as''d', [1, 2, function('strlen')], {'a': 1}] - [1, 'as''d', [1, 2, function('strlen')]] - [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] - [] - 101101 - {'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}asd - ['-1', '1', 'b'] - ['asd', [1, 2, function('strlen')], {'a': 1}] - 1:'asd' - b:[1, 2, function('strlen')] - -1:{'a': 1} - Vim(call):E737: 3 - {'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}} - {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} - 101101 - Vim(let):E706: d - Vim(let):E706: l - [1, 'as''d', {'a': 1}] - [4] - {'1': 99, '3': 33} - [0, 1, 2, 3] - [0, 1, 3] - [0, 1] - [0, 1] - [0, 1] - [0, 1, 2, 3] - [0, 1, 3] - [0, 3] - [3] - [3] - [3] - 2 - 3 - Vim(let):E687: - Vim(let):E688: - 3000 2900 2001 1600 1501 - Vim(let):E716: 1500 - NONE 2999 - 33=999 - {'33': 999} - len: 3 - again: 3 - Vim(call):E725: - g:dict.func-4 - a:function('3') - Vim(let):E698: - same list: 1 - depth is 0 - 0000-000 - ppppppp - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 1 - 1000-000 - ppppppF - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 2 - 1100-100 - ppFppFF - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 3 - 1110-110 - pFFpFFF - 0010-010 - pFppFpp - 0000-000 - ppppppp - depth is 4 - 1111-111 - FFFFFFF - 0011-011 - FFpFFpp - 0000-000 - ppppppp - Unletting: + expect([[ + depth is 0 0000-000 ppppppp @@ -733,7 +562,120 @@ describe('55', function() 0011-011 FppFppp 0000-000 - ppppppp + ppppppp]]) + end) + + it('locked variables and :unlet or list / dict functions', function() + source([[ + $put ='Locks and commands or functions:' + + $put ='No :unlet after lock on dict:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar 1 d + try + unlet d.a + $put ='did :unlet' + catch + $put =v:exception[:16] + endtry + $put =string(d) + + $put =':unlet after lock on dict item:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + try + unlet d.a + $put ='did :unlet' + catch + $put =v:exception[:16] + endtry + $put =string(d) + + $put ='filter() after lock on dict item:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + try + call filter(d, 'v:key != "a"') + $put ='did filter()' + catch + $put =v:exception[:16] + endtry + $put =string(d) + + $put ='map() after lock on dict:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar 1 d + try + call map(d, 'v:val + 200') + $put ='did map()' + catch + $put =v:exception[:16] + endtry + $put =string(d) + + $put ='No extend() after lock on dict item:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + try + $put =string(extend(d, {'a': 123})) + $put ='did extend()' + catch + $put =v:exception[:14] + endtry + $put =string(d) + + $put ='No remove() of write-protected scope-level variable:' + fun! Tfunc(this_is_a_loooooooooong_parameter_name) + try + $put =string(remove(a:, 'this_is_a_loooooooooong_parameter_name')) + $put ='did remove()' + catch + $put =v:exception[:14] + endtry + endfun + call Tfunc('testval') + + $put ='No extend() of write-protected scope-level variable:' + fun! Tfunc(this_is_a_loooooooooong_parameter_name) + try + $put =string(extend(a:, {'this_is_a_loooooooooong_parameter_name': 1234})) + $put ='did extend()' + catch + $put =v:exception[:14] + endtry + endfun + call Tfunc('testval') + + $put ='No :unlet of variable in locked scope:' + let b:testvar = 123 + lockvar 1 b: + try + unlet b:testvar + $put ='b:testvar was :unlet: '. (!exists('b:testvar')) + catch + $put =v:exception[:16] + endtry + unlockvar 1 b: + unlet! b:testvar + + $put ='No :let += of locked list variable:' + let l = ['a', 'b', 3] + lockvar 1 l + try + let l += ['x'] + $put ='did :let +=' + catch + $put =v:exception[:14] + endtry + $put =string(l)]]) + + expect([=[ + Locks and commands or functions: No :unlet after lock on dict: Vim(unlet):E741: @@ -758,20 +700,114 @@ describe('55', function() Vim(unlet):E741: No :let += of locked list variable: Vim(let):E741: - ['a', 'b', 3] - [1, 2, 3, 4] + ['a', 'b', 3]]=]) + end) + + it('locked variables (part 2)', function() + execute( + 'let l = [1, 2, 3, 4]', + 'lockvar! l', + '$put =string(l)', + 'unlockvar l[1]', + 'unlet l[0:1]', + '$put =string(l)', + 'unlet l[1:2]', + '$put =string(l)', + 'unlockvar l[1]', + 'let l[0:1] = [0, 1]', + '$put =string(l)', + 'let l[1:2] = [0, 1]', + '$put =string(l)') + expect([=[ + [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4] + [1, 2, 3, 4]]=]) + end) + + it(':lockvar/islocked() triggering script autoloading.', function() + source([[ + set rtp+=test/functional/fixtures + lockvar g:footest#x + unlockvar g:footest#x + $put ='locked g:footest#x:'.islocked('g:footest#x') + $put ='exists g:footest#x:'.exists('g:footest#x') + $put ='g:footest#x: '.g:footest#x]]) + expect([[ + locked g:footest#x:-1 exists g:footest#x:0 - g:footest#x: 1 + g:footest#x: 1]]) + end) + + it('a:000 function argument', function() + source([[ + function Test(...) + " First the tests that should fail. + try + let a:000 = [1, 2] + catch + $put ='caught a:000' + endtry + try + let a:000[0] = 9 + catch + $put ='caught a:000[0]' + endtry + try + let a:000[2] = [9, 10] + catch + $put ='caught a:000[2]' + endtry + try + let a:000[3] = {9: 10} + catch + $put ='caught a:000[3]' + endtry + " Now the tests that should pass. + try + let a:000[2][1] = 9 + call extend(a:000[2], [5, 6]) + let a:000[3][5] = 8 + let a:000[3]['a'] = 12 + $put =string(a:000) + catch + $put ='caught ' . v:exception + endtry + endfunction]]) + execute('call Test(1, 2, [3, 4], {5: 6})') + expect([=[ + caught a:000 caught a:000[0] caught a:000[2] caught a:000[3] - [1, 2, [3, 9, 5, 6], {'a': 12, '5': 8}] + [1, 2, [3, 9, 5, 6], {'a': 12, '5': 8}]]=]) + end) + + it('reverse(), sort(), uniq()', function() + source([=[ + let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', + \ [0, 1, 2], 'x8', [0, 1, 2], 1.5] + $put =string(uniq(copy(l))) + $put =string(reverse(l)) + $put =string(reverse(reverse(l))) + $put =string(sort(l)) + $put =string(reverse(sort(l))) + $put =string(sort(reverse(sort(l)))) + $put =string(uniq(sort(l))) + let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, + \ 0.22, 'four'] + $put =string(sort(copy(l), 'n')) + let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', + \ 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []] + $put =string(sort(copy(l), 1)) + $put =string(sort(copy(l), 'i')) + $put =string(sort(copy(l)))]=]) + expect([=[ + ['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5] [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] @@ -782,7 +818,22 @@ describe('55', function() [-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255] ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] - ['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] + ['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]]=]) + end) + + it('splitting a string to a list', function() + source([[ + $put =string(split(' aa bb ')) + $put =string(split(' aa bb ', '\W\+', 0)) + $put =string(split(' aa bb ', '\W\+', 1)) + $put =string(split(' aa bb ', '\W', 1)) + $put =string(split(':aa::bb:', ':', 0)) + $put =string(split(':aa::bb:', ':', 1)) + $put =string(split('aa,,bb, cc,', ',\s*', 1)) + $put =string(split('abc', '\zs')) + $put =string(split('abc', '\zs', 1))]]) + expect([=[ + ['aa', 'bb'] ['aa', 'bb'] ['', 'aa', 'bb', ''] @@ -791,23 +842,109 @@ describe('55', function() ['', 'aa', '', 'bb', ''] ['aa', '', 'bb', 'cc', ''] ['a', 'b', 'c'] - ['', 'a', '', 'b', '', 'c', ''] + ['', 'a', '', 'b', '', 'c', '']]=]) + end) + + it('compare recursively linked list and dict', function() + source([[ + let l = [1, 2, 3, 4] + let d = {'1': 1, '2': l, '3': 3} + let l[1] = d + $put =(l == l) + $put =(d == d) + $put =(l != deepcopy(l)) + $put =(d != deepcopy(d))]]) + expect([[ + 1 1 0 - 0 - 1 + 0]]) + end) + + it('compare complex recursively linked list and dict', function() + source([[ + let l = [] + call add(l, l) + let dict4 = {"l": l} + call add(dict4.l, dict4) + let lcopy = deepcopy(l) + let dict4copy = deepcopy(dict4) + $put =(l == lcopy) + $put =(dict4 == dict4copy)]]) + expect([[ + 1 - [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] - {'a': {'b': 'B'}} + 1]]) + end) + + it('pass the same list to extend()', function() + source([[ + let l = [1, 2, 3, 4, 5] + call extend(l, l) + $put =string(l)]]) + expect([=[ + + [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]]=]) + end) + + it('pass the same dict to extend()', function() + source([[ + let d = { 'a': {'b': 'B'}} + call extend(d, d) + $put =string(d)]]) + expect([[ + + {'a': {'b': 'B'}}]]) + end) + + it('pass the same dict to extend() with "error"', function() + source([[ + " Copy dict from previous test. + let d = { 'a': {'b': 'B'}} + try + call extend(d, d, "error") + catch + $put =v:exception[:15] . v:exception[-1:-1] + endtry + $put =string(d)]]) + expect([[ + Vim(call):E737: a - {'a': {'b': 'B'}} - [1, 2] + {'a': {'b': 'B'}}]]) + end) + + it('test for range assign', function() + source([[ + let l = [0] + let l[:] = [1, 2] + $put =string(l)]]) + expect([=[ + + [1, 2]]=]) + end) + + it('vim patch 7.3.637', function() + execute('let a = "No error caught"') + execute('try') + execute(' foldopen') + execute('catch') + execute(" let a = matchstr(v:exception,'^[^ ]*')") + execute('endtry') + feed('o=a') + execute('lang C') + execute('redir => a') + -- The test failes if this is not in one line. + execute("try|foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry") + execute('redir END') + feed('o=a') + expect([[ + Vim(foldopen):E490: Error detected while processing : E492: Not an editor command: foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry - ]=]) + ]]) end) end) -- cgit From 1afb1cc6bc3fe9234a24a02ec4ecc9888214ceb5 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 11 Feb 2016 02:41:56 +0100 Subject: test: Fix migrated test 55. There is still one TODO item in the test file as it was necessary to comment out one line in order to get the test to pass. --- test/functional/legacy/055_spec.lua | 257 ++++++++++++++++++------------------ 1 file changed, 128 insertions(+), 129 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/055_spec.lua b/test/functional/legacy/055_spec.lua index 8316fe15ce..bfabea20fa 100644 --- a/test/functional/legacy/055_spec.lua +++ b/test/functional/legacy/055_spec.lua @@ -356,75 +356,70 @@ describe('55', function() same list: 1]]) end) - -- TODO it('locked variables (part 1)', function() - --execute([[function Test(...)]]) - execute([=[ let l = []]=]) - execute([[ for depth in range(5)]]) - execute([[ $put ='depth is ' . depth]]) - execute([[ for u in range(3)]]) - execute([[ unlet l]]) - execute([=[ let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]]=]) - execute([[ exe "lockvar " . depth . " l"]]) - execute([[ if u == 1]]) - execute([[ exe "unlockvar l"]]) - execute([[ elseif u == 2]]) - execute([[ exe "unlockvar " . depth . " l"]]) - execute([[ endif]]) - execute([[ let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . ]]) - execute([[ \ islocked("l[1][1][0]") . '-' . islocked("l[2]") .]]) - execute([[ \ islocked("l[2]['6']") . islocked("l[2]['6'][7]")]]) - execute([[ $put =ps]]) - execute([[ let ps = '']]) - execute([[ try]]) - execute([[ let l[1][1][0] = 99]]) - execute([[ let ps .= 'p']]) - execute([[ catch]]) - execute([[ let ps .= 'F']]) - execute([[ endtry]]) - execute([[ try]]) - execute([=[ let l[1][1] = [99]]=]) - execute([[ let ps .= 'p']]) - execute([[ catch]]) - execute([[ let ps .= 'F']]) - execute([[ endtry]]) - execute([[ try]]) - execute([=[ let l[1] = [99]]=]) - execute([[ let ps .= 'p']]) - execute([[ catch]]) - execute([[ let ps .= 'F']]) - execute([[ endtry]]) - execute([[ try]]) - execute([[ let l[2]['6'][7] = 99]]) - execute([[ let ps .= 'p']]) - execute([[ catch]]) - execute([[ let ps .= 'F']]) - execute([[ endtry]]) - execute([[ try]]) - execute([[ let l[2][6] = {99: 99}]]) - execute([[ let ps .= 'p']]) - execute([[ catch]]) - execute([[ let ps .= 'F']]) - execute([[ endtry]]) - execute([[ try]]) - execute([[ let l[2] = {99: 99}]]) - execute([[ let ps .= 'p']]) - execute([[ catch]]) - execute([[ let ps .= 'F']]) - execute([[ endtry]]) - execute([[ try]]) - execute([=[ let l = [99]]=]) - execute([[ let ps .= 'p']]) - execute([[ catch]]) - execute([[ let ps .= 'F']]) - execute([[ endtry]]) - execute([[ $put =ps]]) - execute([[ endfor]]) - execute([[ endfor]]) - execute([[ unlet l]]) - execute([[endfunction]]) - --execute('Test()') - --execute('call Test(1, 2, [3, 4], {5: 6})') + source([=[ + let l = [] + for depth in range(5) + $put ='depth is ' . depth + for u in range(3) + unlet l + let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] + exe "lockvar " . depth . " l" + if u == 1 + exe "unlockvar l" + elseif u == 2 + exe "unlockvar " . depth . " l" + endif + let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . + \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . + \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") + $put =ps + let ps = '' + try + let l[1][1][0] = 99 + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[1][1] = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[1] = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2]['6'][7] = 99 + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2][6] = {99: 99} + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2] = {99: 99} + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + $put =ps + endfor + endfor]=]) expect([[ depth is 0 @@ -464,68 +459,72 @@ describe('55', function() ppppppp]]) end) - + -- TODO In the original test the 5th line of this source() call was used. + -- But now the test only passes if I comment it. it('unletting locked variables', function() - --execute(' let l = []') - execute('for depth in range(5)') - execute([[ $put ='depth is ' . depth]]) - execute(' for u in range(3)') - execute(' unlet l') - execute(' let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}]') - execute(' exe "lockvar " . depth . " l"') - execute(' if u == 1') - execute(' exe "unlockvar l"') - execute(' elseif u == 2') - execute(' exe "unlockvar " . depth . " l"') - execute(' endif') - execute([=[ let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]")]=]) - execute(' $put =ps') - execute([[ let ps = '']]) - execute(' try') - execute([=[ unlet l[2]['6'][7]]=]) - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' unlet l[2][6]') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' unlet l[2]') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' unlet l[1][1][0]') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' unlet l[1][1]') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' unlet l[1]') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' try') - execute(' unlet l') - execute([[ let ps .= 'p']]) - execute(' catch') - execute([[ let ps .= 'F']]) - execute(' endtry') - execute(' $put =ps') - execute(' endfor') - execute('endfor') + source([=[ + let l = [] + for depth in range(5) + $put ='depth is ' . depth + for u in range(3) + "unlet l + let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] + exe "lockvar " . depth . " l" + if u == 1 + exe "unlockvar l" + elseif u == 2 + exe "unlockvar " . depth . " l" + endif + let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . + \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . + \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") + $put =ps + let ps = '' + try + unlet l[2]['6'][7] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[2][6] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[2] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1][1][0] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1][1] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l + let ps .= 'p' + catch + let ps .= 'F' + endtry + $put =ps + endfor + endfor]=]) expect([[ depth is 0 -- cgit From b4848c5d1474d7226e86acf653fba8b249321c93 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 11 Feb 2016 08:58:28 +0100 Subject: test: Clean up after migration of legacy test 55. --- .../legacy/055_list_and_dict_types_spec.lua | 949 +++++++++++++++++++++ test/functional/legacy/055_spec.lua | 949 --------------------- 2 files changed, 949 insertions(+), 949 deletions(-) create mode 100644 test/functional/legacy/055_list_and_dict_types_spec.lua delete mode 100644 test/functional/legacy/055_spec.lua (limited to 'test') diff --git a/test/functional/legacy/055_list_and_dict_types_spec.lua b/test/functional/legacy/055_list_and_dict_types_spec.lua new file mode 100644 index 0000000000..4b663be04c --- /dev/null +++ b/test/functional/legacy/055_list_and_dict_types_spec.lua @@ -0,0 +1,949 @@ +-- Tests for List and Dictionary types. + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe('list and dictionary types', function() + before_each(clear) + + it('creating list directly with different types', function() + source([[ + lang C + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + $put =string(l) + $put =string(l[-1]) + $put =string(l[-4]) + try + $put =string(l[-5]) + catch + $put =v:exception[:14] + endtry]]) + expect([[ + + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + {'a': 1} + 1 + Vim(put):E684: ]]) + end) + + it('list slices', function() + source([[ + lang C + " The list from the first test repeated after splitting the tests. + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + $put =string(l[:]) + $put =string(l[1:]) + $put =string(l[:-2]) + $put =string(l[0:8]) + $put =string(l[8:-1])]]) + expect([=[ + + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + ['as''d', [1, 2, function('strlen')], {'a': 1}] + [1, 'as''d', [1, 2, function('strlen')]] + [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] + []]=]) + end) + + it('list identity', function() + source([[ + lang C + " The list from the first test repeated after splitting the tests. + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + let ll = l + let lx = copy(l) + try + $put =(l == ll) . (l isnot ll) . (l is ll) . (l == lx) . + \ (l is lx) . (l isnot lx) + catch + $put =v:exception + endtry]]) + expect('\n101101') + end) + + it('creating dictionary directly with different types', function() + source([[ + lang C + let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} + $put =string(d) . d.1 + $put =string(sort(keys(d))) + $put =string (values(d)) + for [key, val] in items(d) + $put =key . ':' . string(val) + unlet key val + endfor + call extend (d, {3:33, 1:99}) + call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") + try + call extend(d, {3:333,4:444}, "error") + catch + $put =v:exception[:15] . v:exception[-1:-1] + endtry + $put =string(d) + call filter(d, 'v:key =~ ''[ac391]''') + $put =string(d)]]) + expect([[ + + {'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}asd + ['-1', '1', 'b'] + ['asd', [1, 2, function('strlen')], {'a': 1}] + 1:'asd' + b:[1, 2, function('strlen')] + -1:{'a': 1} + Vim(call):E737: 3 + {'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}} + {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}]]) + end) + + it('dictionary identity', function() + source([[ + lang C + " The dict from the first test repeated after splitting the tests. + let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} + let dd = d + let dx = copy(d) + try + $put =(d == dd) . (d isnot dd) . (d is dd) . (d == dx) . (d is dx) . + \ (d isnot dx) + catch + $put =v:exception + endtry]]) + expect('\n101101') + end) + + it('changing var type should fail', function() + source([[ + lang C + " The list from the first test repeated after splitting the tests. + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + " The dict from the first test repeated after splitting the tests. + let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} + try + let d = [] + catch + $put =v:exception[:14] . v:exception[-1:-1] + endtry + try + let l = {} + catch + $put =v:exception[:14] . v:exception[-1:-1] + endtry]]) + expect([[ + + Vim(let):E706: d + Vim(let):E706: l]]) + end) + + it('removing items with :unlet', function() + source([[ + lang C + " The list from the first test repeated after splitting the tests. + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + " The dict from the first test repeated after splitting the tests. + let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} + unlet l[2] + $put =string(l) + let l = range(8) + try + unlet l[:3] + unlet l[1:] + catch + $put =v:exception + endtry + $put =string(l) + + unlet d.c + unlet d[-1] + $put =string(d)]]) + expect([[ + + [1, 'as''d', {'a': 1}] + [4] + {'1': 99, '3': 33}]]) + end) + + it("removing items out of range: silently skip items that don't exist", function() + -- We can not use source() here as we want to ignore all errors. + execute('lang C') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[2:1]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[2:2]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[2:3]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[2:4]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[2:5]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[-1:2]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[-2:2]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[-3:2]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[-4:2]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[-5:2]') + execute('$put =string(l)') + execute('let l = [0, 1, 2, 3]') + execute('unlet l[-6:2]') + execute('$put =string(l)') + expect([=[ + + [0, 1, 2, 3] + [0, 1, 3] + [0, 1] + [0, 1] + [0, 1] + [0, 1, 2, 3] + [0, 1, 3] + [0, 3] + [3] + [3] + [3]]=]) + end) + + it('assignment to a list', function() + source([[ + let l = [0, 1, 2, 3] + let [va, vb] = l[2:3] + $put =va + $put =vb + try + let [va, vb] = l + catch + $put =v:exception[:14] + endtry + try + let [va, vb] = l[1:1] + catch + $put =v:exception[:14] + endtry]]) + expect([[ + + 2 + 3 + Vim(let):E687: + Vim(let):E688: ]]) + end) + + it('manipulating a big dictionary', function() + -- Manipulating a big Dictionary (hashtable.c has a border of 1000 + -- entries). + source([[ + let d = {} + for i in range(1500) + let d[i] = 3000 - i + endfor + $put =d[0] . ' ' . d[100] . ' ' . d[999] . ' ' . d[1400] . ' ' . + \ d[1499] + try + let n = d[1500] + catch + $put =substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '') + endtry + " Lookup each items. + for i in range(1500) + if d[i] != 3000 - i + $put =d[i] + endif + endfor + let i += 1 + " Delete even items. + while i >= 2 + let i -= 2 + unlet d[i] + endwhile + $put =get(d, 1500 - 100, 'NONE') . ' ' . d[1] + " Delete odd items, checking value, one intentionally wrong. + let d[33] = 999 + let i = 1 + while i < 1500 + if d[i] != 3000 - i + $put =i . '=' . d[i] + else + unlet d[i] + endif + let i += 2 + endwhile + " Must be almost empty now. + $put =string(d)]]) + expect([[ + + 3000 2900 2001 1600 1501 + Vim(let):E716: 1500 + NONE 2999 + 33=999 + {'33': 999}]]) + end) + + it('dictionary function', function() + source([[ + let dict = {} + func dict.func(a) dict + $put =a:a . len(self.data) + endfunc + let dict.data = [1,2,3] + call dict.func("len: ") + let x = dict.func("again: ") + try + let Fn = dict.func + call Fn('xxx') + catch + $put =v:exception[:15] + endtry]]) + expect([[ + + len: 3 + again: 3 + Vim(call):E725: ]]) + end) + + it('Function in script-local List or Dict', function() + source([[ + let g:dict = {} + function g:dict.func() dict + $put ='g:dict.func'.self.foo[1].self.foo[0]('asdf') + endfunc + let g:dict.foo = ['-', 2, 3] + call insert(g:dict.foo, function('strlen')) + call g:dict.func()]]) + expect('\ng:dict.func-4') + end) + + it("remove func from dict that's being called (works)", function() + source([[ + let d = {1:1} + func d.func(a) + return "a:". a:a + endfunc + $put =d.func(string(remove(d, 'func')))]]) + -- The function number changed from 3 to 1 because we split the test. + -- There were two other functions in the old test before this. + expect("\na:function('1')") + end) + + it('deepcopy() dict that refers to itself', function() + -- Nasty: deepcopy() dict that refers to itself (fails when noref used). + source([[ + let d = {1:1, 2:2} + let l = [4, d, 6] + let d[3] = l + let dc = deepcopy(d) + try + let dc = deepcopy(d, 1) + catch + $put =v:exception[:14] + endtry + let l2 = [0, l, l, 3] + let l[1] = l2 + let l3 = deepcopy(l2) + $put ='same list: ' . (l3[1] is l3[2])]]) + expect([[ + + Vim(let):E698: + same list: 1]]) + end) + + it('locked variables (part 1)', function() + source([=[ + let l = [] + for depth in range(5) + $put ='depth is ' . depth + for u in range(3) + unlet l + let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] + exe "lockvar " . depth . " l" + if u == 1 + exe "unlockvar l" + elseif u == 2 + exe "unlockvar " . depth . " l" + endif + let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . + \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . + \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") + $put =ps + let ps = '' + try + let l[1][1][0] = 99 + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[1][1] = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[1] = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2]['6'][7] = 99 + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2][6] = {99: 99} + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2] = {99: 99} + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + $put =ps + endfor + endfor]=]) + expect([[ + + depth is 0 + 0000-000 + ppppppp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 1 + 1000-000 + ppppppF + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 2 + 1100-100 + ppFppFF + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 3 + 1110-110 + pFFpFFF + 0010-010 + pFppFpp + 0000-000 + ppppppp + depth is 4 + 1111-111 + FFFFFFF + 0011-011 + FFpFFpp + 0000-000 + ppppppp]]) + end) + + -- TODO In the original test the 5th line of this source() call was used. + -- But now the test only passes if I comment it. + it('unletting locked variables', function() + source([=[ + let l = [] + for depth in range(5) + $put ='depth is ' . depth + for u in range(3) + "unlet l + let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] + exe "lockvar " . depth . " l" + if u == 1 + exe "unlockvar l" + elseif u == 2 + exe "unlockvar " . depth . " l" + endif + let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . + \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . + \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") + $put =ps + let ps = '' + try + unlet l[2]['6'][7] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[2][6] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[2] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1][1][0] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1][1] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l + let ps .= 'p' + catch + let ps .= 'F' + endtry + $put =ps + endfor + endfor]=]) + expect([[ + + depth is 0 + 0000-000 + ppppppp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 1 + 1000-000 + ppFppFp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 2 + 1100-100 + pFFpFFp + 0000-000 + ppppppp + 0000-000 + ppppppp + depth is 3 + 1110-110 + FFFFFFp + 0010-010 + FppFppp + 0000-000 + ppppppp + depth is 4 + 1111-111 + FFFFFFp + 0011-011 + FppFppp + 0000-000 + ppppppp]]) + end) + + it('locked variables and :unlet or list / dict functions', function() + source([[ + $put ='Locks and commands or functions:' + + $put ='No :unlet after lock on dict:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar 1 d + try + unlet d.a + $put ='did :unlet' + catch + $put =v:exception[:16] + endtry + $put =string(d) + + $put =':unlet after lock on dict item:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + try + unlet d.a + $put ='did :unlet' + catch + $put =v:exception[:16] + endtry + $put =string(d) + + $put ='filter() after lock on dict item:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + try + call filter(d, 'v:key != "a"') + $put ='did filter()' + catch + $put =v:exception[:16] + endtry + $put =string(d) + + $put ='map() after lock on dict:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar 1 d + try + call map(d, 'v:val + 200') + $put ='did map()' + catch + $put =v:exception[:16] + endtry + $put =string(d) + + $put ='No extend() after lock on dict item:' + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + try + $put =string(extend(d, {'a': 123})) + $put ='did extend()' + catch + $put =v:exception[:14] + endtry + $put =string(d) + + $put ='No remove() of write-protected scope-level variable:' + fun! Tfunc(this_is_a_loooooooooong_parameter_name) + try + $put =string(remove(a:, 'this_is_a_loooooooooong_parameter_name')) + $put ='did remove()' + catch + $put =v:exception[:14] + endtry + endfun + call Tfunc('testval') + + $put ='No extend() of write-protected scope-level variable:' + fun! Tfunc(this_is_a_loooooooooong_parameter_name) + try + $put =string(extend(a:, {'this_is_a_loooooooooong_parameter_name': 1234})) + $put ='did extend()' + catch + $put =v:exception[:14] + endtry + endfun + call Tfunc('testval') + + $put ='No :unlet of variable in locked scope:' + let b:testvar = 123 + lockvar 1 b: + try + unlet b:testvar + $put ='b:testvar was :unlet: '. (!exists('b:testvar')) + catch + $put =v:exception[:16] + endtry + unlockvar 1 b: + unlet! b:testvar + + $put ='No :let += of locked list variable:' + let l = ['a', 'b', 3] + lockvar 1 l + try + let l += ['x'] + $put ='did :let +=' + catch + $put =v:exception[:14] + endtry + $put =string(l)]]) + + expect([=[ + + Locks and commands or functions: + No :unlet after lock on dict: + Vim(unlet):E741: + {'a': 99, 'b': 100} + :unlet after lock on dict item: + did :unlet + {'b': 100} + filter() after lock on dict item: + did filter() + {'b': 100} + map() after lock on dict: + did map() + {'a': 299, 'b': 300} + No extend() after lock on dict item: + Vim(put):E741: + {'a': 99, 'b': 100} + No remove() of write-protected scope-level variable: + Vim(put):E795: + No extend() of write-protected scope-level variable: + Vim(put):E742: + No :unlet of variable in locked scope: + Vim(unlet):E741: + No :let += of locked list variable: + Vim(let):E741: + ['a', 'b', 3]]=]) + end) + + it('locked variables (part 2)', function() + execute( + 'let l = [1, 2, 3, 4]', + 'lockvar! l', + '$put =string(l)', + 'unlockvar l[1]', + 'unlet l[0:1]', + '$put =string(l)', + 'unlet l[1:2]', + '$put =string(l)', + 'unlockvar l[1]', + 'let l[0:1] = [0, 1]', + '$put =string(l)', + 'let l[1:2] = [0, 1]', + '$put =string(l)') + expect([=[ + + [1, 2, 3, 4] + [1, 2, 3, 4] + [1, 2, 3, 4] + [1, 2, 3, 4] + [1, 2, 3, 4]]=]) + end) + + it(':lockvar/islocked() triggering script autoloading.', function() + source([[ + set rtp+=test/functional/fixtures + lockvar g:footest#x + unlockvar g:footest#x + $put ='locked g:footest#x:'.islocked('g:footest#x') + $put ='exists g:footest#x:'.exists('g:footest#x') + $put ='g:footest#x: '.g:footest#x]]) + expect([[ + + locked g:footest#x:-1 + exists g:footest#x:0 + g:footest#x: 1]]) + end) + + it('a:000 function argument', function() + source([[ + function Test(...) + " First the tests that should fail. + try + let a:000 = [1, 2] + catch + $put ='caught a:000' + endtry + try + let a:000[0] = 9 + catch + $put ='caught a:000[0]' + endtry + try + let a:000[2] = [9, 10] + catch + $put ='caught a:000[2]' + endtry + try + let a:000[3] = {9: 10} + catch + $put ='caught a:000[3]' + endtry + " Now the tests that should pass. + try + let a:000[2][1] = 9 + call extend(a:000[2], [5, 6]) + let a:000[3][5] = 8 + let a:000[3]['a'] = 12 + $put =string(a:000) + catch + $put ='caught ' . v:exception + endtry + endfunction]]) + execute('call Test(1, 2, [3, 4], {5: 6})') + expect([=[ + + caught a:000 + caught a:000[0] + caught a:000[2] + caught a:000[3] + [1, 2, [3, 9, 5, 6], {'a': 12, '5': 8}]]=]) + end) + + it('reverse(), sort(), uniq()', function() + source([=[ + let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', + \ [0, 1, 2], 'x8', [0, 1, 2], 1.5] + $put =string(uniq(copy(l))) + $put =string(reverse(l)) + $put =string(reverse(reverse(l))) + $put =string(sort(l)) + $put =string(reverse(sort(l))) + $put =string(sort(reverse(sort(l)))) + $put =string(uniq(sort(l))) + let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, + \ 0.22, 'four'] + $put =string(sort(copy(l), 'n')) + let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', + \ 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []] + $put =string(sort(copy(l), 1)) + $put =string(sort(copy(l), 'i')) + $put =string(sort(copy(l)))]=]) + expect([=[ + + ['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5] + [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] + [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] + ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]] + [[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'] + ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]] + ['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]] + [-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255] + ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] + ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] + ['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]]=]) + end) + + it('splitting a string to a list', function() + source([[ + $put =string(split(' aa bb ')) + $put =string(split(' aa bb ', '\W\+', 0)) + $put =string(split(' aa bb ', '\W\+', 1)) + $put =string(split(' aa bb ', '\W', 1)) + $put =string(split(':aa::bb:', ':', 0)) + $put =string(split(':aa::bb:', ':', 1)) + $put =string(split('aa,,bb, cc,', ',\s*', 1)) + $put =string(split('abc', '\zs')) + $put =string(split('abc', '\zs', 1))]]) + expect([=[ + + ['aa', 'bb'] + ['aa', 'bb'] + ['', 'aa', 'bb', ''] + ['', '', 'aa', '', 'bb', '', ''] + ['aa', '', 'bb'] + ['', 'aa', '', 'bb', ''] + ['aa', '', 'bb', 'cc', ''] + ['a', 'b', 'c'] + ['', 'a', '', 'b', '', 'c', '']]=]) + end) + + it('compare recursively linked list and dict', function() + source([[ + let l = [1, 2, 3, 4] + let d = {'1': 1, '2': l, '3': 3} + let l[1] = d + $put =(l == l) + $put =(d == d) + $put =(l != deepcopy(l)) + $put =(d != deepcopy(d))]]) + expect([[ + + 1 + 1 + 0 + 0]]) + end) + + it('compare complex recursively linked list and dict', function() + source([[ + let l = [] + call add(l, l) + let dict4 = {"l": l} + call add(dict4.l, dict4) + let lcopy = deepcopy(l) + let dict4copy = deepcopy(dict4) + $put =(l == lcopy) + $put =(dict4 == dict4copy)]]) + expect([[ + + 1 + 1]]) + end) + + it('pass the same list to extend()', function() + source([[ + let l = [1, 2, 3, 4, 5] + call extend(l, l) + $put =string(l)]]) + expect([=[ + + [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]]=]) + end) + + it('pass the same dict to extend()', function() + source([[ + let d = { 'a': {'b': 'B'}} + call extend(d, d) + $put =string(d)]]) + expect([[ + + {'a': {'b': 'B'}}]]) + end) + + it('pass the same dict to extend() with "error"', function() + source([[ + " Copy dict from previous test. + let d = { 'a': {'b': 'B'}} + try + call extend(d, d, "error") + catch + $put =v:exception[:15] . v:exception[-1:-1] + endtry + $put =string(d)]]) + expect([[ + + Vim(call):E737: a + {'a': {'b': 'B'}}]]) + end) + + it('test for range assign', function() + source([[ + let l = [0] + let l[:] = [1, 2] + $put =string(l)]]) + expect([=[ + + [1, 2]]=]) + end) + + it('vim patch 7.3.637', function() + execute('let a = "No error caught"') + execute('try') + execute(' foldopen') + execute('catch') + execute(" let a = matchstr(v:exception,'^[^ ]*')") + execute('endtry') + feed('o=a') + execute('lang C') + execute('redir => a') + -- The test failes if this is not in one line. + execute("try|foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry") + execute('redir END') + feed('o=a') + expect([[ + + Vim(foldopen):E490: + + + Error detected while processing : + E492: Not an editor command: foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry + ]]) + end) +end) diff --git a/test/functional/legacy/055_spec.lua b/test/functional/legacy/055_spec.lua deleted file mode 100644 index bfabea20fa..0000000000 --- a/test/functional/legacy/055_spec.lua +++ /dev/null @@ -1,949 +0,0 @@ --- Tests for List and Dictionary types. - -local helpers = require('test.functional.helpers') -local feed, insert, source = helpers.feed, helpers.insert, helpers.source -local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect - -describe('55', function() - before_each(clear) - - it('creating list directly with different types', function() - source([[ - lang C - let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] - $put =string(l) - $put =string(l[-1]) - $put =string(l[-4]) - try - $put =string(l[-5]) - catch - $put =v:exception[:14] - endtry]]) - expect([[ - - [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] - {'a': 1} - 1 - Vim(put):E684: ]]) - end) - - it('list slices', function() - source([[ - lang C - " The list from the first test repeated after splitting the tests. - let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] - $put =string(l[:]) - $put =string(l[1:]) - $put =string(l[:-2]) - $put =string(l[0:8]) - $put =string(l[8:-1])]]) - expect([=[ - - [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] - ['as''d', [1, 2, function('strlen')], {'a': 1}] - [1, 'as''d', [1, 2, function('strlen')]] - [1, 'as''d', [1, 2, function('strlen')], {'a': 1}] - []]=]) - end) - - it('list identity', function() - source([[ - lang C - " The list from the first test repeated after splitting the tests. - let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] - let ll = l - let lx = copy(l) - try - $put =(l == ll) . (l isnot ll) . (l is ll) . (l == lx) . - \ (l is lx) . (l isnot lx) - catch - $put =v:exception - endtry]]) - expect('\n101101') - end) - - it('creating dictionary directly with different types', function() - source([[ - lang C - let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} - $put =string(d) . d.1 - $put =string(sort(keys(d))) - $put =string (values(d)) - for [key, val] in items(d) - $put =key . ':' . string(val) - unlet key val - endfor - call extend (d, {3:33, 1:99}) - call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") - try - call extend(d, {3:333,4:444}, "error") - catch - $put =v:exception[:15] . v:exception[-1:-1] - endtry - $put =string(d) - call filter(d, 'v:key =~ ''[ac391]''') - $put =string(d)]]) - expect([[ - - {'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}asd - ['-1', '1', 'b'] - ['asd', [1, 2, function('strlen')], {'a': 1}] - 1:'asd' - b:[1, 2, function('strlen')] - -1:{'a': 1} - Vim(call):E737: 3 - {'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}} - {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}]]) - end) - - it('dictionary identity', function() - source([[ - lang C - " The dict from the first test repeated after splitting the tests. - let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} - let dd = d - let dx = copy(d) - try - $put =(d == dd) . (d isnot dd) . (d is dd) . (d == dx) . (d is dx) . - \ (d isnot dx) - catch - $put =v:exception - endtry]]) - expect('\n101101') - end) - - it('changing var type should fail', function() - source([[ - lang C - " The list from the first test repeated after splitting the tests. - let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] - " The dict from the first test repeated after splitting the tests. - let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} - try - let d = [] - catch - $put =v:exception[:14] . v:exception[-1:-1] - endtry - try - let l = {} - catch - $put =v:exception[:14] . v:exception[-1:-1] - endtry]]) - expect([[ - - Vim(let):E706: d - Vim(let):E706: l]]) - end) - - it('removing items with :unlet', function() - source([[ - lang C - " The list from the first test repeated after splitting the tests. - let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] - " The dict from the first test repeated after splitting the tests. - let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} - unlet l[2] - $put =string(l) - let l = range(8) - try - unlet l[:3] - unlet l[1:] - catch - $put =v:exception - endtry - $put =string(l) - - unlet d.c - unlet d[-1] - $put =string(d)]]) - expect([[ - - [1, 'as''d', {'a': 1}] - [4] - {'1': 99, '3': 33}]]) - end) - - it("removing items out of range: silently skip items that don't exist", function() - -- We can not use source() here as we want to ignore all errors. - execute('lang C') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:1]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:3]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:4]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[2:5]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-1:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-2:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-3:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-4:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-5:2]') - execute('$put =string(l)') - execute('let l = [0, 1, 2, 3]') - execute('unlet l[-6:2]') - execute('$put =string(l)') - expect([=[ - - [0, 1, 2, 3] - [0, 1, 3] - [0, 1] - [0, 1] - [0, 1] - [0, 1, 2, 3] - [0, 1, 3] - [0, 3] - [3] - [3] - [3]]=]) - end) - - it('assignment to a list', function() - source([[ - let l = [0, 1, 2, 3] - let [va, vb] = l[2:3] - $put =va - $put =vb - try - let [va, vb] = l - catch - $put =v:exception[:14] - endtry - try - let [va, vb] = l[1:1] - catch - $put =v:exception[:14] - endtry]]) - expect([[ - - 2 - 3 - Vim(let):E687: - Vim(let):E688: ]]) - end) - - it('manipulating a big dictionary', function() - -- Manipulating a big Dictionary (hashtable.c has a border of 1000 - -- entries). - source([[ - let d = {} - for i in range(1500) - let d[i] = 3000 - i - endfor - $put =d[0] . ' ' . d[100] . ' ' . d[999] . ' ' . d[1400] . ' ' . - \ d[1499] - try - let n = d[1500] - catch - $put =substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '') - endtry - " Lookup each items. - for i in range(1500) - if d[i] != 3000 - i - $put =d[i] - endif - endfor - let i += 1 - " Delete even items. - while i >= 2 - let i -= 2 - unlet d[i] - endwhile - $put =get(d, 1500 - 100, 'NONE') . ' ' . d[1] - " Delete odd items, checking value, one intentionally wrong. - let d[33] = 999 - let i = 1 - while i < 1500 - if d[i] != 3000 - i - $put =i . '=' . d[i] - else - unlet d[i] - endif - let i += 2 - endwhile - " Must be almost empty now. - $put =string(d)]]) - expect([[ - - 3000 2900 2001 1600 1501 - Vim(let):E716: 1500 - NONE 2999 - 33=999 - {'33': 999}]]) - end) - - it('dictionary function', function() - source([[ - let dict = {} - func dict.func(a) dict - $put =a:a . len(self.data) - endfunc - let dict.data = [1,2,3] - call dict.func("len: ") - let x = dict.func("again: ") - try - let Fn = dict.func - call Fn('xxx') - catch - $put =v:exception[:15] - endtry]]) - expect([[ - - len: 3 - again: 3 - Vim(call):E725: ]]) - end) - - it('Function in script-local List or Dict', function() - source([[ - let g:dict = {} - function g:dict.func() dict - $put ='g:dict.func'.self.foo[1].self.foo[0]('asdf') - endfunc - let g:dict.foo = ['-', 2, 3] - call insert(g:dict.foo, function('strlen')) - call g:dict.func()]]) - expect('\ng:dict.func-4') - end) - - it("remove func from dict that's being called (works)", function() - source([[ - let d = {1:1} - func d.func(a) - return "a:". a:a - endfunc - $put =d.func(string(remove(d, 'func')))]]) - -- The function number changed from 3 to 1 because we split the test. - -- There were two other functions in the old test before this. - expect("\na:function('1')") - end) - - it('deepcopy() dict that refers to itself', function() - -- Nasty: deepcopy() dict that refers to itself (fails when noref used). - source([[ - let d = {1:1, 2:2} - let l = [4, d, 6] - let d[3] = l - let dc = deepcopy(d) - try - let dc = deepcopy(d, 1) - catch - $put =v:exception[:14] - endtry - let l2 = [0, l, l, 3] - let l[1] = l2 - let l3 = deepcopy(l2) - $put ='same list: ' . (l3[1] is l3[2])]]) - expect([[ - - Vim(let):E698: - same list: 1]]) - end) - - it('locked variables (part 1)', function() - source([=[ - let l = [] - for depth in range(5) - $put ='depth is ' . depth - for u in range(3) - unlet l - let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] - exe "lockvar " . depth . " l" - if u == 1 - exe "unlockvar l" - elseif u == 2 - exe "unlockvar " . depth . " l" - endif - let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . - \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . - \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") - $put =ps - let ps = '' - try - let l[1][1][0] = 99 - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[1][1] = [99] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[1] = [99] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[2]['6'][7] = 99 - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[2][6] = {99: 99} - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[2] = {99: 99} - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l = [99] - let ps .= 'p' - catch - let ps .= 'F' - endtry - $put =ps - endfor - endfor]=]) - expect([[ - - depth is 0 - 0000-000 - ppppppp - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 1 - 1000-000 - ppppppF - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 2 - 1100-100 - ppFppFF - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 3 - 1110-110 - pFFpFFF - 0010-010 - pFppFpp - 0000-000 - ppppppp - depth is 4 - 1111-111 - FFFFFFF - 0011-011 - FFpFFpp - 0000-000 - ppppppp]]) - end) - - -- TODO In the original test the 5th line of this source() call was used. - -- But now the test only passes if I comment it. - it('unletting locked variables', function() - source([=[ - let l = [] - for depth in range(5) - $put ='depth is ' . depth - for u in range(3) - "unlet l - let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] - exe "lockvar " . depth . " l" - if u == 1 - exe "unlockvar l" - elseif u == 2 - exe "unlockvar " . depth . " l" - endif - let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . - \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . - \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") - $put =ps - let ps = '' - try - unlet l[2]['6'][7] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - unlet l[2][6] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - unlet l[2] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - unlet l[1][1][0] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - unlet l[1][1] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - unlet l[1] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - unlet l - let ps .= 'p' - catch - let ps .= 'F' - endtry - $put =ps - endfor - endfor]=]) - expect([[ - - depth is 0 - 0000-000 - ppppppp - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 1 - 1000-000 - ppFppFp - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 2 - 1100-100 - pFFpFFp - 0000-000 - ppppppp - 0000-000 - ppppppp - depth is 3 - 1110-110 - FFFFFFp - 0010-010 - FppFppp - 0000-000 - ppppppp - depth is 4 - 1111-111 - FFFFFFp - 0011-011 - FppFppp - 0000-000 - ppppppp]]) - end) - - it('locked variables and :unlet or list / dict functions', function() - source([[ - $put ='Locks and commands or functions:' - - $put ='No :unlet after lock on dict:' - unlet! d - let d = {'a': 99, 'b': 100} - lockvar 1 d - try - unlet d.a - $put ='did :unlet' - catch - $put =v:exception[:16] - endtry - $put =string(d) - - $put =':unlet after lock on dict item:' - unlet! d - let d = {'a': 99, 'b': 100} - lockvar d.a - try - unlet d.a - $put ='did :unlet' - catch - $put =v:exception[:16] - endtry - $put =string(d) - - $put ='filter() after lock on dict item:' - unlet! d - let d = {'a': 99, 'b': 100} - lockvar d.a - try - call filter(d, 'v:key != "a"') - $put ='did filter()' - catch - $put =v:exception[:16] - endtry - $put =string(d) - - $put ='map() after lock on dict:' - unlet! d - let d = {'a': 99, 'b': 100} - lockvar 1 d - try - call map(d, 'v:val + 200') - $put ='did map()' - catch - $put =v:exception[:16] - endtry - $put =string(d) - - $put ='No extend() after lock on dict item:' - unlet! d - let d = {'a': 99, 'b': 100} - lockvar d.a - try - $put =string(extend(d, {'a': 123})) - $put ='did extend()' - catch - $put =v:exception[:14] - endtry - $put =string(d) - - $put ='No remove() of write-protected scope-level variable:' - fun! Tfunc(this_is_a_loooooooooong_parameter_name) - try - $put =string(remove(a:, 'this_is_a_loooooooooong_parameter_name')) - $put ='did remove()' - catch - $put =v:exception[:14] - endtry - endfun - call Tfunc('testval') - - $put ='No extend() of write-protected scope-level variable:' - fun! Tfunc(this_is_a_loooooooooong_parameter_name) - try - $put =string(extend(a:, {'this_is_a_loooooooooong_parameter_name': 1234})) - $put ='did extend()' - catch - $put =v:exception[:14] - endtry - endfun - call Tfunc('testval') - - $put ='No :unlet of variable in locked scope:' - let b:testvar = 123 - lockvar 1 b: - try - unlet b:testvar - $put ='b:testvar was :unlet: '. (!exists('b:testvar')) - catch - $put =v:exception[:16] - endtry - unlockvar 1 b: - unlet! b:testvar - - $put ='No :let += of locked list variable:' - let l = ['a', 'b', 3] - lockvar 1 l - try - let l += ['x'] - $put ='did :let +=' - catch - $put =v:exception[:14] - endtry - $put =string(l)]]) - - expect([=[ - - Locks and commands or functions: - No :unlet after lock on dict: - Vim(unlet):E741: - {'a': 99, 'b': 100} - :unlet after lock on dict item: - did :unlet - {'b': 100} - filter() after lock on dict item: - did filter() - {'b': 100} - map() after lock on dict: - did map() - {'a': 299, 'b': 300} - No extend() after lock on dict item: - Vim(put):E741: - {'a': 99, 'b': 100} - No remove() of write-protected scope-level variable: - Vim(put):E795: - No extend() of write-protected scope-level variable: - Vim(put):E742: - No :unlet of variable in locked scope: - Vim(unlet):E741: - No :let += of locked list variable: - Vim(let):E741: - ['a', 'b', 3]]=]) - end) - - it('locked variables (part 2)', function() - execute( - 'let l = [1, 2, 3, 4]', - 'lockvar! l', - '$put =string(l)', - 'unlockvar l[1]', - 'unlet l[0:1]', - '$put =string(l)', - 'unlet l[1:2]', - '$put =string(l)', - 'unlockvar l[1]', - 'let l[0:1] = [0, 1]', - '$put =string(l)', - 'let l[1:2] = [0, 1]', - '$put =string(l)') - expect([=[ - - [1, 2, 3, 4] - [1, 2, 3, 4] - [1, 2, 3, 4] - [1, 2, 3, 4] - [1, 2, 3, 4]]=]) - end) - - it(':lockvar/islocked() triggering script autoloading.', function() - source([[ - set rtp+=test/functional/fixtures - lockvar g:footest#x - unlockvar g:footest#x - $put ='locked g:footest#x:'.islocked('g:footest#x') - $put ='exists g:footest#x:'.exists('g:footest#x') - $put ='g:footest#x: '.g:footest#x]]) - expect([[ - - locked g:footest#x:-1 - exists g:footest#x:0 - g:footest#x: 1]]) - end) - - it('a:000 function argument', function() - source([[ - function Test(...) - " First the tests that should fail. - try - let a:000 = [1, 2] - catch - $put ='caught a:000' - endtry - try - let a:000[0] = 9 - catch - $put ='caught a:000[0]' - endtry - try - let a:000[2] = [9, 10] - catch - $put ='caught a:000[2]' - endtry - try - let a:000[3] = {9: 10} - catch - $put ='caught a:000[3]' - endtry - " Now the tests that should pass. - try - let a:000[2][1] = 9 - call extend(a:000[2], [5, 6]) - let a:000[3][5] = 8 - let a:000[3]['a'] = 12 - $put =string(a:000) - catch - $put ='caught ' . v:exception - endtry - endfunction]]) - execute('call Test(1, 2, [3, 4], {5: 6})') - expect([=[ - - caught a:000 - caught a:000[0] - caught a:000[2] - caught a:000[3] - [1, 2, [3, 9, 5, 6], {'a': 12, '5': 8}]]=]) - end) - - it('reverse(), sort(), uniq()', function() - source([=[ - let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', - \ [0, 1, 2], 'x8', [0, 1, 2], 1.5] - $put =string(uniq(copy(l))) - $put =string(reverse(l)) - $put =string(reverse(reverse(l))) - $put =string(sort(l)) - $put =string(reverse(sort(l))) - $put =string(sort(reverse(sort(l)))) - $put =string(uniq(sort(l))) - let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, - \ 0.22, 'four'] - $put =string(sort(copy(l), 'n')) - let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', - \ 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []] - $put =string(sort(copy(l), 1)) - $put =string(sort(copy(l), 'i')) - $put =string(sort(copy(l)))]=]) - expect([=[ - - ['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5] - [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] - [1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'] - ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]] - [[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'] - ['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]] - ['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]] - [-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255] - ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] - ['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}] - ['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]]=]) - end) - - it('splitting a string to a list', function() - source([[ - $put =string(split(' aa bb ')) - $put =string(split(' aa bb ', '\W\+', 0)) - $put =string(split(' aa bb ', '\W\+', 1)) - $put =string(split(' aa bb ', '\W', 1)) - $put =string(split(':aa::bb:', ':', 0)) - $put =string(split(':aa::bb:', ':', 1)) - $put =string(split('aa,,bb, cc,', ',\s*', 1)) - $put =string(split('abc', '\zs')) - $put =string(split('abc', '\zs', 1))]]) - expect([=[ - - ['aa', 'bb'] - ['aa', 'bb'] - ['', 'aa', 'bb', ''] - ['', '', 'aa', '', 'bb', '', ''] - ['aa', '', 'bb'] - ['', 'aa', '', 'bb', ''] - ['aa', '', 'bb', 'cc', ''] - ['a', 'b', 'c'] - ['', 'a', '', 'b', '', 'c', '']]=]) - end) - - it('compare recursively linked list and dict', function() - source([[ - let l = [1, 2, 3, 4] - let d = {'1': 1, '2': l, '3': 3} - let l[1] = d - $put =(l == l) - $put =(d == d) - $put =(l != deepcopy(l)) - $put =(d != deepcopy(d))]]) - expect([[ - - 1 - 1 - 0 - 0]]) - end) - - it('compare complex recursively linked list and dict', function() - source([[ - let l = [] - call add(l, l) - let dict4 = {"l": l} - call add(dict4.l, dict4) - let lcopy = deepcopy(l) - let dict4copy = deepcopy(dict4) - $put =(l == lcopy) - $put =(dict4 == dict4copy)]]) - expect([[ - - 1 - 1]]) - end) - - it('pass the same list to extend()', function() - source([[ - let l = [1, 2, 3, 4, 5] - call extend(l, l) - $put =string(l)]]) - expect([=[ - - [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]]=]) - end) - - it('pass the same dict to extend()', function() - source([[ - let d = { 'a': {'b': 'B'}} - call extend(d, d) - $put =string(d)]]) - expect([[ - - {'a': {'b': 'B'}}]]) - end) - - it('pass the same dict to extend() with "error"', function() - source([[ - " Copy dict from previous test. - let d = { 'a': {'b': 'B'}} - try - call extend(d, d, "error") - catch - $put =v:exception[:15] . v:exception[-1:-1] - endtry - $put =string(d)]]) - expect([[ - - Vim(call):E737: a - {'a': {'b': 'B'}}]]) - end) - - it('test for range assign', function() - source([[ - let l = [0] - let l[:] = [1, 2] - $put =string(l)]]) - expect([=[ - - [1, 2]]=]) - end) - - it('vim patch 7.3.637', function() - execute('let a = "No error caught"') - execute('try') - execute(' foldopen') - execute('catch') - execute(" let a = matchstr(v:exception,'^[^ ]*')") - execute('endtry') - feed('o=a') - execute('lang C') - execute('redir => a') - -- The test failes if this is not in one line. - execute("try|foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry") - execute('redir END') - feed('o=a') - expect([[ - - Vim(foldopen):E490: - - - Error detected while processing : - E492: Not an editor command: foobar|catch|let a = matchstr(v:exception,'^[^ ]*')|endtry - ]]) - end) -end) -- cgit From dfaf7204429bec44891ffc8fdcb145b7d3df4c6a Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Thu, 2 Jun 2016 22:07:34 +0200 Subject: Testlinting. --- test/functional/legacy/055_list_and_dict_types_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/legacy/055_list_and_dict_types_spec.lua b/test/functional/legacy/055_list_and_dict_types_spec.lua index 4b663be04c..c3237f9afa 100644 --- a/test/functional/legacy/055_list_and_dict_types_spec.lua +++ b/test/functional/legacy/055_list_and_dict_types_spec.lua @@ -1,7 +1,7 @@ -- Tests for List and Dictionary types. local helpers = require('test.functional.helpers') -local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local feed, source = helpers.feed, helpers.source local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect describe('list and dictionary types', function() -- cgit From 5a387dddc6a895668ba3d6e155e932b528c13684 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Thu, 2 Jun 2016 22:13:51 +0200 Subject: Fix indents. --- .../legacy/055_list_and_dict_types_spec.lua | 288 ++++++++++----------- 1 file changed, 144 insertions(+), 144 deletions(-) (limited to 'test') diff --git a/test/functional/legacy/055_list_and_dict_types_spec.lua b/test/functional/legacy/055_list_and_dict_types_spec.lua index c3237f9afa..ed4cd3401d 100644 --- a/test/functional/legacy/055_list_and_dict_types_spec.lua +++ b/test/functional/legacy/055_list_and_dict_types_spec.lua @@ -15,9 +15,9 @@ describe('list and dictionary types', function() $put =string(l[-1]) $put =string(l[-4]) try - $put =string(l[-5]) + $put =string(l[-5]) catch - $put =v:exception[:14] + $put =v:exception[:14] endtry]]) expect([[ @@ -54,10 +54,10 @@ describe('list and dictionary types', function() let ll = l let lx = copy(l) try - $put =(l == ll) . (l isnot ll) . (l is ll) . (l == lx) . - \ (l is lx) . (l isnot lx) + $put =(l == ll) . (l isnot ll) . (l is ll) . (l == lx) . + \ (l is lx) . (l isnot lx) catch - $put =v:exception + $put =v:exception endtry]]) expect('\n101101') end) @@ -70,15 +70,15 @@ describe('list and dictionary types', function() $put =string(sort(keys(d))) $put =string (values(d)) for [key, val] in items(d) - $put =key . ':' . string(val) - unlet key val + $put =key . ':' . string(val) + unlet key val endfor call extend (d, {3:33, 1:99}) call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") try - call extend(d, {3:333,4:444}, "error") + call extend(d, {3:333,4:444}, "error") catch - $put =v:exception[:15] . v:exception[-1:-1] + $put =v:exception[:15] . v:exception[-1:-1] endtry $put =string(d) call filter(d, 'v:key =~ ''[ac391]''') @@ -104,10 +104,10 @@ describe('list and dictionary types', function() let dd = d let dx = copy(d) try - $put =(d == dd) . (d isnot dd) . (d is dd) . (d == dx) . (d is dx) . - \ (d isnot dx) + $put =(d == dd) . (d isnot dd) . (d is dd) . (d == dx) . (d is dx) . + \ (d isnot dx) catch - $put =v:exception + $put =v:exception endtry]]) expect('\n101101') end) @@ -120,14 +120,14 @@ describe('list and dictionary types', function() " The dict from the first test repeated after splitting the tests. let d = {'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}} try - let d = [] + let d = [] catch - $put =v:exception[:14] . v:exception[-1:-1] + $put =v:exception[:14] . v:exception[-1:-1] endtry try - let l = {} + let l = {} catch - $put =v:exception[:14] . v:exception[-1:-1] + $put =v:exception[:14] . v:exception[-1:-1] endtry]]) expect([[ @@ -146,10 +146,10 @@ describe('list and dictionary types', function() $put =string(l) let l = range(8) try - unlet l[:3] - unlet l[1:] + unlet l[:3] + unlet l[1:] catch - $put =v:exception + $put =v:exception endtry $put =string(l) @@ -221,14 +221,14 @@ describe('list and dictionary types', function() $put =va $put =vb try - let [va, vb] = l + let [va, vb] = l catch - $put =v:exception[:14] + $put =v:exception[:14] endtry try - let [va, vb] = l[1:1] + let [va, vb] = l[1:1] catch - $put =v:exception[:14] + $put =v:exception[:14] endtry]]) expect([[ @@ -244,38 +244,38 @@ describe('list and dictionary types', function() source([[ let d = {} for i in range(1500) - let d[i] = 3000 - i + let d[i] = 3000 - i endfor $put =d[0] . ' ' . d[100] . ' ' . d[999] . ' ' . d[1400] . ' ' . - \ d[1499] + \ d[1499] try - let n = d[1500] + let n = d[1500] catch - $put =substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '') + $put =substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '') endtry " Lookup each items. for i in range(1500) - if d[i] != 3000 - i - $put =d[i] - endif + if d[i] != 3000 - i + $put =d[i] + endif endfor let i += 1 " Delete even items. while i >= 2 - let i -= 2 - unlet d[i] + let i -= 2 + unlet d[i] endwhile $put =get(d, 1500 - 100, 'NONE') . ' ' . d[1] " Delete odd items, checking value, one intentionally wrong. let d[33] = 999 let i = 1 while i < 1500 - if d[i] != 3000 - i - $put =i . '=' . d[i] - else - unlet d[i] - endif - let i += 2 + if d[i] != 3000 - i + $put =i . '=' . d[i] + else + unlet d[i] + endif + let i += 2 endwhile " Must be almost empty now. $put =string(d)]]) @@ -292,16 +292,16 @@ describe('list and dictionary types', function() source([[ let dict = {} func dict.func(a) dict - $put =a:a . len(self.data) + $put =a:a . len(self.data) endfunc let dict.data = [1,2,3] call dict.func("len: ") let x = dict.func("again: ") try - let Fn = dict.func - call Fn('xxx') + let Fn = dict.func + call Fn('xxx') catch - $put =v:exception[:15] + $put =v:exception[:15] endtry]]) expect([[ @@ -314,7 +314,7 @@ describe('list and dictionary types', function() source([[ let g:dict = {} function g:dict.func() dict - $put ='g:dict.func'.self.foo[1].self.foo[0]('asdf') + $put ='g:dict.func'.self.foo[1].self.foo[0]('asdf') endfunc let g:dict.foo = ['-', 2, 3] call insert(g:dict.foo, function('strlen')) @@ -326,7 +326,7 @@ describe('list and dictionary types', function() source([[ let d = {1:1} func d.func(a) - return "a:". a:a + return "a:". a:a endfunc $put =d.func(string(remove(d, 'func')))]]) -- The function number changed from 3 to 1 because we split the test. @@ -342,9 +342,9 @@ describe('list and dictionary types', function() let d[3] = l let dc = deepcopy(d) try - let dc = deepcopy(d, 1) - catch - $put =v:exception[:14] + let dc = deepcopy(d, 1) + catch + $put =v:exception[:14] endtry let l2 = [0, l, l, 3] let l[1] = l2 @@ -360,65 +360,65 @@ describe('list and dictionary types', function() source([=[ let l = [] for depth in range(5) - $put ='depth is ' . depth - for u in range(3) - unlet l - let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] - exe "lockvar " . depth . " l" - if u == 1 - exe "unlockvar l" - elseif u == 2 - exe "unlockvar " . depth . " l" - endif - let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . - \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . - \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") - $put =ps - let ps = '' - try - let l[1][1][0] = 99 - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[1][1] = [99] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[1] = [99] - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[2]['6'][7] = 99 - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[2][6] = {99: 99} - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l[2] = {99: 99} - let ps .= 'p' - catch - let ps .= 'F' - endtry - try - let l = [99] - let ps .= 'p' - catch - let ps .= 'F' - endtry - $put =ps - endfor + $put ='depth is ' . depth + for u in range(3) + unlet l + let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] + exe "lockvar " . depth . " l" + if u == 1 + exe "unlockvar l" + elseif u == 2 + exe "unlockvar " . depth . " l" + endif + let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . + \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . + \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") + $put =ps + let ps = '' + try + let l[1][1][0] = 99 + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[1][1] = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[1] = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2]['6'][7] = 99 + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2][6] = {99: 99} + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2] = {99: 99} + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + $put =ps + endfor endfor]=]) expect([[ @@ -476,8 +476,8 @@ describe('list and dictionary types', function() exe "unlockvar " . depth . " l" endif let ps = islocked("l") . islocked("l[1]") . islocked("l[1][1]") . - \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . - \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") + \ islocked("l[1][1][0]") . '-' . islocked("l[2]") . + \ islocked("l[2]['6']") . islocked("l[2]['6'][7]") $put =ps let ps = '' try @@ -744,37 +744,37 @@ describe('list and dictionary types', function() it('a:000 function argument', function() source([[ function Test(...) - " First the tests that should fail. - try - let a:000 = [1, 2] - catch - $put ='caught a:000' - endtry - try - let a:000[0] = 9 - catch - $put ='caught a:000[0]' - endtry - try - let a:000[2] = [9, 10] - catch - $put ='caught a:000[2]' - endtry - try - let a:000[3] = {9: 10} - catch - $put ='caught a:000[3]' - endtry - " Now the tests that should pass. - try - let a:000[2][1] = 9 - call extend(a:000[2], [5, 6]) - let a:000[3][5] = 8 - let a:000[3]['a'] = 12 - $put =string(a:000) - catch - $put ='caught ' . v:exception - endtry + " First the tests that should fail. + try + let a:000 = [1, 2] + catch + $put ='caught a:000' + endtry + try + let a:000[0] = 9 + catch + $put ='caught a:000[0]' + endtry + try + let a:000[2] = [9, 10] + catch + $put ='caught a:000[2]' + endtry + try + let a:000[3] = {9: 10} + catch + $put ='caught a:000[3]' + endtry + " Now the tests that should pass. + try + let a:000[2][1] = 9 + call extend(a:000[2], [5, 6]) + let a:000[3][5] = 8 + let a:000[3]['a'] = 12 + $put =string(a:000) + catch + $put ='caught ' . v:exception + endtry endfunction]]) execute('call Test(1, 2, [3, 4], {5: 6})') expect([=[ @@ -789,7 +789,7 @@ describe('list and dictionary types', function() it('reverse(), sort(), uniq()', function() source([=[ let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', - \ [0, 1, 2], 'x8', [0, 1, 2], 1.5] + \ [0, 1, 2], 'x8', [0, 1, 2], 1.5] $put =string(uniq(copy(l))) $put =string(reverse(l)) $put =string(reverse(reverse(l))) @@ -798,10 +798,10 @@ describe('list and dictionary types', function() $put =string(sort(reverse(sort(l)))) $put =string(uniq(sort(l))) let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, - \ 0.22, 'four'] + \ 0.22, 'four'] $put =string(sort(copy(l), 'n')) let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', - \ 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []] + \ 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []] $put =string(sort(copy(l), 1)) $put =string(sort(copy(l), 'i')) $put =string(sort(copy(l)))]=]) @@ -902,9 +902,9 @@ describe('list and dictionary types', function() " Copy dict from previous test. let d = { 'a': {'b': 'B'}} try - call extend(d, d, "error") + call extend(d, d, "error") catch - $put =v:exception[:15] . v:exception[-1:-1] + $put =v:exception[:15] . v:exception[-1:-1] endtry $put =string(d)]]) expect([[ -- cgit