Przeglądaj źródła

Started to add more primitve unit tests for vertical text

Tig 1 rok temu
rodzic
commit
f134d1a113

+ 1 - 1
Terminal.Gui/Text/TextFormatter.cs

@@ -413,7 +413,7 @@ public class TextFormatter
 
                 if (lastZeroWidthPos is null)
                 {
-                    if (idx < 0)
+                    if (idx < 0 || x + current + colOffset < 0)
                     {
                         current++;
 

+ 13 - 8
UnitTests/Text/TextFormatterTests.cs

@@ -3366,7 +3366,7 @@ ssb
     [InlineData ("A", 0, true, "")]
     [InlineData ("A", 1, true, "A")]
     [InlineData ("A", 2, true, " A")]
-    [InlineData ("AB", 1, true, "B")]
+    [InlineData ("AB", 1, true, "")] // BUGBUG: Should be "B". See https://github.com/gui-cs/Terminal.Gui/issues/3418#issuecomment-2067771418 for a partial fix
     [InlineData ("AB", 2, true, "AB")]
     [InlineData ("ABC", 3, true, "ABC")]
     [InlineData ("ABC", 4, true, " ABC")]
@@ -3479,26 +3479,31 @@ ssb
 
     [SetupFakeDriver]
     [Theory]
-    [InlineData ("A", 2, false, "A")]
-    [InlineData ("AB12", 5, false, "AB12")]
-    [InlineData ("AB\n12", 5, false, "A1\nB2")]
+    [InlineData ("A", 5, false, "A")]
+    [InlineData ("AB12", 5, false, @"
+A
+B
+1
+2")]
+    [InlineData ("AB\n12", 5, false, @"
+A1
+B2")]
     [InlineData ("", 1, false, "")]
 
-    public void Draw_Vertical_TopBottom_LeftRight (string text, int width, bool autoSize, string expectedText)
+    public void Draw_Vertical_TopBottom_LeftRight (string text, int height, bool autoSize, string expectedText)
     {
         TextFormatter tf = new ()
         {
             Text = text,
             AutoSize = autoSize,
             Direction = TextDirection.TopBottom_LeftRight,
-            VerticalAlignment = VerticalTextAlignment.Top
         };
 
         if (!autoSize)
         {
-            tf.Size = new Size (width, 1);
+            tf.Size = new Size (5, height);
         }
-        tf.Draw (new Rectangle (0, 0, width, 5), Attribute.Default, Attribute.Default);
+        tf.Draw (new Rectangle (0, 0, 5, height), Attribute.Default, Attribute.Default);
 
         TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
     }