robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
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 () 13before_each ( clear ) 14 15-- oldtest: Test_getchar_cursor_position() 16it ( 'cursor positioning' , function () 17local screen =Screen . new ( 40 , 6 ) 18exec ( [[ 19call setline(1, ['foobar', 'foobar', 'foobar']) 20call cursor(3, 6) 21]] ) 22screen : expect ( [[ 23foobar |*2 24fooba^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. 31for _ , 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 39async_command ( cmd ) 40screen : expect ( [[ 41foobar |*3 42{1:~ }|*2 431234^ | 44]] ) 45feed ( 'a' ) 46screen : expect ( [[ 47foobar |*2 48fooba^r | 49{1:~ }|*2 501234 | 51]] ) 52end 53 54-- Default: behaves like "keep" when not immediately after printing a message. 55for _ , 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 61async_command ( cmd ) 62poke_eventloop () 63screen : expect_unchanged () 64feed ( 'a' ) 65poke_eventloop () 66screen : expect_unchanged () 67end 68 69async_command ( "call getchar(-1, #{cursor: 'msg'})" ) 70screen : expect ( [[ 71foobar |*3 72{1:~ }|*2 73^1234 | 74]] ) 75feed ( 'a' ) 76screen : expect ( [[ 77foobar |*2 78fooba^r | 79{1:~ }|*2 801234 | 81]] ) 82 83async_command ( "call getchar(-1, #{cursor: 'hide'})" ) 84screen : expect ( [[ 85foobar |*3 86{1:~ }|*2 871234 | 88]] ) 89feed ( 'a' ) 90screen : expect ( [[ 91foobar |*2 92fooba^r | 93{1:~ }|*2 941234 | 95]] ) 96end ) 97end )