Skip to content

Commit b0612cc

Browse files
committed
Add tests
1 parent dc7a6e7 commit b0612cc

17 files changed

+189
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
test/*.out
2+
test/*.vimout

test/run.vim

Lines changed: 28 additions & 3 deletions
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

Lines changed: 53 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if 1
2+
set nocp
3+
endif

test/test_curly.vimok

Lines changed: 9 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
" test_emptylc
2+
echo 1

test/test_funcattr.vimok

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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)

0 commit comments

Comments
 (0)