tests: Directly diff expected_region_highlight against region_highlight

This commit is contained in:
Matthew Martin 2018-02-06 19:14:26 -06:00
parent 622358f32d
commit a9be0975c8
78 changed files with 219 additions and 121 deletions

View file

@ -33,5 +33,4 @@ BUFFER=': $foo[bar]'
CURSOR=6 # cursor is zero-based
expected_region_highlight=(
"11 11 NONE"
)

View file

@ -27,6 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
unsorted=1
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
ZSH_HIGHLIGHT_STYLES[bracket-level-3]=
@ -35,5 +37,11 @@ BUFFER=': ((( )))'
CURSOR=2 # cursor is zero-based
expected_region_highlight=(
"3 3 bracket-level-1"
"4 4 bracket-level-2"
"5 5 bracket-level-3"
"7 7 bracket-level-3"
"8 8 bracket-level-2"
"9 9 bracket-level-1"
"9 9 cursor-matchingbracket"
)

View file

@ -30,5 +30,4 @@
BUFFER=': (x)'
expected_region_highlight=(
"1 5 NONE"
)

View file

@ -27,6 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
unsorted=1
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
ZSH_HIGHLIGHT_STYLES[bracket-level-3]=

View file

@ -27,6 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
unsorted=1
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=

View file

@ -27,6 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
unsorted=1
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
@ -34,10 +36,7 @@ BUFFER=': {"{x}"}'
expected_region_highlight=(
"3 3 bracket-level-1"
"4 4 NONE"
"5 5 bracket-level-2"
"6 6 NONE"
"7 7 bracket-level-2"
"8 8 NONE"
"9 9 bracket-level-1"
)

View file

@ -27,6 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
unsorted=1
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=
ZSH_HIGHLIGHT_STYLES[bracket-level-3]=

View file

@ -30,6 +30,5 @@
BUFFER=': x)'
expected_region_highlight=(
"1 3 NONE"
"4 4 bracket-error" # )
)

View file

@ -30,7 +30,5 @@
BUFFER='echo "foo ( bar"'
expected_region_highlight=(
"1 10 NONE"
"11 11 bracket-error"
"12 16 NONE"
)

View file

@ -27,6 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
unsorted=1
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=

View file

@ -27,6 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
unsorted=1
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
ZSH_HIGHLIGHT_STYLES[bracket-level-2]=

View file

@ -27,6 +27,8 @@
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------
unsorted=1
ZSH_HIGHLIGHT_STYLES[bracket-level-1]=
BUFFER='echo {x})'

View file

@ -34,4 +34,5 @@ BUFFER='x=y ls'
expected_region_highlight=(
"1 3 unknown-token" # x=y
"5 6 default" # ls
)

View file

@ -49,5 +49,6 @@ if zmodload -e zsh/parameter || [[ "$(type -w x.alias2)" == *suffix* ]]; then
)
fi
expected_region_highlight+=(
"9 9 commandseparator" # ;
"11 16 alias" # alias1
)

View file

@ -37,5 +37,8 @@ expected_region_highlight=(
"16 17 reserved-word" # ()
"19 19 reserved-word" # {
"21 24 builtin" # echo
"26 30 default" # world
"32 32 reserved-word" # }
"34 43 default" # "argument"
"34 43 double-quoted-argument" # "argument"
)

View file

@ -31,4 +31,7 @@ BUFFER='a+=(lorem ipsum)'
expected_region_highlight=(
"1 4 assign" # a+=(
"5 9 default" # lorem
"11 15 default" # ipsum
"16 16 assign" # )
)

View file

@ -32,6 +32,8 @@ BUFFER='(A=(hello world))'
expected_region_highlight=(
"1 1 reserved-word" # (
"2 4 assign" # A=(
"5 9 default" # hello
"11 15 default" # world
"16 16 assign" # )
"17 17 reserved-word" # )
)

View file

@ -31,6 +31,8 @@ BUFFER='A=(hello world) ls'
expected_region_highlight=(
"1 3 assign" # A=(
"4 8 default" # hello
"10 14 default" # world
"15 15 assign" # )
"17 18 command" # ls
)

