blob: 49d35108a96bac47b15ef922d9db43a5f6967756 [file] [log] [blame]
Christian Brabandt95886662023-11-12 16:55:01 +01001" 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 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)
31endfunc
32
33" Test for clearing paren highlight when switching buffers
34func 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)
62endfunc
63
zeertzjq49ffb6b2024-03-11 21:38:58 +010064" Test for matchparen highlight when switching buffer in win_execute()
65func 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)
87endfunc
88
Christian Brabandt95886662023-11-12 16:55:01 +010089" Test for scrolling that modifies buffer during visual block
90func 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)
109endfunc
110
zeertzjq81e75132024-08-24 16:32:24 +0200111" Test that matchparen works with multibyte chars in 'matchpairs'
112func 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)
140endfunc
Christian Brabandt95886662023-11-12 16:55:01 +0100141
142" vim: shiftwidth=2 sts=2 expandtab