Browse Source

Fixed unit tests

Tig 1 year ago
parent
commit
acd308803e

+ 1 - 58
UnitTests/View/Text/AutoSizeFalseTests.cs

@@ -25,64 +25,7 @@ public class AutoSizeFalseTests (ITestOutputHelper output)
         Assert.True (view.IsInitialized);
         Assert.Equal (expectedViewBounds, view.Viewport);
     }
-
-    [Fact]
-    [SetupFakeDriver]
-    public void AutoSize_False_View_IsEmpty_False_Return_Null_Lines ()
-    {
-        var text = "Views";
-        var view = new View { Width = Dim.Fill () - text.Length, Height = 1, Text = text };
-        var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () };
-        frame.Add (view);
-
-        ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
-        frame.BeginInit ();
-        frame.EndInit ();
-        frame.LayoutSubviews ();
-
-        Assert.Equal (5, text.Length);
-        Assert.Equal (new (0, 0, 3, 1), view.Frame);
-        Assert.Equal (new (3, 1), view.TextFormatter.Size);
-        Assert.Equal (new() { "Vie" }, view.TextFormatter.GetLines ());
-        Assert.Equal (new (0, 0, 10, 4), frame.Frame);
-
-        frame.LayoutSubviews ();
-        frame.Clear ();
-        frame.Draw ();
-
-        var expected = @"
-┌────────┐
-│Vie     │
-│        │
-└────────┘
-";
-
-        Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
-        Assert.Equal (new (0, 0, 10, 4), pos);
-
-        text = "0123456789";
-        Assert.Equal (10, text.Length);
-        view.Width = Dim.Fill () - text.Length;
-
-        frame.LayoutSubviews ();
-        frame.Clear ();
-        frame.Draw ();
-
-        Assert.Equal (new (0, 0, 0, 1), view.Frame);
-        Assert.Equal (new (0, 1), view.TextFormatter.Size);
-        Assert.Equal (new() { string.Empty }, view.TextFormatter.GetLines ());
-
-        expected = @"
-┌────────┐
-│        │
-│        │
-└────────┘
-";
-
-        pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
-        Assert.Equal (new (0, 0, 10, 4), pos);
-    }
-
+    
     [Fact]
     [SetupFakeDriver]
     public void AutoSize_False_Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()

+ 5 - 6
UnitTests/View/Text/AutoSizeTrueTests.cs

@@ -745,19 +745,17 @@ public class AutoSizeTrueTests (ITestOutputHelper output)
     [SetupFakeDriver]
     public void AutoSize_False_Label_Height_Zero_Stays_Zero ()
     {
+        ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
         var text = "Label";
         var label = new Label
         {
             Text = text,
-            Width = Dim.Auto (Dim.DimAutoStyle.Text),
-            Height = Dim.Auto (Dim.DimAutoStyle.Text)
         };
         label.Width = Dim.Fill () - text.Length;
         label.Height = 0;
 
         var win = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () };
         win.Add (label);
-        ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
         win.BeginInit ();
         win.EndInit ();
         win.LayoutSubviews ();
@@ -1029,7 +1027,7 @@ Y
     [AutoInitShutdown]
     public void AutoSize_True_Setting_With_Height_Vertical ()
     {
-        // BUGBUG: Label is AutoSize = true, so Width & Height are ignored
+        // BUGBUG: Label is Width = Dim.Auto (), Height = Dim.Auto (), so Width & Height are ignored
         var label = new Label
         { /*Width = 2, Height = 10, */
             TextDirection = TextDirection.TopBottom_LeftRight, ValidatePosDim = true
@@ -1598,7 +1596,8 @@ Y
 
         var horizontalView = new View
         {
-            Id = "horizontalView", AutoSize = true, Text = text
+            Id = "horizontalView",
+            Width = Dim.Auto (), Height = Dim.Auto (), Text = text
         };
 
         var verticalView = new View
@@ -1736,7 +1735,7 @@ Y
         // Frame: 0, 0, 1, 12
         var verticalView = new View
         {
-            AutoSize = true, TextDirection = TextDirection.TopBottom_LeftRight
+            Width = Dim.Auto (), Height = Dim.Auto (), TextDirection = TextDirection.TopBottom_LeftRight
         };
         verticalView.Text = text;
         verticalView.TextFormatter.HotKeySpecifier = (Rune)'_';

+ 21 - 14
UnitTests/View/TitleTests.cs

@@ -1,17 +1,10 @@
 using System.Text;
 using Xunit.Abstractions;
 
-//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
-
-// Alias Console to MockConsole so we don't accidentally use Console
-
 namespace Terminal.Gui.ViewTests;
 
-public class TitleTests
+public class TitleTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public TitleTests (ITestOutputHelper output) { this._output = output; }
-
     [Fact]
     public void Set_Title_Fires_TitleChanged ()
     {
@@ -81,27 +74,41 @@ public class TitleTests
     [Fact]
     public void Change_View_Size_Update_Title_Size ()
     {
-        var view = new View { Title = "_Hello World", Width = Dim.Auto (), Height = Dim.Auto (), BorderStyle = LineStyle.Single};
+        var view = new View
+        {
+            Title = "_Hello World",
+            Width = Dim.Auto (), Height = Dim.Auto (),
+            BorderStyle = LineStyle.Single
+        };
         var top = new Toplevel ();
         top.Add (view);
-        Application.Begin (top);
+        top.BeginInit ();
+        top.EndInit ();
 
         Assert.Equal (string.Empty, view.Text);
         Assert.Equal (new (2, 2), view.Frame.Size);
-        TestHelpers.AssertDriverContentsWithFrameAre (@"
+        top.Draw ();
+
+        TestHelpers.AssertDriverContentsWithFrameAre (
+                                                      @"
 ┌┐
-└┘", _output);
+└┘",
+                                                      output);
 
         var text = "This text will increment the view size and display the title.";
         view.Text = text;
         top.Draw ();
         Assert.Equal (text, view.Text);
+
         // SetupFakeDriver only create a screen with 25 cols and 25 rows
         Assert.Equal (new (25, 3), view.Frame.Size);
-        TestHelpers.AssertDriverContentsWithFrameAre (@"
+
+        TestHelpers.AssertDriverContentsWithFrameAre (
+                                                      @"
 ┌┤Hello World├──────────┐
 │This text will incremen│
-└───────────────────────┘", _output);
+└───────────────────────┘",
+                                                      output);
 
         top.Dispose ();
     }