test cases for truncating strings of equal length to the specificed length #106
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.
This PR creates a few unit tests to check situations where the string may be exactly equal length with the trunctation target, as reported in charmbracelet/lipgloss#324
The naive "equalascii" test seems to be relatively straight forward to fixe, but the "equalcontrolemoji" is trickier. The best I can come up with is when the target string length is reached, to scan the rest of the input string to see if the remainder is all control characters or has more printable characters.
While potentially slower, this scan would only need to be done once, at the the point were the truncation would begin, and could be short circuited if any printable characters are found. The slowest case would be when nothing but control characters remain.
I added an
equalemoji
which gets truncated - emojis and chinese characters are treated as double width and therefor truncated, even though they only take up one character space. I'm not sure if that is intentional or not.