From 6afe4c85ae77062441de78c4ac5c97e701f1e01e Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 14 Nov 2025 20:54:24 +0000 Subject: [PATCH] Upgrade Wcwidth to version 4.0.0 --- Directory.Packages.props | 2 +- .../UnitTestsParallelizable/Text/RuneTests.cs | 6 +- .../Text/StringTests.cs | 98 ++++++++++--------- 3 files changed, 57 insertions(+), 49 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index d62a1d298..2fdb4633e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -18,7 +18,7 @@ - + diff --git a/Tests/UnitTestsParallelizable/Text/RuneTests.cs b/Tests/UnitTestsParallelizable/Text/RuneTests.cs index f5bc5ab67..4e03e8048 100644 --- a/Tests/UnitTestsParallelizable/Text/RuneTests.cs +++ b/Tests/UnitTestsParallelizable/Text/RuneTests.cs @@ -88,7 +88,7 @@ public class RuneTests 1 )] // the letters ᄇα…₯α†Έ join to form the Korean word for "rice:" U+BC95 법 (read from top left to bottom right) [InlineData ("\U0001F468\u200D\U0001F469\u200D\U0001F467", "πŸ‘¨β€πŸ‘©β€πŸ‘§", 8, 2, 8)] // Man, Woman and Girl emoji. - [InlineData ("\u0915\u093f", "ΰ€•ΰ€Ώ", 2, 2, 2)] // Hindi ΰ€•ΰ€Ώ with DEVANAGARI LETTER KA and DEVANAGARI VOWEL SIGN I + //[InlineData ("\u0915\u093f", "ΰ€•ΰ€Ώ", 2, 2, 2)] // Hindi ΰ€•ΰ€Ώ with DEVANAGARI LETTER KA and DEVANAGARI VOWEL SIGN I [InlineData ( "\u0e4d\u0e32", "ํา", @@ -213,7 +213,7 @@ public class RuneTests [InlineData ( '\u1161', "α…‘", - 1, + 0, 1, 3 )] // α…‘ Hangul Jungseong A - Unicode Hangul Jamo for join with column width equal to 0 alone. @@ -231,7 +231,7 @@ public class RuneTests )] // δ·€Hexagram For The Creative Heaven - U+4dc0 - https://github.com/microsoft/terminal/blob/main/src/types/unicode_width_overrides.xml // See https://github.com/microsoft/terminal/issues/19389 - [InlineData ('\ud7b0', "ힰ", 1, 1, 3)] // ힰ ─Hangul Jungseong O-Yeo - ힰ U+d7b0')] + [InlineData ('\ud7b0', "ힰ", 0, 1, 3)] // ힰ ─Hangul Jungseong O-Yeo - ힰ U+d7b0')] [InlineData ('\uf61e', "", 1, 1, 3)] // Private Use Area [InlineData ('\u23f0', "⏰", 2, 1, 3)] // Alarm Clock - ⏰ U+23f0 [InlineData ('\u1100', "α„€", 2, 1, 3)] // α„€ Hangul Choseong Kiyeok diff --git a/Tests/UnitTestsParallelizable/Text/StringTests.cs b/Tests/UnitTestsParallelizable/Text/StringTests.cs index efbc2e406..a3c4e52ba 100644 --- a/Tests/UnitTestsParallelizable/Text/StringTests.cs +++ b/Tests/UnitTestsParallelizable/Text/StringTests.cs @@ -4,6 +4,13 @@ public class StringTests { + [Fact] + public void TestGetColumns_Null () + { + string? str = null; + Assert.Equal (0, str!.GetColumns ()); + } + [Fact] public void TestGetColumns_Empty () { @@ -11,6 +18,20 @@ public class StringTests Assert.Equal (0, str.GetColumns ()); } + [Fact] + public void TestGetColumns_SingleRune () + { + var str = "a"; + Assert.Equal (1, str.GetColumns ()); + } + + [Fact] + public void TestGetColumns_Zero_Width () + { + var str = "\u200D"; + Assert.Equal (0, str.GetColumns ()); + } + [Theory] [InlineData ("a", 1)] [InlineData ("Γ‘", 1)] @@ -30,44 +51,37 @@ public class StringTests // Test known wide codepoints [Theory] - [InlineData ("πŸ™‚", 1, 2)] - [InlineData ("aπŸ™‚", 2, 3)] - [InlineData ("πŸ™‚a", 2, 3)] - [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦", 1, 2)] - [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ™‚", 2, 4)] - [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ™‚a", 3, 5)] - [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦aπŸ™‚", 3, 5)] - [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦", 2, 4)] - [InlineData ("ΰΈ²ΰΈ³", 1, 2)] // ΰΈ² U+0E32 - THAI CHARACTER SARA AA with ΰΈ³ U+0E33 - THAI CHARACTER SARA AM - [InlineData ("ε±±", 1, 2)] // The character for "mountain" in Chinese/Japanese/Korean (ε±±), Unicode U+5C71 - [InlineData ("ε±±πŸ™‚", 2, 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 - // // Combining Ligature Right Half - U+fe21 -https://github.com/microsoft/terminal/blob/main/src/types/unicode_width_overrides.xml - public void TestGetColumns_MultiRune_WideBMP_Graphemes (string str, int graphemesCount, int expected) + [InlineData ("πŸ™‚", 2, 1, 2)] + [InlineData ("aπŸ™‚", 3, 2, 3)] + [InlineData ("πŸ™‚a", 3, 2, 3)] + [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦", 8, 1, 2)] + [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ™‚", 10, 2, 4)] + [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ™‚a", 11, 3, 5)] + [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦aπŸ™‚", 11, 3, 5)] + [InlineData ("πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦", 16, 2, 4)] + [InlineData ("ΰΈ²ΰΈ³", 2, 1, 2)] // ΰΈ² U+0E32 - THAI CHARACTER SARA AA with ΰΈ³ U+0E33 - THAI CHARACTER SARA AM + [InlineData ("ε±±", 2, 1, 2)] // The character for "mountain" in Chinese/Japanese/Korean (ε±±), Unicode U+5C71 + [InlineData ("ε±±πŸ™‚", 4, 2, 4)] // The character for "mountain" in Chinese/Japanese/Korean (ε±±), Unicode U+5C71 + [InlineData ("a\ufe20e\ufe21", 2, 2, 2)] // Combining Ligature Left Half οΈ  - U+fe20 -https://github.com/microsoft/terminal/blob/main/src/types/unicode_width_overrides.xml + // Combining Ligature Right Half - U+fe21 -https://github.com/microsoft/terminal/blob/main/src/types/unicode_width_overrides.xml + //[InlineData ("ΰ€•", 1, 1, 1)] // ΰ€• U+0915 Devanagari Letter Ka + //[InlineData ("ΰ€Ώ", 1, 1, 1)] // U+093F Devanagari Vowel Sign I ΰ€Ώ (i-kar). + //[InlineData ("ΰ€•ΰ€Ώ", 2, 1, 2)] // "ΰ€•ΰ€Ώ" is U+0915 for the base consonant "ΰ€•" with U+093F for the vowel sign "ΰ€Ώ" (i-kar). + [InlineData ("α„€", 2, 1, 2)] // α„€ U+1100 HANGUL CHOSEONG KIYEOK (consonant) + [InlineData ("α…‘", 0, 1, 0)] // α…‘ U+1161 HANGUL JUNGSEONG A (vowel) + [InlineData ("α„€α…‘", 2, 1, 2)] // α„€ U+1100 HANGUL CHOSEONG KIYEOK (consonant) with α…‘ U+1161 HANGUL JUNGSEONG A (vowel) + [InlineData ("α„’", 2, 1, 2)] // α„’ U+1112 Hangul Choseong Hieuh + [InlineData ("α…΅", 0, 1, 0)] // α…΅ U+1175 Hangul Jungseong I + [InlineData ("ᇂ", 0, 1, 0)] // ᇂ U+11C2 Hangul Jongseong Hieuh + [InlineData ("핳", 2, 1, 2)] // α„’ (choseong h) + α…΅ (jungseong i) + ᇂ (jongseong h) + [InlineData ("ힰ", 0, 1, 0)] // U+D7B0 ힰ Hangul Jungseong O-Yeo + [InlineData ("α„€νž°", 2, 1, 2)] // α„€ U+1100 HANGUL CHOSEONG KIYEOK (consonant) with U+D7B0 ힰ Hangul Jungseong O-Yeo + //[InlineData ("ΰ€·ΰ€Ώ", 2, 1, 2)] // U+0937 ΰ€· DEVANAGARI LETTER SSA with U+093F ΰ€Ώ COMBINING DEVANAGARI VOWEL SIGN I + public void TestGetColumns_MultiRune_WideBMP_Graphemes (string str, int expectedRunesWidth, int expectedGraphemesCount, int expectedWidth) { - Assert.Equal (graphemesCount, GraphemeHelper.GetGraphemes (str).ToArray ().Length); - Assert.Equal (expected, str.GetColumns ()); - } - - [Fact] - public void TestGetColumns_Null () - { - string? str = null; - Assert.Equal (0, str!.GetColumns ()); - } - - [Fact] - public void TestGetColumns_SingleRune () - { - var str = "a"; - Assert.Equal (1, str.GetColumns ()); - } - - [Fact] - public void TestGetColumns_Zero_Width () - { - var str = "\u200D"; - Assert.Equal (0, str.GetColumns ()); + Assert.Equal (expectedRunesWidth, str.EnumerateRunes ().Sum (r => r.GetColumns ())); + Assert.Equal (expectedGraphemesCount, GraphemeHelper.GetGraphemes (str).ToArray ().Length); + Assert.Equal (expectedWidth, str.GetColumns ()); } [Theory] @@ -75,14 +89,8 @@ public class StringTests [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 ()); - } + // ReSharper disable once InvokeAsExtensionMethod + Assert.Equal (0, StringExtensions.GetColumns (text!)); } public class ReadOnlySpanExtensionsTests