aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/getchar_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
committerJosh Rahm <joshuarahm@gmail.com>2025-02-05 23:09:29 +0000
commitd5f194ce780c95821a855aca3c19426576d28ae0 (patch)
treed45f461b19f9118ad2bb1f440a7a08973ad18832 /test/functional/vimscript/getchar_spec.lua
parentc5d770d311841ea5230426cc4c868e8db27300a8 (diff)
parent44740e561fc93afe3ebecfd3618bda2d2abeafb0 (diff)
downloadrneovim-rahm.tar.gz
rneovim-rahm.tar.bz2
rneovim-rahm.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309HEADrahm
Diffstat (limited to 'test/functional/vimscript/getchar_spec.lua')
-rw-r--r--test/functional/vimscript/getchar_spec.lua95
1 files changed, 95 insertions, 0 deletions
diff --git a/test/functional/vimscript/getchar_spec.lua b/test/functional/vimscript/getchar_spec.lua
new file mode 100644
index 0000000000..4ecf082f97
--- /dev/null
+++ b/test/functional/vimscript/getchar_spec.lua
@@ -0,0 +1,95 @@
+local n = require('test.functional.testnvim')()
+local Screen = require('test.functional.ui.screen')
+
+local clear = n.clear
+local exec = n.exec
+local feed = n.feed
+local async_command = n.async_meths.nvim_command
+local poke_eventloop = n.poke_eventloop
+
+describe('getchar()', function()
+ before_each(clear)
+
+ -- oldtest: Test_getchar_cursor_position()
+ it('cursor positioning', function()
+ local screen = Screen.new(40, 6)
+ exec([[
+ call setline(1, ['foobar', 'foobar', 'foobar'])
+ call cursor(3, 6)
+ ]])
+ screen:expect([[
+ foobar |*2
+ fooba^r |
+ {1:~ }|*2
+ |
+ ]])
+
+ -- Default: behaves like "msg" when immediately after printing a message,
+ -- even if :sleep moved cursor elsewhere.
+ for _, cmd in ipairs({
+ 'echo 1234 | call getchar()',
+ 'echo 1234 | call getchar(-1, {})',
+ "echo 1234 | call getchar(-1, #{cursor: 'msg'})",
+ 'echo 1234 | sleep 1m | call getchar()',
+ 'echo 1234 | sleep 1m | call getchar(-1, {})',
+ "echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'msg'})",
+ }) do
+ async_command(cmd)
+ screen:expect([[
+ foobar |*3
+ {1:~ }|*2
+ 1234^ |
+ ]])
+ feed('a')
+ screen:expect([[
+ foobar |*2
+ fooba^r |
+ {1:~ }|*2
+ 1234 |
+ ]])
+ end
+
+ -- Default: behaves like "keep" when not immediately after printing a message.
+ for _, cmd in ipairs({
+ 'call getchar()',
+ 'call getchar(-1, {})',
+ "call getchar(-1, #{cursor: 'keep'})",
+ "echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'keep'})",
+ }) do
+ async_command(cmd)
+ poke_eventloop()
+ screen:expect_unchanged()
+ feed('a')
+ poke_eventloop()
+ screen:expect_unchanged()
+ end
+
+ async_command("call getchar(-1, #{cursor: 'msg'})")
+ screen:expect([[
+ foobar |*3
+ {1:~ }|*2
+ ^1234 |
+ ]])
+ feed('a')
+ screen:expect([[
+ foobar |*2
+ fooba^r |
+ {1:~ }|*2
+ 1234 |
+ ]])
+
+ async_command("call getchar(-1, #{cursor: 'hide'})")
+ screen:expect([[
+ foobar |*3
+ {1:~ }|*2
+ 1234 |
+ ]])
+ feed('a')
+ screen:expect([[
+ foobar |*2
+ fooba^r |
+ {1:~ }|*2
+ 1234 |
+ ]])
+ end)
+end)