2
0
Эх сурвалжийг харах

Broke out DimView tests.
Added Equals test. Found bug. Fixed.

Tig 1 жил өмнө
parent
commit
aa1b5ed111

+ 1 - 1
Terminal.Gui/View/Layout/Dim.cs

@@ -724,7 +724,7 @@ public class DimView : Dim
     public Dimension Dimension { get; }
 
     /// <inheritdoc/>
-    public override bool Equals (object other) { return other is DimView abs && abs.Target == Target; }
+    public override bool Equals (object other) { return other is DimView abs && abs.Target == Target && abs.Dimension == Dimension; }
 
     /// <inheritdoc/>
     public override int GetHashCode () { return Target.GetHashCode (); }

+ 0 - 60
UnitTests/View/Layout/Dim.Tests.cs

@@ -32,17 +32,6 @@ public class DimTests
         Assert.Equal (10, result);
     }
 
-
-    [Fact]
-    public void DimView_Calculate_ReturnsCorrectValue ()
-    {
-        var view = new View { Width = 10 };
-        var dim = new DimView (view, Dimension.Width);
-        var result = dim.Calculate (0, 100, null, Dimension.None);
-        Assert.Equal (10, result);
-    }
-
-
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
     // A new test that does not depend on Application is needed.
     [Fact]
@@ -94,30 +83,6 @@ public class DimTests
         Assert.Equal (20, count);
     }
 
-    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
-    // TODO: A new test that calls SetRelativeLayout directly is needed.
-    [Fact]
-    [TestRespondersDisposed]
-    public void Dim_Referencing_SuperView_Does_Not_Throw ()
-    {
-        var super = new View { Width = 10, Height = 10, Text = "super" };
-
-        var view = new View
-        {
-            Width = Dim.Width (super), // this is allowed
-            Height = Dim.Height (super), // this is allowed
-            Text = "view"
-        };
-
-        super.Add (view);
-        super.BeginInit ();
-        super.EndInit ();
-
-        Exception exception = Record.Exception (super.LayoutSubviews);
-        Assert.Null (exception);
-        super.Dispose ();
-    }
-
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
     // TODO: A new test that calls SetRelativeLayout directly is needed.
     [Fact]
@@ -181,31 +146,6 @@ public class DimTests
         Assert.Equal (0, count);
     }
 
-    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
-    // TODO: A new test that calls SetRelativeLayout directly is needed.
-    [Fact]
-    [TestRespondersDisposed]
-    public void Dim_SyperView_Referencing_SubView_Throws ()
-    {
-        var super = new View { Width = 10, Height = 10, Text = "super" };
-        var view2 = new View { Width = 10, Height = 10, Text = "view2" };
-
-        var view = new View
-        {
-            Width = Dim.Width (view2), // this is not allowed
-            Height = Dim.Height (view2), // this is not allowed
-            Text = "view"
-        };
-
-        view.Add (view2);
-        super.Add (view);
-        super.BeginInit ();
-        super.EndInit ();
-
-        Assert.Throws<InvalidOperationException> (super.LayoutSubviews);
-        super.Dispose ();
-    }
-
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
     // TODO: A new test that calls SetRelativeLayout directly is needed.
     [Fact]

+ 87 - 0
UnitTests/View/Layout/Dim.ViewTests.cs

@@ -0,0 +1,87 @@
+using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
+
+namespace Terminal.Gui.LayoutTests;
+
+public class DimViewTests (ITestOutputHelper output)
+{
+    private readonly ITestOutputHelper _output = output;
+
+    [Fact]
+    public void DimView_Equal ()
+    {
+        var view1 = new View ();
+        var view2 = new View ();
+
+        Dim dim1 = Width (view1);
+        Dim dim2 = Width (view1);
+        Assert.Equal (dim1, dim2);
+
+        dim2 = Width (view2);
+        Assert.NotEqual (dim1, dim2);
+
+        dim2 = Height (view1);
+        Assert.NotEqual (dim1, dim2);
+    }
+
+
+    [Fact]
+    public void DimView_Calculate_ReturnsCorrectValue ()
+    {
+        var view = new View { Width = 10 };
+        var dim = new DimView (view, Dimension.Width);
+        var result = dim.Calculate (0, 100, null, Dimension.None);
+        Assert.Equal (10, result);
+    }
+
+    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
+    // TODO: A new test that calls SetRelativeLayout directly is needed.
+    [Fact]
+    [TestRespondersDisposed]
+    public void Dim_Referencing_SuperView_Does_Not_Throw ()
+    {
+        var super = new View { Width = 10, Height = 10, Text = "super" };
+
+        var view = new View
+        {
+            Width = Dim.Width (super), // this is allowed
+            Height = Dim.Height (super), // this is allowed
+            Text = "view"
+        };
+
+        super.Add (view);
+        super.BeginInit ();
+        super.EndInit ();
+
+        Exception exception = Record.Exception (super.LayoutSubviews);
+        Assert.Null (exception);
+        super.Dispose ();
+    }
+
+
+    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
+    // TODO: A new test that calls SetRelativeLayout directly is needed.
+    [Fact]
+    [TestRespondersDisposed]
+    public void Dim_SuperView_Referencing_SubView_Throws ()
+    {
+        var super = new View { Width = 10, Height = 10, Text = "super" };
+        var view2 = new View { Width = 10, Height = 10, Text = "view2" };
+
+        var view = new View
+        {
+            Width = Dim.Width (view2), // this is not allowed
+            Height = Dim.Height (view2), // this is not allowed
+            Text = "view"
+        };
+
+        view.Add (view2);
+        super.Add (view);
+        super.BeginInit ();
+        super.EndInit ();
+
+        Assert.Throws<InvalidOperationException> (super.LayoutSubviews);
+        super.Dispose ();
+    }
+
+}