View file

@ -31,6 +31,8 @@ BUFFER='A=(hello world) b=42'
expected_region_highlight=(
"1 3 assign" # A=(
"4 8 default" # hello
"10 14 default" # world
"15 15 assign" # )
"17 20 assign" # b=42
)

View file

@ -30,6 +30,9 @@
BUFFER='A=1; echo hello world'
expected_region_highlight=(
"1 3 assign" # A=1
"4 4 commandseparator" # ;
"6 9 builtin" # echo
"11 15 default" # hello
"17 21 default" # world
)

View file

@ -32,6 +32,7 @@ BUFFER='A=1 b=("foo" bar)'
expected_region_highlight=(
"1 3 assign" # A=1
"5 7 assign" # b=(
"8 12 default" # "foo"
"8 12 double-quoted-argument" # "foo"
"14 16 default" # bar
"17 17 assign" # )

View file

@ -31,9 +31,12 @@
BUFFER='echo `echo \`42\`` "is `echo equal` to" `echo 6 times 9'
expected_region_highlight=(
"1 4 builtin" # echo
"6 18 default" # `echo \`42\``
"6 18 back-quoted-argument" # `echo \`42\``
"20 23 double-quoted-argument" # "is
"20 39 default" # "is `echo equal` to"
"20 39 double-quoted-argument" # "is `echo equal` to"
"24 35 back-quoted-argument" # `echo equal`
"36 39 double-quoted-argument" # to"
"41 55 default" # `echo 6 times 9
"41 55 back-quoted-argument-unclosed" # `echo 6 times 9
)

View file

@ -34,6 +34,7 @@ expected_region_highlight=(
'1 3 reserved-word' # for
'5 5 default' # n
'7 8 default' # in
'10 10 default' # *
'10 10 globbing' # *
'11 11 commandseparator' # ;
'13 14 reserved-word' # do

View file

@ -30,6 +30,7 @@
BUFFER=':; pwd &! ls'
expected_region_highlight=(
"1 1 builtin" # :
"2 2 commandseparator" # ;
"4 6 builtin" # pwd
"8 9 commandseparator" # &!

View file

@ -32,6 +32,5 @@ setopt interactive_comments
BUFFER='# echo foo'
expected_region_highlight=(
"1 1 comment" # #
"2 10 comment" # " echo foo"
"1 10 comment" # # echo foo
)

View file

@ -33,6 +33,7 @@ BUFFER='echo "foo #bar" #baz # quux'
expected_region_highlight=(
"1 4 builtin" # echo
"6 15 default" # "foo #bar"
"6 15 double-quoted-argument" # "foo #bar"
"17 27 comment" # #baz # quux
)

View file

@ -32,5 +32,6 @@ BUFFER='$x "argument"'
expected_region_highlight=(
"1 2 command" # $x
"4 13 default" # "argument"
"4 13 double-quoted-argument" # "argument"
)

View file

@ -34,17 +34,24 @@ expected_region_highlight+=(
"7 8 reserved-word" # if
"10 13 builtin" # echo
"15 19 default" # Hello
"20 20 commandseparator" # ;
"22 25 reserved-word" # then
"27 28 command" # ls
"30 30 path" # /
"31 31 commandseparator" # ;
"33 36 reserved-word" # else
"38 39 command" # ls
"40 40 commandseparator" # ;
"42 43 reserved-word" # fi
"44 44 commandseparator" # ;
"46 47 reserved-word" # do
"49 52 command" # stat
"54 56 default" # "x"
"54 56 double-quoted-argument" # "x"
"57 57 commandseparator" # ;
"59 62 reserved-word" # done
"63 63 commandseparator" # ;
"65 70 reserved-word" # repeat
"72 73 default" # 10
"75 76 command" # ls
)

View file

@ -32,8 +32,8 @@ BUFFER=': "$$ $$foo"'
expected_region_highlight=(
'1 1 builtin' # :
'3 3 double-quoted-argument' # "
'3 12 default' # "$$ $$foo"
'3 12 double-quoted-argument' # "$$ $$foo"
'4 5 dollar-double-quoted-argument' # $$
'7 8 dollar-double-quoted-argument' # $$
'9 12 double-quoted-argument' # foo"
)

View file

@ -32,15 +32,11 @@ BUFFER=': "$- $# $* $@ $?"'
expected_region_highlight=(
'1 1 builtin' # :
'3 3 double-quoted-argument' # "
'3 18 default' # "$- $# $* $@ $?"
'3 18 double-quoted-argument' # "$- $# $* $@ $?"
'4 5 dollar-double-quoted-argument' # $-
'6 6 double-quoted-argument' # <space>
'7 8 dollar-double-quoted-argument' # $#
'9 9 double-quoted-argument' # <space>
'10 11 dollar-double-quoted-argument' # $*
'12 12 double-quoted-argument' # <space>
'13 14 dollar-double-quoted-argument' # $@
'15 15 double-quoted-argument' # <space>
'16 17 dollar-double-quoted-argument' # $?
'18 18 double-quoted-argument' # "
)

View file

@ -32,7 +32,7 @@ BUFFER=': "$(:)"'
expected_region_highlight=(
'1 1 builtin' # :
'3 3 double-quoted-argument' # "
'3 8 default' # "$(:)"
'3 8 double-quoted-argument' # "$(:)"
'4 4 dollar-double-quoted-argument' # $
'5 8 double-quoted-argument' # (:)"
)

View file

@ -30,6 +30,9 @@
BUFFER=": \$'*' 'foo'"
expected_region_highlight=(
"1 1 builtin" # :
"3 6 default" # $'*'
"3 6 dollar-quoted-argument" # $'*' - not a glob
"8 12 default" # 'foo'
"8 12 single-quoted-argument" # 'foo'
)

View file

@ -30,11 +30,10 @@
BUFFER=": \$'foo\xbar\udeadbeef\uzzzz'"
expected_region_highlight=(
"3 7 dollar-quoted-argument" # $'foo
"1 1 builtin" # :
"3 29 default" # $'foo\xbar\udeadbeef\uzzzz'
"3 29 dollar-quoted-argument" # $'foo\xbar\udeadbeef\uzzzz'
"8 11 back-dollar-quoted-argument" # \xba
"12 12 dollar-quoted-argument" # r
"13 18 back-dollar-quoted-argument" # \dead
"19 22 dollar-quoted-argument" # beef
"23 24 unknown-token" # \u
"25 29 dollar-quoted-argument" # zzzz'
)

View file

@ -32,6 +32,8 @@
BUFFER=": \$'\xa1"
expected_region_highlight=(
"3 4 dollar-quoted-argument-unclosed" # $'
"1 1 builtin" # :
"3 8 default" # $'\xa1
"3 8 dollar-quoted-argument-unclosed" # $'\xa1
"5 8 back-dollar-quoted-argument" # \xa1
)

View file

@ -30,5 +30,6 @@
BUFFER='hello --world'
expected_region_highlight=(
"1 5 unknown-token" # hello
"7 13 double-hyphen-option" # --world
)

View file

@ -31,15 +31,12 @@ BUFFER=': "foo$bar:\`:\":\$:'
BUFFER+=\\\\:\"
expected_region_highlight=(
"3 6 double-quoted-argument" # "foo
"1 1 builtin" # :
"3 24 default" # "foo$bar:\`:\":\$:\\:"
"3 24 double-quoted-argument" # "foo$bar:\`:\":\$:\\:"
"7 10 dollar-double-quoted-argument" # $bar
"11 11 double-quoted-argument" # :
"12 13 back-double-quoted-argument" # \`
"14 14 double-quoted-argument" # :
"15 16 back-double-quoted-argument" # \$
"17 17 double-quoted-argument" # :
"18 19 back-double-quoted-argument" # \"
"20 20 double-quoted-argument" # :
"21 22 back-double-quoted-argument" # \\
"23 24 double-quoted-argument" # :"
)

View file

@ -32,6 +32,8 @@
BUFFER=': "foo$bar'
expected_region_highlight=(
"3 6 double-quoted-argument-unclosed" # "foo
"1 1 builtin" # :
"3 10 default" # "foo$bar
"3 10 double-quoted-argument-unclosed" # "foo$bar
"7 10 dollar-double-quoted-argument" # $bar
)

View file

@ -31,9 +31,12 @@ BUFFER=': "$" "$42foo"'
BUFFER+=\ \"\\\'\\x\"
expected_region_highlight=(
"1 1 builtin" # :
"3 5 default" # "$"
"3 5 double-quoted-argument" # "$"
"7 7 double-quoted-argument" # "
"7 14 default" # "$42foo"
"7 14 double-quoted-argument" # "$42foo"
"8 10 dollar-double-quoted-argument" # $42
"11 14 double-quoted-argument" # foo"
"16 21 default" # "\'\x"
"16 21 double-quoted-argument" # "\'\x" - \' and \x are not escape sequences
)

View file

@ -30,7 +30,8 @@
BUFFER=': "${foo}bar"'
expected_region_highlight=(
"3 3 double-quoted-argument" # "
"1 1 builtin" # :
"3 13 default" # "${foo}bar"
"3 13 double-quoted-argument" # "${foo}bar"
"4 9 dollar-double-quoted-argument" # ${foo}
"10 13 double-quoted-argument" # bar"
)

View file

@ -30,6 +30,7 @@
BUFFER='echo; ;'
expected_region_highlight=(
"1 4 builtin" # echo
"5 5 commandseparator" # ;
"7 7 unknown-token" # ;
)

View file

@ -33,6 +33,7 @@ touch ';'
BUFFER='echo; ;'
expected_region_highlight=(
"1 4 builtin" # echo
"5 5 commandseparator" # ;
"7 7 unknown-token" # ;
)

View file

@ -32,7 +32,7 @@ BUFFER=$': \'foo\'\\\'\'bar\'' # <<<: 'foo'\''bar'>>>
expected_region_highlight=(
'1 1 builtin' # :
'3 14 default' # 'foo'\''bar'
'3 7 single-quoted-argument' # 'foo'
'8 9 default' # \'
'10 14 single-quoted-argument' # 'bar'
)

View file

@ -37,5 +37,6 @@ BUFFER='cd;ls'
expected_region_highlight=(
"1 2 function" # cd
"3 3 commandseparator" # ;
"4 5 function" # ls
)

View file

@ -31,11 +31,11 @@ BUFFER=': foo* bar? *baz qux\?'
expected_region_highlight=(
"1 1 builtin" # :
"3 5 default" # foo
"3 6 default" # foo*
"6 6 globbing" # *
"8 10 default" # bar
"8 11 default" # bar?
"11 11 globbing" # ?
"13 16 default" # *baz
"13 13 globbing" # *
"14 16 default" # baz
"18 22 default" # qux\?
)

View file

@ -32,6 +32,7 @@ BUFFER=$': "foo"*\'bar\'?"baz?"<17-29>"qu*ux"'
expected_region_highlight=(
'1 1 builtin' # :
'3 34 default' # "foo"*'bar'?"baz?"<17-29>"qu*ux"
'3 7 double-quoted-argument' # "foo"
'8 8 globbing' # *
'9 13 single-quoted-argument' # 'bar'

View file

@ -32,7 +32,7 @@ BUFFER='echo "Hello\!"'
expected_region_highlight=(
'1 4 builtin' # echo
'6 11 double-quoted-argument' # "Hello
'6 14 default' # "Hello\!"
'6 14 double-quoted-argument' # "Hello\!"
'12 13 back-double-quoted-argument' # \!
'14 14 double-quoted-argument' # "Hello\!"
)

View file

@ -32,5 +32,6 @@ BUFFER='echo "foo != bar !{baz}"'
expected_region_highlight=(
'1 4 builtin' # echo
'6 24 default' # "foo != bar !{baz}"
'6 24 double-quoted-argument' # "foo != bar !{baz}" - no history expansions
)

View file

@ -32,7 +32,7 @@ BUFFER='echo "Hello!"'
expected_region_highlight=(
'1 4 builtin' # echo
'6 11 double-quoted-argument' # "Hello
'6 13 default' # "Hello!"
'6 13 double-quoted-argument' # "Hello!"
'12 12 history-expansion' # !
'13 13 double-quoted-argument' # "
)

View file

@ -32,7 +32,7 @@ BUFFER='echo "foo !bar"'
expected_region_highlight=(
'1 4 builtin' # echo
'6 10 double-quoted-argument' # "foo
'6 15 default' # "foo !bar"
'6 15 double-quoted-argument' # "foo !bar"
'11 11 history-expansion' # !
'12 15 double-quoted-argument' # bar"
)

View file

@ -33,6 +33,7 @@ expected_region_highlight=(
"1 4 history-expansion" # !foo
"6 8 default" # bar
"10 13 history-expansion" # !baz
"15 15 default" # ! (before the semicolon)
"19 19 reserved-word" # ! (after the semicolon)
"15 15 default" # !
"17 17 commandseparator" # ;
"19 19 reserved-word" # !
)

View file

@ -31,6 +31,7 @@ PREBUFFER=$'echo "foo1\n'
BUFFER='foo2" ./'
expected_region_highlight=(
"1 5 default" # 'foo2"'
"1 5 double-quoted-argument" # 'foo2"'
"7 8 path" # './'
)

View file

@ -30,5 +30,7 @@
BUFFER=$'echo \'foo1\n'
expected_region_highlight=(
"6 10 single-quoted-argument-unclosed" # 'foo1
"1 4 builtin" # echo
"6 11 default" # 'foo1\n
"6 11 single-quoted-argument-unclosed" # 'foo1\n
)

View file

@ -30,18 +30,13 @@
BUFFER=$': \'foo\'bar"baz$quux/foo\\\\bar"baz$\'quux\\nfoo\\001bar\'baz'
expected_region_highlight=(
"1 1 builtin" # :
"3 54 default" # 'foo'bar"baz$quux/foo\\bar"baz$'quux\nfoo\001'baz
"3 7 single-quoted-argument" # 'foo'
"8 10 default" # bar
"11 14 double-quoted-argument" #"baz
"11 29 double-quoted-argument" #"baz
"15 19 dollar-double-quoted-argument" # $quux
"20 23 double-quoted-argument" # /foo
"24 25 back-double-quoted-argument" # \\
"26 29 double-quoted-argument" # bar"
"30 32 default" # baz
"33 38 dollar-quoted-argument" # $'quux
"33 51 dollar-quoted-argument" # $'quux\nfoo\001bar'
"39 40 back-dollar-quoted-argument" # \n
"41 43 dollar-quoted-argument" # foo
"44 47 back-dollar-quoted-argument" # \001
"48 51 dollar-quoted-argument" # bar'
"52 54 default" # baz
)

View file

@ -31,5 +31,6 @@ alias x=command
BUFFER='x ls'
expected_region_highlight=(
"1 1 alias" # x
"3 4 command" # ls
)

View file

@ -30,5 +30,9 @@
BUFFER=':; noglob echo *'
expected_region_highlight=(
"1 1 builtin" # :
"2 2 commandseparator" # ;
"4 9 precommand" # noglob
"11 14 builtin" # echo
"16 16 default" # *
)

View file

@ -30,6 +30,11 @@
BUFFER='noglob echo *; echo *'
expected_region_highlight=(
"1 6 precommand" # noglob
"8 11 builtin" # echo
"13 13 default" # *
"14 14 commandseparator" # ;
"16 19 builtin" # echo
"21 21 default" # *
"21 21 globbing" # *
)

View file

@ -32,5 +32,7 @@ touch \*
BUFFER='noglob echo *'
expected_region_highlight=(
"1 6 precommand" # noglob
"8 11 builtin" # echo
"13 13 path" # *
)

View file

@ -32,10 +32,10 @@ BUFFER='print <-> x<->y <foo2-3>'
expected_region_highlight=(
'1 5 builtin' # print
'7 9 default' # <->
'7 9 globbing' # <->
'11 11 default' # x
'11 15 default' # x<->y
'12 14 globbing' # <->
'15 15 default' # y
'17 17 redirection' # <
'18 23 default' # foo2-3 (the filename)
'24 24 redirection' # >

View file

@ -32,6 +32,6 @@ BUFFER=$': --user="phy1729"'
expected_region_highlight=(
'1 1 builtin' # :
'3 9 double-hyphen-option' # --user=
'3 18 double-hyphen-option' # --user="phy1729"
'10 18 double-quoted-argument' # "phy1729"
)

View file

@ -33,6 +33,7 @@ BUFFER=': * \*'
expected_region_highlight=(
'1 1 builtin' # :
'3 3 default' # *
'3 3 globbing' # *
'5 6 path' # \*
)

View file

@ -32,5 +32,9 @@ BUFFER='() { : $* }'
# This tests that $* isn't highlighted as a glob.
# If we ever add a "unquoted parameter" style, the expectation may change.
expected_region_highlight=(
"1 2 reserved-word" # ()
"4 4 reserved-word" # {
"6 6 builtin" # :
"8 9 default" # $*
"11 11 reserved-word" # }
)

View file

@ -35,6 +35,7 @@ else
CURSOR=5 # to make path_prefix ineligible
expected_region_highlight=(
"1 1 builtin" # :
"3 16 path" # broken-symlink
)
fi

View file

@ -32,5 +32,6 @@ touch \$lambda
BUFFER=': \$lambda'
expected_region_highlight=(
"3 8 path" # \$lambda
"1 1 builtin" # :
"3 10 path" # \$lambda
)

View file

@ -33,5 +33,6 @@ BUFFER='$PWD; ${PWD}'
expected_region_highlight=(
"1 4 unknown-token" # $PWD - not eval'd; issue #328
"5 5 commandseparator" # ;
"7 12 unknown-token" # ${PWD}
)

View file

@ -37,17 +37,17 @@ touch A/mu
BUFFER='ls /bin/ / A/mu A/m'
expected_region_highlight=(
"1 2 command" # ls
"4 8 path" # /bin/
"4 4 path_pathseparator" # /
"5 7 path" # bin
"8 8 path_pathseparator" # /
"10 10 path" # /
"10 10 path_pathseparator" # /
"12 12 path" # A
"12 15 path" # A/mu
"13 13 path_pathseparator" # /
"14 15 path" # mu
"17 17 path_prefix" # A
"17 19 path_prefix" # A/m
"18 18 path_prefix_pathseparator" # /
"19 19 path_prefix" # m
)

View file

@ -35,5 +35,6 @@ ZSH_HIGHLIGHT_STYLES[path_pathseparator]=value
BUFFER='ls /bin/'
expected_region_highlight=(
"1 2 command" # ls
"4 8 path" # /bin/
)

View file

@ -33,5 +33,5 @@ BUFFER='ls A/mu\ with\ spaces'
expected_region_highlight=(
"1 2 command" # ls
"4 19 path" # A/mu\ with\ spaces
"4 21 path" # A/mu\ with\ spaces
)

View file

@ -33,5 +33,6 @@
BUFFER='ls /bin/s'
expected_region_highlight=(
"4 9 path_prefix" # /bin/s
"1 2 command" # ls
"4 9 path_prefix" # /bin/s
)

View file

@ -34,5 +34,6 @@ BUFFER='ls /bin/s'
WIDGET=zle-line-finish
expected_region_highlight=(
"4 9 default" # /bin/s
"1 2 command" # ls
"4 9 default" # /bin/s
)

View file

@ -30,10 +30,13 @@
BUFFER='>/tmp >/tmp command echo >/tmp foo'
expected_region_highlight=(
"1 1 redirection" # >
"2 5 path" # /tmp
"7 7 redirection" # >
"8 11 path" # /tmp
"13 19 precommand" # command
"21 24 builtin" # echo
"26 26 redirection" # >
"27 30 path" # /tmp
"32 34 default" # foo
)

View file

@ -32,8 +32,8 @@ setopt RC_QUOTES
BUFFER=": 'foo''bar'baz"
expected_region_highlight=(
"3 6 single-quoted-argument" # 'foo
"1 1 builtin" # :
"3 15 default" # 'foo''bar'baz
"3 12 single-quoted-argument" # 'foo''bar'
"7 8 rc-quote" # ''
"9 12 single-quoted-argument" # bar'
"13 15 default" # baz
)

View file

@ -32,5 +32,8 @@ BUFFER='<<<foo echo >>&!bar'
expected_region_highlight=(
"1 3 redirection" # <<<
"4 6 default" # foo
"8 11 builtin" # echo
"13 16 redirection" # >>&!
"17 19 default" # bar
)

View file

@ -31,6 +31,7 @@ BUFFER='repeat "1" do done'
expected_region_highlight=(
"1 6 reserved-word" # repeat
"8 10 default" # "1"
"8 10 double-quoted-argument" # "1"
"12 13 reserved-word" # do
"15 18 reserved-word" # done

View file

@ -31,10 +31,20 @@ BUFFER='tar cf - * | (cd /target; tar xfp -) | { cat }'
expected_region_highlight=(
"1 3 command" # tar
"5 6 default" # cf
"8 8 single-hyphen-option" # -
"10 10 default" # *
"10 10 globbing" # *
"12 12 commandseparator" # |
"14 14 reserved-word" # (
"15 16 builtin" # cd
"18 24 default" # /target
"25 25 commandseparator" # ;
"27 29 command" # tar
"31 33 default" # xfp
"35 35 single-hyphen-option" # -
"36 36 reserved-word" # )
"38 38 commandseparator" # |
"40 40 reserved-word" # {
"42 44 command" # cat
"46 46 reserved-word" # }

View file

@ -43,7 +43,12 @@ expected_region_highlight=(
"23 24 single-hyphen-option" # -i
"26 27 command" # ls
"29 29 path" # /
"30 30 commandseparator" # ;
"32 35 precommand" # sudo
"37 37 unknown-token" # ;, error because empty command
"39 42 precommand" # sudo
"44 45 single-hyphen-option" # -u
"47 47 unknown-token" # ;, error because incomplete command
"49 52 precommand" # sudo
"54 64 unknown-token" # notacommand - doesn't falls back to "not a command word" codepath
)

View file

@ -34,5 +34,10 @@ CURSOR=4
MARK=12
expected_region_highlight=(
"1 3 standout" # foo
"1 3 unknown-token" # foo
"5 7 default" # foo
"8 8 commandseparator" # \n
"9 11 unknown-token" # bar
"13 15 default" # bar
"1 15 standout" # foo foo\nbar bar
)

View file

@ -13,12 +13,13 @@ The value of that parameter is a list of strings of the form `"$i $j $style"`.
or `"$i $j $style $todo"`.
Each string specifies the highlighting that `$BUFFER[$i,$j]` should have;
that is, `$i` and `$j` specify a range, 1-indexed, inclusive of both endpoints.
`$style` is either a key of `$ZSH_HIGHLIGHT_STYLES` or `NONE` to specify no
highlighting should be observed.
`$style` is a key of `$ZSH_HIGHLIGHT_STYLES`.
If `$todo` exists, the test point is marked as TODO (the failure of that test
point will not fail the test), and `$todo` is used as the explanation.
If a test sets `$skip_test` to a non-empty string, the test will be skipped
with the provided string as the reason.
If a test sets `unsorted=1` the order of highlights in `$expected_region_highlight`
need not match the order in `$region_highlight`.
**Note**: `$region_highlight` uses the same `"$i $j $style"` syntax but
interprets the indexes differently.

View file

@ -97,7 +97,7 @@ run_test_internal() {
echo "# ${1:t:r}"
# Load the data and prepare checking it.
local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET skip_test
local BUFFER CURSOR MARK PENDING PREBUFFER REGION_ACTIVE WIDGET skip_test unsorted=0
local -a expected_region_highlight region_highlight
. "$srcdir"/"$1"
@ -106,7 +106,7 @@ run_test_internal() {
# Check the data declares $PREBUFFER or $BUFFER.
[[ -z $PREBUFFER && -z $BUFFER ]] && { echo >&2 "Bail out! On ${(qq)1}: Either 'PREBUFFER' or 'BUFFER' must be declared and non-blank"; return 1; }
# Check the data declares $expected_region_highlight.
(( ${#expected_region_highlight} == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared or empty."; return 1; }
(( $+expected_region_highlight == 0 )) && { echo >&2 "Bail out! On ${(qq)1}: 'expected_region_highlight' is not declared."; return 1; }
# Set sane defaults for ZLE variables
: ${CURSOR=$#BUFFER} ${PENDING=0} ${WIDGET=z-sy-h-test-harness-test-widget}
@ -114,54 +114,48 @@ run_test_internal() {
# Process the data.
_zsh_highlight
# Overlapping regions can be declared in region_highlight, so we first build an array of the
# observed highlighting.
local i j
local -A observed_result
for ((i=1; i<=${#region_highlight}; i++)); do
local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} )
integer start=$highlight_zone[1] end=$highlight_zone[2]
if (( start < end )) # region_highlight ranges are half-open
then
(( --end )) # convert to closed range, like expected_region_highlight
(( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed
for j in {$start..$end}; do
observed_result[$j]=$highlight_zone[3]
done
else
# noop range; ignore.
fi
unset start end
unset highlight_zone
done
if (( unsorted )); then
region_highlight=("${(@n)region_highlight}")
expected_region_highlight=("${(@n)expected_region_highlight}")
fi
# Then we compare the observed result with the expected one.
echo "1..${#expected_region_highlight}"
for ((i=1; i<=${#expected_region_highlight}; i++)); do
local -a highlight_zone; highlight_zone=( ${(z)expected_region_highlight[$i]} )
echo "1..$(( $#expected_region_highlight + 1))"
local i
for ((i=1; i<=$#expected_region_highlight; i++)); do
local -a expected_highlight_zone; expected_highlight_zone=( ${(z)expected_region_highlight[i]} )
integer exp_start=$expected_highlight_zone[1] exp_end=$expected_highlight_zone[2]
local todo=
integer start=$highlight_zone[1] end=$highlight_zone[2]
(( $+expected_highlight_zone[4] )) && todo="# TODO $expected_highlight_zone[4]"
if ! (( $+region_highlight[i] )); then
print -r -- "not ok $i - unmatched expectation ($exp_start $exp_end $expected_highlight_zone[3])"
continue
fi
local -a highlight_zone; highlight_zone=( ${(z)region_highlight[i]} )
integer start=$(( highlight_zone[1] + 1 )) end=$highlight_zone[2]
# Escape # as ♯ and newline as ↵ they are illegal in the 'description' part of TAP output
local desc="[$start,$end] «${${BUFFER[$start,$end]//'#'/♯}//$'\n'/↵}»"
(( $+highlight_zone[4] )) && todo="# TODO $highlight_zone[4]"
for j in {$start..$end}; do
if
if [[ $highlight_zone[3] == NONE ]]; then
(( $+observed_result[$j] ))
else
[[ "$observed_result[$j]" != "$highlight_zone[3]" ]]
fi
then
print -r -- "not ok $i - $desc - expected ${(qqq)highlight_zone[3]}, observed ${(qqq)observed_result[$j]-NONE}. $todo"
continue 2
fi
done
print -r -- "ok $i - $desc${todo:+ - }$todo"
unset desc
unset start end
if
[[ $start != $exp_start ]] ||
[[ $end != $exp_end ]] ||
[[ $highlight_zone[3] != $expected_highlight_zone[3] ]]
then
print -r -- "not ok $i - $desc - expected ($exp_start $exp_end ${(qqq)expected_highlight_zone[3]}), observed ($start $end ${(qqq)highlight_zone[3]}). $todo"
else
print -r -- "ok $i - $desc${todo:+ - }$todo"
fi
unset expected_highlight_zone
unset exp_start exp_end
unset todo
unset highlight_zone
unset start end
unset desc
done
if (( $#expected_region_highlight == $#region_highlight )); then
print -r -- "ok $i - cardinality check"
else
print -r -- "not ok $i - have $#expected_region_highlight expectations and $#region_highlight region_highlight entries"
fi
}
# Run a single test file. The exit status is 1 if the test harness had