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