Skip to content

Commit 4ad8e4d

Browse files
committed
update tests
1 parent 5770224 commit 4ad8e4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+306
-8
lines changed

test/node_position/test_position.ok

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function! F()
2+
let x =
3+
\ 1
4+
5+
let x = "
6+
\1
7+
\2 <- tab
8+
\3 マルチバイト
9+
\4"
10+
endfunction

test/node_position/test_position.vim

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
let s:vimlparser = vimlparser#import()
2+
3+
function! s:run()
4+
let src = [
5+
\ '',
6+
\ 'function! F()',
7+
\ ' let x =',
8+
\ '\ 1',
9+
\ '',
10+
\ ' let x = "',
11+
\ ' \1',
12+
\ ' \2 <- tab',
13+
\ ' \3 マルチバイト',
14+
\ ' \4"',
15+
\ 'endfunction',
16+
\ '',
17+
\ '" END',
18+
\]
19+
let r = s:vimlparser.StringReader.new(src)
20+
let p = s:vimlparser.VimLParser.new(0)
21+
let c = s:vimlparser.Compiler.new()
22+
let toplevel = p.parse(r)
23+
let func = toplevel.body[0]
24+
let body = s:extract_body(func, src)
25+
call writefile(split(body, "\n"), 'test/node_position/test_position.out')
26+
qall!
27+
endfunction
28+
29+
function! s:extract_body(func, src)
30+
let pos = a:func.pos
31+
32+
" FIXME calculating endpos is workaround. Ideally, it should have the end
33+
" position of the node.
34+
35+
let endpos = a:func.endfunction.pos
36+
let endfunc = a:func.endfunction.ea
37+
let cmdlen = endfunc.argpos.offset - endfunc.cmdpos.offset
38+
let endpos.offset += cmdlen
39+
40+
return join(a:src, "\n")[pos.offset : endpos.offset]
41+
endfunction
42+
43+
call s:run()

test/run.bat

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
@echo off
2-
vim -u NONE -N --cmd "let &rtp .= ',' . getcwd()" -S test/run.vim
2+
vim -Nu test/vimrc -S test/run.vim
3+
set EXIT=%ERRORLEVEL%
4+
if exist test.log type test.log
5+
exit /b %EXIT%

test/run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
#!/bin/sh
2-
vim -u NONE -N --cmd "let &rtp .= ',' . getcwd()" -S test/run.vim
2+
vim -Nu test/vimrc -S test/run.vim
3+
EXIT=$?
4+
[ -e test.log ] && cat test.log
5+
exit $EXIT

test/run.vim

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
2-
31
let s:vimlparser = vimlparser#import()
42

53
let s:sdir = expand('<sfile>:p:h')
64

75
function! s:run()
6+
enew
7+
set buftype=nofile
8+
let ng = 0
89
for vimfile in glob(s:sdir . '/test*.vim', 0, 1)
910
let okfile = fnamemodify(vimfile, ':r') . '.ok'
1011
let outfile = fnamemodify(vimfile, ':r') . '.out'
12+
let skip = filereadable(fnamemodify(vimfile, ':r') . '.skip')
1113
let src = readfile(vimfile)
1214
let r = s:vimlparser.StringReader.new(src)
1315
if vimfile =~# 'test_neo'
@@ -23,13 +25,28 @@ function! s:run()
2325
catch
2426
call writefile([v:exception], outfile)
2527
endtry
26-
if system(printf('diff %s %s', shellescape(okfile), shellescape(outfile))) == ""
28+
let diff = system(printf('diff -u %s %s', shellescape(okfile), shellescape(outfile)))
29+
if empty(diff)
2730
let line = printf('%s => ok', fnamemodify(vimfile, ':.'))
31+
call append(line('$'), line)
2832
else
29-
let line = printf('%s => ng', fnamemodify(vimfile, ':.'))
33+
if !skip
34+
let ng += 1
35+
endif
36+
let line = printf('%s => ' . (skip ? 'skip' : 'ng'), fnamemodify(vimfile, ':.'))
37+
call append(line('$'), line)
38+
for line in split(diff, '\n')
39+
call append(line('$'), ' ' . line)
40+
endfor
3041
endif
31-
call append(line('$'), line)
3242
endfor
43+
if $CI == 'true'
44+
call writefile(getline(1, '$'), 'test.log')
45+
if ng == 0
46+
quit!
47+
endif
48+
cquit!
49+
endif
3350
syntax enable
3451
match Error /^.* => ng$/
3552
endfunction

