annotate src/testdir/test_lua.vim @ 23452:8fa9d31cd248 v8.2.2269

patch 8.2.2269: not all :hardcopy code covered by tests Commit: https://github.com/vim/vim/commit/edc10b541b468f5f5aa2e2d5ef58a3e17e043bff Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 1 21:34:37 2021 +0100 patch 8.2.2269: not all :hardcopy code covered by tests Problem: Not all :hardcopy code covered by tests. Solution: Test more combinations. (Dominique Pell?, closes https://github.com/vim/vim/issues/7595)
author Bram Moolenaar <Bram@vim.org>
date Fri, 01 Jan 2021 21:45:04 +0100
parents 8da5e18effc5
children c424821dc031
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for Lua.
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
17089
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
3 source check.vim
22719
8da5e18effc5 patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents: 21283
diff changeset
4
8da5e18effc5 patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents: 21283
diff changeset
5 " This test also works without the lua feature.
8da5e18effc5 patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents: 21283
diff changeset
6 func Test_skip_lua()
8da5e18effc5 patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents: 21283
diff changeset
7 if 0
8da5e18effc5 patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents: 21283
diff changeset
8 lua print("Not executed")
8da5e18effc5 patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents: 21283
diff changeset
9 endif
8da5e18effc5 patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents: 21283
diff changeset
10 endfunc
8da5e18effc5 patch 8.2.1908: Lua is initialized even when not used
Bram Moolenaar <Bram@vim.org>
parents: 21283
diff changeset
11
17089
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
12 CheckFeature lua
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
13 CheckFeature float
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
15 let s:luaver = split(split(luaeval('_VERSION'), ' ')[1], '\.')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
16 let s:major = str2nr(s:luaver[0])
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
17 let s:minor = str2nr(s:luaver[1])
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
18 if s:major < 5 || (s:major == 5 && s:minor < 3)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
19 let s:lua_53_or_later = 0
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
20 else
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
21 let s:lua_53_or_later = 1
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
22 endif
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
23
15997
725255793949 patch 8.1.1004: function "luaV_setref()" not covered with tests
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
24 func TearDown()
725255793949 patch 8.1.1004: function "luaV_setref()" not covered with tests
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
25 " Run garbage collection after each test to exercise luaV_setref().
725255793949 patch 8.1.1004: function "luaV_setref()" not covered with tests
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
26 call test_garbagecollect_now()
725255793949 patch 8.1.1004: function "luaV_setref()" not covered with tests
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
27 endfunc
725255793949 patch 8.1.1004: function "luaV_setref()" not covered with tests
Bram Moolenaar <Bram@vim.org>
parents: 15328
diff changeset
28
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
29 " Check that switching to another buffer does not trigger ml_get error.
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
30 func Test_lua_command_new_no_ml_get_error()
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 new
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 let wincount = winnr('$')
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call setline(1, ['one', 'two', 'three'])
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 luado vim.command("new")
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 call assert_equal(wincount + 1, winnr('$'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
36 %bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
37 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
38
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
39 " Test vim.command()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
40 func Test_lua_command()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
41 new
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
42 call setline(1, ['one', 'two', 'three'])
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
43 luado vim.command("1,2d_")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
44 call assert_equal(['three'], getline(1, '$'))
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 bwipe!
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
46 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
47
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
48 func Test_lua_luado()
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
49 new
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
50 call setline(1, ['one', 'two'])
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
51 luado return(linenr)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
52 call assert_equal(['1', '2'], getline(1, '$'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
53 close!
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
54
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
55 " Error cases
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
56 call assert_fails('luado string.format()',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
57 \ "[string \"vim chunk\"]:1: bad argument #1 to 'format' (string expected, got no value)")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
58 call assert_fails('luado func()',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
59 \ s:lua_53_or_later
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
60 \ ? "[string \"vim chunk\"]:1: attempt to call a nil value (global 'func')"
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
61 \ : "[string \"vim chunk\"]:1: attempt to call global 'func' (a nil value)")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
62 call assert_fails('luado error("failed")', "[string \"vim chunk\"]:1: failed")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
63 endfunc
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
64
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
65 " Test vim.eval()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
66 func Test_lua_eval()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
67 " lua.eval with a number
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
68 lua v = vim.eval('123')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
69 call assert_equal('number', luaeval('vim.type(v)'))
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
70 call assert_equal(123, luaeval('v'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
71
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
72 " lua.eval with a string
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
73 lua v = vim.eval('"abc"')
17916
2e53305f2239 patch 8.1.1954: more functions can be used as a method
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
74 call assert_equal('string', 'vim.type(v)'->luaeval())
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
75 call assert_equal('abc', luaeval('v'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
76
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
77 " lua.eval with a list
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
78 lua v = vim.eval("['a']")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
79 call assert_equal('list', luaeval('vim.type(v)'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
80 call assert_equal(['a'], luaeval('v'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
81
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
82 " lua.eval with a dict
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
83 lua v = vim.eval("{'a':'b'}")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
84 call assert_equal('dict', luaeval('vim.type(v)'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
85 call assert_equal({'a':'b'}, luaeval('v'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
86
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
87 " lua.eval with a blob
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
88 lua v = vim.eval("0z00112233.deadbeef")
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
89 call assert_equal('blob', luaeval('vim.type(v)'))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
90 call assert_equal(0z00112233.deadbeef, luaeval('v'))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
91
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
92 " lua.eval with a float
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
93 lua v = vim.eval('3.14')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
94 call assert_equal('number', luaeval('vim.type(v)'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
95 call assert_equal(3.14, luaeval('v'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
96
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
97 " lua.eval with a bool
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
98 lua v = vim.eval('v:true')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
99 call assert_equal('number', luaeval('vim.type(v)'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
100 call assert_equal(1, luaeval('v'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
101 lua v = vim.eval('v:false')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
102 call assert_equal('number', luaeval('vim.type(v)'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
103 call assert_equal(0, luaeval('v'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
104
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
105 " lua.eval with a null
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
106 lua v = vim.eval('v:null')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
107 call assert_equal('nil', luaeval('vim.type(v)'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
108 call assert_equal(v:null, luaeval('v'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
109
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
110 call assert_fails('lua v = vim.eval(nil)',
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
111 \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got nil)")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
112 call assert_fails('lua v = vim.eval(true)',
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
113 \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got boolean)")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
114 call assert_fails('lua v = vim.eval({})',
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
115 \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got table)")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
116 call assert_fails('lua v = vim.eval(print)',
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
117 \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got function)")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
118 call assert_fails('lua v = vim.eval(vim.buffer())',
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
119 \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got userdata)")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
120
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
121 lua v = nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
122 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
123
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
124 " Test vim.window()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
125 func Test_lua_window()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
126 e Xfoo2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
127 new Xfoo1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
128
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
129 " Window 1 (top window) contains Xfoo1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
130 " Window 2 (bottom window) contains Xfoo2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
131 call assert_equal('Xfoo1', luaeval('vim.window(1):buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
132 call assert_equal('Xfoo2', luaeval('vim.window(2):buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
133
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
134 " Window 3 does not exist so vim.window(3) should return nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
135 call assert_equal('nil', luaeval('tostring(vim.window(3))'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
136
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
137 call assert_fails("let n = luaeval('vim.window().xyz()')",
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
138 \ s:lua_53_or_later
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
139 \ ? "[string \"luaeval\"]:1: attempt to call a nil value (field 'xyz')"
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
140 \ : "[string \"luaeval\"]:1: attempt to call field 'xyz' (a nil value)")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
141 call assert_fails('lua vim.window().xyz = 1',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
142 \ "[string \"vim chunk\"]:1: invalid window property: `xyz'")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
143
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
144 %bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
145 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
146
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
147 " Test vim.window().height
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
148 func Test_lua_window_height()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
149 new
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
150 lua vim.window().height = 2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
151 call assert_equal(2, winheight(0))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
152 lua vim.window().height = vim.window().height + 1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
153 call assert_equal(3, winheight(0))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
154 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
155 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
156
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
157 " Test vim.window().width
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
158 func Test_lua_window_width()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
159 vert new
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
160 lua vim.window().width = 2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
161 call assert_equal(2, winwidth(0))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
162 lua vim.window().width = vim.window().width + 1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
163 call assert_equal(3, winwidth(0))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
164 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
165 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
166
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
167 " Test vim.window().line and vim.window.col
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
168 func Test_lua_window_line_col()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
169 new
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
170 call setline(1, ['line1', 'line2', 'line3'])
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
171 lua vim.window().line = 2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
172 lua vim.window().col = 4
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
173 call assert_equal([0, 2, 4, 0], getpos('.'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
174 lua vim.window().line = vim.window().line + 1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
175 lua vim.window().col = vim.window().col - 1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
176 call assert_equal([0, 3, 3, 0], getpos('.'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
177
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
178 call assert_fails('lua vim.window().line = 10',
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
179 \ '[string "vim chunk"]:1: line out of range')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
180 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
181 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
182
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
183 " Test vim.call
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
184 func Test_lua_call()
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
185 call assert_equal(has('lua'), luaeval('vim.call("has", "lua")'))
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
186 call assert_equal(printf("Hello %s", "vim"), luaeval('vim.call("printf", "Hello %s", "vim")'))
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
187
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
188 " Error cases
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
189 call assert_fails("call luaeval('vim.call(\"min\", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)')",
21283
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
190 \ s:lua_53_or_later
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
191 \ ? '[string "luaeval"]:1: Function called with too many arguments'
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
192 \ : 'Function called with too many arguments')
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
193 lua co = coroutine.create(function () print("hi") end)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
194 call assert_fails("call luaeval('vim.call(\"type\", co)')",
21283
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
195 \ s:lua_53_or_later
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
196 \ ? '[string "luaeval"]:1: lua: cannot convert value'
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
197 \ : 'lua: cannot convert value')
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
198 lua co = nil
21283
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
199 call assert_fails("call luaeval('vim.call(\"abc\")')",
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
200 \ ['E117:', s:lua_53_or_later ? '\[string "luaeval"]:1: lua: call_vim_function failed'
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
201 \ : 'lua: call_vim_function failed'])
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
202 endfunc
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
203
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
204 " Test vim.fn.*
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
205 func Test_lua_fn()
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
206 call assert_equal(has('lua'), luaeval('vim.fn.has("lua")'))
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
207 call assert_equal(printf("Hello %s", "vim"), luaeval('vim.fn.printf("Hello %s", "vim")'))
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
208 endfunc
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
209
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
210 " Test setting the current window
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
211 func Test_lua_window_set_current()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
212 new Xfoo1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
213 lua w1 = vim.window()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
214 new Xfoo2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
215 lua w2 = vim.window()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
216
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
217 call assert_equal('Xfoo2', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
218 lua w1()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
219 call assert_equal('Xfoo1', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
220 lua w2()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
221 call assert_equal('Xfoo2', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
222
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
223 lua w1, w2 = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
224 %bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
225 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
226
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
227 " Test vim.window().buffer
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
228 func Test_lua_window_buffer()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
229 new Xfoo1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
230 lua w1 = vim.window()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
231 lua b1 = w1.buffer()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
232 new Xfoo2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
233 lua w2 = vim.window()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
234 lua b2 = w2.buffer()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
235
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
236 lua b1()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
237 call assert_equal('Xfoo1', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
238 lua b2()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
239 call assert_equal('Xfoo2', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
240
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
241 lua b1, b2, w1, w2 = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
242 %bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
243 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
244
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
245 " Test vim.window():previous() and vim.window():next()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
246 func Test_lua_window_next_previous()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
247 new Xfoo1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
248 new Xfoo2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
249 new Xfoo3
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
250 wincmd j
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
251
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
252 call assert_equal('Xfoo2', luaeval('vim.window().buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
253 call assert_equal('Xfoo1', luaeval('vim.window():next():buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
254 call assert_equal('Xfoo3', luaeval('vim.window():previous():buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
255
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
256 %bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
257 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
258
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
259 " Test vim.window():isvalid()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
260 func Test_lua_window_isvalid()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
261 new Xfoo
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
262 lua w = vim.window()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
263 call assert_true(luaeval('w:isvalid()'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
264
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
265 " FIXME: how to test the case when isvalid() returns v:false?
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
266 " isvalid() gives errors when the window is deleted. Is it a bug?
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
267
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
268 lua w = nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
269 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
270 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
271
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
272 " Test vim.buffer() with and without argument
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
273 func Test_lua_buffer()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
274 new Xfoo1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
275 let bn1 = bufnr('%')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
276 new Xfoo2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
277 let bn2 = bufnr('%')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
278
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
279 " Test vim.buffer() without argument.
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
280 call assert_equal('Xfoo2', luaeval("vim.buffer().name"))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
281
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
282 " Test vim.buffer() with string argument.
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
283 call assert_equal('Xfoo1', luaeval("vim.buffer('Xfoo1').name"))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
284 call assert_equal('Xfoo2', luaeval("vim.buffer('Xfoo2').name"))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
285
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
286 " Test vim.buffer() with integer argument.
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
287 call assert_equal('Xfoo1', luaeval("vim.buffer(" . bn1 . ").name"))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
288 call assert_equal('Xfoo2', luaeval("vim.buffer(" . bn2 . ").name"))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
289
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
290 lua bn1, bn2 = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
291 %bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
292 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
293
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
294 " Test vim.buffer().name and vim.buffer().fname
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
295 func Test_lua_buffer_name()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
296 new
14296
396b71b242b2 patch 8.1.0164: luaeval('vim.buffer().name') returns an error
Christian Brabandt <cb@256bit.org>
parents: 14245
diff changeset
297 call assert_equal('', luaeval('vim.buffer().name'))
396b71b242b2 patch 8.1.0164: luaeval('vim.buffer().name') returns an error
Christian Brabandt <cb@256bit.org>
parents: 14245
diff changeset
298 call assert_equal('', luaeval('vim.buffer().fname'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
299 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
300
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
301 new Xfoo
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
302 call assert_equal('Xfoo', luaeval('vim.buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
303 call assert_equal(expand('%:p'), luaeval('vim.buffer().fname'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
304 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
305 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
306
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
307 " Test vim.buffer().number
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
308 func Test_lua_buffer_number()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
309 " All numbers in Lua are floating points number (no integers).
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
310 call assert_equal(bufnr('%'), float2nr(luaeval('vim.buffer().number')))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
311 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
312
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
313 " Test inserting lines in buffer.
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
314 func Test_lua_buffer_insert()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
315 new
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
316 lua vim.buffer()[1] = '3'
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
317 lua vim.buffer():insert('1', 0)
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
318 lua vim.buffer():insert('2', 1)
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
319 lua vim.buffer():insert('4', 10)
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
320
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
321 call assert_equal(['1', '2', '3', '4'], getline(1, '$'))
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
322 call assert_equal('4', luaeval('vim.buffer()[4]'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
323 call assert_equal(v:null, luaeval('vim.buffer()[5]'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
324 call assert_equal(v:null, luaeval('vim.buffer()[{}]'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
325 call assert_fails('lua vim.buffer():xyz()',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
326 \ s:lua_53_or_later
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
327 \ ? "[string \"vim chunk\"]:1: attempt to call a nil value (method 'xyz')"
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
328 \ : "[string \"vim chunk\"]:1: attempt to call method 'xyz' (a nil value)")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
329 call assert_fails('lua vim.buffer()[1] = {}',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
330 \ '[string "vim chunk"]:1: wrong argument to change')
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
331 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
332 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
333
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
334 " Test deleting line in buffer
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
335 func Test_lua_buffer_delete()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
336 new
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
337 call setline(1, ['1', '2', '3'])
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
338 call cursor(3, 1)
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
339 lua vim.buffer()[2] = nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
340 call assert_equal(['1', '3'], getline(1, '$'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
341
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
342 call assert_fails('lua vim.buffer()[3] = nil',
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
343 \ '[string "vim chunk"]:1: invalid line number')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
344 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
345 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
346
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
347 " Test #vim.buffer() i.e. number of lines in buffer
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
348 func Test_lua_buffer_number_lines()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
349 new
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
350 call setline(1, ['a', 'b', 'c'])
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
351 call assert_equal(3, luaeval('#vim.buffer()'))
10757
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
352 bwipe!
6c3d42d18366 patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
353 endfunc
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
354
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
355 " Test vim.buffer():next() and vim.buffer():previous()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
356 " Note that these functions get the next or previous buffers
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
357 " but do not switch buffer.
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
358 func Test_lua_buffer_next_previous()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
359 new Xfoo1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
360 new Xfoo2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
361 new Xfoo3
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
362 b Xfoo2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
363
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
364 lua bn = vim.buffer():next()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
365 lua bp = vim.buffer():previous()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
366
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
367 call assert_equal('Xfoo2', luaeval('vim.buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
368 call assert_equal('Xfoo1', luaeval('bp.name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
369 call assert_equal('Xfoo3', luaeval('bn.name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
370
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
371 call assert_equal('Xfoo2', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
372
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
373 lua bn()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
374 call assert_equal('Xfoo3', luaeval('vim.buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
375 call assert_equal('Xfoo3', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
376
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
377 lua bp()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
378 call assert_equal('Xfoo1', luaeval('vim.buffer().name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
379 call assert_equal('Xfoo1', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
380
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
381 lua bn, bp = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
382 %bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
383 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
384
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
385 " Test vim.buffer():isvalid()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
386 func Test_lua_buffer_isvalid()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
387 new Xfoo
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
388 lua b = vim.buffer()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
389 call assert_true(luaeval('b:isvalid()'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
390
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
391 " FIXME: how to test the case when isvalid() returns v:false?
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
392 " isvalid() gives errors when the buffer is wiped. Is it a bug?
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
393
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
394 lua b = nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
395 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
396 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
397
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
398 func Test_lua_list()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
399 call assert_equal([], luaeval('vim.list()'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
400
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
401 let l = []
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
402 lua l = vim.eval('l')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
403 lua l:add(123)
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
404 lua l:add('abc')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
405 lua l:add(true)
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
406 lua l:add(false)
15328
f7130bc17248 patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents: 14395
diff changeset
407 lua l:add(nil)
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
408 lua l:add(vim.eval("[1, 2, 3]"))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
409 lua l:add(vim.eval("{'a':1, 'b':2, 'c':3}"))
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
410 call assert_equal([123, 'abc', v:true, v:false, v:null, [1, 2, 3], {'a': 1, 'b': 2, 'c': 3}], l)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
411 call assert_equal(7, luaeval('#l'))
14245
f445c5edb6af patch 8.1.0139: Lua tests fail on some platforms
Christian Brabandt <cb@256bit.org>
parents: 14239
diff changeset
412 call assert_match('^list: \%(0x\)\?\x\+$', luaeval('tostring(l)'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
413
21030
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
414 lua l[1] = 124
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
415 lua l[6] = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
416 lua l:insert('first')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
417 lua l:insert('xx', 3)
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
418 call assert_fails('lua l:insert("xx", -20)',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
419 \ '[string "vim chunk"]:1: invalid position')
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
420 call assert_equal(['first', 124, 'abc', 'xx', v:true, v:false, v:null, {'a': 1, 'b': 2, 'c': 3}], l)
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
421
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
422 lockvar 1 l
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
423 call assert_fails('lua l:add("x")', '[string "vim chunk"]:1: list is locked')
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
424 call assert_fails('lua l:insert(2)', '[string "vim chunk"]:1: list is locked')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
425 call assert_fails('lua l[9] = 1', '[string "vim chunk"]:1: list is locked')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
426
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
427 unlockvar l
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
428 let l = [1, 2]
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
429 lua ll = vim.eval('l')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
430 let x = luaeval("ll[3]")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
431 call assert_equal(v:null, x)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
432 call assert_fails('let x = luaeval("ll:xyz(3)")',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
433 \ s:lua_53_or_later
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
434 \ ? "[string \"luaeval\"]:1: attempt to call a nil value (method 'xyz')"
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
435 \ : "[string \"luaeval\"]:1: attempt to call method 'xyz' (a nil value)")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
436 let y = luaeval("ll[{}]")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
437 call assert_equal(v:null, y)
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
438
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
439 lua l = nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
440 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
441
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
442 func Test_lua_list_table()
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
443 " See :help lua-vim
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
444 " Non-numeric keys should not be used to initialize the list
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
445 " so say = 'hi' should be ignored.
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
446 lua t = {3.14, 'hello', false, true, say = 'hi'}
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
447 call assert_equal([3.14, 'hello', v:false, v:true], luaeval('vim.list(t)'))
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
448 lua t = nil
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
449
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
450 call assert_fails('lua vim.list(1)', '[string "vim chunk"]:1: table expected, got number')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
451 call assert_fails('lua vim.list("x")', '[string "vim chunk"]:1: table expected, got string')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
452 call assert_fails('lua vim.list(print)', '[string "vim chunk"]:1: table expected, got function')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
453 call assert_fails('lua vim.list(true)', '[string "vim chunk"]:1: table expected, got boolean')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
454 endfunc
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
455
21060
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
456 func Test_lua_list_table_insert_remove()
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
457 if !s:lua_53_or_later
21060
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
458 throw 'Skipped: Lua version < 5.3'
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
459 endif
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
460
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
461 let l = [1, 2]
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
462 lua t = vim.eval('l')
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
463 lua table.insert(t, 10)
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
464 lua t[#t + 1] = 20
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
465 lua table.insert(t, 2, 30)
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
466 call assert_equal(l, [1, 30, 2, 10, 20])
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
467 lua table.remove(t, 2)
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
468 call assert_equal(l, [1, 2, 10, 20])
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
469 lua t[3] = nil
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
470 call assert_equal(l, [1, 2, 20])
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
471 lua removed_value = table.remove(t, 3)
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
472 call assert_equal(luaeval('removed_value'), 20)
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
473 lua t = nil
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
474 lua removed_value = nil
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
475 unlet l
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
476 endfunc
89aba7895bb2 patch 8.2.1081: Lua: cannot use table.insert() and table.remove()
Bram Moolenaar <Bram@vim.org>
parents: 21030
diff changeset
477
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
478 " Test l() i.e. iterator on list
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
479 func Test_lua_list_iter()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
480 lua l = vim.list():add('foo'):add('bar')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
481 lua str = ''
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
482 lua for v in l() do str = str .. v end
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
483 call assert_equal('foobar', luaeval('str'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
484
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
485 lua str, l = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
486 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
487
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
488 func Test_lua_recursive_list()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
489 lua l = vim.list():add(1):add(2)
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
490 lua l = l:add(l)
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
491
21030
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
492 call assert_equal(1, luaeval('l[1]'))
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
493 call assert_equal(2, luaeval('l[2]'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
494
21030
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
495 call assert_equal(1, luaeval('l[3][1]'))
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
496 call assert_equal(2, luaeval('l[3][2]'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
497
21030
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
498 call assert_equal(1, luaeval('l[3][3][1]'))
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
499 call assert_equal(2, luaeval('l[3][3][2]'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
500
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
501 call assert_equal('[1, 2, [...]]', string(luaeval('l')))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
502
14245
f445c5edb6af patch 8.1.0139: Lua tests fail on some platforms
Christian Brabandt <cb@256bit.org>
parents: 14239
diff changeset
503 call assert_match('^list: \%(0x\)\?\x\+$', luaeval('tostring(l)'))
21030
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
504 call assert_equal(luaeval('tostring(l)'), luaeval('tostring(l[3])'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
505
21030
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
506 call assert_equal(luaeval('l'), luaeval('l[3]'))
08e284594211 patch 8.2.1066: Lua arrays are zero based
Bram Moolenaar <Bram@vim.org>
parents: 21006
diff changeset
507 call assert_equal(luaeval('l'), luaeval('l[3][3]'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
508
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
509 lua l = nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
510 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
511
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
512 func Test_lua_dict()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
513 call assert_equal({}, luaeval('vim.dict()'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
514
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
515 let d = {}
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
516 lua d = vim.eval('d')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
517 lua d[0] = 123
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
518 lua d[1] = "abc"
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
519 lua d[2] = true
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
520 lua d[3] = false
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
521 lua d[4] = vim.eval("[1, 2, 3]")
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
522 lua d[5] = vim.eval("{'a':1, 'b':2, 'c':3}")
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
523 call assert_equal({'0':123, '1':'abc', '2':v:true, '3':v:false, '4': [1, 2, 3], '5': {'a':1, 'b':2, 'c':3}}, d)
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
524 call assert_equal(6, luaeval('#d'))
14245
f445c5edb6af patch 8.1.0139: Lua tests fail on some platforms
Christian Brabandt <cb@256bit.org>
parents: 14239
diff changeset
525 call assert_match('^dict: \%(0x\)\?\x\+$', luaeval('tostring(d)'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
526
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
527 call assert_equal('abc', luaeval('d[1]'))
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
528 call assert_equal(v:null, luaeval('d[22]'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
529
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
530 lua d[0] = 124
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
531 lua d[4] = nil
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
532 call assert_equal({'0':124, '1':'abc', '2':v:true, '3':v:false, '5': {'a':1, 'b':2, 'c':3}}, d)
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
533
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
534 lockvar 1 d
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
535 call assert_fails('lua d[6] = 1', '[string "vim chunk"]:1: dict is locked')
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
536 unlockvar d
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
537
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
538 " Error case
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
539 lua d = {}
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
540 lua d[''] = 10
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
541 call assert_fails("let t = luaeval('vim.dict(d)')",
21283
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
542 \ s:lua_53_or_later
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
543 \ ? '[string "luaeval"]:1: table has empty key'
1d2c814f4bed patch 8.2.1192: Lua test fails with older Lua version
Bram Moolenaar <Bram@vim.org>
parents: 21269
diff changeset
544 \ : 'table has empty key')
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
545 let d = {}
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
546 lua x = vim.eval('d')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
547 call assert_fails("lua x[''] = 10", '[string "vim chunk"]:1: empty key')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
548 lua x['a'] = nil
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
549 call assert_equal({}, d)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
550
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
551 " cannot assign funcrefs in the global scope
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
552 lua x = vim.eval('g:')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
553 call assert_fails("lua x['min'] = vim.funcref('max')",
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
554 \ '[string "vim chunk"]:1: cannot assign funcref to builtin scope')
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
555
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
556 lua d = nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
557 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
558
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
559 func Test_lua_dict_table()
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
560 lua t = {key1 = 'x', key2 = 3.14, key3 = true, key4 = false}
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
561 call assert_equal({'key1': 'x', 'key2': 3.14, 'key3': v:true, 'key4': v:false},
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
562 \ luaeval('vim.dict(t)'))
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
563
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
564 " Same example as in :help lua-vim.
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
565 lua t = {math.pi, false, say = 'hi'}
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
566 " FIXME: commented out as it currently does not work as documented:
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
567 " Expected {'say': 'hi'}
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
568 " but got {'1': 3.141593, '2': v:false, 'say': 'hi'}
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
569 " Is the documentation or the code wrong?
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
570 "call assert_equal({'say' : 'hi'}, luaeval('vim.dict(t)'))
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
571 lua t = nil
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
572
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
573 call assert_fails('lua vim.dict(1)', '[string "vim chunk"]:1: table expected, got number')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
574 call assert_fails('lua vim.dict("x")', '[string "vim chunk"]:1: table expected, got string')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
575 call assert_fails('lua vim.dict(print)', '[string "vim chunk"]:1: table expected, got function')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
576 call assert_fails('lua vim.dict(true)', '[string "vim chunk"]:1: table expected, got boolean')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
577 endfunc
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
578
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
579 " Test d() i.e. iterator on dictionary
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
580 func Test_lua_dict_iter()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
581 let d = {'a': 1, 'b':2}
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
582 lua d = vim.eval('d')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
583 lua str = ''
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
584 lua for k,v in d() do str = str .. k ..':' .. v .. ',' end
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
585 call assert_equal('a:1,b:2,', luaeval('str'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
586
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
587 lua str, d = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
588 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
589
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
590 func Test_lua_blob()
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
591 call assert_equal(0z, luaeval('vim.blob("")'))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
592 call assert_equal(0z31326162, luaeval('vim.blob("12ab")'))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
593 call assert_equal(0z00010203, luaeval('vim.blob("\x00\x01\x02\x03")'))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
594 call assert_equal(0z8081FEFF, luaeval('vim.blob("\x80\x81\xfe\xff")'))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
595
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
596 lua b = vim.blob("\x00\x00\x00\x00")
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
597 call assert_equal(0z00000000, luaeval('b'))
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
598 call assert_equal(4, luaeval('#b'))
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
599 lua b[0], b[1], b[2], b[3] = 1, 32, 256, 0xff
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
600 call assert_equal(0z012000ff, luaeval('b'))
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
601 lua b[4] = string.byte("z", 1)
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
602 call assert_equal(0z012000ff.7a, luaeval('b'))
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
603 call assert_equal(5, luaeval('#b'))
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
604 call assert_fails('lua b[#b+1] = 0x80', '[string "vim chunk"]:1: index out of range')
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
605 lua b:add("12ab")
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
606 call assert_equal(0z012000ff.7a313261.62, luaeval('b'))
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
607 call assert_equal(9, luaeval('#b'))
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
608 call assert_fails('lua b:add(nil)', '[string "vim chunk"]:1: string expected, got nil')
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
609 call assert_fails('lua b:add(true)', '[string "vim chunk"]:1: string expected, got boolean')
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
610 call assert_fails('lua b:add({})', '[string "vim chunk"]:1: string expected, got table')
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
611 lua b = nil
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
612
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
613 let b = 0z0102
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
614 lua lb = vim.eval('b')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
615 let n = luaeval('lb[1]')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
616 call assert_equal(2, n)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
617 let n = luaeval('lb[6]')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
618 call assert_equal(v:null, n)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
619 call assert_fails('let x = luaeval("lb:xyz(3)")',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
620 \ s:lua_53_or_later
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
621 \ ? "[string \"luaeval\"]:1: attempt to call a nil value (method 'xyz')"
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
622 \ : "[string \"luaeval\"]:1: attempt to call method 'xyz' (a nil value)")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
623 let y = luaeval("lb[{}]")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
624 call assert_equal(v:null, y)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
625
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
626 lockvar b
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
627 call assert_fails('lua lb[1] = 2', '[string "vim chunk"]:1: blob is locked')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
628 call assert_fails('lua lb:add("12")', '[string "vim chunk"]:1: blob is locked')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
629
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
630 " Error cases
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
631 lua t = {}
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
632 call assert_fails('lua b = vim.blob(t)',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
633 \ '[string "vim chunk"]:1: string expected, got table')
16076
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
634 endfunc
a2f0e93a5857 patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents: 16028
diff changeset
635
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
636 func Test_lua_funcref()
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
637 function I(x)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
638 return a:x
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
639 endfunction
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
640 let R = function('I')
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
641 lua i1 = vim.funcref"I"
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
642 lua i2 = vim.eval"R"
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
643 lua msg = "funcref|test|" .. (#i2(i1) == #i1(i2) and "OK" or "FAIL")
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
644 lua msg = vim.funcref"tr"(msg, "|", " ")
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
645 call assert_equal("funcref test OK", luaeval('msg'))
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
646
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
647 " Error cases
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
648 call assert_fails('lua f1 = vim.funcref("")',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
649 \ '[string "vim chunk"]:1: invalid function name: ')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
650 call assert_fails('lua f1 = vim.funcref("10")',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
651 \ '[string "vim chunk"]:1: invalid function name: 10')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
652 let fname = test_null_string()
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
653 call assert_fails('lua f1 = vim.funcref(fname)',
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
654 \ "[string \"vim chunk\"]:1: bad argument #1 to 'funcref' (string expected, got nil)")
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
655 call assert_fails('lua vim.funcref("abc")()',
21269
0a8322506058 patch 8.2.1185: some other tests fail
Bram Moolenaar <Bram@vim.org>
parents: 21108
diff changeset
656 \ ['E117:', '\[string "vim chunk"]:1: cannot call funcref'])
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
657
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
658 " dict funcref
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
659 function Mylen() dict
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
660 return len(self.data)
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
661 endfunction
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
662 let l = [0, 1, 2, 3]
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
663 let mydict = {'data': l}
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
664 lua d = vim.eval"mydict"
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
665 lua d.len = vim.funcref"Mylen" -- assign d as 'self'
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
666 lua res = (d.len() == vim.funcref"len"(vim.eval"l")) and "OK" or "FAIL"
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
667 call assert_equal("OK", luaeval('res'))
16028
8ad2cda3757d patch 8.1.1019: Lua: may garbage collect function reference in use
Bram Moolenaar <Bram@vim.org>
parents: 15997
diff changeset
668 call assert_equal(function('Mylen', {'data': l, 'len': function('Mylen')}), mydict.len)
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
669
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
670 lua i1, i2, msg, d, res = nil
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
671 endfunc
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
672
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
673 " Test vim.type()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
674 func Test_lua_type()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
675 " The following values are identical to Lua's type function.
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
676 call assert_equal('string', luaeval('vim.type("foo")'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
677 call assert_equal('number', luaeval('vim.type(1)'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
678 call assert_equal('number', luaeval('vim.type(1.2)'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
679 call assert_equal('function', luaeval('vim.type(print)'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
680 call assert_equal('table', luaeval('vim.type({})'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
681 call assert_equal('boolean', luaeval('vim.type(true)'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
682 call assert_equal('boolean', luaeval('vim.type(false)'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
683 call assert_equal('nil', luaeval('vim.type(nil)'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
684
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
685 " The following values are specific to Vim.
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
686 call assert_equal('window', luaeval('vim.type(vim.window())'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
687 call assert_equal('buffer', luaeval('vim.type(vim.buffer())'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
688 call assert_equal('list', luaeval('vim.type(vim.list())'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
689 call assert_equal('dict', luaeval('vim.type(vim.dict())'))
14235
e3bc8cdc94dd patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents: 14230
diff changeset
690 call assert_equal('funcref', luaeval('vim.type(vim.funcref("Test_type"))'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
691 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
692
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
693 " Test vim.open()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
694 func Test_lua_open()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
695 call assert_notmatch('XOpen', execute('ls'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
696
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
697 " Open a buffer XOpen1, but do not jump to it.
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
698 lua b = vim.open('XOpen1')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
699 call assert_equal('XOpen1', luaeval('b.name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
700 call assert_equal('', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
701
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
702 call assert_match('XOpen1', execute('ls'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
703 call assert_notequal('XOpen2', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
704
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
705 " Open a buffer XOpen2 and jump to it.
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
706 lua b = vim.open('XOpen2')()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
707 call assert_equal('XOpen2', luaeval('b.name'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
708 call assert_equal('XOpen2', bufname('%'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
709
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
710 lua b = nil
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
711 %bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
712 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
713
20609
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20441
diff changeset
714 func Test_update_package_paths()
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20441
diff changeset
715 set runtimepath+=./testluaplugin
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20441
diff changeset
716 call assert_equal("hello from lua", luaeval("require('testluaplugin').hello()"))
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20441
diff changeset
717 endfunc
054ba681412d patch 8.2.0858: not easy to require Lua modules
Bram Moolenaar <Bram@vim.org>
parents: 20441
diff changeset
718
21006
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
719 func Vim_func_call_lua_callback(Concat, Cb)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
720 let l:message = a:Concat("hello", "vim")
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
721 call a:Cb(l:message)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
722 endfunc
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
723
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
724 func Test_pass_lua_callback_to_vim_from_lua()
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
725 lua pass_lua_callback_to_vim_from_lua_result = ""
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
726 call assert_equal("", luaeval("pass_lua_callback_to_vim_from_lua_result"))
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
727 lua <<EOF
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
728 vim.funcref('Vim_func_call_lua_callback')(
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
729 function(greeting, message)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
730 return greeting .. " " .. message
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
731 end,
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
732 function(message)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
733 pass_lua_callback_to_vim_from_lua_result = message
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
734 end)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
735 EOF
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
736 call assert_equal("hello vim", luaeval("pass_lua_callback_to_vim_from_lua_result"))
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
737 endfunc
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
738
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
739 func Vim_func_call_metatable_lua_callback(Greet)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
740 return a:Greet("world")
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
741 endfunc
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
742
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
743 func Test_pass_lua_metatable_callback_to_vim_from_lua()
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
744 let result = luaeval("vim.funcref('Vim_func_call_metatable_lua_callback')(setmetatable({ space = ' '}, { __call = function(tbl, msg) return 'hello' .. tbl.space .. msg end }) )")
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
745 call assert_equal("hello world", result)
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
746 endfunc
ae185f35e256 patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents: 20609
diff changeset
747
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
748 " Test vim.line()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
749 func Test_lua_line()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
750 new
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
751 call setline(1, ['first line', 'second line'])
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
752 1
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
753 call assert_equal('first line', luaeval('vim.line()'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
754 2
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
755 call assert_equal('second line', luaeval('vim.line()'))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
756 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
757 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
758
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
759 " Test vim.beep()
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
760 func Test_lua_beep()
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
761 call assert_beeps('lua vim.beep()')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
762 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
763
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
764 " Test errors in luaeval()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
765 func Test_luaeval_error()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
766 " Compile error
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
767 call assert_fails("call luaeval('-nil')",
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
768 \ '[string "luaeval"]:1: attempt to perform arithmetic on a nil value')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
769 call assert_fails("call luaeval(']')",
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
770 \ "[string \"luaeval\"]:1: unexpected symbol near ']'")
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
771 lua co = coroutine.create(function () print("hi") end)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
772 call assert_fails('let i = luaeval("co")', 'luaeval: cannot convert value')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
773 lua co = nil
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
774 call assert_fails('let m = luaeval("{}")', 'luaeval: cannot convert value')
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
775 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
776
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
777 " Test :luafile foo.lua
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
778 func Test_luafile()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
779 call delete('Xlua_file')
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
780 call writefile(["str = 'hello'", "num = 123" ], 'Xlua_file')
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
781 call setfperm('Xlua_file', 'r-xr-xr-x')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
782
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
783 luafile Xlua_file
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
784 call assert_equal('hello', luaeval('str'))
20441
86dde5c4b375 patch 8.2.0775: not easy to call a Vim function from Lua
Bram Moolenaar <Bram@vim.org>
parents: 20233
diff changeset
785 call assert_equal(123, luaeval('num'))
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
786
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
787 lua str, num = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
788 call delete('Xlua_file')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
789 endfunc
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
790
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
791 " Test :luafile %
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
792 func Test_luafile_percent()
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
793 new Xlua_file
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
794 append
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
795 str, num = 'foo', 321.0
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
796 print(string.format('str=%s, num=%d', str, num))
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
797 .
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
798 w!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
799 luafile %
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
800 let msg = split(execute('message'), "\n")[-1]
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
801 call assert_equal('str=foo, num=321', msg)
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
802
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
803 lua str, num = nil
14230
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
804 call delete('Xlua_file')
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
805 bwipe!
2e95ea9afa1e patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents: 10757
diff changeset
806 endfunc
14239
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
807
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
808 " Test :luafile with syntax error
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
809 func Test_luafile_error()
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
810 new Xlua_file
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
811 call writefile(['nil = 0' ], 'Xlua_file')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
812 call setfperm('Xlua_file', 'r-xr-xr-x')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
813
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
814 call assert_fails('luafile Xlua_file', "Xlua_file:1: unexpected symbol near 'nil'")
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
815
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
816 call delete('Xlua_file')
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
817 bwipe!
7457bf2db968 patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents: 14235
diff changeset
818 endfunc
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
819
21108
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
820 " Test for dealing with strings containing newlines and null character
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
821 func Test_lua_string_with_newline()
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
822 let x = execute('lua print("Hello\nWorld")')
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
823 call assert_equal("\nHello\nWorld", x)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
824 new
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
825 lua k = vim.buffer(vim.eval('bufnr()'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
826 lua k:insert("Hello\0World", 0)
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
827 call assert_equal(["Hello\nWorld", ''], getline(1, '$'))
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
828 close!
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
829 endfunc
43e82e8133b9 patch 8.2.1105: insufficient test coverage for Lua
Bram Moolenaar <Bram@vim.org>
parents: 21060
diff changeset
830
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 17916
diff changeset
831 func Test_lua_set_cursor()
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
832 " Check that setting the cursor position works.
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
833 new
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
834 call setline(1, ['first line', 'second line'])
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
835 normal gg
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
836 lua << trim EOF
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
837 w = vim.window()
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
838 w.line = 1
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
839 w.col = 5
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
840 EOF
14395
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
841 call assert_equal([1, 5], [line('.'), col('.')])
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
842
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
843 " Check that movement after setting cursor position keeps current column.
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
844 normal j
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
845 call assert_equal([2, 5], [line('.'), col('.')])
c15bef307de6 patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents: 14296
diff changeset
846 endfunc
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
847
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
848 " Test for various heredoc syntax
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
849 func Test_lua_heredoc()
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
850 lua << END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
851 vim.command('let s = "A"')
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
852 END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
853 lua <<
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
854 vim.command('let s ..= "B"')
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
855 .
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
856 lua << trim END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
857 vim.command('let s ..= "C"')
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
858 END
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
859 lua << trim
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
860 vim.command('let s ..= "D"')
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
861 .
20233
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
862 lua << trim eof
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
863 vim.command('let s ..= "E"')
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
864 eof
5f9c2c7d3d73 patch 8.2.0672: heredoc in scripts does not accept lower case marker
Bram Moolenaar <Bram@vim.org>
parents: 20045
diff changeset
865 call assert_equal('ABCDE', s)
20045
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
866 endfunc
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
867
04ef2ccf2519 patch 8.2.0578: heredoc for interfaces does not support "trim"
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
868 " vim: shiftwidth=2 sts=2 expandtab