tree-sitter icon indicating copy to clipboard operation
tree-sitter copied to clipboard

Support for testing lack of highlighting

Open guillaumebrunerie opened this issue 3 years ago • 1 comments

Maybe I missed it, but there currently doesn’t seem to be a way to test the lack of highlighting, or to negate a given class. I would suggest an exclamation mark to negate a given highlighting class, and maybe a lone exclamation mark to state that there should be no highlighting at all

const f1 = ({y: x}) => x;
//            ^ !operator
// Tests that the colon is not being given the "operator" highlight

const f2 = ({y: x}) => x;
//       ^ !
// Tests that the equal sign is not being given any highlight

guillaumebrunerie avatar Aug 03 '22 18:08 guillaumebrunerie

To test the complete lack of highlighting, another suggestion would be to use "none"

const f2 = ({y: x}) => x;
//       ^ none
// Tests that the equal sign is not being given any highlight

It currently fails with the error message

    Failure - row: x, column: y, expected highlight 'none', actual highlights: none.

Of course it would clash if someone were to define a highlight name called "none", but I’m not sure if anyone would want to do that.

guillaumebrunerie avatar Aug 03 '22 19:08 guillaumebrunerie

Negations in tests are a thing now, I hope that fits your use case.

amaanq avatar Feb 14 '24 00:02 amaanq