From 1037ce2e461034a20e35ad59969fd05d5ad68b91 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 9 Dec 2023 20:42:00 +0800 Subject: test: avoid repeated screen lines in expected states This is the command invoked repeatedly to make the changes: :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g --- test/functional/lua/loop_spec.lua | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'test/functional/lua/loop_spec.lua') diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index c0924fa0c0..4f98fe0977 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -112,14 +112,7 @@ describe('vim.uv', function() screen:expect([[ ^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*8 howdy | ]]) eq(true, eval("get(g:, 'valid', v:false)")) @@ -137,14 +130,7 @@ describe('vim.uv', function() ]]) screen:expect([[ sneaky^ | - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*8 {5:-- INSERT --} | ]]) eq({blocking=false, mode='n'}, exec_lua("return _G.mode")) -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/lua/loop_spec.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'test/functional/lua/loop_spec.lua') diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index 4f98fe0977..e46dbe7455 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -15,16 +15,15 @@ local retry = helpers.retry before_each(clear) describe('vim.uv', function() - it('version', function() - assert(funcs.luaeval('vim.uv.version()')>=72961, "libuv version too old") - matches("(%d+)%.(%d+)%.(%d+)", funcs.luaeval('vim.uv.version_string()')) + assert(funcs.luaeval('vim.uv.version()') >= 72961, 'libuv version too old') + matches('(%d+)%.(%d+)%.(%d+)', funcs.luaeval('vim.uv.version_string()')) end) it('timer', function() exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {}) - local code=[[ + local code = [[ local uv = vim.uv local touch = 0 @@ -61,14 +60,14 @@ describe('vim.uv', function() end) it('is API safe', function() - local screen = Screen.new(50,10) + local screen = Screen.new(50, 10) screen:attach() screen:set_default_attr_ids({ - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, - [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, - [5] = {bold = true}, + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red }, + [4] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + [5] = { bold = true }, }) -- deferred API functions are disabled, as their safety can't be guaranteed @@ -96,7 +95,7 @@ describe('vim.uv', function() ]]) feed('') eq(false, eval("get(g:, 'valid', v:false)")) - eq(true, exec_lua("return _G.is_fast")) + eq(true, exec_lua('return _G.is_fast')) -- callbacks can be scheduled to be executed in the main event loop -- where the entire API is available @@ -116,7 +115,7 @@ describe('vim.uv', function() howdy | ]]) eq(true, eval("get(g:, 'valid', v:false)")) - eq(false, exec_lua("return _G.is_fast")) + eq(false, exec_lua('return _G.is_fast')) -- fast (not deferred) API functions are allowed to be called directly exec_lua([[ @@ -133,7 +132,7 @@ describe('vim.uv', function() {1:~ }|*8 {5:-- INSERT --} | ]]) - eq({blocking=false, mode='n'}, exec_lua("return _G.mode")) + eq({ blocking = false, mode = 'n' }, exec_lua('return _G.mode')) end) it("is equal to require('luv')", function() -- cgit From 7a259d01aed52134a1675e47d9054ccad7ef7cbb Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 11:41:09 +0000 Subject: test: remove helpers.sleep() --- test/functional/lua/loop_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/lua/loop_spec.lua') diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index e46dbe7455..38d6f1c24f 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -4,7 +4,7 @@ local Screen = require('test.functional.ui.screen') local funcs = helpers.funcs local meths = helpers.meths local clear = helpers.clear -local sleep = helpers.sleep +local sleep = vim.uv.sleep local feed = helpers.feed local eq = helpers.eq local eval = helpers.eval -- cgit From 284e0ad26dd9de90c3a813dd1b357a425eca6bad Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:03:25 +0000 Subject: test: use vim.mpack and vim.uv directly --- test/functional/lua/loop_spec.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/functional/lua/loop_spec.lua') diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index 38d6f1c24f..3bce30bffb 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -24,13 +24,11 @@ describe('vim.uv', function() exec_lua('vim.api.nvim_set_var("coroutine_cnt", 0)', {}) local code = [[ - local uv = vim.uv - local touch = 0 local function wait(ms) local this = coroutine.running() assert(this) - local timer = uv.new_timer() + local timer = vim.uv.new_timer() timer:start(ms, 0, vim.schedule_wrap(function () timer:close() touch = touch + 1 -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/lua/loop_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/lua/loop_spec.lua') diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index 3bce30bffb..9452866b8e 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -48,13 +48,13 @@ describe('vim.uv', function() end)() ]] - eq(0, meths.get_var('coroutine_cnt')) + eq(0, meths.nvim_get_var('coroutine_cnt')) exec_lua(code) retry(2, nil, function() sleep(50) - eq(2, meths.get_var('coroutine_cnt')) + eq(2, meths.nvim_get_var('coroutine_cnt')) end) - eq(3, meths.get_var('coroutine_cnt_1')) + eq(3, meths.nvim_get_var('coroutine_cnt_1')) end) it('is API safe', function() -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/lua/loop_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/functional/lua/loop_spec.lua') diff --git a/test/functional/lua/loop_spec.lua b/test/functional/lua/loop_spec.lua index 9452866b8e..71eaf29009 100644 --- a/test/functional/lua/loop_spec.lua +++ b/test/functional/lua/loop_spec.lua @@ -1,8 +1,8 @@ -- Test suite for testing interactions with API bindings local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local funcs = helpers.funcs -local meths = helpers.meths +local fn = helpers.fn +local api = helpers.api local clear = helpers.clear local sleep = vim.uv.sleep local feed = helpers.feed @@ -16,8 +16,8 @@ before_each(clear) describe('vim.uv', function() it('version', function() - assert(funcs.luaeval('vim.uv.version()') >= 72961, 'libuv version too old') - matches('(%d+)%.(%d+)%.(%d+)', funcs.luaeval('vim.uv.version_string()')) + assert(fn.luaeval('vim.uv.version()') >= 72961, 'libuv version too old') + matches('(%d+)%.(%d+)%.(%d+)', fn.luaeval('vim.uv.version_string()')) end) it('timer', function() @@ -48,13 +48,13 @@ describe('vim.uv', function() end)() ]] - eq(0, meths.nvim_get_var('coroutine_cnt')) + eq(0, api.nvim_get_var('coroutine_cnt')) exec_lua(code) retry(2, nil, function() sleep(50) - eq(2, meths.nvim_get_var('coroutine_cnt')) + eq(2, api.nvim_get_var('coroutine_cnt')) end) - eq(3, meths.nvim_get_var('coroutine_cnt_1')) + eq(3, api.nvim_get_var('coroutine_cnt_1')) end) it('is API safe', function() -- cgit