robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each =t . describe , t . it , t . before_each 5local setpos =n . fn . setpos 6local getpos =n . fn . getpos 7local insert =n . insert 8local clear =n . clear 9local command =n . command 10local eval =n . eval 11local eq =t . eq 12 13describe ( 'setpos() function' , function () 14before_each ( function () 15clear () 16insert ( [[ 17First line of text 18Second line of text 19Third line of text]] ) 20command ( 'new' ) 21insert ( [[ 22Line of text 1 23Line of text 2 24Line of text 3]] ) 25end ) 26it ( 'can set the current cursor position' , function () 27setpos ( '.' , { 0 , 2 , 1 , 0 } ) 28eq ( { 0 , 2 , 1 , 0 } , getpos ( '.' )) 29setpos ( '.' , { 2 , 1 , 1 , 0 } ) 30eq ( { 0 , 1 , 1 , 0 } , getpos ( '.' )) 31command ( 'call setpos(".", [1, 1, 1, 0])' ) 32end ) 33it ( 'can set lowercase marks in the current buffer' , function () 34setpos ( "'d" , { 0 , 2 , 1 , 0 } ) 35eq ( { 0 , 2 , 1 , 0 } , getpos ( "'d" )) 36command ( 'undo' ) 37command ( 'call setpos("\'d", [2, 3, 1, 0])' ) 38eq ( { 0 , 3 , 1 , 0 } , getpos ( "'d" )) 39end ) 40it ( 'can set lowercase marks in other buffers' , function () 41local retval =setpos ( "'d" , { 1 , 2 , 1 , 0 } ) 42eq ( 0 , retval ) 43setpos ( "'d" , { 1 , 2 , 1 , 0 } ) 44eq ( { 0 , 0 , 0 , 0 } , getpos ( "'d" )) 45command ( 'wincmd w' ) 46eq ( 1 , eval ( 'bufnr("%")' )) 47eq ( { 0 , 2 , 1 , 0 } , getpos ( "'d" )) 48end ) 49it ( "fails when setting a mark in a buffer that doesn't exist" , function () 50local retval =setpos ( "'d" , { 3 , 2 , 1 , 0 } ) 51eq ( - 1 , retval ) 52eq ( { 0 , 0 , 0 , 0 } , getpos ( "'d" )) 53retval =setpos ( "'D" , { 3 , 2 , 1 , 0 } ) 54eq ( - 1 , retval ) 55eq ( { 0 , 0 , 0 , 0 } , getpos ( "'D" )) 56end ) 57it ( 'can set uppercase marks' , function () 58setpos ( "'D" , { 2 , 2 , 3 , 0 } ) 59eq ( { 2 , 2 , 3 , 0 } , getpos ( "'D" )) 60-- Can set a mark in another buffer 61setpos ( "'D" , { 1 , 2 , 2 , 0 } ) 62eq ( { 1 , 2 , 2 , 0 } , getpos ( "'D" )) 63end ) 64end )