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