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 api =n . api 6local clear =n . clear 7local command =n . command 8local eq =t . eq 9local eval =n . eval 10local feed =n . feed 11local fn =n . fn 12 13local function set_lines ( lines ) 14api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , lines ) 15end 16 17local function get_lines () 18return api . nvim_buf_get_lines ( 0 , 0 , - 1 , true ) 19end 20 21local function set_cursor ( row , col ) 22api . nvim_win_set_cursor ( 0 , { row , col } ) 23end 24 25describe ( 'line textobject' , function () 26before_each ( clear ) 27 28it ( 'selects the current line without surrounding whitespace' , function () 29set_lines ( { 'one' , ' two words ' , 'three' } ) 30set_cursor ( 2 , 4 ) 31feed ( 'yil' ) 32eq ( 'two words' , fn . getreg ( '"' )) 33 34set_cursor ( 2 , 4 ) 35feed ( 'vily' ) 36eq ( 'two words' , fn . getreg ( '"' )) 37eq ( 'v' , fn . visualmode ()) 38 39set_cursor ( 2 , 4 ) 40feed ( 'Vily' ) 41eq ( 'two words' , fn . getreg ( '"' )) 42eq ( 'v' , fn . visualmode ()) 43 44set_cursor ( 2 , 0 ) 45feed ( '0v$ily' ) 46eq ( 'two words' , fn . getreg ( '"' )) 47 48set_cursor ( 1 , 0 ) 49feed ( 'Vjily' ) 50eq ( 'two words' , fn . getreg ( '"' )) 51 52command ( 'set selection=exclusive' ) 53set_cursor ( 2 , 4 ) 54feed ( 'vily' ) 55eq ( 'two words' , fn . getreg ( '"' )) 56command ( 'set selection&' ) 57 58set_cursor ( 2 , 4 ) 59feed ( 'dil' ) 60eq ( { 'one' , ' ' , 'three' } , get_lines ()) 61 62set_lines ( { ' αβ ' , ' ' , 'last' } ) 63set_cursor ( 1 , 2 ) 64feed ( 'yil' ) 65eq ( 'αβ' , fn . getreg ( '"' )) 66 67command ( 'set selection=exclusive' ) 68set_cursor ( 1 , 2 ) 69feed ( 'vily' ) 70eq ( 'αβ' , fn . getreg ( '"' )) 71command ( 'set selection&' ) 72 73fn . setreg ( '"' , 'unchanged' ) 74set_cursor ( 2 , 0 ) 75eq ( 0 , fn . assert_beeps ( 'normal yil' )) 76eq ( 'unchanged' , fn . getreg ( '"' )) 77 78set_cursor ( 2 , 0 ) 79eq ( 0 , fn . assert_beeps ( 'normal vily' )) 80eq ( 'unchanged' , fn . getreg ( '"' )) 81end ) 82 83it ( 'selects all lines without moving the cursor for yank' , function () 84set_lines ( { ' αβ ' , ' ' , 'last' } ) 85command ( 'let g:textobj_line_yank_pos = []' ) 86command ( [[autocmd TextYankPost <buffer> ++once let g:textobj_line_yank_pos = getpos('.')]] ) 87 88set_cursor ( 3 , 0 ) 89feed ( 'yal' ) 90eq ( ' αβ \n \nlast\n' , fn . getreg ( '"' )) 91eq ( { 0 , 3 , 1 , 0 } , fn . getpos ( '.' )) 92eq ( { 0 , 3 , 1 , 0 } , eval ( 'g:textobj_line_yank_pos' )) 93 94set_cursor ( 3 , 0 ) 95feed ( 'valy' ) 96eq ( ' αβ \n \nlast\n' , fn . getreg ( '"' )) 97eq ( 'V' , fn . visualmode ()) 98 99set_cursor ( 2 , 0 ) 100feed ( 'dal' ) 101eq ( { '' } , get_lines ()) 102end ) 103end )