robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
63094e0013
master
1" Test :z 2 3func Test_z () 4call setline ( 1 , range ( 1 , 100 )) 5 6let a = execute ( '20z3' ) 7call assert_equal ( "\n20\n21\n22" , a ) 8call assert_equal ( 22 , line ( '.' )) 9" 'window' should be set to the {count} value. 10call assert_equal ( 3 , & window ) 11 12" If there is only one window, then twice the amount of 'scroll' is used. 13set scroll = 2 14let a = execute ( '20z' ) 15call assert_equal ( "\n20\n21\n22\n23" , a ) 16call assert_equal ( 23 , line ( '.' )) 17 18let a = execute ( '20z+3' ) 19" FIXME: I would expect the same result as '20z3' since 'help z' 20" says: Specifying no mark at all is the same as "+". 21" However it " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"? 22"call assert_equal("\n20\n21\n22", a) 23"call assert_equal(22, line('.')) 24 25let a = execute ( '20z-3' ) 26call assert_equal ( "\n18\n19\n20" , a ) 27call assert_equal ( 20 , line ( '.' )) 28 29let a = execute ( '20z=3' ) 30call assert_match ( "^\n18\n19\n-\\+\n20\n-\\+\n21\n22$" , a ) 31call assert_equal ( 20 , line ( '.' )) 32 33let a = execute ( '20z^3' ) 34call assert_equal ( "\n14\n15\n16\n17" , a ) 35call assert_equal ( 17 , line ( '.' )) 36 37let a = execute ( '20z.3' ) 38call assert_equal ( "\n19\n20\n21" , a ) 39call assert_equal ( 21 , line ( '.' )) 40 41let a = execute ( '20z#3' ) 42call assert_equal ( "\n 20 20\n 21 21\n 22 22" , a ) 43call assert_equal ( 22 , line ( '.' )) 44 45let a = execute ( '20z#-3' ) 46call assert_equal ( "\n 18 18\n 19 19\n 20 20" , a ) 47call assert_equal ( 20 , line ( '.' )) 48 49let a = execute ( '20z#=3' ) 50call assert_match ( "^\n 18 18\n 19 19\n-\\+\n 20 20\n-\\+\n 21 21\n 22 22$" , a ) 51call assert_equal ( 20 , line ( '.' )) 52 53" Test with {count} bigger than the number of lines in buffer. 54let a = execute ( '20z1000' ) 55call assert_match ( "^\n20\n21\n.*\n99\n100$" , a ) 56call assert_equal ( 100 , line ( '.' )) 57 58let a = execute ( '20z-1000' ) 59call assert_equal ( 20 , line ( '.' )) 60 61let a = execute ( '20z=1000' ) 62call assert_match ( "^\n1\n.*\n-\\+\n20\n-\\\+\n.*\n100$" , a ) 63call assert_equal ( 20 , line ( '.' )) 64 65" Tests with multiple windows. 665 split 67call setline ( 1 , range ( 1 , 100 )) 68" Without a count, the number line is window height - 3. 69let a = execute ( '20z' ) 70call assert_equal ( "\n20\n21" , a ) 71call assert_equal ( 21 , line ( '.' )) 72" If window height - 3 is less than 1, it should be clamped to 1. 73resize 2 74let a = execute ( '20z' ) 75call assert_equal ( "\n20" , a ) 76call assert_equal ( 20 , line ( '.' )) 77 78call assert_fails ( '20z=a' , 'E144:' ) 79 80set window & scroll & 81bw ! 82endfunc 83 84" :z! is the same as :z but count uses the Vim window height when not specified. 85func Test_z_bang () 864 split 87call setline ( 1 , range ( 1 , 20 )) 88 89let a = execute ( '10z!' ) 90call assert_equal ( "\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20" , a ) 91 92let a = execute ( '10z!#' ) 93call assert_equal ( "\n 10 10\n 11 11\n 12 12\n 13 13\n 14 14\n 15 15\n 16 16\n 17 17\n 18 18\n 19 19\n 20 20" , a ) 94 95let a = execute ( '10z!3' ) 96call assert_equal ( "\n10\n11\n12" , a ) 97 98 %bwipe ! 99endfunc 100 101func Test_z_overflow () 102" This used to access invalid memory as a result of an integer overflow 103" and freeze vim. 104normal ox 105normal Heat 106z 777777776666666 107 ') 108endfunc 109 110func Test_z_negative_lnum () 111new 112z ^ 113call assert_equal ( 1 , line ( '.' )) 114bwipe ! 115endfunc