test/run_command.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
if [ $# -eq 0 ]; then
4+
echo "USAGE: ./test/run_command.sh <vimlparser command>"
5+
echo " Example: ./test/run_command.sh python3 py/vimlparser.py"
6+
exit 1
7+
fi
8+
vimlparser=$@
9+
10+
exit_status=0
11+
12+
test_file() {
13+
local vimfile=$1
14+
local base=$(basename "$vimfile" ".vim")
15+
local okfile="test/${base}.ok"
16+
local outfile="test/${base}.out"
17+
18+
if [[ -f "test/${base}.skip" ]]; then
19+
return
20+
fi
21+
22+
local neovim=""
23+
if [[ $vimfile =~ "test_neo" ]]; then
24+
neovim="--neovim"
25+
fi
26+
27+
rm -f ${outfile}
28+
29+
${vimlparser} ${neovim} ${vimfile} &> ${outfile}
30+
31+
diffout=$(diff -u ${outfile} ${okfile})
32+
if [ -n "$diffout" ]; then
33+
exit_status=1
34+
echo "${diffout}"
35+
fi
36+
}
37+
38+
for f in test/test*.vim; do
39+
test_file ${f}
40+
done
41+
42+
exit $exit_status

test/test1.ok

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
; test1
22
(function (s:foo a b . ...)
33
(return 0))
4+
(function (s:bar (a 1) (b 2) . ...)
5+
(return 0))
6+
(function (s:baz a (b 2) . ...)
7+
(return 0))
48
(if 1
59
(echo "if 1")
610
elseif 2
@@ -14,6 +18,8 @@
1418
(echo a b c))
1519
(delfunction s:foo)
1620
(call (s:foo 1 2 3))
21+
(eval (filter odds 'v:val % 2'))
22+
(eval 42)
1723
(let = a (dict ("x" "y")))
1824
(let = (a b . c) (list 1 2 3))
1925
(let += (a b . c) (list 1 2 3))
@@ -46,3 +52,16 @@
4652
(echo (subscript x 0) (subscript x y))
4753
(echo (slice x 1 2) (slice x 1 nil) (slice x nil 2) (slice x nil nil))
4854
(echo (dot x y) (dot (dot x y) z))
55+
(let = a 1)
56+
(let += a 2)
57+
(let *= a 3)
58+
(let /= a 4)
59+
(let %= a 5)
60+
(let ..= a 'foo')
61+
(echo (concat (concat 'foo' 'bar') 'baz'))
62+
(echo (concat 'foo' (concat 'bar' 'baz')))
63+
(echo (concat (concat 'foo' 'bar') 'baz'))
64+
(let = a '🐥')
65+
(const = a 1)
66+
(const = (a b) (list 1 2))
67+
(const = (a b . c) (list 1 2 3))

test/test1.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
function s:foo(a, b, ...)
33
return 0
44
endfunction
5+
function s:bar(a = 1, b = 2, ...)
6+
return 0
7+
endfunction
8+
function s:baz(a, b = 2, ...)
9+
return 0
10+
endfunction
511
if 1
612
echo "if 1"
713
elseif 2
@@ -18,6 +24,8 @@ for [a, b; c] in d
1824
endfor
1925
delfunction s:foo
2026
call s:foo(1, 2, 3)
27+
eval filter(odds, 'v:val % 2')
28+
eval 42
2129
let a = {"x": "y"}
2230
let [a, b; c] = [1, 2, 3]
2331
let [a, b; c] += [1, 2, 3]
@@ -51,3 +59,16 @@ echo {} {"x":"y"} {"x":"y","z":"w",}
5159
echo x[0] x[y]
5260
echo x[1:2] x[1:] x[:2] x[:]
5361
echo x.y x.y.z
62+
let a = 1
63+
let a += 2
64+
let a *= 3
65+
let a /= 4
66+
let a %= 5
67+
let a ..= 'foo'
68+
echo ('foo' .. 'bar')..'baz'
69+
echo 'foo' .. ('bar'..'baz')
70+
echo 'foo' .. 'bar' .. 'baz'
71+
let a = '🐥'
72+
const a = 1
73+
const [a, b] = [1, 2]
74+
const [a, b; c] = [1, 2, 3]

test/test_blob.ok

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(echo 0z)
2+
(echo 0z11)
3+
(echo 0zdeadbeef)
4+
(echo 0Zdeadbeef)
5+
(echo 0zDEADBEEF)
6+
(echo 0ZDEADBEEF)
7+
(echo 0ZDEAD.BEEF)
8+
(echo (+ 0z00 0zFF))

test/test_blob.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
echo 0z
2+
echo 0z11
3+
echo 0zdeadbeef
4+
echo 0Zdeadbeef
5+
echo 0zDEADBEEF
6+
echo 0ZDEADBEEF
7+
echo 0ZDEAD.BEEF
8+
echo 0z00 + 0zFF

0 commit comments

Comments
 (0)