فهرست منبع

Review feedback

Tig 1 سال پیش
والد
کامیت
c7ae986789
3فایلهای تغییر یافته به همراه61 افزوده شده و 11 حذف شده
  1. 1 2
      Terminal.Gui/Text/TextFormatter.cs
  2. 1 1
      UnitTests/View/Layout/Pos.PercentTests.cs
  3. 59 8
      UnitTests/View/TextTests.cs

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

@@ -579,6 +579,7 @@ public class TextFormatter
     /// </remarks>
     public List<string> GetLines ()
     {
+        string text = _text!;
         int width = _constrainToWidth.GetValueOrDefault ();
         int height = _constrainToHeight.GetValueOrDefault ();
 
@@ -596,8 +597,6 @@ public class TextFormatter
             return _lines;
         }
 
-        string text = _text!;
-
         if (FindHotKey (_text!, HotKeySpecifier, out _hotKeyPos, out Key newHotKey))
         {
             HotKey = newHotKey;

+ 1 - 1
UnitTests/View/Layout/Pos.PercentTests.cs

@@ -75,7 +75,7 @@ public class PosPercentTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void PosPercent_ThrowsOnIvalid ()
+    public void PosPercent_ThrowsOnInvalid ()
     {
         Pos pos = Percent (0);
         Assert.Throws<ArgumentOutOfRangeException> (() => pos = Percent (-1));

+ 59 - 8
UnitTests/View/TextTests.cs

@@ -734,10 +734,11 @@ w ";
         Application.End (rs);
         top.Dispose ();
     }
-
-    [Fact]
+    [Theory]
     [AutoInitShutdown]
-    public void View_Draw_Horizontal_Simple_TextAlignments ()
+    [InlineData (true)]
+    [InlineData (false)]
+    public void View_Draw_Horizontal_Simple_TextAlignments (bool autoSize)
     {
         var text = "Hello World";
         var width = 20;
@@ -749,6 +750,12 @@ w ";
             Height = 1
         };
 
+        if (autoSize)
+        {
+            lblLeft.Width = Dim.Auto ();
+            lblLeft.Height = Dim.Auto ();
+        }
+
         var lblCenter = new View
         {
             Text = text,
@@ -758,6 +765,12 @@ w ";
             TextAlignment = Alignment.Center
         };
 
+        if (autoSize)
+        {
+            lblCenter.Width = Dim.Auto ();
+            lblCenter.Height = Dim.Auto ();
+        }
+
         var lblRight = new View
         {
             Text = text,
@@ -767,6 +780,12 @@ w ";
             TextAlignment = Alignment.End
         };
 
+        if (autoSize)
+        {
+            lblRight.Width = Dim.Auto ();
+            lblRight.Height = Dim.Auto ();
+        }
+
         var lblJust = new View
         {
             Text = text,
@@ -776,6 +795,12 @@ w ";
             TextAlignment = Alignment.Fill
         };
 
+        if (autoSize)
+        {
+            lblJust.Width = Dim.Auto ();
+            lblJust.Height = Dim.Auto ();
+        }
+
         var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () };
         frame.Add (lblLeft, lblCenter, lblRight, lblJust);
         var top = new Toplevel ();
@@ -784,16 +809,41 @@ w ";
         ((FakeDriver)Application.Driver).SetBufferSize (width + 2, 6);
 
         // frame.Width is width + border wide (20 + 2) and 6 high
-        Size expectedSize = new (width, 1);
-        Assert.Equal (expectedSize, lblLeft.TextFormatter.ConstrainToSize);
-        Assert.Equal (expectedSize, lblCenter.TextFormatter.ConstrainToSize);
-        Assert.Equal (expectedSize, lblRight.TextFormatter.ConstrainToSize);
-        Assert.Equal (expectedSize, lblJust.TextFormatter.ConstrainToSize);
+
+        if (autoSize)
+        {
+            Size expectedSize = new (11, 1);
+            Assert.Equal (expectedSize, lblLeft.TextFormatter.ConstrainToSize);
+            Assert.Equal (expectedSize, lblCenter.TextFormatter.ConstrainToSize);
+            Assert.Equal (expectedSize, lblRight.TextFormatter.ConstrainToSize);
+            Assert.Equal (expectedSize, lblJust.TextFormatter.ConstrainToSize);
+        }
+        else
+        {
+            Size expectedSize = new (width, 1);
+            Assert.Equal (expectedSize, lblLeft.TextFormatter.ConstrainToSize);
+            Assert.Equal (expectedSize, lblCenter.TextFormatter.ConstrainToSize);
+            Assert.Equal (expectedSize, lblRight.TextFormatter.ConstrainToSize);
+            Assert.Equal (expectedSize, lblJust.TextFormatter.ConstrainToSize);
+        }
 
         Assert.Equal (new (0, 0, width + 2, 6), frame.Frame);
 
         string expected;
 
+        if (autoSize)
+        {
+            expected = @"
+┌────────────────────┐
+│Hello World         │
+│Hello World         │
+│Hello World         │
+│Hello World         │
+└────────────────────┘
+";
+        }
+        else
+        {
             expected = @"
 ┌────────────────────┐
 │Hello World         │
@@ -802,6 +852,7 @@ w ";
 │Hello          World│
 └────────────────────┘
 ";
+        }
 
         Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
         Assert.Equal (new (0, 0, width + 2, 6), pos);