mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 08:47:59 +01:00
Fixes #4382. StringExtensions.GetColumns method should only return the total text width and not the sum of all runes width (#4383)
* Fixes #4382. StringExtensions.GetColumns method should only return the total text width and not the sum of all runes width * Trying to fix unit test error * Update StringExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add unit test to prove that null and empty string doesn't not throws anything. --------- Co-authored-by: Tig <tig@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -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,26 @@ 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 ());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (null)]
|
||||
[InlineData ("")]
|
||||
public void TestGetColumns_Does_Not_Throws_With_Null_And_Empty_String (string? text)
|
||||
{
|
||||
if (text is null)
|
||||
{
|
||||
Assert.Equal (0, StringExtensions.GetColumns (text!));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal (0, text.GetColumns ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user