Skip to content

Commit e1648e7

Browse files
authored
Merge pull request #43 from arp242/test
Add a few tests
2 parents 75d252c + 8d0b50e commit e1648e7

File tree

7 files changed

+160
-1
lines changed

7 files changed

+160
-1
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "testing.vim"]
2+
path = testing.vim
3+
url = [email protected]:arp242/testing.vim.git

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
zip:
2-
@rm -f zsh-runtime.zip; find . -type f -name "*.vim" | zip -@ zsh-runtime.zip
2+
@rm -f zsh-runtime.zip
3+
@find . -type f -name "*.vim" -a -not -name '*_test.vim' -a -not -name 'tvim.vim' | zip -@ zsh-runtime.zip
34

45
submit:
56
@echo "Set environment variable '\$$MSG' to the tag message, like this:"
67
@echo "MSG='My tag message'"
78
@echo "git tag -f -s \`date +'%Y%m%d'\` -m \"\$$MSG\""
9+
10+
test:
11+
@git submodule update
12+
@./testing.vim/tvim test ./...
13+
14+
update-tests:
15+
@git submodule update
16+
./testing.vim/tvim gen-syn ./testdata/*.zsh > syntax_test.vim

syntax_test.vim

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
" This file is automatically generated by test-syntax from testing.vim
2+
3+
fun! Test_if() abort
4+
call TestSyntax(g:test_packdir . '/testdata/if.zsh',
5+
\ [
6+
\ [['zshComment', 1, 50]],
7+
\ [],
8+
\ [['zshConditional', 1, 3], ['zshDeref', 6, 10], ['zshOperator', 12, 13], ['zshConditional', 14, 17]],
9+
\ [],
10+
\ [['zshConditional', 1, 5], ['zshDeref', 9, 13], ['zshOperator', 16, 17], ['zshConditional', 18, 21]],
11+
\ [],
12+
\ [['zshConditional', 1, 5], ['zshSubstDelim', 6, 8], ['zshDeref', 9, 13], ['zshSubstDelim', 14, 14], ['zshOperator', 16, 17], ['zshConditional', 18, 21]],
13+
\ [],
14+
\ [['zshConditional', 1, 2]],
15+
\ [],
16+
\ [['zshConditional', 1, 3], ['zshSubstDelim', 4, 6], ['zshSubstDelim', 14, 14], ['zshOperator', 15, 16], ['zshDelimiter', 17, 18]],
17+
\ [],
18+
\ [['zshConditional', 1, 5], ['zshSubstDelim', 9, 11], ['zshSubstDelim', 19, 20], ['zshNumber', 25, 27], ['zshOperator', 30, 31], ['zshConditional', 32, 35]],
19+
\ [],
20+
\ [['zshConditional', 1, 5], ['zshSubstDelim', 6, 8], ['zshSubstDelim', 9, 11], ['zshSubstDelim', 19, 20], ['zshNumber', 23, 25], ['zshSubstDelim', 26, 26], ['zshOperator', 28, 29], ['zshConditional', 30, 33]],
21+
\ [],
22+
\ [['zshConditional', 1, 2]],
23+
\ [],
24+
\ [['zshSubstDelim', 4, 6], ['zshSubstDelim', 14, 15], ['zshNumber', 20, 22], ['zshOperator', 26, 28], ['zshCommands', 29, 34]],
25+
\ [['zshSubstDelim', 1, 3], ['zshSubstDelim', 4, 6], ['zshSubstDelim', 14, 15], ['zshNumber', 18, 20], ['zshSubstDelim', 21, 23], ['zshOperator', 26, 28], ['zshCommands', 29, 34]],
26+
\ [],
27+
\ [['zshComment', 1, 38]],
28+
\ [['zshOperator', 12, 12], ['zshSubstDelim', 14, 14], ['zshNumber', 16, 17], ['zshNumber', 18, 18], ['zshSubstDelim', 19, 19], ['zshOperator', 21, 23], ['zshCommands', 24, 29]],
29+
\ [],
30+
\ [['zshComment', 1, 1], ['zshTodo', 3, 3], ['zshComment', 7, 71]],
31+
\ [['zshVariableDef', 3, 4], ['zshOperator', 9, 11], ['zshVariableDef', 13, 14]],
32+
\ ])
33+
endfun
34+
35+
fun! Test_quotes() abort
36+
call TestSyntax(g:test_packdir . '/testdata/quotes.zsh',
37+
\ [
38+
\ [['zshComment', 1, 15]],
39+
\ [],
40+
\ [['zshStringDelimiter', 2, 2], ['zshString', 3, 3], ['zshStringDelimiter', 9, 10], ['zshStringDelimiter', 13, 13], ['zshString', 14, 14], ['zshStringDelimiter', 23, 24], ['zshStringDelimiter', 27, 27], ['zshString', 28, 28], ['zshStringDelimiter', 40, 41], ['zshStringDelimiter', 44, 44], ['zshString', 45, 45], ['zshStringDelimiter', 62, 62]],
41+
\ [['zshStringDelimiter', 2, 2], ['zshString', 3, 3], ['zshStringDelimiter', 9, 10], ['zshStringDelimiter', 13, 13], ['zshString', 14, 14], ['zshDeref', 19, 19], ['zshStringDelimiter', 23, 24], ['zshStringDelimiter', 27, 27], ['zshString', 28, 28], ['zshSubstDelim', 35, 35], ['zshString', 37, 37], ['zshSubstDelim', 39, 39], ['zshStringDelimiter', 40, 41], ['zshStringDelimiter', 44, 44], ['zshString', 45, 45], ['zshQuoted', 50, 50], ['zshString', 52, 52], ['zshQuoted', 53, 53], ['zshString', 55, 55], ['zshQuoted', 58, 58], ['zshString', 60, 60], ['zshStringDelimiter', 62, 62], ['zshComment', 63, 63], ['zshTodo', 66, 66], ['zshComment', 70, 103]],
42+
\ [['zshStringDelimiter', 1, 1], ['zshPOSIXString', 3, 3], ['zshStringDelimiter', 9, 10], ['zshStringDelimiter', 12, 12], ['zshPOSIXString', 14, 14], ['zshStringDelimiter', 23, 24], ['zshStringDelimiter', 26, 26], ['zshPOSIXString', 28, 28], ['zshStringDelimiter', 40, 41], ['zshStringDelimiter', 43, 43], ['zshPOSIXString', 45, 45], ['zshQuoted', 50, 50], ['zshPOSIXString', 52, 52], ['zshPOSIXQuoted', 53, 53], ['zshPOSIXString', 57, 57], ['zshPOSIXQuoted', 58, 58], ['zshStringDelimiter', 62, 62]],
43+
\ [['zshSubstDelim', 2, 2], ['zshOldSubst', 3, 3], ['zshSubstDelim', 9, 10], ['zshSubstDelim', 13, 13], ['zshOldSubst', 14, 14], ['zshDeref', 19, 19], ['zshSubstDelim', 23, 24], ['zshSubstDelim', 27, 27], ['zshOldSubst', 28, 28], ['zshSubstDelim', 35, 35], ['zshOldSubst', 37, 37], ['zshSubstDelim', 39, 41], ['zshSubstDelim', 44, 44], ['zshOldSubst', 45, 45], ['zshQuoted', 50, 50], ['zshOldSubst', 52, 52], ['zshPOSIXQuoted', 53, 53], ['zshOldSubst', 57, 57], ['zshPOSIXQuoted', 58, 58], ['zshSubstDelim', 62, 62]],
44+
\ [],
45+
\ [['zshStringDelimiter', 1, 1], ['zshString', 2, 2], ['zshStringDelimiter', 8, 9], ['zshStringDelimiter', 10, 10], ['zshSubstDelim', 11, 11], ['zshOldSubst', 12, 12], ['zshSubstDelim', 16, 16], ['zshStringDelimiter', 17, 17]],
46+
\ [['zshStringDelimiter', 1, 1], ['zshString', 2, 2], ['zshStringDelimiter', 8, 9], ['zshStringDelimiter', 10, 10], ['zshString', 11, 11], ['zshStringDelimiter', 17, 17]],
47+
\ [],
48+
\ [['zshStringDelimiter', 2, 2], ['zshString', 3, 3], ['zshQuoted', 11, 11], ['zshString', 13, 13], ['zshQuoted', 14, 14], ['zshString', 16, 16], ['zshQuoted', 17, 17], ['zshString', 19, 19], ['zshQuoted', 20, 20], ['zshString', 22, 22], ['zshStringDelimiter', 29, 29]],
49+
\ [['zshStringDelimiter', 2, 2], ['zshString', 3, 3], ['zshStringDelimiter', 15, 16], ['zshQuoted', 17, 19], ['zshQuoted', 20, 22], ['zshStringDelimiter', 29, 29], ['zshString', 30, 30], ['zshStringDelimiter', 57, 58]],
50+
\ [['zshStringDelimiter', 1, 1], ['zshPOSIXString', 3, 3], ['zshQuoted', 11, 11], ['zshPOSIXString', 13, 13], ['zshQuoted', 14, 14], ['zshPOSIXString', 16, 16], ['zshQuoted', 17, 17], ['zshPOSIXString', 19, 19], ['zshQuoted', 20, 20], ['zshPOSIXString', 22, 22], ['zshStringDelimiter', 29, 29]],
51+
\ ])
52+
endfun
53+
54+
fun! Test_var() abort
55+
call TestSyntax(g:test_packdir . '/testdata/var.zsh',
56+
\ [
57+
\ [['zshComment', 1, 16]],
58+
\ [],
59+
\ [['zshComment', 1, 29]],
60+
\ [['zshVariableDef', 1, 2]],
61+
\ [['zshVariableDef', 1, 4]],
62+
\ [['zshTypes', 1, 6], ['zshVariableDef', 7, 8]],
63+
\ [['zshTypes', 1, 8], ['zshVariableDef', 12, 13]],
64+
\ [],
65+
\ [['zshCommands', 1, 6], ['zshDeref', 7, 8]],
66+
\ [['zshCommands', 1, 6], ['zshSubstDelim', 7, 7], ['zshSubst', 9, 9], ['zshSubstDelim', 10, 10]],
67+
\ [],
68+
\ [['zshCommands', 1, 6], ['zshDeref', 7, 9], ['zshComment', 11, 11], ['zshTodo', 15, 15], ['zshComment', 19, 57]],
69+
\ [['zshCommands', 1, 6], ['zshSubstDelim', 7, 7], ['zshSubst', 9, 9], ['zshSubstDelim', 12, 12]],
70+
\ [],
71+
\ [['zshCommands', 1, 6], ['zshSubstDelim', 7, 7], ['zshSubst', 9, 9], ['zshSubstDelim', 15, 15]],
72+
\ [['zshCommands', 1, 6], ['zshDeref', 7, 11], ['zshNumber', 12, 13], ['zshComment', 14, 14], ['zshTodo', 19, 19], ['zshComment', 23, 69]],
73+
\ [['zshCommands', 1, 6], ['zshSubstDelim', 7, 7], ['zshSubst', 9, 9], ['zshSubstDelim', 15, 15]],
74+
\ [['zshCommands', 1, 6], ['zshDeref', 7, 11]],
75+
\ [],
76+
\ [['zshCommands', 1, 6], ['zshSubstDelim', 7, 7], ['zshSubst', 9, 9], ['zshSubstDelim', 18, 18]],
77+
\ [['zshCommands', 1, 6], ['zshSubstDelim', 7, 7], ['zshSubst', 9, 9], ['zshSubstDelim', 18, 18]],
78+
\ [],
79+
\ [['zshCommands', 1, 6], ['zshShortDeref', 7, 9], ['zshShortDeref', 10, 12], ['zshDeref', 13, 15], ['zshShortDeref', 16, 17]],
80+
\ ])
81+
endfun

testdata/if.zsh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Test "if" and related constructs in various way.
2+
3+
if [ $foo ]; then
4+
:
5+
elif [[ $foo ]]; then
6+
:
7+
elif (( $foo )); then
8+
:
9+
fi
10+
11+
if $(grep x y); do
12+
:
13+
elif [[ $(grep x y) -gt 42 ]]; then
14+
:
15+
elif (( $(grep x y) > 42 )); then
16+
:
17+
fi
18+
19+
[[ $(grep x y) -gt 42 ]] && print x
20+
(( $(grep x y) > 42 )) && print x
21+
22+
# Unlike [/[[, (( doesn't need spaces.
23+
[[ x = y ]]&&((1>0))&& print x
24+
25+
# TODO: maybe show error for these invalid constructs (missing spaces)?
26+
# Since these are valid glob patterns (though unlikely), we can highlight it as
27+
# an error only if it's after a zshConditional, or if it's preceded or followed
28+
# by zshOperator.
29+
[[x=x]] && [x=x]

testdata/quotes.zsh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Test quoting.
2+
3+
'single' 'var: $var' 'subst: $(ls)' 'esc: \n \x01 \001'
4+
"double" "var: $var" "subst: $(ls)" "esc: \n \x01 \001"
5+
$'single' $'var: $var' $'subst: $(ls)' $'esc: \n \x01 \001'
6+
`batick` `var: $var` `subst: $(ls)` `esc: \n \x01 \001`
7+
8+
"'nest'" "`nest`"
9+
'"nest"' '`nest`'
10+
11+
"escape: \" \' \` \\ escape"
12+
'escape: \" \' \` \\ escape'
13+
$'escape: \" \' \` \\ escape'

testdata/var.zsh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Test variables
2+
3+
# Declaration and assignment.
4+
x=var.zsh
5+
arr=(one two three)
6+
local a=b
7+
typeset -U c=()
8+
9+
print $x
10+
print ${x}
11+
12+
print $x:t # TODO: ":t" should probably get highlighted.
13+
print ${x:t}
14+
15+
print ${arr[1]}
16+
print $arr[1] # TODO: [1] should probably get highlighted the same?
17+
print ${arr[@]}
18+
print $arr[@]
19+
20+
print ${(j:x:)arr}
21+
print ${(j/x/)arr}
22+
23+
print $@ $# $_ $0

testing.vim

Submodule testing.vim added at 963d2c2

0 commit comments

Comments
 (0)