robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
3.2 KiB97 linesraw
1local n = require('test.functional.testnvim')()
2local t = require('test.testutil')
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local exec = n.exec
8local feed = n.feed
9local async_command = n.async_meths.nvim_command
10local poke_eventloop = n.poke_eventloop
11
12describe('getchar()', function()
13  before_each(clear)
14
15  -- oldtest: Test_getchar_cursor_position()
16  it('cursor positioning', function()
17    local screen = Screen.new(40, 6)
18    exec([[
19      call setline(1, ['foobar', 'foobar', 'foobar'])
20      call cursor(3, 6)
21    ]])
22    screen:expect([[
23      foobar                                  |*2
24      fooba^r                                  |
25      {1:~                                       }|*2
26                                              |
27    ]])
28
29    -- Default: behaves like "msg" when immediately after printing a message,
30    -- even if :sleep moved cursor elsewhere.
31    for _, cmd in ipairs({
32      'echo 1234 | call getchar()',
33      'echo 1234 | call getchar(-1, {})',
34      "echo 1234 | call getchar(-1, #{cursor: 'msg'})",
35      'echo 1234 | sleep 1m | call getchar()',
36      'echo 1234 | sleep 1m | call getchar(-1, {})',
37      "echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'msg'})",
38    }) do
39      async_command(cmd)
40      screen:expect([[
41        foobar                                  |*3
42        {1:~                                       }|*2
43        1234^                                    |
44      ]])
45      feed('a')
46      screen:expect([[
47        foobar                                  |*2
48        fooba^r                                  |
49        {1:~                                       }|*2
50        1234                                    |
51      ]])
52    end
53
54    -- Default: behaves like "keep" when not immediately after printing a message.
55    for _, cmd in ipairs({
56      'call getchar()',
57      'call getchar(-1, {})',
58      "call getchar(-1, #{cursor: 'keep'})",
59      "echo 1234 | sleep 1m | call getchar(-1, #{cursor: 'keep'})",
60    }) do
61      async_command(cmd)
62      poke_eventloop()
63      screen:expect_unchanged()
64      feed('a')
65      poke_eventloop()
66      screen:expect_unchanged()
67    end
68
69    async_command("call getchar(-1, #{cursor: 'msg'})")
70    screen:expect([[
71      foobar                                  |*3
72      {1:~                                       }|*2
73      ^1234                                    |
74    ]])
75    feed('a')
76    screen:expect([[
77      foobar                                  |*2
78      fooba^r                                  |
79      {1:~                                       }|*2
80      1234                                    |
81    ]])
82
83    async_command("call getchar(-1, #{cursor: 'hide'})")
84    screen:expect([[
85      foobar                                  |*3
86      {1:~                                       }|*2
87      1234                                    |
88    ]])
89    feed('a')
90    screen:expect([[
91      foobar                                  |*2
92      fooba^r                                  |
93      {1:~                                       }|*2
94      1234                                    |
95    ]])
96  end)
97end)