Mercurial > vim
annotate src/testdir/test_lua.vim @ 18130:1e5672da6a69
Updte runtime files
Commit: https://github.com/vim/vim/commit/589edb340454e7f1b19358f129287a636d53d0e1
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Sep 20 14:38:13 2019 +0200
Updte runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 20 Sep 2019 14:45:05 +0200 |
parents | 2e53305f2239 |
children | 2a017e9dc6da |
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 |
8e9e9124c7a2
patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents:
17049
diff
changeset
|
4 CheckFeature lua |
10757
6c3d42d18366
patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 |
15997
725255793949
patch 8.1.1004: function "luaV_setref()" not covered with tests
Bram Moolenaar <Bram@vim.org>
parents:
15328
diff
changeset
|
6 func TearDown() |
725255793949
patch 8.1.1004: function "luaV_setref()" not covered with tests
Bram Moolenaar <Bram@vim.org>
parents:
15328
diff
changeset
|
7 " 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
|
8 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
|
9 endfunc |
725255793949
patch 8.1.1004: function "luaV_setref()" not covered with tests
Bram Moolenaar <Bram@vim.org>
parents:
15328
diff
changeset
|
10 |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
11 " Check that switching to another buffer does not trigger ml_get error. |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
12 func Test_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
|
13 new |
6c3d42d18366
patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 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
|
15 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
|
16 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
|
17 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
|
18 %bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
19 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
20 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
21 " Test vim.command() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
22 func Test_command() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
23 new |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
24 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
|
25 luado vim.command("1,2d_") |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
26 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
|
27 bwipe! |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
28 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
29 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
30 " Test vim.eval() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
31 func Test_eval() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
32 " lua.eval with a number |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
33 lua v = vim.eval('123') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
34 call assert_equal('number', luaeval('vim.type(v)')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
35 call assert_equal(123.0, luaeval('v')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
36 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
37 " lua.eval with a string |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
42 " lua.eval with a list |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
43 lua v = vim.eval("['a']") |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
44 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
|
45 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
|
46 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
47 " lua.eval with a dict |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
52 " 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
|
53 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
|
54 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
|
55 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
|
56 |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
57 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
|
58 \ "[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
|
59 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
|
60 \ "[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
|
61 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
|
62 \ "[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
|
63 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
|
64 \ "[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
|
65 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
|
66 \ "[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
|
67 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
68 lua v = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
69 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
70 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
71 " Test vim.window() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
72 func Test_window() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
73 e Xfoo2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
74 new Xfoo1 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
75 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
76 " 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
|
77 " 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
|
78 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
|
79 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
|
80 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
81 " 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
|
82 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
|
83 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
84 %bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
85 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
86 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
87 " Test vim.window().height |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
88 func Test_window_height() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
89 new |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
90 lua vim.window().height = 2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
95 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
96 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
97 " Test vim.window().width |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
98 func Test_window_width() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
99 vert new |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
100 lua vim.window().width = 2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
105 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
106 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
107 " Test vim.window().line and vim.window.col |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
108 func Test_window_line_col() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
109 new |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
110 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
|
111 lua vim.window().line = 2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
112 lua vim.window().col = 4 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 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
|
117 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
118 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
|
119 \ '[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
|
120 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
121 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
122 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
123 " Test setting the current window |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
124 func Test_window_set_current() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
125 new Xfoo1 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
126 lua w1 = vim.window() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
127 new Xfoo2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
128 lua w2 = vim.window() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
129 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
130 call assert_equal('Xfoo2', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
131 lua w1() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
132 call assert_equal('Xfoo1', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
133 lua w2() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
134 call assert_equal('Xfoo2', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
135 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
136 lua w1, w2 = nil |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
137 %bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
138 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
139 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
140 " Test vim.window().buffer |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
141 func Test_window_buffer() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
142 new Xfoo1 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
143 lua w1 = vim.window() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
144 lua b1 = w1.buffer() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
145 new Xfoo2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
146 lua w2 = vim.window() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
147 lua b2 = w2.buffer() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
148 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
149 lua b1() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
150 call assert_equal('Xfoo1', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
151 lua b2() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
152 call assert_equal('Xfoo2', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
153 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
154 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
|
155 %bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
156 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
157 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
158 " Test vim.window():previous() and vim.window():next() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
159 func Test_window_next_previous() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
160 new Xfoo1 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
161 new Xfoo2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
162 new Xfoo3 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
163 wincmd j |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
164 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
165 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
|
166 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
|
167 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
|
168 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
169 %bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
170 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
171 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
172 " Test vim.window():isvalid() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
173 func Test_window_isvalid() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
174 new Xfoo |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
175 lua w = vim.window() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
176 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
|
177 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
178 " 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
|
179 " 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
|
180 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
181 lua w = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
182 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
183 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
184 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
185 " Test vim.buffer() with and without argument |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
186 func Test_buffer() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
187 new Xfoo1 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
188 let bn1 = bufnr('%') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
189 new Xfoo2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
190 let bn2 = bufnr('%') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
191 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
192 " Test vim.buffer() without argument. |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
193 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
|
194 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
195 " 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
|
196 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
|
197 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
|
198 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
199 " 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
|
200 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
|
201 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
|
202 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
203 lua bn1, bn2 = nil |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
204 %bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
205 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
206 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
207 " Test vim.buffer().name and vim.buffer().fname |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
208 func Test_buffer_name() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
209 new |
14296
396b71b242b2
patch 8.1.0164: luaeval('vim.buffer().name') returns an error
Christian Brabandt <cb@256bit.org>
parents:
14245
diff
changeset
|
210 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
|
211 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
|
212 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
213 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
214 new Xfoo |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
215 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
|
216 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
|
217 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
218 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
219 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
220 " Test vim.buffer().number |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
221 func Test_buffer_number() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
222 " 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
|
223 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
|
224 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
225 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
226 " Test inserting lines in buffer. |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
227 func Test_buffer_insert() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
228 new |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
229 lua vim.buffer()[1] = '3' |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
230 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
|
231 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
|
232 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
|
233 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
234 call assert_equal(['1', '2', '3', '4'], getline(1, '$')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
235 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
236 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
237 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
238 " Test deleting line in buffer |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
239 func Test_buffer_delete() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
240 new |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
241 call setline(1, ['1', '2', '3']) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
242 lua vim.buffer()[2] = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
243 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
|
244 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
245 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
|
246 \ '[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
|
247 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
248 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
249 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
250 " Test #vim.buffer() i.e. number of lines in buffer |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
251 func Test_buffer_number_lines() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
252 new |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
253 call setline(1, ['a', 'b', 'c']) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
254 call assert_equal(3.0, 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
|
255 bwipe! |
6c3d42d18366
patch 8.0.0268: may get ml_get error when :luado deletes lines
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
256 endfunc |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
257 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
258 " 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
|
259 " 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
|
260 " but do not switch buffer. |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
261 func Test_buffer_next_previous() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
262 new Xfoo1 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
263 new Xfoo2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
264 new Xfoo3 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
265 b Xfoo2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
266 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
267 lua bn = vim.buffer():next() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
268 lua bp = vim.buffer():previous() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
269 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
274 call assert_equal('Xfoo2', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
275 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
276 lua bn() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
277 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
|
278 call assert_equal('Xfoo3', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
279 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
280 lua bp() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
281 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
|
282 call assert_equal('Xfoo1', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
283 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
284 lua bn, bp = nil |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
285 %bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
286 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
287 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
288 " Test vim.buffer():isvalid() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
289 func Test_buffer_isvalid() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
290 new Xfoo |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
291 lua b = vim.buffer() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
292 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
|
293 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
294 " 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
|
295 " 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
|
296 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
297 lua b = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
298 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
299 endfunc |
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 func Test_list() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
302 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
|
303 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
304 let l = [] |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
305 lua l = vim.eval('l') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
306 lua l:add(123) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
307 lua l:add('abc') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
308 lua l:add(true) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
309 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
|
310 lua l:add(nil) |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
311 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
|
312 lua l:add(vim.eval("{'a':1, 'b':2, 'c':3}")) |
15328
f7130bc17248
patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents:
14395
diff
changeset
|
313 call assert_equal([123.0, 'abc', v:true, v:false, v:null, [1, 2, 3], {'a': 1, 'b': 2, 'c': 3}], l) |
f7130bc17248
patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents:
14395
diff
changeset
|
314 call assert_equal(7.0, luaeval('#l')) |
14245
f445c5edb6af
patch 8.1.0139: Lua tests fail on some platforms
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
315 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
|
316 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
317 lua l[0] = 124 |
15328
f7130bc17248
patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents:
14395
diff
changeset
|
318 lua l[5] = nil |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
319 lua l:insert('first') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
320 lua l:insert('xx', 3) |
15328
f7130bc17248
patch 8.1.0672: the Lua interface doesn't know about v:null
Bram Moolenaar <Bram@vim.org>
parents:
14395
diff
changeset
|
321 call assert_equal(['first', 124.0, '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
|
322 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
323 lockvar 1 l |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
324 call assert_fails('lua l:add("x")', '[string "vim chunk"]:1: list is locked') |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
325 |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
326 lua l = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
327 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
328 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
329 func Test_list_table() |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
330 " 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
|
331 " 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
|
332 " 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
|
333 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
|
334 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
|
335 lua t = nil |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
336 |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 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
|
341 endfunc |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
342 |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
343 " Test l() i.e. iterator on list |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
344 func Test_list_iter() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
345 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
|
346 lua str = '' |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
347 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
|
348 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
|
349 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
350 lua str, l = nil |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
351 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
352 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
353 func Test_recursive_list() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
354 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
|
355 lua l = l:add(l) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
356 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
357 call assert_equal(1.0, luaeval('l[0]')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
358 call assert_equal(2.0, luaeval('l[1]')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
359 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
360 call assert_equal(1.0, luaeval('l[2][0]')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
361 call assert_equal(2.0, luaeval('l[2][1]')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
362 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
363 call assert_equal(1.0, luaeval('l[2][2][0]')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
364 call assert_equal(2.0, luaeval('l[2][2][1]')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
365 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
366 call assert_equal('[1.0, 2.0, [...]]', string(luaeval('l'))) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
367 |
14245
f445c5edb6af
patch 8.1.0139: Lua tests fail on some platforms
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
368 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
|
369 call assert_equal(luaeval('tostring(l)'), luaeval('tostring(l[2])')) |
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(luaeval('l'), luaeval('l[2]')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
372 call assert_equal(luaeval('l'), luaeval('l[2][2]')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
373 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
374 lua l = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
375 endfunc |
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 func Test_dict() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
378 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
|
379 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
380 let d = {} |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
381 lua d = vim.eval('d') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
382 lua d[0] = 123 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
383 lua d[1] = "abc" |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
384 lua d[2] = true |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
385 lua d[3] = false |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
386 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
|
387 lua d[5] = vim.eval("{'a':1, 'b':2, 'c':3}") |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
388 call assert_equal({'0':123.0, '1':'abc', '2':v:true, '3':v:false, '4': [1, 2, 3], '5': {'a':1, 'b':2, 'c':3}}, d) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
389 call assert_equal(6.0, luaeval('#d')) |
14245
f445c5edb6af
patch 8.1.0139: Lua tests fail on some platforms
Christian Brabandt <cb@256bit.org>
parents:
14239
diff
changeset
|
390 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
|
391 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
392 call assert_equal('abc', luaeval('d[1]')) |
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 d[0] = 124 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
395 lua d[4] = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
396 call assert_equal({'0':124.0, '1':'abc', '2':v:true, '3':v:false, '5': {'a':1, 'b':2, 'c':3}}, d) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
397 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
398 lockvar 1 d |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
399 call assert_fails('lua d[6] = 1', '[string "vim chunk"]:1: dict is locked') |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
400 |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
401 lua d = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
402 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
403 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
404 func Test_dict_table() |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
405 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
|
406 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
|
407 \ 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
|
408 |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
409 " 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
|
410 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
|
411 " 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
|
412 " Expected {'say': 'hi'} |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
413 " 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
|
414 " 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
|
415 "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
|
416 lua t = nil |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
417 |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 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
|
422 endfunc |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
423 |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
424 " Test d() i.e. iterator on dictionary |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
425 func Test_dict_iter() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
426 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
|
427 lua d = vim.eval('d') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
428 lua str = '' |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
429 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
|
430 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
|
431 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
432 lua str, d = nil |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
433 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
434 |
16076
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
435 func Test_blob() |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
436 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
|
437 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
|
438 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
|
439 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
|
440 |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
441 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
|
442 call assert_equal(0z00000000, luaeval('b')) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
443 call assert_equal(4.0, luaeval('#b')) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
444 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
|
445 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
|
446 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
|
447 call assert_equal(0z012000ff.7a, luaeval('b')) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
448 call assert_equal(5.0, luaeval('#b')) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
449 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
|
450 lua b:add("12ab") |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
451 call assert_equal(0z012000ff.7a313261.62, luaeval('b')) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
452 call assert_equal(9.0, luaeval('#b')) |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 lua b = nil |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
457 endfunc |
a2f0e93a5857
patch 8.1.1043: Lua interface does not support Blob
Bram Moolenaar <Bram@vim.org>
parents:
16028
diff
changeset
|
458 |
14235
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
459 func Test_funcref() |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
460 function I(x) |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
461 return a:x |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
462 endfunction |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
463 let R = function('I') |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
464 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
|
465 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
|
466 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
|
467 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
|
468 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
|
469 |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
470 " dict funcref |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
471 function Mylen() dict |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
472 return len(self.data) |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
473 endfunction |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
474 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
|
475 let mydict = {'data': l} |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
476 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
482 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
|
483 endfunc |
e3bc8cdc94dd
patch 8.1.0134: Lua interface does not support funcref
Christian Brabandt <cb@256bit.org>
parents:
14230
diff
changeset
|
484 |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
485 " Test vim.type() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
486 func Test_type() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
487 " 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
497 " 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
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
504 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
505 " Test vim.open() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
506 func Test_open() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
507 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
|
508 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
509 " 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
|
510 lua b = vim.open('XOpen1') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
511 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
|
512 call assert_equal('', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
513 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
514 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
|
515 call assert_notequal('XOpen2', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
516 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
517 " 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
|
518 lua b = vim.open('XOpen2')() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
519 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
|
520 call assert_equal('XOpen2', bufname('%')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
521 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
522 lua b = nil |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
523 %bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
524 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
525 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
526 " Test vim.line() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
527 func Test_line() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
528 new |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
529 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
|
530 1 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
531 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
|
532 2 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
533 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
|
534 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
535 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
536 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
537 " Test vim.beep() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
538 func Test_beep() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
539 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
|
540 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
541 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
542 " Test errors in luaeval() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
543 func Test_luaeval_error() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
544 " Compile error |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
545 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
|
546 \ '[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
|
547 call assert_fails("call luaeval(']')", |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
548 \ "[string \"luaeval\"]:1: unexpected symbol near ']'") |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
549 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
550 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
551 " Test :luafile foo.lua |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
552 func Test_luafile() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
553 call delete('Xlua_file') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
554 call writefile(["str = 'hello'", "num = 123.0" ], 'Xlua_file') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
555 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
|
556 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
557 luafile Xlua_file |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
558 call assert_equal('hello', luaeval('str')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
559 call assert_equal(123.0, luaeval('num')) |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
560 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
561 lua str, num = nil |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
562 call delete('Xlua_file') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
563 endfunc |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
564 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
565 " Test :luafile % |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
566 func Test_luafile_percent() |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
567 new Xlua_file |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
568 append |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
569 str, num = 'foo', 321.0 |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
570 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
|
571 . |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
572 w! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
573 luafile % |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
574 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
|
575 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
|
576 |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
577 lua str, num = nil |
14230
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
578 call delete('Xlua_file') |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
579 bwipe! |
2e95ea9afa1e
patch 8.1.0132: lua tests are old style
Christian Brabandt <cb@256bit.org>
parents:
10757
diff
changeset
|
580 endfunc |
14239
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
581 |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
582 " 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
|
583 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
|
584 new Xlua_file |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
585 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
|
586 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
|
587 |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
588 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
|
589 |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
590 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
|
591 bwipe! |
7457bf2db968
patch 8.1.0136: Lua tests don't cover new features
Christian Brabandt <cb@256bit.org>
parents:
14235
diff
changeset
|
592 endfunc |
14395
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
593 |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
594 func Test_set_cursor() |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
595 " 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
|
596 new |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
597 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
|
598 normal gg |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
599 lua << EOF |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
600 w = vim.window() |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
601 w.line = 1 |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
602 w.col = 5 |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
603 EOF |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
604 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
|
605 |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
606 " 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
|
607 normal j |
c15bef307de6
patch 8.1.0212: preferred cursor column not set in interfaces
Christian Brabandt <cb@256bit.org>
parents:
14296
diff
changeset
|
608 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
|
609 endfunc |