robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
9.0 KiB297 linesraw
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()
12  before_each(clear)
13
14  -- oldtest: Test_visual_block_scroll()
15  it('redraws properly after scrolling with scrolloff=1', function()
16    local screen = Screen.new(30, 7)
17    exec([[
18      source $VIMRUNTIME/plugin/matchparen.lua
19      set scrolloff=1
20      call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'])
21      call cursor(5, 1)
22    ]])
23
24    feed('V<c-d><c-d>')
25    screen:expect([[
26      {17:{}                             |
27      {17:}}                             |
28      {17:{}                             |
29      {17:f}                             |
30      {17:^g}                             |
31      }                             |
32      {5:-- VISUAL LINE --}             |
33    ]])
34  end)
35
36  -- oldtest: Test_matchparen_clear_highlight()
37  it('matchparen highlight is cleared when switching buffer', function()
38    local screen = Screen.new(20, 5)
39    screen:add_extra_attr_ids {
40      [100] = { background = Screen.colors.Cyan1 },
41    }
42
43    local screen1 = [[
44      {100:^()}                  |
45      {1:~                   }|*3
46                          |
47    ]]
48    local screen2 = [[
49      ^aa                  |
50      {1:~                   }|*3
51                          |
52    ]]
53
54    exec([[
55      source $VIMRUNTIME/plugin/matchparen.lua
56      set hidden
57      call setline(1, ['()'])
58      normal 0
59
60      func OtherBuffer()
61         enew
62         exe "normal iaa\<Esc>0"
63      endfunc
64    ]])
65    screen:expect(screen1)
66
67    exec('call OtherBuffer()')
68    screen:expect(screen2)
69
70    feed('<C-^>')
71    screen:expect(screen1)
72
73    feed('<C-^>')
74    screen:expect(screen2)
75  end)
76
77  -- oldtest: Test_matchparen_win_execute()
78  it('matchparen highlight when switching buffer in win_execute()', function()
79    local screen = Screen.new(20, 5)
80    screen:add_extra_attr_ids {
81      [100] = { background = Screen.colors.Cyan1 },
82    }
83
84    exec([[
85      source $VIMRUNTIME/plugin/matchparen.lua
86      let s:win = win_getid()
87      call setline(1, '{}')
88      split
89
90      func SwitchBuf()
91        call win_execute(s:win, 'enew | buffer #')
92      endfunc
93    ]])
94    screen: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.
103    exec('call SwitchBuf()')
104    screen:expect_unchanged()
105  end)
106
107  -- oldtest: Test_matchparen_pum_clear()
108  it('is cleared when completion popup is shown', function()
109    local screen = Screen.new(30, 9)
110
111    exec([[
112      source $VIMRUNTIME/plugin/matchparen.lua
113      set completeopt=menuone
114      call setline(1, ['aa', 'aaa', 'aaaa', '(a)'])
115      call cursor(4, 3)
116    ]])
117
118    feed('i<C-X><C-N><C-N>')
119    screen:expect([[
120      aa                            |
121      aaa                           |
122      aaaa                          |
123      (aaa^)                         |
124      {4: aa             }{1:              }|
125      {12: aaa            }{1:              }|
126      {4: aaaa           }{1:              }|
127      {1:~                             }|
128      {5:-- }{6:match 2 of 3}               |
129    ]])
130  end)
131
132  -- oldtest: Test_matchparen_mbyte()
133  it("works with multibyte chars in 'matchpairs'", function()
134    local screen = Screen.new(30, 10)
135    screen:add_extra_attr_ids {
136      [100] = { background = Screen.colors.Cyan1 },
137    }
138
139    exec([[
140      source $VIMRUNTIME/plugin/matchparen.lua
141      call setline(1, ['aaaaaaaa(', 'bbbb)cc'])
142      set matchpairs+=(:)
143    ]])
144
145    screen:expect([[
146      ^aaaaaaaa(                    |
147      bbbb)cc                      |
148      {1:~                             }|*7
149                                    |
150    ]])
151    feed('$')
152    screen:expect([[
153      aaaaaaaa{100:^(}                    |
154      bbbb{100:)}cc                      |
155      {1:~                             }|*7
156                                    |
157    ]])
158    feed('j')
159    screen:expect([[
160      aaaaaaaa(                    |
161      bbbb)c^c                      |
162      {1:~                             }|*7
163                                    |
164    ]])
165    feed('2h')
166    screen:expect([[
167      aaaaaaaa{100:(}                    |
168      bbbb{100:^)}cc                      |
169      {1:~                             }|*7
170                                    |
171    ]])
172    feed('0')
173    screen:expect([[
174      aaaaaaaa(                    |
175      ^bbbb)cc                      |
176      {1:~                             }|*7
177                                    |
178    ]])
179    feed('kA')
180    screen:expect([[
181      aaaaaaaa{100:(}^                    |
182      bbbb{100:)}cc                      |
183      {1:~                             }|*7
184      {5:-- INSERT --}                  |
185    ]])
186    feed('<Down>')
187    screen:expect([[
188      aaaaaaaa(                    |
189      bbbb)cc^                      |
190      {1:~                             }|*7
191      {5:-- INSERT --}                  |
192    ]])
193    feed('<C-W>')
194    screen:expect([[
195      aaaaaaaa{100:(}                    |
196      bbbb{100:)}^                        |
197      {1:~                             }|*7
198      {5:-- INSERT --}                  |
199    ]])
200  end)
201
202  -- oldtest: Test_matchparen_ignore_sh_case()
203  it('ignores shell case statements', function()
204    local screen = Screen.new(40, 15)
205    exec([[
206      syntax on
207      source $VIMRUNTIME/plugin/matchparen.lua
208      set ft=sh
209      call 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            \ ])
223      call cursor(4, 26)
224    ]])
225    screen:add_extra_attr_ids({
226      [100] = { foreground = tonumber('0x6a0dad') },
227    })
228    screen: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.
245    for _, c in ipairs({ 'A', ' ', 'f', 'o', 'o', 'b', 'a', 'r' }) do
246      feed(c)
247      poke_eventloop()
248    end
249    screen: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    ]])
265  end)
266
267  -- oldtest: Test_scroll_winscrolled()
268  it('with scrolling', function()
269    local screen = Screen.new(30, 7)
270    exec([[
271      source $VIMRUNTIME/plugin/matchparen.lua
272      set scrolloff=1
273      call setline(1, ['foobar {', '', '', '', '}'])
274      call cursor(5, 1)
275    ]])
276    screen:add_extra_attr_ids({
277      [100] = { background = Screen.colors.Aqua },
278    })
279    local s1 = [[
280      foobar {100:{}                      |
281                                    |*3
282      {100:^}}                             |
283      {1:~                             }|
284                                    |
285    ]]
286    screen:expect(s1)
287    feed('<C-E>')
288    screen:expect([[
289                                    |*3
290      ^}                             |
291      {1:~                             }|*2
292                                    |
293    ]])
294    feed('<C-Y>')
295    screen:expect(s1)
296  end)
297end)