Skip to content

Commit b0612cc

Browse files
committed
Add tests
1 parent dc7a6e7 commit b0612cc

17 files changed

+189
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
test/*.out
2+
test/*.vimout

test/run.vim

+28-3
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,60 @@ function! s:run()
99
for vimfile in glob(s:sdir . '/test*.vim', 0, 1)
1010
let okfile = fnamemodify(vimfile, ':r') . '.ok'
1111
let outfile = fnamemodify(vimfile, ':r') . '.out'
12+
let vimokfile = fnamemodify(vimfile, ':r') . '.vimok'
13+
let vimoutfile = fnamemodify(vimfile, ':r') . '.vimout'
1214
let skip = filereadable(fnamemodify(vimfile, ':r') . '.skip')
1315
let src = readfile(vimfile)
14-
let r = s:vimlparser.StringReader.new(src)
1516
if vimfile =~# 'test_neo'
1617
let l:neovim = 1
1718
else
1819
let l:neovim = 0
1920
endif
2021
let p = s:vimlparser.VimLParser.new(l:neovim)
2122
let c = s:vimlparser.Compiler.new()
23+
let pr = s:vimlparser.Printer.new()
2224
try
25+
let r = s:vimlparser.StringReader.new(src)
2326
let out = c.compile(p.parse(r))
2427
call writefile(out, outfile)
2528
catch
2629
call writefile([v:exception], outfile)
2730
endtry
2831
if system(printf('diff %s %s', shellescape(okfile), shellescape(outfile))) == ""
29-
let line = printf('%s => ok', fnamemodify(vimfile, ':.'))
32+
let line = printf('%s(compiler) => ok', fnamemodify(vimfile, ':.'))
3033
call append(line('$'), line)
3134
else
3235
if !skip
3336
let ng += 1
3437
endif
35-
let line = printf('%s => ' . (skip ? 'skip' : 'ng'), fnamemodify(vimfile, ':.'))
38+
let line = printf('%s(compiler) => ' . (skip ? 'skip' : 'ng'), fnamemodify(vimfile, ':.'))
3639
call append(line('$'), line)
3740
for line in readfile(outfile)
3841
call append(line('$'), ' ' . line)
3942
endfor
4043
endif
44+
if vimfile !~# 'err\|neo'
45+
try
46+
let r = s:vimlparser.StringReader.new(src)
47+
let vimout = pr.print(p.parse(r))
48+
call writefile(vimout, vimoutfile)
49+
catch
50+
call writefile([v:exception], vimoutfile)
51+
endtry
52+
if system(printf('diff %s %s', shellescape(filereadable(vimokfile) ? vimokfile : vimfile), shellescape(vimoutfile))) == ""
53+
let line = printf('%s(printer) => ok', fnamemodify(vimfile, ':.'))
54+
call append(line('$'), line)
55+
else
56+
if !skip
57+
let ng += 1
58+
endif
59+
let line = printf('%s(printer) => ' . (skip ? 'skip' : 'ng'), fnamemodify(vimfile, ':.'))
60+
call append(line('$'), line)
61+
for line in readfile(vimoutfile)
62+
call append(line('$'), ' ' . line)
63+
endfor
64+
endif
65+
endif
4166
endfor
4267
if $CI == 'true'
4368
call writefile(getline(1, '$'), 'test.log')

test/test1.vimok

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
" test1
2+
function s:foo(a, b, ...)
3+
return 0
4+
endfunction
5+
if 1
6+
echo "if 1"
7+
elseif 2
8+
echo "elseif 2"
9+
else
10+
echo "else"
11+
endif
12+
while 1
13+
continue
14+
break
15+
endwhile
16+
for [a, b; c] in d
17+
echo a b c
18+
endfor
19+
delfunction s:foo
20+
call s:foo(1, 2, 3)
21+
let a = {"x" : "y"}
22+
let [a, b; c] = [1, 2, 3]
23+
let [a, b; c] += [1, 2, 3]
24+
let [a, b; c] -= [1, 2, 3]
25+
let [a, b; c] .= [1, 2, 3]
26+
let foo.bar.baz = 123
27+
let foo[bar()][baz()] = 456
28+
let foo[bar()].baz = 789
29+
let foo[1:2] = [3, 4]
30+
unlet a b c
31+
lockvar a b c
32+
lockvar 1 a b c
33+
unlockvar a b c
34+
unlockvar 1 a b c
35+
try
36+
throw "err"
37+
catch /err/
38+
echo "catch /err/"
39+
catch
40+
echo "catch"
41+
finally
42+
echo "finally"
43+
endtry
44+
echohl Error
45+
echon "echon"
46+
echomsg "echomsg"
47+
echoerr "echoerr"
48+
execute "normal ihello"
49+
echo [] [1, 2, 3] [1, 2, 3]
50+
echo {} {"x" : "y"} {"x" : "y", "z" : "w"}
51+
echo x[0] x[y]
52+
echo x[1:2] x[1:] x[:2] x[:]
53+
echo x.y x.y.z

test/test_bar.vimok

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if 1
2+
set nocp
3+
endif

test/test_curly.vimok

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
" test_curly
2+
echo xy{z}
3+
echo x{y}z
4+
echo {x}yz
5+
echo {x}{y}{z}
6+
echo {x{y{z}}}
7+
echo x{("y" . "w")}z
8+
echo {x}
9+
echo x#{y}#z

test/test_dict.vimok

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
" test_dict
2+
echo {}
3+
echo {'1' : 1}
4+
echo {1 : 1}
5+
echo {x : 1}
6+
echo {"\<cr>" : 1}
7+
echo {"vim" : 1}
8+
echo {(1 + 1) : 2}
9+
" XXX: echo {x:1}
10+
echo {'x' : {}}
11+
echo [{}]

test/test_dot.vimok

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
echo foo.bar
2+
echo foo.bar.baz
3+
echo ("foo" . "bar")
4+
echo (foo . "bar")
5+
echo ("foo" . bar)
6+
echo foo.bar()
7+
echo (foo . s:bar)
8+
echo foo.123
9+
echo foo.123abc

test/test_emptylc.vimok

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
" test_emptylc
2+
echo 1

test/test_funcattr.vimok

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function! F() abort
2+
endfunction
3+
function! F() abort closure dict range
4+
endfunction

test/test_lambda.vimok

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
" test_lambda
2+
echo { -> (1 + 1)}
3+
echo {i, v -> (v >= s:x)}
4+
echo {... -> a:000}
5+
echo {x -> (x * 2)}(14)

test/test_modifier_commands.vimok

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
aboveleft belowright botright browse confirm hide keepalt keepjumps keepmarks keeppatterns lockmarks noswapfile silent tab topleft verbose vertical
2+
call Func()
3+
aboveleft belowright botright browse confirm hide keepalt keepjumps keepmarks keeppatterns lockmarks noswapfile silent tab topleft verbose vertical
4+
call Func()

test/test_op.vimok

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
echo (a is b)
2+
echo (a is? b)
3+
echo (a is# b)
4+
echo (a isnot b)
5+
echo (a isnot? b)
6+
echo (a isnot# b)
7+
echo (a || b)
8+
echo (a && b)
9+
echo (a == b)
10+
echo (a ==? b)
11+
echo (a ==# b)
12+
echo (a != b)
13+
echo (a !=? b)
14+
echo (a !=# b)
15+
echo (a >= b)
16+
echo (a >=? b)
17+
echo (a >=# b)
18+
echo (a <= b)
19+
echo (a <=? b)
20+
echo (a <=# b)
21+
echo (a =~ b)
22+
echo (a =~? b)
23+
echo (a =~# b)
24+
echo (a !~ b)
25+
echo (a !~? b)
26+
echo (a !~# b)
27+
echo (a > b)
28+
echo (a >? b)
29+
echo (a ># b)
30+
echo (a < b)
31+
echo (a <? b)
32+
echo (a <# b)
33+
echo (a + b)
34+
echo (a - b)
35+
echo (a . b)
36+
echo (a * b)
37+
echo (a / b)
38+
echo (a % b)
39+
echo (!(a))
40+
echo (a ? b : c)

test/test_syncmd.vimok

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if 1
2+
syntax on
3+
endif
4+
syntax
5+
syntax enable
6+
syntax list GroupName
7+
syn match pythonError "[&|]\{2,}" display
8+
syntax match qfFileName /^\zs\S[^|]\+\/\ze[^|\/]\+\/[^|\/]\+|/ conceal cchar=+
9+
syntax region jsString start=+"+ skip=+\\\("\|$\)+ end=+"\|$+ contains=jsSpecial,@Spell extend

test/test_wincmd.vimok

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if 1
2+
wincmd p
3+
endif

test/test_xxx_call_last_comma.vimok

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
call foo(a, b)
2+
call bar(c, d)
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function F(a)
2+
endfunction
3+
function G(a)
4+
endfunction
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
echo {a -> 0}
2+
echo {a -> 0}

0 commit comments

Comments
 (0)