robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
af23d17388
master
1" Test using the window ID. 2 3source check.vim 4 5func Test_win_getid () 6edit one 7let id1 = win_getid () 8let w: one = 'one' 9split two 10let id2 = win_getid () 11let bufnr2 = bufnr ( '%' ) 12let w: two = 'two' 13split three 14let id3 = win_getid () 15let w: three = 'three' 16tabnew 17edit four 18let id4 = win_getid () 19let w: four = 'four' 20split five 21let id5 = win_getid () 22let bufnr5 = bufnr ( '%' ) 23let w: five = 'five' 24tabnext 25 26wincmd w 27call assert_equal ( "two" , expand ( "%" )) 28call assert_equal ( id2 , win_getid ()) 29let nr2 = winnr () 30wincmd w 31call assert_equal ( "one" , expand ( "%" )) 32call assert_equal ( id1 , win_getid ()) 33let nr1 = winnr () 34wincmd w 35call assert_equal ( "three" , expand ( "%" )) 36call assert_equal ( id3 , win_getid ()) 37let nr3 = winnr () 38call assert_equal ( 'one' , getwinvar ( id1 , 'one' )) 39call assert_equal ( 'two' , getwinvar ( id2 , 'two' )) 40call assert_equal ( 'three' , getwinvar ( id3 , 'three' )) 41tabnext 42call assert_equal ( "five" , expand ( "%" )) 43call assert_equal ( id5 , win_getid ()) 44let nr5 = winnr () 45wincmd w 46call assert_equal ( "four" , expand ( "%" )) 47call assert_equal ( id4 , win_getid ()) 48let nr4 = winnr () 49call assert_equal ( 'four' , getwinvar ( id4 , 'four' )) 50call assert_equal ( 'five' , getwinvar ( id5 , 'five' )) 51call settabwinvar ( 1 , id2 , 'two' , '2' ) 52call setwinvar ( id4 , 'four' , '4' ) 53tabnext 54call assert_equal ( '4' , gettabwinvar ( 2 , id4 , 'four' )) 55call assert_equal ( 'five' , gettabwinvar ( 2 , id5 , 'five' )) 56call assert_equal ( '2' , getwinvar ( id2 , 'two' )) 57 58exe nr1 . "wincmd w" 59call assert_equal ( id1 , win_getid ()) 60exe nr2 . "wincmd w" 61call assert_equal ( id2 , win_getid ()) 62exe nr3 . "wincmd w" 63call assert_equal ( id3 , win_getid ()) 64tabnext 65exe nr4 . "wincmd w" 66call assert_equal ( id4 , win_getid ()) 67exe nr5 . "wincmd w" 68call assert_equal ( id5 , win_getid ()) 69 70call win_gotoid ( id2 ) 71call assert_equal ( "two" , expand ( "%" )) 72eval id4 ->win_gotoid () 73call assert_equal ( "four" , expand ( "%" )) 74call win_gotoid ( id1 ) 75call assert_equal ( "one" , expand ( "%" )) 76call win_gotoid ( id5 ) 77call assert_equal ( "five" , expand ( "%" )) 78 79call assert_equal ( 0 , win_id2win ( 9999 )) 80call assert_equal ( nr5 , id5 ->win_id2win ()) 81call assert_equal ( 0 , win_id2win ( id1 )) 82tabnext 83call assert_equal ( nr1 , win_id2win ( id1 )) 84 85call assert_equal ([ 0 , 0 ], win_id2tabwin ( 9999 )) 86call assert_equal ([ 1 , nr2 ], id2 ->win_id2tabwin ()) 87call assert_equal ([ 2 , nr4 ], win_id2tabwin ( id4 )) 88 89call assert_equal ([], win_findbuf ( 9999 )) 90call assert_equal ([ id2 ], bufnr2 ->win_findbuf ()) 91call win_gotoid ( id5 ) 92split 93call assert_equal ( sort ([ id5 , win_getid ()]), sort ( win_findbuf ( bufnr5 ))) 94 95call assert_fails ( 'let w = win_getid([])' , 'E745:' ) 96call assert_equal ( 0 , win_getid ( -1 )) 97call assert_equal ( -1 , win_getid ( 1 , -1 )) 98 99only ! 100endfunc 101 102func Test_win_getid_curtab () 103CheckFeature quickfix 104 105tabedit X 106tabfirst 107copen 108only 109call assert_equal ( win_getid ( 1 ), 1 ->win_getid ( 1 )) 110tabclose ! 111endfunc 112 113func Test_winlayout () 114let w1 = win_getid () 115call assert_equal ([ 'leaf' , w1 ], winlayout ()) 116 117split 118let w2 = win_getid () 119call assert_equal ([ 'col' , [[ 'leaf' , w2 ], [ 'leaf' , w1 ]]], winlayout ()) 120 121split 122let w3 = win_getid () 123call assert_equal ([ 'col' , [[ 'leaf' , w3 ], [ 'leaf' , w2 ], [ 'leaf' , w1 ]]], winlayout ()) 124 1252 wincmd w 126vsplit 127let w4 = win_getid () 128call assert_equal ([ 'col' , [[ 'leaf' , w3 ], [ 'row' , [[ 'leaf' , w4 ], [ 'leaf' , w2 ]]], [ 'leaf' , w1 ]]], winlayout ()) 129 130only ! 131 132let w1 = win_getid () 133call assert_equal ([ 'leaf' , w1 ], winlayout ( 1 )) 134tabnew 135let w2 = win_getid () 136call assert_equal ([ 'leaf' , w2 ], 2 ->winlayout ()) 137tabclose 138 139call assert_equal ([], winlayout ( -1 )) 140endfunc 141 142" vim: shiftwidth=2 sts=2 expandtab