diff --git a/Tests/UnitTests/Text/TextFormatterTests.cs b/Tests/UnitTests/Text/TextFormatterTests.cs index 9a5f7e9f7..4b8e69677 100644 --- a/Tests/UnitTests/Text/TextFormatterTests.cs +++ b/Tests/UnitTests/Text/TextFormatterTests.cs @@ -15,62 +15,6 @@ public class TextFormatterTests public static IEnumerable CMGlyphs => new List { new object [] { $"{Glyphs.LeftBracket} Say Hello 你 {Glyphs.RightBracket}", 16, 15 } }; - [SetupFakeDriver] - [Theory] - [InlineData ("A", 1, 0, "")] - [InlineData ("A", 0, 1, "")] - [InlineData ("AB1 2", 2, 1, "2")] - [InlineData ("AB12", 5, 1, "21BA")] - [InlineData ("AB\n12", 5, 2, "21\nBA")] - [InlineData ("ABC 123 456", 7, 2, "CBA \n654 321")] - [InlineData ("こんにちは", 1, 1, "")] - [InlineData ("こんにちは", 2, 1, "は")] - [InlineData ("こんにちは", 5, 1, "はち")] - [InlineData ("こんにちは", 10, 1, "はちにんこ")] - [InlineData ("こんにちは\nAB\n12", 10, 3, "21 \nBA \nはちにんこ")] - public void Draw_Horizontal_RightLeft_BottomTop (string text, int width, int height, string expectedText) - { - TextFormatter tf = new () - { - Text = text, - Direction = TextDirection.RightLeft_BottomTop - }; - - tf.ConstrainToWidth = width; - tf.ConstrainToHeight = height; - tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default); - - DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output); - } - - [SetupFakeDriver] - [Theory] - [InlineData ("A", 1, 0, "")] - [InlineData ("A", 0, 1, "")] - [InlineData ("AB1 2", 2, 1, "2")] - [InlineData ("AB12", 5, 1, "21BA")] - [InlineData ("AB\n12", 5, 2, "BA\n21")] - [InlineData ("ABC 123 456", 7, 2, "654 321\nCBA ")] - [InlineData ("こんにちは", 1, 1, "")] - [InlineData ("こんにちは", 2, 1, "は")] - [InlineData ("こんにちは", 5, 1, "はち")] - [InlineData ("こんにちは", 10, 1, "はちにんこ")] - [InlineData ("こんにちは\nAB\n12", 10, 3, "はちにんこ\nBA \n21 ")] - public void Draw_Horizontal_RightLeft_TopBottom (string text, int width, int height, string expectedText) - { - TextFormatter tf = new () - { - Text = text, - Direction = TextDirection.RightLeft_TopBottom - }; - - tf.ConstrainToWidth = width; - tf.ConstrainToHeight = height; - tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default); - - DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output); - } - [SetupFakeDriver] [Theory] diff --git a/Tests/UnitTestsParallelizable/Text/TextFormatterTests.cs b/Tests/UnitTestsParallelizable/Text/TextFormatterTests.cs index b0e986b8c..8056d564b 100644 --- a/Tests/UnitTestsParallelizable/Text/TextFormatterTests.cs +++ b/Tests/UnitTestsParallelizable/Text/TextFormatterTests.cs @@ -3091,33 +3091,96 @@ public class TextFormatterTests } /// - /// Helper method to extract text content from driver for testing + /// Helper method to extract text content from driver for testing (handles multi-line) /// private string GetDriverContents (IConsoleDriver driver, int width, int height) { - var sb = new System.Text.StringBuilder (); - for (int row = 0; row < height; row++) + // Use Application.ToString which properly handles double-wide chars + string fullContents = Application.ToString (driver); + + // Extract only the region we care about + string[] allLines = fullContents.Split (new[] { '\r', '\n' }, StringSplitOptions.None); + var lines = new List (); + + for (int i = 0; i < height && i < allLines.Length; i++) { - for (int col = 0; col < width; col++) + string line = allLines[i]; + // Take up to width characters + if (line.Length > width) { - if (col < driver.Cols && row < driver.Rows) - { - sb.Append ((char)driver.Contents [row, col].Rune.Value); - } - } - if (row < height - 1) - { - sb.AppendLine (); + line = line.Substring (0, width); } + // Trim trailing spaces from each line + lines.Add (line.TrimEnd ()); } - // Trim trailing whitespace from each line to match DriverAssert behavior - string result = sb.ToString (); - string[] lines = result.Split (new[] { '\r', '\n' }, StringSplitOptions.None); - for (int i = 0; i < lines.Length; i++) + + return string.Join ("\n", lines); + } + + [Theory] + [InlineData ("A", 1, 0, "")] + [InlineData ("A", 0, 1, "")] + [InlineData ("AB1 2", 2, 1, "2")] + [InlineData ("AB12", 5, 1, "21BA")] + [InlineData ("AB\n12", 5, 2, "21\nBA")] + [InlineData ("ABC 123 456", 7, 2, "CBA\n654 321")] + [InlineData ("こんにちは", 1, 1, "")] + [InlineData ("こんにちは", 2, 1, "は")] + [InlineData ("こんにちは", 5, 1, "はち")] + [InlineData ("こんにちは", 10, 1, "はちにんこ")] + [InlineData ("こんにちは\nAB\n12", 10, 3, "21\nBA\nはちにんこ")] + public void Draw_Horizontal_RightLeft_BottomTop (string text, int width, int height, string expectedText) + { + // Create a local driver instance for this test + var factory = new FakeDriverFactory (); + var driver = factory.Create (); + driver.SetBufferSize (Math.Max (25, width), Math.Max (25, height)); + + TextFormatter tf = new () { - lines[i] = lines[i].TrimEnd (); - } - return string.Join ("", lines); + Text = text, + Direction = TextDirection.RightLeft_BottomTop + }; + + tf.ConstrainToWidth = width; + tf.ConstrainToHeight = height; + tf.Draw (new Rectangle (0, 0, width, height), Attribute.Default, Attribute.Default, driver: driver); + + string actualText = GetDriverContents (driver, width, height); + Assert.Equal (expectedText, actualText); + } + + [Theory] + [InlineData ("A", 1, 0, "")] + [InlineData ("A", 0, 1, "")] + [InlineData ("AB1 2", 2, 1, "2")] + [InlineData ("AB12", 5, 1, "21BA")] + [InlineData ("AB\n12", 5, 2, "BA\n21")] + [InlineData ("ABC 123 456", 7, 2, "654 321\nCBA")] + [InlineData ("こんにちは", 1, 1, "")] + [InlineData ("こんにちは", 2, 1, "は")] + [InlineData ("こんにちは", 5, 1, "はち")] + [InlineData ("こんにちは", 10, 1, "はちにんこ")] + [InlineData ("こんにちは\nAB\n12", 10, 3, "はちにんこ\nBA\n21")] + public void Draw_Horizontal_RightLeft_TopBottom (string text, int width, int height, string expectedText) + { + // Create a local driver instance for this test + var factory = new FakeDriverFactory (); + var driver = factory.Create (); + driver.SetBufferSize (Math.Max (25, width), Math.Max (25, height)); + + TextFormatter tf = new () + { + Text = text, + Direction = TextDirection.RightLeft_TopBottom + }; + + tf.ConstrainToWidth = width; + tf.ConstrainToHeight = height; + tf.Draw (new Rectangle (0, 0, width, height), Attribute.Default, Attribute.Default, driver: driver); + + string actualText = GetDriverContents (driver, width, height); + Assert.Equal (expectedText, actualText); } #endregion