Skip to content

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

Merged
merged 6 commits into from
Feb 11, 2018

Conversation

phy1729
Copy link
Member

@phy1729 phy1729 commented Jan 20, 2018

Still has a few TODOs

  • comment-followed: Should the newline ending a comment be considered a commandseparator?
  • redirections2: What style should >(wc) be?
  • vanilla-newline: Unexpected entry "0 0 unknown-token". Seems to be due to the last newline in $PREBUFFER.
  • vi-linewise-mode: I think that standout should be 1 15, but I'm not sure.
  • -unclosed styles are off by one.

@danielshahaf
Copy link
Member

Would this allow #475 to be implemented?

@phy1729
Copy link
Member Author

phy1729 commented Jan 20, 2018

It couldn't test how ZLE combines styles, but it would ensure we know if we set $region_highlight differently.

@danielshahaf
Copy link
Member

danielshahaf commented Jan 20, 2018 via email

@phy1729
Copy link
Member Author

phy1729 commented Feb 7, 2018

Tests pass now. There is still one XXX left which is point one above:

comment-followed: Should the newline ending a comment be considered a commandseparator?

Ready for review.

@danielshahaf
Copy link
Member

danielshahaf commented Feb 7, 2018

Is there any region_highlight style that affects newlines?

@phy1729
Copy link
Member Author

phy1729 commented Feb 7, 2018

Even with ZSH_HIGHLIGHT_STYLES[commandseparator]=bg=cyan,fg=cyan,bold,standout,underline, which seems to be every type of highlighting ZLE supports, I don't see anything for

: foo
bar

Although that newline is highlighted as commandseparator. I suppose this means the issue is purely academic until #327.

@danielshahaf
Copy link
Member

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 if) is always commandseparator.

I also agree that it's an academic concern until #327 (and as such not a blocker).

@phy1729
Copy link
Member Author

phy1729 commented Feb 10, 2018

Filed #501 and changed the test to XFAIL. Rebased onto master.

@danielshahaf danielshahaf self-requested a review February 10, 2018 20:03
@@ -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 }
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

done

if (( $#expected_region_highlight == $#region_highlight )); then
print -r -- "ok $i - cardnality check"
Copy link
Member

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
Copy link
Member

@danielshahaf danielshahaf Feb 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this double highlighting is the subject of #495 or #481.

done
if (( unsorted )); then
region_highlight=("${(@n)region_highlight}")
expected_region_highlight=("${(@n)expected_region_highlight}")
Copy link
Member

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).

Copy link
Member Author

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.

Copy link
Member

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:

https://github.com/zsh-users/zsh/blob/567733906210feaebce94675985eb1e77602bfd8/Src/sort.c#L119-L143

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In English:

  1. Skip characters that are equal.
  2. Store the comparison between the two different chars (This is how (n) falls back to lexicographical).
  3. Assuming one of the differing characters is a digit, rewind to the start of digits.
  4. Skip 0s.
  5. Skip equal digits.
  6. Store the difference.
  7. 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-- ))
Copy link
Member

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. 👍

@danielshahaf
Copy link
Member

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.

@phy1729 phy1729 merged commit a9be097 into zsh-users:master Feb 11, 2018
@phy1729 phy1729 deleted the direct-test branch February 11, 2018 00:49
@phy1729 phy1729 added this to the 0.7.0 milestone Feb 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants