瀏覽代碼

Moved AutoSizeFalse tests to more logical locations; nuked invalid tests

Tig 1 年之前
父節點
當前提交
e28b12e321
共有 3 個文件被更改,包括 144 次插入151 次删除
  1. 20 0
      UnitTests/View/Layout/Dim.FillTests.cs
  2. 0 151
      UnitTests/View/Text/AutoSizeFalseTests.cs
  3. 124 0
      UnitTests/View/Text/TextTests.cs

+ 20 - 0
UnitTests/View/Layout/Dim.FillTests.cs

@@ -145,4 +145,24 @@ public class DimFillTests (ITestOutputHelper output)
         Assert.Equal (100, result);
     }
 
+    [Fact]
+    public void ResizeView_With_Dim_Fill_After_IsInitialized ()
+    {
+        var super = new View { Frame = new (0, 0, 30, 80) };
+        var view = new View { Width = Dim.Fill (), Height = Dim.Fill () };
+        super.Add (view);
+
+        view.Text = "New text\nNew line";
+        super.LayoutSubviews ();
+        Rectangle expectedViewBounds = new (0, 0, 30, 80);
+
+        Assert.Equal (expectedViewBounds, view.Viewport);
+        Assert.False (view.IsInitialized);
+
+        super.BeginInit ();
+        super.EndInit ();
+
+        Assert.True (view.IsInitialized);
+        Assert.Equal (expectedViewBounds, view.Viewport);
+    }
 }

+ 0 - 151
UnitTests/View/Text/AutoSizeFalseTests.cs

@@ -1,151 +0,0 @@
-using Xunit.Abstractions;
-
-namespace Terminal.Gui.ViewTests;
-
-/// <summary>Tests of the  <see cref="View.Text"/> property with AutoSize set to false.</summary>
-public class AutoSizeFalseTests (ITestOutputHelper output)
-{
-    [Fact]
-    public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
-    {
-        var super = new View { Frame = new (0, 0, 30, 80) };
-        var view = new View { Width = Dim.Fill (), Height = Dim.Fill () };
-        super.Add (view);
-
-        view.Text = "New text\nNew line";
-        super.LayoutSubviews ();
-        Rectangle expectedViewBounds = new (0, 0, 30, 80);
-
-        Assert.Equal (expectedViewBounds, view.Viewport);
-        Assert.False (view.IsInitialized);
-
-        super.BeginInit ();
-        super.EndInit ();
-
-        Assert.True (view.IsInitialized);
-        Assert.Equal (expectedViewBounds, view.Viewport);
-    }
-    
-    [Fact]
-    [SetupFakeDriver]
-    public void AutoSize_False_Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
-    {
-        ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
-        var top = new View { Width = 32, Height = 32 };
-
-        var text = $"First line{Environment.NewLine}Second line";
-        var horizontalView = new View { Width = 20, Height = 1, Text = text };
-
-        // Autosize is off, so we have to explicitly set TextFormatter.Size
-        horizontalView.TextFormatter.Size = new (20, 1);
-
-        var verticalView = new View
-        {
-            Y = 3,
-            Height = 20,
-            Width = 1,
-            Text = text,
-            TextDirection = TextDirection.TopBottom_LeftRight
-        };
-
-        // Autosize is off, so we have to explicitly set TextFormatter.Size
-        verticalView.TextFormatter.Size = new (1, 20);
-
-        var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window" };
-        frame.Add (horizontalView, verticalView);
-        top.Add (frame);
-        top.BeginInit ();
-        top.EndInit ();
-
-        Assert.Equal (new (0, 0, 20, 1), horizontalView.Frame);
-        Assert.Equal (new (0, 3, 1, 20), verticalView.Frame);
-
-        top.Draw ();
-
-        var expected = @"
-┌──────────────────────────────┐
-│First line Second li          │
-│                              │
-│                              │
-│F                             │
-│i                             │
-│r                             │
-│s                             │
-│t                             │
-│                              │
-│l                             │
-│i                             │
-│n                             │
-│e                             │
-│                              │
-│S                             │
-│e                             │
-│c                             │
-│o                             │
-│n                             │
-│d                             │
-│                              │
-│l                             │
-│i                             │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-└──────────────────────────────┘
-";
-
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
-
-        verticalView.Text = $"最初の行{Environment.NewLine}二行目";
-        Assert.True (verticalView.TextFormatter.NeedsFormat);
-
-        // Autosize is off, so we have to explicitly set TextFormatter.Size
-        // We know these glpyhs are 2 cols wide, so we need to widen the view
-        verticalView.Width = 2;
-        verticalView.TextFormatter.Size = new (2, 20);
-        Assert.True (verticalView.TextFormatter.NeedsFormat);
-
-        top.Draw ();
-        Assert.Equal (new (0, 3, 2, 20), verticalView.Frame);
-
-        expected = @"
-┌──────────────────────────────┐
-│First line Second li          │
-│                              │
-│                              │
-│最                            │
-│初                            │
-│の                            │
-│行                            │
-│                              │
-│二                            │
-│行                            │
-│目                            │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-│                              │
-└──────────────────────────────┘
-";
-
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
-    }
-}

