robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40542 from zeertzjq/vim-9.2.0392f33364a41d

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