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