robin/laufey

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

zeertzjqvim-patch:9.2.0969: runtime(shaderslang): matchit % breaks on braces (#41371)53211ade2b

master
2.1 KiB76 linesraw
1" Tests for the matchit plugin
2
3func SetUp()
4  filetype plugin on
5  packadd matchit
6  call assert_equal('<Plug>(MatchitNormalForward)', maparg('%', 'n', 0))
7endfunc
8
9func TearDown()
10  filetype plugin off
11endfunc
12
13func s:Setup(lines, ft)
14  new
15  call setline(1, a:lines)
16  exe "setl ft=".. a:ft
17  call assert_true(exists('b:match_words'))
18  call assert_true(!empty(b:match_words))
19endfunc
20
21func s:PercentTo(arg)
22  call call('cursor', a:arg)
23  normal %
24  return line('.')
25endfunc
26
27func Test_html_matchit_simple_tag()
28  call s:Setup(['<b>', '<big>some text</big>', '</b>'], 'html')
29  call assert_equal(3, s:PercentTo([1, 2]))
30  call assert_equal(1, s:PercentTo([3, 3]))
31  call assert_equal(2, s:PercentTo([2, 2]))
32  normal %
33  call assert_equal(2, line('.'))
34  bwipe!
35endfunc
36
37func Test_html_matchit_tag_with_attribute()
38  call s:Setup(['<b id="123">', '<big>some text</big>', '</b>'], 'html')
39  call assert_equal(3, s:PercentTo([1, 2]))
40  call assert_equal(1, s:PercentTo([3, 3]))
41  call assert_equal(2, s:PercentTo([2, 2]))
42  normal %
43  call assert_equal(2, line('.'))
44  bwipe!
45endfunc
46
47func Test_html_matchit_tag_multiline_attributes()
48  call s:Setup(['<b', '  id="123"', '  name="abc"', '>',
49        \ '<big>some text</big>', '</b>'], 'html')
50  call assert_equal(6, s:PercentTo([1, 2]))
51  call assert_equal(1, s:PercentTo([6, 3]))
52  call assert_equal(5, s:PercentTo([5, 2]))
53  normal %
54  call assert_equal(5, line('.'))
55  bwipe!
56endfunc
57
58func Test_shaderslang_matchit_switch_break()
59  call s:Setup(['void main() {', '  switch (x) {', '    case 1:',
60        \ '      break;', '  }', '}'], 'shaderslang')
61  call assert_equal(5, s:PercentTo([2, 14]))
62  call assert_equal(2, s:PercentTo([5, 3]))
63  bwipe!
64endfunc
65
66func Test_shaderslang_matchit_loop_break()
67  call s:Setup(['void f() {', '  for (int i = 0; i < 4; ++i) {',
68        \ '    if (i == 2)', '      break;', '    total += i;', '  }',
69        \ '  int after = 1;', '}'], 'shaderslang')
70  call assert_equal(8, s:PercentTo([1, 10]))
71  call assert_equal(6, s:PercentTo([2, 31]))
72  call assert_equal(2, s:PercentTo([6, 3]))
73  bwipe!
74endfunc
75
76" vim: shiftwidth=2 sts=2 expandtab