robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
6fa9f45723
master
1" Tests for the changelist functionality 2 3" When splitting a window the changelist position is wrong. 4" Test the changelist position after splitting a window. 5" Test for the bug fixed by 7.4.386 6func Test_changelist () 7let save_ul = & ul 8enew ! 9call append ( '$' , [ '1' , '2' ]) 10exe "normal i\<C-G>u" 11exe "normal Gkylpa\<C-G>u" 12set ul = 100 13exe "normal Gylpa\<C-G>u" 14set ul = 100 15normal gg 16vsplit 17normal g; 18call assert_equal ([ 3 , 2 ], [ line ( '.' ), col ( '.' )]) 19normal g; 20call assert_equal ([ 2 , 2 ], [ line ( '.' ), col ( '.' )]) 21call assert_fails ( 'normal g;' , 'E662:' ) 22new 23call assert_fails ( 'normal g;' , 'E664:' ) 24 %bwipe ! 25let & ul = save_ul 26endfunc 27 28" Moving a split should not change its changelist index. 29func Test_changelist_index_move_split () 30exe "norm! iabc\<C-G>u\ndef\<C-G>u\nghi" 31vsplit 32normal 99g; 33call assert_equal ( 0 , getchangelist ( '%' )[ 1 ]) 34wincmd L 35call assert_equal ( 0 , getchangelist ( '%' )[ 1 ]) 36endfunc 37 38" Tests for the getchangelist() function 39func Test_changelist_index () 40edit Xgclfile1.txt 41exe "normal iabc\<C-G>u\ndef\<C-G>u\nghi" 42call assert_equal ( 3 , getchangelist ( '%' )[ 1 ]) 43" Move one step back in the changelist. 44normal 2g; 45 46hide edit Xgclfile2.txt 47exe "normal iabcd\<C-G>u\ndefg\<C-G>u\nghij" 48call assert_equal ( 3 , getchangelist ( '%' )[ 1 ]) 49" Move to the beginning of the changelist. 50normal 99g; 51 52" Check the changelist indices. 53call assert_equal ( 0 , getchangelist ( '%' )[ 1 ]) 54call assert_equal ( 1 , getchangelist ( '#' )[ 1 ]) 55 56bwipe ! 57call delete ( 'Xgclfile1.txt' ) 58call delete ( 'Xgclfile2.txt' ) 59endfunc 60 61func Test_getchangelist () 62bwipe ! 63enew 64call assert_equal ([], 10 ->getchangelist ()) 65call assert_equal ([[], 0 ], getchangelist ()) 66 67call writefile ([ 'line1' , 'line2' , 'line3' ], 'Xclistfile1.txt' ) 68call writefile ([ 'line1' , 'line2' , 'line3' ], 'Xclistfile2.txt' ) 69 70edit Xclistfile1.txt 71let buf_1 = bufnr () 72exe "normal 1Goline\<C-G>u1.1" 73exe "normal 3Goline\<C-G>u2.1" 74exe "normal 5Goline\<C-G>u3.1" 75normal g; 76call assert_equal ([[ 77 \{ 'lnum' : 2 , 'col' : 4 , 'coladd' : 0 }, 78 \{ 'lnum' : 4 , 'col' : 4 , 'coladd' : 0 }, 79 \{ 'lnum' : 6 , 'col' : 4 , 'coladd' : 0 }], 2 ], 80 \getchangelist ( '%' )) 81 82hide edit Xclistfile2.txt 83let buf_2 = bufnr () 84exe "normal 1GOline\<C-G>u1.0" 85exe "normal 2Goline\<C-G>u2.0" 86call assert_equal ([[ 87 \{ 'lnum' : 1 , 'col' : 6 , 'coladd' : 0 }, 88 \{ 'lnum' : 3 , 'col' : 6 , 'coladd' : 0 }], 2 ], 89 \getchangelist ( '%' )) 90hide enew 91 92call assert_equal ([[ 93 \{ 'lnum' : 2 , 'col' : 4 , 'coladd' : 0 }, 94 \{ 'lnum' : 4 , 'col' : 4 , 'coladd' : 0 }, 95 \{ 'lnum' : 6 , 'col' : 4 , 'coladd' : 0 }], 2 ], 96 \getchangelist ( buf_1 )) 97call assert_equal ([[ 98 \{ 'lnum' : 1 , 'col' : 6 , 'coladd' : 0 }, 99 \{ 'lnum' : 3 , 'col' : 6 , 'coladd' : 0 }], 2 ], 100 \getchangelist ( buf_2 )) 101 102bwipe ! 103call delete ( 'Xclistfile1.txt' ) 104call delete ( 'Xclistfile2.txt' ) 105endfunc 106 107" vim: shiftwidth=2 sts=2 expandtab