Fixes #4382. StringExtensions.GetColumns method should only return the total text width and not the sum of all runes width

This commit is contained in:
BDisp
2025-11-08 01:42:54 +00:00
parent 559dea9239
commit 3c6e945d1b
3 changed files with 43 additions and 10 deletions

View File

@@ -33,11 +33,11 @@ public class StringTests
[InlineData ("🙂", 2)]
[InlineData ("a🙂", 3)]
[InlineData ("🙂a", 3)]
[InlineData ("👨‍👩‍👦‍👦", 8)]
[InlineData ("👨‍👩‍👦‍👦🙂", 10)]
[InlineData ("👨👩👦👦🙂a", 11)]
[InlineData ("👨👩👦👦a🙂", 11)]
[InlineData ("👨‍👩‍👦‍👦👨‍👩‍👦‍👦", 16)]
[InlineData ("👨‍👩‍👦‍👦", 2)]
[InlineData ("👨‍👩‍👦‍👦🙂", 4)]
[InlineData ("👨👩👦👦🙂a", 5)]
[InlineData ("👨👩👦👦a🙂", 5)]
[InlineData ("👨‍👩‍👦‍👦👨‍👩‍👦‍👦", 4)]
[InlineData ("山", 2)] // The character for "mountain" in Chinese/Japanese/Korean (山), Unicode U+5C71
[InlineData ("山🙂", 4)] // The character for "mountain" in Chinese/Japanese/Korean (山), Unicode U+5C71
//[InlineData ("\ufe20\ufe21", 2)] // Combining Ligature Left Half ︠ - U+fe20 -https://github.com/microsoft/terminal/blob/main/src/types/unicode_width_overrides.xml
@@ -57,4 +57,11 @@ public class StringTests
var str = "a";
Assert.Equal (1, str.GetColumns ());
}
[Fact]
public void TestGetColumns_Zero_Width ()
{
var str = "\u200D";
Assert.Equal (0, str.GetColumns ());
}
}