diff --git a/autoload/tabular.vim b/autoload/tabular.vim index 9ed6033..a3b8432 100644 --- a/autoload/tabular.vim +++ b/autoload/tabular.vim @@ -276,6 +276,50 @@ function! tabular#PipeRange(includepat, ...) range call s:SetLines(top, bot - top + 1, lines) endfunction +function! s:SplitDelimTest(string, delim, expected) + let result = s:SplitDelim(a:string, a:delim) + + if result !=# a:expected + echomsg 'Test failed!' + echomsg ' string=' . string(a:string) . ' delim=' . string(a:delim) + echomsg ' Returned=' . string(result) + echomsg ' Expected=' . string(a:expected) + endif +endfunction + +function! tabular#SplitDelimUnitTest() + let assignment = '[|&+*/%<>=!~-]\@!=]=\|=\~\)\@![|&+*/%<>=!~-]*=' + let two_spaces = ' ' + let ternary_operator = '^.\{-}\zs?\|:' + let cpp_io = '<<\|>>' + let pascal_assign = ':=' + let trailing_c_comments = '\/\*\|\*\/\|\/\/' + + call s:SplitDelimTest('a+=b', assignment, ['a', '+=', 'b']) + call s:SplitDelimTest('a-=b', assignment, ['a', '-=', 'b']) + call s:SplitDelimTest('a!=b', assignment, ['a!=b']) + call s:SplitDelimTest('a==b', assignment, ['a==b']) + call s:SplitDelimTest('a&=b', assignment, ['a', '&=', 'b']) + call s:SplitDelimTest('a|=b', assignment, ['a', '|=', 'b']) + call s:SplitDelimTest('a=b=c', assignment, ['a', '=', 'b', '=', 'c']) + + call s:SplitDelimTest('a b c', two_spaces, ['a', ' ', 'b', ' ', 'c']) + call s:SplitDelimTest('a b c', two_spaces, ['a b', ' ', ' c']) + call s:SplitDelimTest('ab c', two_spaces, ['ab', ' ', '', ' ', 'c']) + + call s:SplitDelimTest('a?b:c', ternary_operator, ['a', '?', 'b', ':', 'c']) + + call s:SplitDelimTest('a<