From 6bf5b2428b146330688922d66438357c0568725d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 12:26:02 +0800 Subject: vim-patch:8.1.2066: no tests for state() Problem: No tests for state(). Solution: Add tests. Clean up some feature checks. Make "a" flag work. https://github.com/vim/vim/commit/c2585490321854ca3df115efcf0b40986901d96c Co-authored-by: Bram Moolenaar --- test/functional/vimscript/state_spec.lua | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 test/functional/vimscript/state_spec.lua (limited to 'test/functional/vimscript/state_spec.lua') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua new file mode 100644 index 0000000000..dcff3c8d7e --- /dev/null +++ b/test/functional/vimscript/state_spec.lua @@ -0,0 +1,69 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local eq = helpers.eq +local exec = helpers.exec +local exec_lua = helpers.exec_lua +local feed = helpers.feed +local meths = helpers.meths +local poke_eventloop = helpers.poke_eventloop + +before_each(clear) + +describe('state() function', function() + it('works', function() + meths.ui_attach(80, 24, {}) -- Allow hit-enter-prompt + + exec_lua([[ + function _G.Get_state_mode() + _G.res = { vim.fn.state(), vim.api.nvim_get_mode().mode:sub(1, 1) } + end + + function _G.Run_timer() + local timer = vim.uv.new_timer() + timer:start(0, 0, function() + _G.Get_state_mode() + timer:close() + end) + end + ]]) + exec([[ + call setline(1, ['one', 'two', 'three']) + map ;; gg + func RunTimer() + call timer_start(0, {id -> v:lua.Get_state_mode()}) + endfunc + au Filetype foobar call v:lua.Get_state_mode() + ]]) + + -- Using a ":" command Vim is busy, thus "S" is returned + feed([[:call v:lua.Get_state_mode()]]) + eq({ 'S', 'n' }, exec_lua('return _G.res')) + + -- Using a timer callback + feed([[:call RunTimer()]]) + poke_eventloop() -- Allow polling for events + eq({ 'c', 'n' }, exec_lua('return _G.res')) + + -- Halfway a mapping + feed([[:call v:lua.Run_timer();]]) + meths.get_mode() -- Allow polling for fast events + feed(';') + eq({ 'mS', 'n' }, exec_lua('return _G.res')) + + -- Insert mode completion + feed([[:call RunTimer()Got]]) + poke_eventloop() -- Allow polling for events + feed('') + eq({ 'aSc', 'i' }, exec_lua('return _G.res')) + + -- Autocommand executing + feed([[:set filetype=foobar]]) + eq({ 'xS', 'n' }, exec_lua('return _G.res')) + + -- messages scrolled + feed([[:call v:lua.Run_timer() | echo "one\ntwo\nthree"]]) + meths.get_mode() -- Allow polling for fast events + feed('') + eq({ 'Ss', 'r' }, exec_lua('return _G.res')) + end) +end) -- cgit From 71acb7104344e3631e995b973416776aeadda0e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 13:21:28 +0800 Subject: vim-patch:8.1.2099: state() test fails on some Mac systems Problem: state() test fails on some Mac systems. Solution: Increase the wait time. (closes vim/vim#4983) https://github.com/vim/vim/commit/b7a97ef340f03ca08df8c8e00cd5580f61aac824 Co-authored-by: Bram Moolenaar --- test/functional/vimscript/state_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/vimscript/state_spec.lua') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index dcff3c8d7e..fd38a8ad5b 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -29,6 +29,7 @@ describe('state() function', function() exec([[ call setline(1, ['one', 'two', 'three']) map ;; gg + set complete=. func RunTimer() call timer_start(0, {id -> v:lua.Get_state_mode()}) endfunc @@ -51,7 +52,7 @@ describe('state() function', function() eq({ 'mS', 'n' }, exec_lua('return _G.res')) -- Insert mode completion - feed([[:call RunTimer()Got]]) + feed([[:call RunTimer()Got]]) poke_eventloop() -- Allow polling for events feed('') eq({ 'aSc', 'i' }, exec_lua('return _G.res')) -- cgit From 6aa29d0f01e715fe51de4f66dee377e4c1726229 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 13:45:26 +0800 Subject: test: add some tests for SafeState autocommand --- test/functional/vimscript/state_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/functional/vimscript/state_spec.lua') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index fd38a8ad5b..70f68a7494 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -17,7 +17,6 @@ describe('state() function', function() function _G.Get_state_mode() _G.res = { vim.fn.state(), vim.api.nvim_get_mode().mode:sub(1, 1) } end - function _G.Run_timer() local timer = vim.uv.new_timer() timer:start(0, 0, function() -- cgit From 20f76ebf2b5aec799b0f90e5e892a4b88597d427 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 23 Aug 2023 00:00:57 +0800 Subject: test: fix state() test flakiness (#24839) --- test/functional/vimscript/state_spec.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'test/functional/vimscript/state_spec.lua') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index 70f68a7494..1acfb1337d 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -41,18 +41,20 @@ describe('state() function', function() -- Using a timer callback feed([[:call RunTimer()]]) - poke_eventloop() -- Allow polling for events + poke_eventloop() -- Process pending input + poke_eventloop() -- Process time_event eq({ 'c', 'n' }, exec_lua('return _G.res')) -- Halfway a mapping feed([[:call v:lua.Run_timer();]]) - meths.get_mode() -- Allow polling for fast events + meths.get_mode() -- Process pending input and luv timer callback feed(';') eq({ 'mS', 'n' }, exec_lua('return _G.res')) -- Insert mode completion feed([[:call RunTimer()Got]]) - poke_eventloop() -- Allow polling for events + poke_eventloop() -- Process pending input + poke_eventloop() -- Process time_event feed('') eq({ 'aSc', 'i' }, exec_lua('return _G.res')) @@ -62,7 +64,7 @@ describe('state() function', function() -- messages scrolled feed([[:call v:lua.Run_timer() | echo "one\ntwo\nthree"]]) - meths.get_mode() -- Allow polling for fast events + meths.get_mode() -- Process pending input and luv timer callback feed('') eq({ 'Ss', 'r' }, exec_lua('return _G.res')) end) -- cgit From 6462ee1c10f9f1aa66ffc4d4fe1b7b3d9f0f91af Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 23 Aug 2023 06:42:10 +0800 Subject: vim-patch:9.0.1779: Need more state() tests (#24840) Problem: Need more state() tests Solution: Add a few more tests for operater pending mode and register yank command closes: vim/vim#12883 https://github.com/vim/vim/commit/8dabccd295271104ad5af0abc48e283d644cff59 --- test/functional/vimscript/state_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/vimscript/state_spec.lua') diff --git a/test/functional/vimscript/state_spec.lua b/test/functional/vimscript/state_spec.lua index 1acfb1337d..0508b8b1da 100644 --- a/test/functional/vimscript/state_spec.lua +++ b/test/functional/vimscript/state_spec.lua @@ -10,6 +10,7 @@ local poke_eventloop = helpers.poke_eventloop before_each(clear) describe('state() function', function() + -- oldtest: Test_state() it('works', function() meths.ui_attach(80, 24, {}) -- Allow hit-enter-prompt @@ -51,6 +52,20 @@ describe('state() function', function() feed(';') eq({ 'mS', 'n' }, exec_lua('return _G.res')) + -- An operator is pending + feed([[:call RunTimer()y]]) + poke_eventloop() -- Process pending input + poke_eventloop() -- Process time_event + feed('y') + eq({ 'oSc', 'n' }, exec_lua('return _G.res')) + + -- A register was specified + feed([[:call RunTimer()"r]]) + poke_eventloop() -- Process pending input + poke_eventloop() -- Process time_event + feed('yy') + eq({ 'oSc', 'n' }, exec_lua('return _G.res')) + -- Insert mode completion feed([[:call RunTimer()Got]]) poke_eventloop() -- Process pending input -- cgit