robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f33364a41d
master
1" Test for the matchparen plugin 2 3if ! has ( 'gui_running' ) && has ( 'unix' ) 4" set term=ansi 5endif 6 7source view_util.vim 8source check.vim 9source screendump.vim 10 11" Test for scrolling that modifies buffer during visual block 12func Test_visual_block_scroll () 13CheckRunVimInTerminal 14let g: test_is_flaky = 1 15let lines =<< trim END 16source $VIMRUNTIME/plugin/matchparen.vim 17set scrolloff=1 18call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}']) 19call cursor(5, 1) 20END 21 22let filename = 'Xvisualblockmodifiedscroll' 23call writefile ( lines , filename , 'D' ) 24 25let buf = RunVimInTerminal ( '-S ' . filename , #{ rows : 7 }) 26call term_sendkeys ( buf , "V\<C-D>\<C-D>" ) 27 28call WaitForAssert ({ ->assert_equal ( '{' , trim ( term_getline ( buf , 1 )))}, 1000 ) 29call assert_equal ( '}' , trim ( term_getline ( buf , 2 ))) 30call assert_equal ( '{' , trim ( term_getline ( buf , 3 ))) 31call assert_equal ( 'f' , trim ( term_getline ( buf , 4 ))) 32call assert_equal ( 'g' , trim ( term_getline ( buf , 5 ))) 33call assert_equal ( '}' , trim ( term_getline ( buf , 6 ))) 34call assert_match ( 'VISUAL LINE .*1,1\s\+Bot' , term_getline ( buf , 7 )) 35 36call StopVimInTerminal ( buf ) 37endfunc 38 39" Test for clearing paren highlight when switching buffers 40func Test_matchparen_clear_highlight () 41CheckScreendump 42 43let lines =<< trim END 44source $VIMRUNTIME/plugin/matchparen.vim 45set hidden 46call setline(1, ['()']) 47normal 0 48 49func OtherBuffer() 50enew 51exe "normal iaa\<Esc>0" 52endfunc 53END 54call writefile ( lines , 'XMatchparenClear' , 'D' ) 55let buf = RunVimInTerminal ( '-S XMatchparenClear' , #{ rows : 5 }) 56call VerifyScreenDump ( buf , 'Test_matchparen_clear_highlight_1' , {}) 57 58call term_sendkeys ( buf , ":call OtherBuffer()\<CR>:\<Esc>" ) 59call VerifyScreenDump ( buf , 'Test_matchparen_clear_highlight_2' , {}) 60 61call term_sendkeys ( buf , "\<C-^>:\<Esc>" ) 62call VerifyScreenDump ( buf , 'Test_matchparen_clear_highlight_1' , {}) 63 64call term_sendkeys ( buf , "\<C-^>:\<Esc>" ) 65call VerifyScreenDump ( buf , 'Test_matchparen_clear_highlight_2' , {}) 66 67call StopVimInTerminal ( buf ) 68endfunc 69 70" Test for matchparen highlight when switching buffer in win_execute() 71func Test_matchparen_win_execute () 72CheckScreendump 73 74let lines =<< trim END 75source $VIMRUNTIME/plugin/matchparen.vim 76let s:win = win_getid() 77call setline(1, '{}') 78split 79 80func SwitchBuf() 81call win_execute(s:win, 'enew | buffer #') 82endfunc 83END 84call writefile ( lines , 'XMatchparenWinExecute' , 'D' ) 85let buf = RunVimInTerminal ( '-S XMatchparenWinExecute' , #{ rows : 5 }) 86call VerifyScreenDump ( buf , 'Test_matchparen_win_execute_1' , {}) 87 88" Switching buffer away and back shouldn't change matchparen highlight. 89call term_sendkeys ( buf , ":call SwitchBuf()\<CR>:\<Esc>" ) 90call VerifyScreenDump ( buf , 'Test_matchparen_win_execute_1' , {}) 91 92call StopVimInTerminal ( buf ) 93endfunc 94 95" Test for scrolling that modifies buffer during visual block 96func Test_matchparen_pum_clear () 97CheckScreendump 98 99let lines =<< trim END 100source $VIMRUNTIME/plugin/matchparen.vim 101set completeopt=menuone 102call setline(1, ['aa', 'aaa', 'aaaa', '(a)']) 103call cursor(4, 3) 104END 105 106let filename = 'Xmatchparen' 107call writefile ( lines , filename , 'D' ) 108 109let buf = RunVimInTerminal ( '-S ' . filename , #{ rows : 10 }) 110call term_sendkeys ( buf , "i\<C-N>\<C-N>" ) 111 112call VerifyScreenDump ( buf , 'Test_matchparen_pum_clear_1' , {}) 113 114call StopVimInTerminal ( buf ) 115endfunc 116 117" Test that matchparen works with multibyte chars in 'matchpairs' 118func Test_matchparen_mbyte () 119CheckScreendump 120 121let lines =<< trim END 122source $VIMRUNTIME/plugin/matchparen.vim 123call setline(1, ['aaaaaaaa(', 'bbbb)cc']) 124set matchpairs+=(:) 125END 126 127call writefile ( lines , 'XmatchparenMbyte' , 'D' ) 128let buf = RunVimInTerminal ( '-S XmatchparenMbyte' , #{ rows : 10 }) 129call VerifyScreenDump ( buf , 'Test_matchparen_mbyte_1' , {}) 130call term_sendkeys ( buf , "$" ) 131call VerifyScreenDump ( buf , 'Test_matchparen_mbyte_2' , {}) 132call term_sendkeys ( buf , "j" ) 133call VerifyScreenDump ( buf , 'Test_matchparen_mbyte_3' , {}) 134call term_sendkeys ( buf , "2h" ) 135call VerifyScreenDump ( buf , 'Test_matchparen_mbyte_4' , {}) 136call term_sendkeys ( buf , "0" ) 137call VerifyScreenDump ( buf , 'Test_matchparen_mbyte_5' , {}) 138call term_sendkeys ( buf , "kA" ) 139call VerifyScreenDump ( buf , 'Test_matchparen_mbyte_6' , {}) 140call term_sendkeys ( buf , "\<Down>" ) 141call VerifyScreenDump ( buf , 'Test_matchparen_mbyte_7' , {}) 142call term_sendkeys ( buf , "\<C-W>" ) 143call VerifyScreenDump ( buf , 'Test_matchparen_mbyte_8' , {}) 144 145call StopVimInTerminal ( buf ) 146endfunc 147 148" Test for ignoring certain parenthesis 149func Test_matchparen_ignore_sh_case () 150CheckScreendump 151 152let lines =<< trim END 153source $VIMRUNTIME/plugin/matchparen.vim 154set ft=sh 155call setline(1, [ 156\ '#!/bin/sh', 157\ 'SUSUWU_PRINT() (', 158\ ' case "${LEVEL}" in', 159\ ' "$SUSUWU_SH_NOTICE")', 160\ ' ${SUSUWU_S} && return 1', 161\ ' ;;', 162\ ' "$SUSUWU_SH_DEBUG")', 163\ ' (! ${SUSUWU_VERBOSE}) && return 1', 164\ ' ;;', 165\ ' esac', 166\ ' # snip', 167\ ')' 168\ ]) 169call cursor(4, 26) 170END 171 172let filename = 'Xmatchparen_sh' 173call writefile ( lines , filename , 'D' ) 174 175let buf = RunVimInTerminal ( '-S ' . filename , #{ rows : 10 }) 176call VerifyScreenDump ( buf , 'Test_matchparen_sh_case_1' , {}) 177" Send keys one by one so that CursorMoved is triggered. 178for c in 'A foobar' 179call term_sendkeys ( buf , c ) 180call term_wait ( buf ) 181endfor 182call VerifyScreenDump ( buf , 'Test_matchparen_sh_case_2' , {}) 183call StopVimInTerminal ( buf ) 184endfunc 185 186" Test for the WinScrolled event 187func Test_scroll_winscrolled () 188CheckScreendump 189 190let lines =<< trim END 191source $VIMRUNTIME/plugin/matchparen.vim 192set scrolloff=1 193call setline(1, ['foobar {', '', '', '', '}']) 194call cursor(5, 1) 195END 196 197let filename = 'Xmatchparen_winscrolled' 198call writefile ( lines , filename , 'D' ) 199 200let buf = RunVimInTerminal ( '-S ' . filename , #{ rows : 7 }) 201call VerifyScreenDump ( buf , 'Test_matchparen_winscrolled1' , {}) 202call term_sendkeys ( buf , "\<C-E>" ) 203call VerifyScreenDump ( buf , 'Test_matchparen_winscrolled2' , {}) 204call term_sendkeys ( buf , "\<C-Y>" ) 205call VerifyScreenDump ( buf , 'Test_matchparen_winscrolled1' , {}) 206 207call StopVimInTerminal ( buf ) 208endfunc 209 210" vim: shiftwidth=2 sts=2 expandtab