Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tyru committed Nov 19, 2017
1 parent dc7a6e7 commit b0612cc
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
test/*.out
test/*.vimout
31 changes: 28 additions & 3 deletions test/run.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,60 @@ function! s:run()
for vimfile in glob(s:sdir . '/test*.vim', 0, 1)
let okfile = fnamemodify(vimfile, ':r') . '.ok'
let outfile = fnamemodify(vimfile, ':r') . '.out'
let vimokfile = fnamemodify(vimfile, ':r') . '.vimok'
let vimoutfile = fnamemodify(vimfile, ':r') . '.vimout'
let skip = filereadable(fnamemodify(vimfile, ':r') . '.skip')
let src = readfile(vimfile)
let r = s:vimlparser.StringReader.new(src)
if vimfile =~# 'test_neo'
let l:neovim = 1
else
let l:neovim = 0
endif
let p = s:vimlparser.VimLParser.new(l:neovim)
let c = s:vimlparser.Compiler.new()
let pr = s:vimlparser.Printer.new()
try
let r = s:vimlparser.StringReader.new(src)
let out = c.compile(p.parse(r))
call writefile(out, outfile)
catch
call writefile([v:exception], outfile)
endtry
if system(printf('diff %s %s', shellescape(okfile), shellescape(outfile))) == ""
let line = printf('%s => ok', fnamemodify(vimfile, ':.'))
let line = printf('%s(compiler) => ok', fnamemodify(vimfile, ':.'))
call append(line('$'), line)
else
if !skip
let ng += 1
endif
let line = printf('%s => ' . (skip ? 'skip' : 'ng'), fnamemodify(vimfile, ':.'))
let line = printf('%s(compiler) => ' . (skip ? 'skip' : 'ng'), fnamemodify(vimfile, ':.'))
call append(line('$'), line)
for line in readfile(outfile)
call append(line('$'), ' ' . line)
endfor
endif
if vimfile !~# 'err\|neo'
try
let r = s:vimlparser.StringReader.new(src)
let vimout = pr.print(p.parse(r))
call writefile(vimout, vimoutfile)
catch
call writefile([v:exception], vimoutfile)
endtry
if system(printf('diff %s %s', shellescape(filereadable(vimokfile) ? vimokfile : vimfile), shellescape(vimoutfile))) == ""
let line = printf('%s(printer) => ok', fnamemodify(vimfile, ':.'))
call append(line('$'), line)
else
if !skip
let ng += 1
endif
let line = printf('%s(printer) => ' . (skip ? 'skip' : 'ng'), fnamemodify(vimfile, ':.'))
call append(line('$'), line)
for line in readfile(vimoutfile)
call append(line('$'), ' ' . line)
endfor
endif
endif
endfor
if $CI == 'true'
call writefile(getline(1, '$'), 'test.log')
Expand Down
53 changes: 53 additions & 0 deletions test/test1.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
" test1
function s:foo(a, b, ...)
return 0
endfunction
if 1
echo "if 1"
elseif 2
echo "elseif 2"
else
echo "else"
endif
while 1
continue
break
endwhile
for [a, b; c] in d
echo a b c
endfor
delfunction s:foo
call s:foo(1, 2, 3)
let a = {"x" : "y"}
let [a, b; c] = [1, 2, 3]
let [a, b; c] += [1, 2, 3]
let [a, b; c] -= [1, 2, 3]
let [a, b; c] .= [1, 2, 3]
let foo.bar.baz = 123
let foo[bar()][baz()] = 456
let foo[bar()].baz = 789
let foo[1:2] = [3, 4]
unlet a b c
lockvar a b c
lockvar 1 a b c
unlockvar a b c
unlockvar 1 a b c
try
throw "err"
catch /err/
echo "catch /err/"
catch
echo "catch"
finally
echo "finally"
endtry
echohl Error
echon "echon"
echomsg "echomsg"
echoerr "echoerr"
execute "normal ihello"
echo [] [1, 2, 3] [1, 2, 3]
echo {} {"x" : "y"} {"x" : "y", "z" : "w"}
echo x[0] x[y]
echo x[1:2] x[1:] x[:2] x[:]
echo x.y x.y.z
3 changes: 3 additions & 0 deletions test/test_bar.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if 1
set nocp
endif
9 changes: 9 additions & 0 deletions test/test_curly.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
" test_curly
echo xy{z}
echo x{y}z
echo {x}yz
echo {x}{y}{z}
echo {x{y{z}}}
echo x{("y" . "w")}z
echo {x}
echo x#{y}#z
11 changes: 11 additions & 0 deletions test/test_dict.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
" test_dict
echo {}
echo {'1' : 1}
echo {1 : 1}
echo {x : 1}
echo {"\<cr>" : 1}
echo {"vim" : 1}
echo {(1 + 1) : 2}
" XXX: echo {x:1}
echo {'x' : {}}
echo [{}]
9 changes: 9 additions & 0 deletions test/test_dot.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
echo foo.bar
echo foo.bar.baz
echo ("foo" . "bar")
echo (foo . "bar")
echo ("foo" . bar)
echo foo.bar()
echo (foo . s:bar)
echo foo.123
echo foo.123abc
2 changes: 2 additions & 0 deletions test/test_emptylc.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
" test_emptylc
echo 1
4 changes: 4 additions & 0 deletions test/test_funcattr.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function! F() abort
endfunction
function! F() abort closure dict range
endfunction
5 changes: 5 additions & 0 deletions test/test_lambda.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
" test_lambda
echo { -> (1 + 1)}
echo {i, v -> (v >= s:x)}
echo {... -> a:000}
echo {x -> (x * 2)}(14)
4 changes: 4 additions & 0 deletions test/test_modifier_commands.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
aboveleft belowright botright browse confirm hide keepalt keepjumps keepmarks keeppatterns lockmarks noswapfile silent tab topleft verbose vertical
call Func()
aboveleft belowright botright browse confirm hide keepalt keepjumps keepmarks keeppatterns lockmarks noswapfile silent tab topleft verbose vertical
call Func()
40 changes: 40 additions & 0 deletions test/test_op.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
echo (a is b)
echo (a is? b)
echo (a is# b)
echo (a isnot b)
echo (a isnot? b)
echo (a isnot# b)
echo (a || b)
echo (a && b)
echo (a == b)
echo (a ==? b)
echo (a ==# b)
echo (a != b)
echo (a !=? b)
echo (a !=# b)
echo (a >= b)
echo (a >=? b)
echo (a >=# b)
echo (a <= b)
echo (a <=? b)
echo (a <=# b)
echo (a =~ b)
echo (a =~? b)
echo (a =~# b)
echo (a !~ b)
echo (a !~? b)
echo (a !~# b)
echo (a > b)
echo (a >? b)
echo (a ># b)
echo (a < b)
echo (a <? b)
echo (a <# b)
echo (a + b)
echo (a - b)
echo (a . b)
echo (a * b)
echo (a / b)
echo (a % b)
echo (!(a))
echo (a ? b : c)
9 changes: 9 additions & 0 deletions test/test_syncmd.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if 1
syntax on
endif
syntax
syntax enable
syntax list GroupName
syn match pythonError "[&|]\{2,}" display
syntax match qfFileName /^\zs\S[^|]\+\/\ze[^|\/]\+\/[^|\/]\+|/ conceal cchar=+
syntax region jsString start=+"+ skip=+\\\("\|$\)+ end=+"\|$+ contains=jsSpecial,@Spell extend
3 changes: 3 additions & 0 deletions test/test_wincmd.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if 1
wincmd p
endif
2 changes: 2 additions & 0 deletions test/test_xxx_call_last_comma.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
call foo(a, b)
call bar(c, d)
4 changes: 4 additions & 0 deletions test/test_xxx_funcarg_last_comma.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function F(a)
endfunction
function G(a)
endfunction
2 changes: 2 additions & 0 deletions test/test_xxx_lambdaarg_last_comma.vimok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo {a -> 0}
echo {a -> 0}

0 comments on commit b0612cc

Please sign in to comment.