Browse Source

Add 2 more vertical Draw tests (22 test cases total)

Co-authored-by: tig <[email protected]>
copilot-swe-agent[bot] 1 month ago
parent
commit
c68d8efd94

+ 0 - 56
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]

+ 75 - 3
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<string> ();
         
         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
 }