+ 124 - 0
UnitTests/View/Text/TextTests.cs

@@ -1231,6 +1231,130 @@ Y
         Assert.Equal (new Rectangle (0, 0, 1, 5), view.Viewport);
     }
 
+
+    [Fact]
+    [SetupFakeDriver]
+    public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
+    {
+        ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
+        var top = new View { Width = 32, Height = 32 };
+
+        var text = $"First line{Environment.NewLine}Second line";
+        var horizontalView = new View { Width = 20, Height = 1, Text = text };
+
+        // Autosize is off, so we have to explicitly set TextFormatter.Size
+        horizontalView.TextFormatter.Size = new (20, 1);
+
+        var verticalView = new View
+        {
+            Y = 3,
+            Height = 20,
+            Width = 1,
+            Text = text,
+            TextDirection = TextDirection.TopBottom_LeftRight
+        };
+
+        // Autosize is off, so we have to explicitly set TextFormatter.Size
+        verticalView.TextFormatter.Size = new (1, 20);
+
+        var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window" };
+        frame.Add (horizontalView, verticalView);
+        top.Add (frame);
+        top.BeginInit ();
+        top.EndInit ();
+
+        Assert.Equal (new (0, 0, 20, 1), horizontalView.Frame);
+        Assert.Equal (new (0, 3, 1, 20), verticalView.Frame);
+
+        top.Draw ();
+
+        var expected = @"
+┌──────────────────────────────┐
+│First line Second li          │
+│                              │
+│                              │
+│F                             │
+│i                             │
+│r                             │
+│s                             │
+│t                             │
+│                              │
+│l                             │
+│i                             │
+│n                             │
+│e                             │
+│                              │
+│S                             │
+│e                             │
+│c                             │
+│o                             │
+│n                             │
+│d                             │
+│                              │
+│l                             │
+│i                             │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+└──────────────────────────────┘
+";
+
+        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+
+        verticalView.Text = $"最初の行{Environment.NewLine}二行目";
+        Assert.True (verticalView.TextFormatter.NeedsFormat);
+
+        // Autosize is off, so we have to explicitly set TextFormatter.Size
+        // We know these glpyhs are 2 cols wide, so we need to widen the view
+        verticalView.Width = 2;
+        verticalView.TextFormatter.Size = new (2, 20);
+        Assert.True (verticalView.TextFormatter.NeedsFormat);
+
+        top.Draw ();
+        Assert.Equal (new (0, 3, 2, 20), verticalView.Frame);
+
+        expected = @"
+┌──────────────────────────────┐
+│First line Second li          │
+│                              │
+│                              │
+│最                            │
+│初                            │
+│の                            │
+│行                            │
+│                              │
+│二                            │
+│行                            │
+│目                            │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+│                              │
+└──────────────────────────────┘
+";
+
+        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+    }
+
     // Test behavior of AutoSize property. 
     // - Default is false
     // - Setting to true invalidates Height/Width