From c68d8efd94e7374c4387b747cad2a7367e3b6638 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Oct 2025 16:22:26 +0000 Subject: [PATCH] Add 2 more vertical Draw tests (22 test cases total) Co-authored-by: tig <585482+tig@users.noreply.github.com> --- Tests/UnitTests/Text/TextFormatterTests.cs | 56 ------------- .../Text/TextFormatterTests.cs | 78 ++++++++++++++++++- 2 files changed, 75 insertions(+), 59 deletions(-) diff --git a/Tests/UnitTests/Text/TextFormatterTests.cs b/Tests/UnitTests/Text/TextFormatterTests.cs index 4b8e69677..9f142b5cd 100644 --- a/Tests/UnitTests/Text/TextFormatterTests.cs +++ b/Tests/UnitTests/Text/TextFormatterTests.cs @@ -3472,62 +3472,6 @@ public class TextFormatterTests Assert.Equal (expectedY, rect.Y); } - [SetupFakeDriver] - [Theory] - [InlineData ("A", 1, 0, "")] - [InlineData ("A", 0, 1, "")] - [InlineData ("AB1 2", 1, 2, "2")] - [InlineData ("AB12", 1, 5, "2\n1\nB\nA")] - [InlineData ("AB\n12", 2, 5, "B2\nA1")] - [InlineData ("ABC 123 456", 2, 7, "6C\n5B\n4A\n \n3 \n2 \n1 ")] - [InlineData ("こんにちは", 1, 1, "")] - [InlineData ("こんにちは", 2, 1, "は")] - [InlineData ("こんにちは", 2, 5, "は\nち\nに\nん\nこ")] - [InlineData ("こんにちは", 2, 10, "は\nち\nに\nん\nこ")] - [InlineData ("こんにちは\nAB\n12", 4, 10, "はB2\nちA1\nに \nん \nこ ")] - public void Draw_Vertical_BottomTop_LeftRight (string text, int width, int height, string expectedText) - { - TextFormatter tf = new () - { - Text = text, - Direction = TextDirection.BottomTop_LeftRight - }; - - 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", 1, 2, "2")] - [InlineData ("AB12", 1, 5, "2\n1\nB\nA")] - [InlineData ("AB\n12", 2, 5, "2B\n1A")] - [InlineData ("ABC 123 456", 2, 7, "C6\nB5\nA4\n \n 3\n 2\n 1")] - [InlineData ("こんにちは", 1, 1, "")] - [InlineData ("こんにちは", 2, 1, "は")] - [InlineData ("こんにちは", 2, 5, "は\nち\nに\nん\nこ")] - [InlineData ("こんにちは", 2, 10, "は\nち\nに\nん\nこ")] - [InlineData ("こんにちは\nAB\n12", 4, 10, "2Bは\n1Aち\n に\n ん\n こ")] - public void Draw_Vertical_BottomTop_RightLeft (string text, int width, int height, string expectedText) - { - TextFormatter tf = new () - { - Text = text, - Direction = TextDirection.BottomTop_RightLeft - }; - - tf.ConstrainToWidth = width; - tf.ConstrainToHeight = height; - tf.Draw (new (0, 0, width, height), Attribute.Default, Attribute.Default); - - DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output); - } - // Draw tests - Note that these depend on View [Fact] diff --git a/Tests/UnitTestsParallelizable/Text/TextFormatterTests.cs b/Tests/UnitTestsParallelizable/Text/TextFormatterTests.cs index 8056d564b..c5fae4c41 100644 --- a/Tests/UnitTestsParallelizable/Text/TextFormatterTests.cs +++ b/Tests/UnitTestsParallelizable/Text/TextFormatterTests.cs @@ -3098,22 +3098,28 @@ public class TextFormatterTests // Use Application.ToString which properly handles double-wide chars string fullContents = Application.ToString (driver); - // Extract only the region we care about + // 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++) { string line = allLines[i]; - // Take up to width characters + // Take exactly width characters (or less if line is shorter) if (line.Length > width) { line = line.Substring (0, width); } - // Trim trailing spaces from each line + // Trim trailing spaces only - preserve intentional padding within width lines.Add (line.TrimEnd ()); } + // Remove trailing empty lines + while (lines.Count > 0 && string.IsNullOrEmpty (lines[lines.Count - 1])) + { + lines.RemoveAt (lines.Count - 1); + } + return string.Join ("\n", lines); } @@ -3183,5 +3189,71 @@ public class TextFormatterTests Assert.Equal (expectedText, actualText); } + [Theory] + [InlineData ("A", 1, 0, "")] + [InlineData ("A", 0, 1, "")] + [InlineData ("AB1 2", 1, 2, "2")] + [InlineData ("AB12", 1, 5, "2\n1\nB\nA")] + [InlineData ("AB\n12", 2, 5, "B2\nA1")] + [InlineData ("ABC 123 456", 2, 7, "6C\n5B\n4A\n\n3\n2\n1")] + [InlineData ("こんにちは", 1, 1, "")] + [InlineData ("こんにちは", 2, 1, "は")] + [InlineData ("こんにちは", 2, 5, "は\nち\nに\nん\nこ")] + [InlineData ("こんにちは", 2, 10, "は\nち\nに\nん\nこ")] + [InlineData ("こんにちは\nAB\n12", 4, 10, "はB2\nちA1\nに\nん\nこ")] + public void Draw_Vertical_BottomTop_LeftRight (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.BottomTop_LeftRight + }; + + 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", 1, 2, "2")] + [InlineData ("AB12", 1, 5, "2\n1\nB\nA")] + [InlineData ("AB\n12", 2, 5, "2B\n1A")] + [InlineData ("ABC 123 456", 2, 7, "C6\nB5\nA4\n\n 3\n 2\n 1")] + [InlineData ("こんにちは", 1, 1, "")] + [InlineData ("こんにちは", 2, 1, "は")] + [InlineData ("こんにちは", 2, 5, "は\nち\nに\nん\nこ")] + [InlineData ("こんにちは", 2, 10, "は\nち\nに\nん\nこ")] + [InlineData ("こんにちは\nAB\n12", 4, 10, "2Bは\n1Aち\n に\n ん\n こ")] + public void Draw_Vertical_BottomTop_RightLeft (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.BottomTop_RightLeft + }; + + 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 }