-
Notifications
You must be signed in to change notification settings - Fork 1.3k
tests: Directly diff expected_region_highlight against region_highlight #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Would this allow #475 to be implemented? |
It couldn't test how ZLE combines styles, but it would ensure we know if we set |
It couldn't test how ZLE combines styles, but it would ensure we know if
we set `$region_highlight` differently.
Good enough, I think. It'd be nice to run an interactive zsh in a zpty and perform full-stack acceptance tests, but of course that's out of scope of this PR.
|
Tests pass now. There is still one
Ready for review. |
Is there any |
Even with
Although that newline is highlighted as |
To answer your question, I think the newline following a comment should be a commandseparator, to maintain the invariant that the token preceding a command position (a physical one, i.e., not a synthetic one after a precommand or assignment or the keyword I also agree that it's an academic concern until #327 (and as such not a blocker). |
Filed #501 and changed the test to XFAIL. Rebased onto master. |
@@ -104,7 +104,8 @@ _zsh_highlight_main_add_region_highlight() { | |||
(( start -= $#PREBUFFER )) | |||
(( end -= $#PREBUFFER )) | |||
|
|||
(( end < 0 )) && return # having end<0 would be a bug | |||
(( start >= end )) && { print -r -- >&2 'zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start >= end'; return } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest to interpolate "$start"
and "$end"
into the error message.
(Generally, most error message should have something interpolated into them.)
@@ -104,7 +104,8 @@ _zsh_highlight_main_add_region_highlight() { | |||
(( start -= $#PREBUFFER )) | |||
(( end -= $#PREBUFFER )) | |||
|
|||
(( end < 0 )) && return # having end<0 would be a bug | |||
(( start >= end )) && { print -r -- >&2 'zsh-syntax-highlighting: BUG: _zsh_highlight_main_add_region_highlight: start >= end'; return } | |||
(( start < 0 && end <= 0 )) && return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, end <= 0
implies start < 0
so the first conjunct is redundant.
@@ -43,7 +43,7 @@ BUFFER='x.alias2; alias1' | |||
# functionality is present, and skip verifying suffix-alias highlighting | |||
# if it isn't. | |||
expected_region_highlight=() | |||
if [[ "$(type -w x.alias2)" == *suffix* ]]; then | |||
if zmodload -e zsh/parameter || [[ "$(type -w x.alias2)" == *suffix* ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
tests/test-highlighting.zsh
Outdated
done | ||
|
||
if (( $#expected_region_highlight == $#region_highlight )); then | ||
print -r -- "ok $i - cardnality check" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"cardinality" is misspelled.
"3 6 double-quoted-argument-unclosed" # "foo | ||
"1 1 builtin" # : | ||
"3 10 default" # "foo$bar | ||
"3 10 double-quoted-argument-unclosed" # "foo$bar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done | ||
if (( unsorted )); then | ||
region_highlight=("${(@n)region_highlight}") | ||
expected_region_highlight=("${(@n)expected_region_highlight}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppose the input contains both 42 foo
and 42 bar
, is numeric sorting guaranteed to always output them in the same order, regardless of what other elements the input contains?
Plain old lexicographic sorting would definitely have this property but I suspect it would make for less nice failure modes (I presume we'd want failure to be reported on the "first" non-match, for some notion of "match" that depends on the start,stop indices).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% a=(1 3 '2 foo' '2bar' '2 2 bar' '2 14 bar' '21 foo'); printf '<%s>' ${(@n)a}
<1><2 2 bar><2 14 bar><2 foo><2bar><3><21 foo>
So it looks like numeric sorting falls back to lexicographic sorting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of the (n)
sorting flag (NUMERIC_GLOB_SORT option) is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In English:
- Skip characters that are equal.
- Store the comparison between the two different chars (This is how (n) falls back to lexicographical).
- Assuming one of the differing characters is a digit, rewind to the start of digits.
- Skip
0
s. - Skip equal digits.
- Store the difference.
- Find length and return in favor of the longer or the stored difference if equal.
So I think (n)
DTRT.
@@ -888,6 +888,8 @@ _zsh_highlight_main_highlighter_highlight_single_quote() | |||
if [[ $arg[i] == "'" ]]; then | |||
style=single-quoted-argument | |||
else | |||
# If unclosed, i points past the end | |||
(( i-- )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I revert this line, multiline-string2
fails. 👍
Thank you for making this happen! I've went through the diff and added a few comments. I haven't the brainwidth to review all the new logic around byte/character offsets, though; I'm going to go ahead and trust you on it. |
Still has a few TODOs
commandseparator
?>(wc)
be?"0 0 unknown-token"
. Seems to be due to the last newline in$PREBUFFER
.