From b3f66fc8748f75e8f153a68d929fe2f6880f061a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 22 Oct 2018 17:14:48 -0500 Subject: [PATCH 1/6] main: Use zsyh_user_options when splitting alias RHS --- highlighters/main/main-highlighter.zsh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index f4a0cc8a8..b0c5c9275 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -543,8 +543,11 @@ _zsh_highlight_main_highlighter_highlight_list() _zsh_highlight_main__resolve_alias $arg local -a alias_args # Elision is desired in case alias x='' - alias_args=( ${interactive_comments-${(z)REPLY}} - ${interactive_comments+${(zZ+c+)REPLY}} ) + if [[ $zsyh_user_options[interactivecomments] == on ]]; then + alias_args=(${(zZ+c+)REPLY}) + else + alias_args=(${(z)REPLY}) + fi args=( $alias_args $args ) if (( in_alias == 0 )); then _zsh_highlight_main_add_region_highlight $start_pos $end_pos alias From a88d41e095565986ddabb771b898114ee1ec6845 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 22 Oct 2018 17:20:35 -0500 Subject: [PATCH 2/6] main: Fix faulty test sudo -e does not take a command, so use another flag that does. --- .../test-data/alias-precommand-option-argument2.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh index 2fceff81c..ebbb17b6e 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument2.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -28,15 +28,15 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -alias sde='sudo -e' -alias seu='sde -u' +alias sdb='sudo -b' +alias sbu='sdb -u' sudo(){} -BUFFER='seu phy1729 echo foo' +BUFFER='sbu phy1729 echo foo' expected_region_highlight=( - '1 3 alias' # seu - '1 3 precommand' # seu (sudo) + '1 3 alias' # sbu + '1 3 precommand' # sbu (sudo) '5 11 default' # phy1729 '13 16 commmand "issue #540"' # echo (not builtin) '18 20 default' # foo From 9cc0060334c3773531e4f6914eb964650eecb96c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Mon, 22 Oct 2018 07:50:53 -0500 Subject: [PATCH 3/6] main: Stop highlighting alias as its first word too Fixes #565 and #576 --- highlighters/main/main-highlighter.zsh | 25 +++++++++++++------ .../main/test-data/alias-comment1.zsh | 3 +-- .../main/test-data/alias-comment2.zsh | 1 - highlighters/main/test-data/alias-complex.zsh | 1 - highlighters/main/test-data/alias-loop.zsh | 1 - .../test-data/alias-nested-precommand.zsh | 1 - highlighters/main/test-data/alias-nested.zsh | 1 - .../alias-precommand-option-argument1.zsh | 1 - .../alias-precommand-option-argument2.zsh | 1 - .../main/test-data/alias-redirect.zsh | 1 - highlighters/main/test-data/alias-self.zsh | 1 - highlighters/main/test-data/alias-to-dir.zsh | 1 - highlighters/main/test-data/alias.zsh | 1 - highlighters/main/test-data/noglob-alias.zsh | 1 - highlighters/main/test-data/off-by-one.zsh | 1 - 15 files changed, 18 insertions(+), 23 deletions(-) diff --git a/highlighters/main/main-highlighter.zsh b/highlighters/main/main-highlighter.zsh index b0c5c9275..91be6ca00 100644 --- a/highlighters/main/main-highlighter.zsh +++ b/highlighters/main/main-highlighter.zsh @@ -73,8 +73,10 @@ _zsh_highlight_main_add_region_highlight() { integer start=$1 end=$2 shift 2 - (( highlighted_alias )) && return - (( in_alias )) && highlighted_alias=1 + if (( in_alias )); then + [[ $1 == unknown-token ]] && alias_style=unknown-token + return + fi # The calculation was relative to $buf but region_highlight is relative to $BUFFER. (( start += buf_offset )) @@ -377,15 +379,16 @@ _zsh_highlight_highlighter_main_paint() _zsh_highlight_main_highlighter_highlight_list() { integer start_pos end_pos=0 buf_offset=$1 has_end=$3 + # alias_style is the style to apply to an alias once in_alias=0 + # Usually 'alias' but set to 'unknown-token' if any word expanded from + # the alias would be highlighted as unknown-token # last_alias is the last alias arg (lhs) expanded (if in an alias). # This allows for expanding alias ls='ls -l' while avoiding loops. - local arg buf=$4 highlight_glob=true last_alias style + local alias_style arg buf=$4 highlight_glob=true last_alias style local in_array_assignment=false # true between 'a=(' and the matching ')' - # highlighted_alias is 1 when the alias arg has been highlighted with a non-alias style. - # E.g. alias x=ls; x has been highlighted as alias AND command. # in_alias is equal to the number of shifts needed until arg=args[1] pops an # arg from BUFFER and not added by an alias. - integer highlighted_alias=0 in_alias=0 len=$#buf + integer in_alias=0 len=$#buf local -a match mbegin mend list_highlights # seen_alias is a map of aliases already seen to avoid loops like alias a=b b=a local -A seen_alias @@ -458,7 +461,11 @@ _zsh_highlight_main_highlighter_highlight_list() shift args if (( in_alias )); then (( in_alias-- )) - (( in_alias == 0 )) && highlighted_alias=0 last_alias= seen_alias=() + if (( in_alias == 0 )); then + last_alias= seen_alias=() + # start_pos and end_pos are of the alias (previous $arg) here + _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style + fi fi # Initialize this_word and next_word. @@ -535,6 +542,7 @@ _zsh_highlight_main_highlighter_highlight_list() # Avoid looping forever on alias a=b b=c c=b, but allow alias foo='foo bar' # Also mark insane aliases as unknown-token (cf. #263). if (( $+seen_alias[$arg] )) || [[ $arg == ?*=* ]]; then + (( in_alias == 0 )) && in_alias=1 _zsh_highlight_main_add_region_highlight $start_pos $end_pos unknown-token continue fi @@ -550,7 +558,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi args=( $alias_args $args ) if (( in_alias == 0 )); then - _zsh_highlight_main_add_region_highlight $start_pos $end_pos alias + alias_style=alias # Add one because we will in_alias-- on the next loop iteration so # this iteration should be considered in in_alias as well (( in_alias += $#alias_args + 1 )) @@ -909,6 +917,7 @@ _zsh_highlight_main_highlighter_highlight_list() fi _zsh_highlight_main_add_region_highlight $start_pos $end_pos $style done + (( in_alias == 1 )) && in_alias=0 _zsh_highlight_main_add_region_highlight $start_pos $end_pos $alias_style [[ "$proc_buf" = (#b)(#s)(([[:space:]]|\\$'\n')#) ]] REPLY=$(( end_pos + ${#match[1]} - 1 )) reply=($list_highlights) diff --git a/highlighters/main/test-data/alias-comment1.zsh b/highlighters/main/test-data/alias-comment1.zsh index 0c449e1a9..dd5068fc0 100644 --- a/highlighters/main/test-data/alias-comment1.zsh +++ b/highlighters/main/test-data/alias-comment1.zsh @@ -33,6 +33,5 @@ alias x=$'# foo\npwd' BUFFER='x' expected_region_highlight=( - '1 1 alias' # x - '1 1 comment' # x (#) + '1 1 alias "issue #616"' # x ) diff --git a/highlighters/main/test-data/alias-comment2.zsh b/highlighters/main/test-data/alias-comment2.zsh index 8bdc5a8d8..5a4982298 100644 --- a/highlighters/main/test-data/alias-comment2.zsh +++ b/highlighters/main/test-data/alias-comment2.zsh @@ -33,6 +33,5 @@ alias x=$'# foo\npwd' BUFFER='x' expected_region_highlight=( - '1 1 alias' # x '1 1 unknown-token' # x (#) ) diff --git a/highlighters/main/test-data/alias-complex.zsh b/highlighters/main/test-data/alias-complex.zsh index 7a9626e9b..5ad7c0a9c 100644 --- a/highlighters/main/test-data/alias-complex.zsh +++ b/highlighters/main/test-data/alias-complex.zsh @@ -33,7 +33,6 @@ BUFFER='x file echo' expected_region_highlight=( '1 1 alias' # x - '1 1 builtin' # x (echo) '3 6 default' # file '8 11 builtin' # echo ) diff --git a/highlighters/main/test-data/alias-loop.zsh b/highlighters/main/test-data/alias-loop.zsh index b36d1c988..baa122b27 100644 --- a/highlighters/main/test-data/alias-loop.zsh +++ b/highlighters/main/test-data/alias-loop.zsh @@ -33,7 +33,6 @@ alias a=b b=c c=b BUFFER='a foo; :' expected_region_highlight=( - '1 1 alias' # a '1 1 unknown-token' # a (invalid alias loop) '3 5 default' # foo '6 6 commandseparator' # ; diff --git a/highlighters/main/test-data/alias-nested-precommand.zsh b/highlighters/main/test-data/alias-nested-precommand.zsh index 7c2eeebbc..6d4172bcc 100644 --- a/highlighters/main/test-data/alias-nested-precommand.zsh +++ b/highlighters/main/test-data/alias-nested-precommand.zsh @@ -35,7 +35,6 @@ BUFFER='a -u phy1729 echo; :' expected_region_highlight=( '1 1 alias' # a - '1 1 precommand' # a (sudo) '3 4 single-hyphen-option' # -u '6 12 default' # phy1729 '14 17 builtin' # echo diff --git a/highlighters/main/test-data/alias-nested.zsh b/highlighters/main/test-data/alias-nested.zsh index 44ab22bf1..b24b49674 100644 --- a/highlighters/main/test-data/alias-nested.zsh +++ b/highlighters/main/test-data/alias-nested.zsh @@ -34,7 +34,6 @@ BUFFER='a foo; :' expected_region_highlight=( '1 1 alias' # a - '1 1 builtin' # a (:) '3 5 default' # foo '6 6 commandseparator' # ; '8 8 builtin' # : diff --git a/highlighters/main/test-data/alias-precommand-option-argument1.zsh b/highlighters/main/test-data/alias-precommand-option-argument1.zsh index ad1696280..ecdd9f93d 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument1.zsh @@ -35,7 +35,6 @@ BUFFER='sdu phy1729 echo foo' expected_region_highlight=( '1 3 alias' # sdu - '1 3 precommand' # sdu (sudo) '5 11 default' # phy1729 '13 16 commmand "issue #540"' # echo (not builtin) '18 20 default' # foo diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh index ebbb17b6e..95d71f8f2 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument2.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -36,7 +36,6 @@ BUFFER='sbu phy1729 echo foo' expected_region_highlight=( '1 3 alias' # sbu - '1 3 precommand' # sbu (sudo) '5 11 default' # phy1729 '13 16 commmand "issue #540"' # echo (not builtin) '18 20 default' # foo diff --git a/highlighters/main/test-data/alias-redirect.zsh b/highlighters/main/test-data/alias-redirect.zsh index a6a0aab1b..acc3dcbef 100644 --- a/highlighters/main/test-data/alias-redirect.zsh +++ b/highlighters/main/test-data/alias-redirect.zsh @@ -32,7 +32,6 @@ BUFFER='x foo echo bar' expected_region_highlight=( '1 1 alias' # x - '1 1 redirection' # x (>) '3 5 default' # foo '7 10 builtin' # echo '12 14 default' # bar diff --git a/highlighters/main/test-data/alias-self.zsh b/highlighters/main/test-data/alias-self.zsh index 88ed3c8be..c6f12b1a8 100644 --- a/highlighters/main/test-data/alias-self.zsh +++ b/highlighters/main/test-data/alias-self.zsh @@ -34,6 +34,5 @@ BUFFER='echo bar' expected_region_highlight=( '1 4 alias' # echo - '1 4 builtin' # echo '6 8 default' # bar ) diff --git a/highlighters/main/test-data/alias-to-dir.zsh b/highlighters/main/test-data/alias-to-dir.zsh index 93aaa625e..767d3c759 100644 --- a/highlighters/main/test-data/alias-to-dir.zsh +++ b/highlighters/main/test-data/alias-to-dir.zsh @@ -32,6 +32,5 @@ alias x=/ BUFFER=$'x' expected_region_highlight=( - '1 1 alias' # x '1 1 unknown-token "issue #202"' # x (/) ) diff --git a/highlighters/main/test-data/alias.zsh b/highlighters/main/test-data/alias.zsh index 03ca0be62..4cafa8041 100644 --- a/highlighters/main/test-data/alias.zsh +++ b/highlighters/main/test-data/alias.zsh @@ -48,7 +48,6 @@ fi expected_region_highlight+=( "9 9 commandseparator" # ; "11 16 alias" # alias1 - "11 16 command" # alias1 (ls) "17 17 commandseparator" # ; "19 24 unknown-token" # alias2 ) diff --git a/highlighters/main/test-data/noglob-alias.zsh b/highlighters/main/test-data/noglob-alias.zsh index 5676b5a58..2f96445ed 100644 --- a/highlighters/main/test-data/noglob-alias.zsh +++ b/highlighters/main/test-data/noglob-alias.zsh @@ -32,6 +32,5 @@ BUFFER='x ls' expected_region_highlight=( "1 1 alias" # x - "1 1 precommand" # x (command) "3 4 command" # ls ) diff --git a/highlighters/main/test-data/off-by-one.zsh b/highlighters/main/test-data/off-by-one.zsh index 7d6961ac5..872143af2 100644 --- a/highlighters/main/test-data/off-by-one.zsh +++ b/highlighters/main/test-data/off-by-one.zsh @@ -34,7 +34,6 @@ BUFFER='a;f;' expected_region_highlight=( "1 1 alias" # a - "1 1 builtin" # a (:) "2 2 commandseparator" # ; "3 3 function" # f "4 4 commandseparator" # ; From 369620dd2d0b524b7323544843375f68b498f6f3 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 11 Jul 2019 21:33:37 -0500 Subject: [PATCH 4/6] main: Use longer alias name in tests --- .../alias-precommand-option-argument1.zsh | 12 ++++++------ .../alias-precommand-option-argument2.zsh | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/highlighters/main/test-data/alias-precommand-option-argument1.zsh b/highlighters/main/test-data/alias-precommand-option-argument1.zsh index ecdd9f93d..b78b61a75 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument1.zsh @@ -28,14 +28,14 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -alias sdu='sudo -u' +alias sudo_u='sudo -u' sudo(){} -BUFFER='sdu phy1729 echo foo' +BUFFER='sudo_u phy1729 echo foo' expected_region_highlight=( - '1 3 alias' # sdu - '5 11 default' # phy1729 - '13 16 commmand "issue #540"' # echo (not builtin) - '18 20 default' # foo + '1 6 alias' # sudo_u + '8 14 default' # phy1729 + '17 19 commmand "issue #540"' # echo (not builtin) + '21 23 default' # foo ) diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh index 95d71f8f2..1ca8f7e43 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument2.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -28,15 +28,15 @@ # vim: ft=zsh sw=2 ts=2 et # ------------------------------------------------------------------------------------------------- -alias sdb='sudo -b' -alias sbu='sdb -u' +alias sudo_b='sudo -b' +alias sudo_b_u='sudo_b -u' sudo(){} -BUFFER='sbu phy1729 echo foo' +BUFFER='sudo_b_u phy1729 echo foo' expected_region_highlight=( - '1 3 alias' # sbu - '5 11 default' # phy1729 - '13 16 commmand "issue #540"' # echo (not builtin) - '18 20 default' # foo + '1 8 alias' # sudo_b_u + '10 16 default' # phy1729 + '18 21 commmand "issue #540"' # echo (not builtin) + '23 25 default' # foo ) From 1fcd786f77880108414738faabd42719165947e0 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Thu, 11 Jul 2019 21:39:45 -0500 Subject: [PATCH 5/6] main: Add more alias tests Suggested by Daniel. --- .../alias-precommand-option-argument3.zsh | 41 ++++++++++++++++++ .../alias-precommand-option-argument4.zsh | 42 +++++++++++++++++++ .../main/test-data/alias-unknown-token1.zsh | 37 ++++++++++++++++ .../main/test-data/alias-unknown-token2.zsh | 37 ++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 highlighters/main/test-data/alias-precommand-option-argument3.zsh create mode 100644 highlighters/main/test-data/alias-precommand-option-argument4.zsh create mode 100644 highlighters/main/test-data/alias-unknown-token1.zsh create mode 100644 highlighters/main/test-data/alias-unknown-token2.zsh diff --git a/highlighters/main/test-data/alias-precommand-option-argument3.zsh b/highlighters/main/test-data/alias-precommand-option-argument3.zsh new file mode 100644 index 000000000..2c7812163 --- /dev/null +++ b/highlighters/main/test-data/alias-precommand-option-argument3.zsh @@ -0,0 +1,41 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias sudo_u='sudo -u' +sudo(){} + +BUFFER='sudo_u phy1729 ls foo' + +expected_region_highlight=( + '1 6 alias' # sudo_u + '8 14 default' # phy1729 + '16 17 command' # ls + '19 21 default' # foo +) diff --git a/highlighters/main/test-data/alias-precommand-option-argument4.zsh b/highlighters/main/test-data/alias-precommand-option-argument4.zsh new file mode 100644 index 000000000..d47dccb83 --- /dev/null +++ b/highlighters/main/test-data/alias-precommand-option-argument4.zsh @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2018 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias sudo_b='sudo -b' +alias sudo_b_u='sudo_b -u' +sudo(){} + +BUFFER='sudo_b_u phy1729 ls foo' + +expected_region_highlight=( + '1 8 alias' # sudo_b_u + '10 16 default' # phy1729 + '18 19 command' # ls + '21 23 default' # foo +) diff --git a/highlighters/main/test-data/alias-unknown-token1.zsh b/highlighters/main/test-data/alias-unknown-token1.zsh new file mode 100644 index 000000000..9c996bfe1 --- /dev/null +++ b/highlighters/main/test-data/alias-unknown-token1.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias a=b b=foo + +BUFFER='a ' + +expected_region_highlight=( + '1 1 unknown-token' # a +) diff --git a/highlighters/main/test-data/alias-unknown-token2.zsh b/highlighters/main/test-data/alias-unknown-token2.zsh new file mode 100644 index 000000000..ab9facd60 --- /dev/null +++ b/highlighters/main/test-data/alias-unknown-token2.zsh @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh +# ------------------------------------------------------------------------------------------------- +# Copyright (c) 2019 zsh-syntax-highlighting contributors +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are permitted +# provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list of conditions +# and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this list of +# conditions and the following disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors +# may be used to endorse or promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------------------------- +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------------------------- + +alias a='() { ls "$@" ; foo }' + +BUFFER='a ' + +expected_region_highlight=( + '1 1 unknown-token' # a +) From 2bd709fc2878bf95cf64e631d50d8f72c3985c4a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 20 Jul 2019 10:38:53 -0500 Subject: [PATCH 6/6] main: Fix misspelling in test expectation --- .../main/test-data/alias-precommand-option-argument1.zsh | 2 +- .../main/test-data/alias-precommand-option-argument2.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/highlighters/main/test-data/alias-precommand-option-argument1.zsh b/highlighters/main/test-data/alias-precommand-option-argument1.zsh index b78b61a75..30398a31b 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument1.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument1.zsh @@ -36,6 +36,6 @@ BUFFER='sudo_u phy1729 echo foo' expected_region_highlight=( '1 6 alias' # sudo_u '8 14 default' # phy1729 - '17 19 commmand "issue #540"' # echo (not builtin) + '17 19 command "issue #540"' # echo (not builtin) '21 23 default' # foo ) diff --git a/highlighters/main/test-data/alias-precommand-option-argument2.zsh b/highlighters/main/test-data/alias-precommand-option-argument2.zsh index 1ca8f7e43..fbc6eec7d 100644 --- a/highlighters/main/test-data/alias-precommand-option-argument2.zsh +++ b/highlighters/main/test-data/alias-precommand-option-argument2.zsh @@ -37,6 +37,6 @@ BUFFER='sudo_b_u phy1729 echo foo' expected_region_highlight=( '1 8 alias' # sudo_b_u '10 16 default' # phy1729 - '18 21 commmand "issue #540"' # echo (not builtin) + '18 21 command "issue #540"' # echo (not builtin) '23 25 default' # foo )