diff options
Diffstat (limited to 'test/functional/lua')
-rw-r--r-- | test/functional/lua/treesitter_spec.lua | 19 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 81 |
2 files changed, 53 insertions, 47 deletions
diff --git a/test/functional/lua/treesitter_spec.lua b/test/functional/lua/treesitter_spec.lua index 494d6c84bb..f93185d1f6 100644 --- a/test/functional/lua/treesitter_spec.lua +++ b/test/functional/lua/treesitter_spec.lua @@ -245,6 +245,11 @@ static int nlua_schedule(lua_State *const lstate) (primitive_type) @type (sized_type_specifier) @type +; defaults to very magic syntax, for best compatibility +((identifier) @Identifier (match? @Identifier "^l(u)a_")) +; still support \M etc prefixes +((identifier) @Constant (match? @Constant "\M^\[A-Z_]\+$")) + ((binary_expression left: (identifier) @WarningMsg.left right: (identifier) @WarningMsg.right) (eq? @WarningMsg.left @WarningMsg.right)) (comment) @comment @@ -263,7 +268,7 @@ static int nlua_schedule(lua_State *const lstate) [8] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, [9] = {foreground = Screen.colors.Magenta, background = Screen.colors.Red}, [10] = {foreground = Screen.colors.Red, background = Screen.colors.Red}, - + [11] = {foreground = Screen.colors.Cyan4}, }) insert(hl_text) @@ -297,10 +302,10 @@ static int nlua_schedule(lua_State *const lstate) {2:/// Schedule Lua callback on main loop's event queue} | {3:static} {3:int} nlua_schedule(lua_State *{3:const} lstate) | { | - {4:if} (lua_type(lstate, {5:1}) != LUA_TFUNCTION | + {4:if} ({11:lua_type}(lstate, {5:1}) != {5:LUA_TFUNCTION} | || {6:lstate} != {6:lstate}) { | - lua_pushliteral(lstate, {5:"vim.schedule: expected function"}); | - {4:return} lua_error(lstate); | + {11:lua_pushliteral}(lstate, {5:"vim.schedule: expected function"}); | + {4:return} {11:lua_error}(lstate); | } | | {7:LuaRef} cb = nlua_ref(lstate, {5:1}); | @@ -319,10 +324,10 @@ static int nlua_schedule(lua_State *const lstate) {2:/// Schedule Lua callback on main loop's event queue} | {3:static} {3:int} nlua_schedule(lua_State *{3:const} lstate) | { | - {4:if} (lua_type(lstate, {5:1}) != LUA_TFUNCTION | + {4:if} ({11:lua_type}(lstate, {5:1}) != {5:LUA_TFUNCTION} | || {6:lstate} != {6:lstate}) { | - lua_pushliteral(lstate, {5:"vim.schedule: expected function"}); | - {4:return} lua_error(lstate); | + {11:lua_pushliteral}(lstate, {5:"vim.schedule: expected function"}); | + {4:return} {11:lua_error}(lstate); | {8:*^/} | } | | diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 2f459145f5..5ce4bf2973 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -315,10 +315,7 @@ describe('lua stdlib', function() local a = { x = { 1, 2 }, y = 5} local b = vim.deepcopy(a) - local count = 0 - for _ in pairs(b) do count = count + 1 end - - return b.x[1] == 1 and b.x[2] == 2 and b.y == 5 and count == 2 + return b.x[1] == 1 and b.x[2] == 2 and b.y == 5 and vim.tbl_count(b) == 2 and tostring(a) ~= tostring(b) ]])) @@ -326,31 +323,22 @@ describe('lua stdlib', function() local a = {} local b = vim.deepcopy(a) - local count = 0 - for _ in pairs(b) do count = count + 1 end - - return vim.tbl_islist(b) and count == 0 and tostring(a) ~= tostring(b) + return vim.tbl_islist(b) and vim.tbl_count(b) == 0 and tostring(a) ~= tostring(b) ]])) ok(exec_lua([[ local a = vim.empty_dict() local b = vim.deepcopy(a) - local count = 0 - for _ in pairs(b) do count = count + 1 end - - return not vim.tbl_islist(b) and count == 0 + return not vim.tbl_islist(b) and vim.tbl_count(b) == 0 ]])) ok(exec_lua([[ local a = {x = vim.empty_dict(), y = {}} local b = vim.deepcopy(a) - local count = 0 - for _ in pairs(b) do count = count + 1 end - return not vim.tbl_islist(b.x) and vim.tbl_islist(b.y) - and count == 2 + and vim.tbl_count(b) == 2 and tostring(a) ~= tostring(b) ]])) end) @@ -430,10 +418,7 @@ describe('lua stdlib', function() local b = {y = 2} local c = vim.tbl_extend("keep", a, b) - local count = 0 - for _ in pairs(c) do count = count + 1 end - - return c.x == 1 and b.y == 2 and count == 2 + return c.x == 1 and b.y == 2 and vim.tbl_count(c) == 2 ]])) ok(exec_lua([[ @@ -442,10 +427,7 @@ describe('lua stdlib', function() local c = {z = 3} local d = vim.tbl_extend("keep", a, b, c) - local count = 0 - for _ in pairs(d) do count = count + 1 end - - return d.x == 1 and d.y == 2 and d.z == 3 and count == 3 + return d.x == 1 and d.y == 2 and d.z == 3 and vim.tbl_count(d) == 3 ]])) ok(exec_lua([[ @@ -453,10 +435,7 @@ describe('lua stdlib', function() local b = {x = 3} local c = vim.tbl_extend("keep", a, b) - local count = 0 - for _ in pairs(c) do count = count + 1 end - - return c.x == 1 and count == 1 + return c.x == 1 and vim.tbl_count(c) == 1 ]])) ok(exec_lua([[ @@ -464,10 +443,7 @@ describe('lua stdlib', function() local b = {x = 3} local c = vim.tbl_extend("force", a, b) - local count = 0 - for _ in pairs(c) do count = count + 1 end - - return c.x == 3 and count == 1 + return c.x == 3 and vim.tbl_count(c) == 1 ]])) ok(exec_lua([[ @@ -475,10 +451,7 @@ describe('lua stdlib', function() local b = {} local c = vim.tbl_extend("keep", a, b) - local count = 0 - for _ in pairs(c) do count = count + 1 end - - return not vim.tbl_islist(c) and count == 0 + return not vim.tbl_islist(c) and vim.tbl_count(c) == 0 ]])) ok(exec_lua([[ @@ -486,10 +459,7 @@ describe('lua stdlib', function() local b = vim.empty_dict() local c = vim.tbl_extend("keep", a, b) - local count = 0 - for _ in pairs(c) do count = count + 1 end - - return vim.tbl_islist(c) and count == 0 + return vim.tbl_islist(c) and vim.tbl_count(c) == 0 ]])) eq('Error executing lua: .../shared.lua: invalid "behavior": nil', @@ -511,6 +481,19 @@ describe('lua stdlib', function() ) end) + it('vim.tbl_count', function() + eq(0, exec_lua [[ return vim.tbl_count({}) ]]) + eq(0, exec_lua [[ return vim.tbl_count(vim.empty_dict()) ]]) + eq(0, exec_lua [[ return vim.tbl_count({nil}) ]]) + eq(0, exec_lua [[ return vim.tbl_count({a=nil}) ]]) + eq(1, exec_lua [[ return vim.tbl_count({1}) ]]) + eq(2, exec_lua [[ return vim.tbl_count({1, 2}) ]]) + eq(2, exec_lua [[ return vim.tbl_count({1, nil, 3}) ]]) + eq(1, exec_lua [[ return vim.tbl_count({a=1}) ]]) + eq(2, exec_lua [[ return vim.tbl_count({a=1, b=2}) ]]) + eq(2, exec_lua [[ return vim.tbl_count({a=1, b=nil, c=3}) ]]) + end) + it('vim.deep_equal', function() eq(true, exec_lua [[ return vim.deep_equal({a=1}, {a=1}) ]]) eq(true, exec_lua [[ return vim.deep_equal({a={b=1}}, {a={b=1}}) ]]) @@ -844,4 +827,22 @@ describe('lua stdlib', function() eq('2', funcs.luaeval "BUF") eq(2, funcs.luaeval "#vim.api.nvim_list_bufs()") end) + + it('vim.regex', function() + exec_lua [[ + re1 = vim.regex"ab\\+c" + vim.cmd "set nomagic ignorecase" + re2 = vim.regex"xYz" + ]] + eq({}, exec_lua[[return {re1:match_str("x ac")}]]) + eq({3,7}, exec_lua[[return {re1:match_str("ac abbc")}]]) + + meths.buf_set_lines(0, 0, -1, true, {"yy", "abc abbc"}) + eq({}, exec_lua[[return {re1:match_line(0, 0)}]]) + eq({0,3}, exec_lua[[return {re1:match_line(0, 1)}]]) + eq({3,7}, exec_lua[[return {re1:match_line(0, 1, 1)}]]) + eq({3,7}, exec_lua[[return {re1:match_line(0, 1, 1, 8)}]]) + eq({}, exec_lua[[return {re1:match_line(0, 1, 1, 7)}]]) + eq({0,3}, exec_lua[[return {re1:match_line(0, 1, 0, 7)}]]) + end) end) |