Ignore invisible whitespace in text matching#147
Open
passsy wants to merge 1 commit into
Open
Conversation
spotText and the AnyText text selectors now ignore characters that are invisible or visually indistinguishable from a regular space, so tests can be written with plain characters instead of escapes. AnyText.normalizeVisibleText removes meaningless invisibles (ZWSP, soft hyphen, word joiner, BOM) and folds every Unicode space separator (Zs) to a regular space. Meaningful invisibles (ZWJ, bidi controls, the U+FFFC WidgetSpan placeholder) and line structure (tabs, line breaks) are kept. Text extraction is consolidated into AnyText.extractText(), which returns both the raw and normalized text via AnyTextContent. AnyText exposes the normalized value as the 'text' diagnostic prop and the literal as a new 'rawText' prop, generating the whereRawText/withRawText/hasRawText family to match exact characters when needed. Closes #138
22329ae to
c23470f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #138
spotTextand theAnyTexttext selectors now match what a user sees: invisible characters and characters that render as a space are ignored, so tests can use plain characters instead of escapes.Normalization rule
normalizeVisibleText(String)applies a clear, two-part rule:U+200B, Soft HyphenU+00AD, Word JoinerU+2060, BOMU+FEFFZs) — Non-Breaking SpaceU+00A0, Narrow No-Break SpaceU+202F, thin/em/figure spaces, ideographic space, …Deliberately left untouched, because they carry meaning or structure: Zero Width Joiner / Non-Joiner (emoji sequences, Indic/Arabic shaping), bidi controls, the
U+FFFCWidgetSpanplaceholder, tabs and line breaks.Matching the exact characters
When a test needs the literal bytes,
AnyTextnow exposes arawTextproperty alongside the normalizedtext, generating a raw selector family:New:
whereRawText,withRawText,hasRawText,getRawText,hasRawTextWhereonWidgetSelector<AnyText>, plus publicnormalizeVisibleText,extractTextContent(Element), theTextContentholder (raw/normalized), andzeroWidthSpace/nonBreakingSpaceconstants.Scope
The concrete
spot<Text>()/spot<SelectableText>()/spot<EditableText>()selectors read their native diagnostic props and are unchanged. UsespotText/spot<AnyText>for the normalized behavior.Builds on the idea from #139 (thx @MichaelTamm), extended to a complete character set with a raw escape hatch.