TextRules
Namespace: E2E.Internal
public static class TextRulesWhitespace and string matching used by locators. Exact string matches are
case-sensitive after whitespace is collapsed. Inexact matches are
case-insensitive substrings, which is how exact: false behaves upstream.
Inheritance: object
Methods
Section titled “Methods”Bound(string, int)
Section titled “Bound(string, int)”public static string Bound(string text, int maxChars)Caps prose at <code class=“paramref”>maxChars</code>, marking the cut with an ellipsis. A cut never splits a surrogate pair.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string | |
maxChars |
int |
Returns: string
Collapse(string)
Section titled “Collapse(string)”public static string Collapse(string text)App text as one line, as upstream’s collapseText reads it: whitespace collapsed, and a control
character becomes U+FFFD, so app text cannot put it in a prompt.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
Returns: string
Compare(string, TextMatch, bool, bool, bool?)
Section titled “Compare(string, TextMatch, bool, bool, bool?)”public static bool Compare(string actual, TextMatch expected, bool contains, bool normalize, bool? ignoreCase)The text matcher rule. A pattern is tested anywhere in the subject in both modes. A string equals, or is contained by, the subject, folding case when <code class=“paramref”>ignoreCase</code> is true. <code class=“paramref”>normalize</code> collapses whitespace on both sides first.
Parameters
| Name | Type | Description |
|---|---|---|
actual |
string | |
expected |
TextMatch | |
contains |
bool | |
normalize |
bool | |
ignoreCase |
bool? |
Returns: bool
Matches(string?, string, bool)
Section titled “Matches(string?, string, bool)”public static bool Matches(string? actual, string expected, bool exact)Parameters
| Name | Type | Description |
|---|---|---|
actual |
string | |
expected |
string | |
exact |
bool |
Returns: bool
MatchesText(string, TextMatch, bool)
Section titled “MatchesText(string, TextMatch, bool)”public static bool MatchesText(string actual, TextMatch expected, bool exact = true)Matches normalized text against a pattern (upstream’s matchesText): a string is compared exactly, or as a case-insensitive
substring when <code class=“paramref”>exact</code> is false; a regular expression tests the normalized text.
Parameters
| Name | Type | Description |
|---|---|---|
actual |
string | |
expected |
TextMatch | |
exact |
bool |
Returns: bool
Normalize(string)
Section titled “Normalize(string)”public static string Normalize(string text)Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
Returns: string
SanitizeText(string)
Section titled “SanitizeText(string)”public static string SanitizeText(string text)Upstream’s sanitizeText (internal/errors.ts): strips ANSI escape sequences, then every C0 and C1
control character except tab and newline becomes U+FFFD. Libraries color their own messages; left in, the color codes
reach a report as literal text.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string |
Returns: string
TruncateUtf8(string, int)
Section titled “TruncateUtf8(string, int)”public static string TruncateUtf8(string text, int maxBytes)Upstream’s truncateUtf8: cuts the text so its UTF-8 encoding fits <code class=“paramref”>maxBytes</code>, never inside a character.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string | |
maxBytes |
int |
Returns: string
WithHint(string, string)
Section titled “WithHint(string, string)”public static string WithHint(string message, string hint)Upstream’s withHint: appends a remedy to a message, as a clause after a one-line message and on its own line after a
multi-line one, so the hint never dangles off a sentence that already ended.
Parameters
| Name | Type | Description |
|---|---|---|
message |
string | |
hint |
string |
Returns: string