3452
|
1 Test for Lua interface and luaeval() function
|
|
2
|
|
3 STARTTEST
|
|
4 :so small.vim
|
|
5 :so lua.vim
|
|
6 :set nocompatible viminfo+=nviminfo
|
|
7 :lua l = vim.list():add"item0":add"dictionary with list OK":add"item2"
|
|
8 :lua h = vim.dict(); h.list = l
|
|
9 :call garbagecollect()
|
|
10 /^1
|
|
11 :" change buffer contents
|
|
12 :lua curbuf = vim.buffer()
|
|
13 :lua curline = vim.eval"line('.')"
|
|
14 :lua curbuf[curline] = "1 changed line 1"
|
|
15 :" scalar test
|
|
16 :let tmp_string = luaeval('"string"')
|
|
17 :let tmp_1000 = luaeval('1000')
|
|
18 :if printf("%s%.0f", tmp_string, tmp_1000) == "string1000"
|
|
19 :let scalar_res = "OK"
|
|
20 :else
|
|
21 :let scalar_res = "FAILED"
|
|
22 :endif
|
|
23 :call append(search("^1"), "scalar test " . scalar_res)
|
|
24 :" dictionary containing a list
|
|
25 :let tmp = luaeval("h").list[1]
|
|
26 :/^2/put =tmp
|
|
27 :" circular list (at the same time test lists containing lists)
|
|
28 :lua l[2] = l
|
|
29 :let l2 = luaeval("h").list
|
|
30 :if l2[2] == l2
|
|
31 :let res = "OK"
|
|
32 :else
|
|
33 :let res = "FAILED"
|
|
34 :endif
|
|
35 :call setline(search("^3"), "circular test " . res)
|
4293
|
36
|
|
37 :let l = []
|
|
38 :lua l = vim.eval("l")
|
|
39 :lua l:add(123)
|
|
40 :lua l:add("abc")
|
|
41 :lua l:add(vim.eval("[1, 2, 3]"))
|
|
42 :lua l:add(vim.eval("{'a':1, 'b':2, 'c':3}"))
|
|
43 :lua l:insert(123)
|
|
44 :lua l:insert("abc")
|
|
45 :lua l:insert(vim.eval("[1, 2, 3]"))
|
|
46 :lua l:insert(vim.eval("{'a':1, 'b':2, 'c':3}"))
|
|
47 :lua l[0] = l[0]
|
|
48 :lua l[1] = l[1]
|
|
49 :lua l[2] = l[2]
|
|
50 :lua l[3] = l[3]
|
|
51 :lua l[0] = 123
|
|
52 :lua l[1] = "abc"
|
|
53 :lua l[2] = vim.eval("[1, 2, 3]")
|
|
54 :lua l[3] = vim.eval("{'a':1, 'b':2, 'c':3}")
|
|
55 :lua l[3] = nil
|
|
56 :lua l[2] = nil
|
|
57 :lua l[1] = nil
|
|
58 :lua l[0] = nil
|
|
59 :lua l = nil
|
|
60 :$put =string(l)
|
|
61
|
|
62 :let d = {}
|
|
63 :lua d = vim.eval("d")
|
|
64 :lua d[0] = 123
|
|
65 :lua d[1] = "abc"
|
|
66 :lua d[2] = vim.eval("[1, 2, 3]")
|
|
67 :lua d[3] = vim.eval("{'a':1, 'b':2, 'c':3}")
|
|
68 :lua d[4] = d[0]
|
|
69 :lua d[5] = d[1]
|
|
70 :lua d[6] = d[2]
|
|
71 :lua d[7] = d[3]
|
|
72 :lua d[3] = nil
|
|
73 :lua d[2] = nil
|
|
74 :lua d[1] = nil
|
|
75 :lua d[0] = nil
|
|
76 :lua d = nil
|
|
77 :$put =string(d)
|
|
78
|
3452
|
79 :?^1?,$w! test.out
|
|
80 :qa!
|
|
81 ENDTEST
|
|
82
|
|
83 1 line 1
|
|
84 2 line 2
|
|
85 3 line 3
|