robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local n =require ( 'test.functional.testnvim' )() 2local t =require ( 'test.testutil' ) 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear =n . clear 7local exec =n . exec 8local feed =n . feed 9local poke_eventloop =n . poke_eventloop 10 11describe ( 'matchparen' , function () 12before_each ( clear ) 13 14-- oldtest: Test_visual_block_scroll() 15it ( 'redraws properly after scrolling with scrolloff=1' , function () 16local screen =Screen . new ( 30 , 7 ) 17exec ( [[ 18source $VIMRUNTIME/plugin/matchparen.lua 19set scrolloff=1 20call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}']) 21call cursor(5, 1) 22]] ) 23 24feed ( 'V<c-d><c-d>' ) 25screen : expect ( [[ 26{17:{} | 27{17:}} | 28{17:{} | 29{17:f} | 30{17:^g} | 31} | 32{5:-- VISUAL LINE --} | 33]] ) 34end ) 35 36-- oldtest: Test_matchparen_clear_highlight() 37it ( 'matchparen highlight is cleared when switching buffer' , function () 38local screen =Screen . new ( 20 , 5 ) 39screen : add_extra_attr_ids { 40[ 100 ] ={ background =Screen . colors . Cyan1 } , 41} 42 43local screen1 =[[ 44{100:^()} | 45{1:~ }|*3 46| 47]] 48local screen2 =[[ 49^aa | 50{1:~ }|*3 51| 52]] 53 54exec ( [[ 55source $VIMRUNTIME/plugin/matchparen.lua 56set hidden 57call setline(1, ['()']) 58normal 0 59 60func OtherBuffer() 61enew 62exe "normal iaa\<Esc>0" 63endfunc 64]] ) 65screen : expect ( screen1 ) 66 67exec ( 'call OtherBuffer()' ) 68screen : expect ( screen2 ) 69 70feed ( '<C-^>' ) 71screen : expect ( screen1 ) 72 73feed ( '<C-^>' ) 74screen : expect ( screen2 ) 75end ) 76 77-- oldtest: Test_matchparen_win_execute() 78it ( 'matchparen highlight when switching buffer in win_execute()' , function () 79local screen =Screen . new ( 20 , 5 ) 80screen : add_extra_attr_ids { 81[ 100 ] ={ background =Screen . colors . Cyan1 } , 82} 83 84exec ( [[ 85source $VIMRUNTIME/plugin/matchparen.lua 86let s:win = win_getid() 87call setline(1, '{}') 88split 89 90func SwitchBuf() 91call win_execute(s:win, 'enew | buffer #') 92endfunc 93]] ) 94screen : expect ( [[ 95{100:^{}} | 96{3:[No Name] [+] }| 97{} | 98{2:[No Name] [+] }| 99| 100]] ) 101 102-- Switching buffer away and back shouldn't change matchparen highlight. 103exec ( 'call SwitchBuf()' ) 104screen : expect_unchanged () 105end ) 106 107-- oldtest: Test_matchparen_pum_clear() 108it ( 'is cleared when completion popup is shown' , function () 109local screen =Screen . new ( 30 , 9 ) 110 111exec ( [[ 112source $VIMRUNTIME/plugin/matchparen.lua 113set completeopt=menuone 114call setline(1, ['aa', 'aaa', 'aaaa', '(a)']) 115call cursor(4, 3) 116]] ) 117 118feed ( 'i<C-X><C-N><C-N>' ) 119screen : expect ( [[ 120aa | 121aaa | 122aaaa | 123(aaa^) | 124{4: aa }{1: }| 125{12: aaa }{1: }| 126{4: aaaa }{1: }| 127{1:~ }| 128{5:-- }{6:match 2 of 3} | 129]] ) 130end ) 131 132-- oldtest: Test_matchparen_mbyte() 133it ( "works with multibyte chars in 'matchpairs'" , function () 134local screen =Screen . new ( 30 , 10 ) 135screen : add_extra_attr_ids { 136[ 100 ] ={ background =Screen . colors . Cyan1 } , 137} 138 139exec ( [[ 140source $VIMRUNTIME/plugin/matchparen.lua 141call setline(1, ['aaaaaaaa(', 'bbbb)cc']) 142set matchpairs+=(:) 143]] ) 144 145screen : expect ( [[ 146^aaaaaaaa( | 147bbbb)cc | 148{1:~ }|*7 149| 150]] ) 151feed ( '$' ) 152screen : expect ( [[ 153aaaaaaaa{100:^(} | 154bbbb{100:)}cc | 155{1:~ }|*7 156| 157]] ) 158feed ( 'j' ) 159screen : expect ( [[ 160aaaaaaaa( | 161bbbb)c^c | 162{1:~ }|*7 163| 164]] ) 165feed ( '2h' ) 166screen : expect ( [[ 167aaaaaaaa{100:(} | 168bbbb{100:^)}cc | 169{1:~ }|*7 170| 171]] ) 172feed ( '0' ) 173screen : expect ( [[ 174aaaaaaaa( | 175^bbbb)cc | 176{1:~ }|*7 177| 178]] ) 179feed ( 'kA' ) 180screen : expect ( [[ 181aaaaaaaa{100:(}^ | 182bbbb{100:)}cc | 183{1:~ }|*7 184{5:-- INSERT --} | 185]] ) 186feed ( '<Down>' ) 187screen : expect ( [[ 188aaaaaaaa( | 189bbbb)cc^ | 190{1:~ }|*7 191{5:-- INSERT --} | 192]] ) 193feed ( '<C-W>' ) 194screen : expect ( [[ 195aaaaaaaa{100:(} | 196bbbb{100:)}^ | 197{1:~ }|*7 198{5:-- INSERT --} | 199]] ) 200end ) 201 202-- oldtest: Test_matchparen_ignore_sh_case() 203it ( 'ignores shell case statements' , function () 204local screen =Screen . new ( 40 , 15 ) 205exec ( [[ 206syntax on 207source $VIMRUNTIME/plugin/matchparen.lua 208set ft=sh 209call setline(1, [ 210\ '#!/bin/sh', 211\ 'SUSUWU_PRINT() (', 212\ ' case "${LEVEL}" in', 213\ ' "$SUSUWU_SH_NOTICE")', 214\ ' ${SUSUWU_S} && return 1', 215\ ' ;;', 216\ ' "$SUSUWU_SH_DEBUG")', 217\ ' (! ${SUSUWU_VERBOSE}) && return 1', 218\ ' ;;', 219\ ' esac', 220\ ' # snip', 221\ ')' 222\ ]) 223call cursor(4, 26) 224]] ) 225screen : add_extra_attr_ids ( { 226[ 100 ] ={ foreground =tonumber ( '0x6a0dad' ) } , 227} ) 228screen : expect ( [[ 229{18:#!/bin/sh} | 230{25:SUSUWU_PRINT}{16:()} {15:(} | 231{15:case} {15:"}{100:${LEVEL}}{15:"} {15:in} | 232{15:"}{100:$SUSUWU_SH_NOTICE}{15:"^)} | 233{100:${SUSUWU_S}} {15:&&} {15:return} {26:1} | 234{15:;;} | 235{15:"}{100:$SUSUWU_SH_DEBUG}{15:")} | 236{100:(}{15:!} {100:${SUSUWU_VERBOSE})} {15:&&} {15:return} {26:1} | 237{15:;;} | 238{15:esac} | 239{18:# snip} | 240{15:)} | 241{1:~ }|*2 242| 243]] ) 244-- Send keys one by one so that CursorMoved is triggered. 245for _ , c in ipairs ( { 'A' , ' ' , 'f' , 'o' , 'o' , 'b' , 'a' , 'r' } ) do 246feed ( c ) 247poke_eventloop () 248end 249screen : expect ( [[ 250{18:#!/bin/sh} | 251{25:SUSUWU_PRINT}{16:()} {15:(} | 252{15:case} {15:"}{100:${LEVEL}}{15:"} {15:in} | 253{15:"}{100:$SUSUWU_SH_NOTICE}{15:")} foobar^ | 254{100:${SUSUWU_S}} {15:&&} {15:return} {26:1} | 255{15:;;} | 256{15:"}{100:$SUSUWU_SH_DEBUG}{15:")} | 257{100:(}{15:!} {100:${SUSUWU_VERBOSE})} {15:&&} {15:return} {26:1} | 258{15:;;} | 259{15:esac} | 260{18:# snip} | 261{15:)} | 262{1:~ }|*2 263{5:-- INSERT --} | 264]] ) 265end ) 266 267-- oldtest: Test_scroll_winscrolled() 268it ( 'with scrolling' , function () 269local screen =Screen . new ( 30 , 7 ) 270exec ( [[ 271source $VIMRUNTIME/plugin/matchparen.lua 272set scrolloff=1 273call setline(1, ['foobar {', '', '', '', '}']) 274call cursor(5, 1) 275]] ) 276screen : add_extra_attr_ids ( { 277[ 100 ] ={ background =Screen . colors . Aqua } , 278} ) 279local s1 =[[ 280foobar {100:{} | 281|*3 282{100:^}} | 283{1:~ }| 284| 285]] 286screen : expect ( s1 ) 287feed ( '<C-E>' ) 288screen : expect ( [[ 289|*3 290^} | 291{1:~ }|*2 292| 293]] ) 294feed ( '<C-Y>' ) 295screen : expect ( s1 ) 296end ) 297end )