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