Răsfoiți Sursa

Reorganized PosDim unit tests.

Tig 1 an în urmă
părinte
comite
6209aceb5f

+ 65 - 0
UnitTests/View/DrawTests.cs

@@ -975,4 +975,69 @@ public class DrawTests (ITestOutputHelper output)
     }
 
 
+    [Fact]
+    [TestRespondersDisposed]
+    public void Draw_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
+    {
+        Application.Init (new FakeDriver ());
+
+        Toplevel top = new ();
+
+        var view = new View { X = -2, Text = "view" };
+        top.Add (view);
+
+        Application.Iteration += (s, a) =>
+        {
+            Assert.Equal (-2, view.X);
+
+            Application.RequestStop ();
+        };
+
+        try
+        {
+            Application.Run (top);
+        }
+        catch (IndexOutOfRangeException ex)
+        {
+            // After the fix this exception will not be caught.
+            Assert.IsType<IndexOutOfRangeException> (ex);
+        }
+
+        top.Dispose ();
+        // Shutdown must be called to safely clean up Application if Init has been called
+        Application.Shutdown ();
+    }
+
+    [Fact]
+    [TestRespondersDisposed]
+    public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
+    {
+        Application.Init (new FakeDriver ());
+
+        Toplevel top = new ();
+
+        var view = new View { Y = -2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight, Text = "view" };
+        top.Add (view);
+
+        Application.Iteration += (s, a) =>
+        {
+            Assert.Equal (-2, view.Y);
+
+            Application.RequestStop ();
+        };
+
+        try
+        {
+            Application.Run (top);
+        }
+        catch (IndexOutOfRangeException ex)
+        {
+            // After the fix this exception will not be caught.
+            Assert.IsType<IndexOutOfRangeException> (ex);
+        }
+
+        top.Dispose ();
+        // Shutdown must be called to safely clean up Application if Init has been called
+        Application.Shutdown ();
+    }
 }

+ 1 - 1
UnitTests/View/Layout/AbsoluteLayoutTests.cs

@@ -4,7 +4,7 @@
 
 // Alias Console to MockConsole so we don't accidentally use Console
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.LayoutTests;
 
 public class AbsoluteLayoutTests
 {

+ 1 - 1
UnitTests/View/Layout/DimAutoTests.cs → UnitTests/View/Layout/Dim.AutoTests.cs

@@ -7,7 +7,7 @@ using static Terminal.Gui.Dim;
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.PosDimTests;
 
 public class DimAutoTests
 {

+ 156 - 0
UnitTests/View/Layout/Dim.CombineTests.cs

@@ -0,0 +1,156 @@
+using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
+
+namespace Terminal.Gui.PosDimTests;
+
+public class DimCombineTests (ITestOutputHelper output)
+{
+    private readonly ITestOutputHelper _output = output;
+
+
+    [Fact]
+    public void DimCombine_Calculate_ReturnsCorrectValue ()
+    {
+        var dim1 = new DimAbsolute (10);
+        var dim2 = new DimAbsolute (20);
+        var dim = dim1 + dim2;
+        var result = dim.Calculate (0, 100, null, Dim.Dimension.None);
+        Assert.Equal (30, 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 DimCombine_ObtuseScenario_Does_Not_Throw_If_Two_SubViews_Refs_The_Same_SuperView ()
+    {
+        var t = new View { Width = 80, Height = 25, Text = "top" };
+
+        var w = new Window
+        {
+            Width = Dim.Width (t) - 2, // 78
+            Height = Dim.Height (t) - 2 // 23
+        };
+        var f = new FrameView ();
+
+        var v1 = new View
+        {
+            Width = Dim.Width (w) - 2, // 76
+            Height = Dim.Height (w) - 2 // 21
+        };
+
+        var v2 = new View
+        {
+            Width = Dim.Width (v1) - 2, // 74
+            Height = Dim.Height (v1) - 2 // 19
+        };
+
+        f.Add (v1, v2);
+        w.Add (f);
+        t.Add (w);
+        t.BeginInit ();
+        t.EndInit ();
+
+        f.Width = Dim.Width (t) - Dim.Width (w) + 4; // 80 - 74 = 6
+        f.Height = Dim.Height (t) - Dim.Height (w) + 4; // 25 - 19 = 6
+
+        // BUGBUG: v2 - f references t and w here; t is f's super-superview and w is f's superview. This is supported!
+        Exception exception = Record.Exception (t.LayoutSubviews);
+        Assert.Null (exception);
+        Assert.Equal (80, t.Frame.Width);
+        Assert.Equal (25, t.Frame.Height);
+        Assert.Equal (78, w.Frame.Width);
+        Assert.Equal (23, w.Frame.Height);
+        Assert.Equal (6, f.Frame.Width);
+        Assert.Equal (6, f.Frame.Height);
+        Assert.Equal (76, v1.Frame.Width);
+        Assert.Equal (21, v1.Frame.Height);
+        Assert.Equal (74, v2.Frame.Width);
+        Assert.Equal (19, v2.Frame.Height);
+        t.Dispose ();
+    }
+
+    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
+    // TODO: A new test that calls SetRelativeLayout directly is needed.
+
+    /// <summary>This is an intentionally obtuse test. See https://github.com/gui-cs/Terminal.Gui/issues/2461</summary>
+    [Fact]
+    [TestRespondersDisposed]
+    public void DimCombine_ObtuseScenario_Throw_If_SuperView_Refs_SubView ()
+    {
+        var t = new View { Width = 80, Height = 25 };
+
+        var w = new Window
+        {
+            Width = Dim.Width (t) - 2, // 78
+            Height = Dim.Height (t) - 2 // 23
+        };
+        var f = new FrameView ();
+
+        var v1 = new View
+        {
+            Width = Dim.Width (w) - 2, // 76
+            Height = Dim.Height (w) - 2 // 21
+        };
+
+        var v2 = new View
+        {
+            Width = Dim.Width (v1) - 2, // 74
+            Height = Dim.Height (v1) - 2 // 19
+        };
+
+        f.Add (v1, v2);
+        w.Add (f);
+        t.Add (w);
+        t.BeginInit ();
+        t.EndInit ();
+
+        f.Width = Dim.Width (t) - Dim.Width (v2); // 80 - 74 = 6
+        f.Height = Dim.Height (t) - Dim.Height (v2); // 25 - 19 = 6
+
+        Assert.Throws<InvalidOperationException> (t.LayoutSubviews);
+        Assert.Equal (80, t.Frame.Width);
+        Assert.Equal (25, t.Frame.Height);
+        Assert.Equal (78, w.Frame.Width);
+        Assert.Equal (23, w.Frame.Height);
+        Assert.Equal (6, f.Frame.Width);
+        Assert.Equal (6, f.Frame.Height);
+        Assert.Equal (76, v1.Frame.Width);
+        Assert.Equal (21, v1.Frame.Height);
+        Assert.Equal (74, v2.Frame.Width);
+        Assert.Equal (19, v2.Frame.Height);
+        t.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 DimCombine_View_Not_Added_Throws ()
+    {
+        var t = new View { Width = 80, Height = 50 };
+
+        var super = new View { Width = Dim.Width (t) - 2, Height = Dim.Height (t) - 2 };
+        t.Add (super);
+
+        var sub = new View ();
+        super.Add (sub);
+
+        var v1 = new View { Width = Dim.Width (super) - 2, Height = Dim.Height (super) - 2 };
+        var v2 = new View { Width = Dim.Width (v1) - 2, Height = Dim.Height (v1) - 2 };
+        sub.Add (v1);
+
+        // v2 not added to sub; should cause exception on Layout since it's referenced by sub.
+        sub.Width = Dim.Fill () - Dim.Width (v2);
+        sub.Height = Dim.Fill () - Dim.Height (v2);
+
+        t.BeginInit ();
+        t.EndInit ();
+
+        Assert.Throws<InvalidOperationException> (() => t.LayoutSubviews ());
+        t.Dispose ();
+        v2.Dispose ();
+    }
+
+}

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

@@ -0,0 +1,148 @@
+using Xunit.Abstractions;
+
+namespace Terminal.Gui.PosDimTests;
+
+public class DimFillTests (ITestOutputHelper output)
+{
+    private readonly ITestOutputHelper _output = output;
+
+    [Fact]
+    [AutoInitShutdown]
+    public void DimFill_SizedCorrectly ()
+    {
+        var view = new View { Width = Dim.Fill (), Height = Dim.Fill (), BorderStyle = LineStyle.Single };
+        var top = new Toplevel ();
+        top.Add (view);
+        RunState rs = Application.Begin (top);
+        ((FakeDriver)Application.Driver).SetBufferSize (32, 5);
+
+        //view.SetNeedsLayout ();
+        top.LayoutSubviews ();
+
+        //view.SetRelativeLayout (new (0, 0, 32, 5));
+        Assert.Equal (32, view.Frame.Width);
+        Assert.Equal (5, view.Frame.Height);
+    }
+
+
+    [Fact]
+    public void DimFill_Equal ()
+    {
+        var margin1 = 0;
+        var margin2 = 0;
+        Dim dim1 = Dim.Fill (margin1);
+        Dim dim2 = Dim.Fill (margin2);
+        Assert.Equal (dim1, dim2);
+    }
+
+    // Tests that Dim.Fill honors the margin parameter correctly
+    [Theory]
+    [InlineData (0, true, 25)]
+    [InlineData (0, false, 25)]
+    [InlineData (1, true, 24)]
+    [InlineData (1, false, 24)]
+    [InlineData (2, true, 23)]
+    [InlineData (2, false, 23)]
+    [InlineData (-2, true, 27)]
+    [InlineData (-2, false, 27)]
+    public void DimFill_Margin (int margin, bool width, int expected)
+    {
+        var super = new View { Width = 25, Height = 25 };
+
+        var view = new View
+        {
+            X = 0,
+            Y = 0,
+            Width = width ? Dim.Fill (margin) : 1,
+            Height = width ? 1 : Dim.Fill (margin)
+        };
+
+        super.Add (view);
+        super.BeginInit ();
+        super.EndInit ();
+        super.LayoutSubviews ();
+
+        Assert.Equal (25, super.Frame.Width);
+        Assert.Equal (25, super.Frame.Height);
+
+        if (width)
+        {
+            Assert.Equal (expected, view.Frame.Width);
+            Assert.Equal (1, view.Frame.Height);
+        }
+        else
+        {
+            Assert.Equal (1, view.Frame.Width);
+            Assert.Equal (expected, view.Frame.Height);
+        }
+    }
+
+    // Tests that Dim.Fill fills the dimension REMAINING from the View's X position to the end of the super view's width
+    [Theory]
+    [InlineData (0, true, 25)]
+    [InlineData (0, false, 25)]
+    [InlineData (1, true, 24)]
+    [InlineData (1, false, 24)]
+    [InlineData (2, true, 23)]
+    [InlineData (2, false, 23)]
+    [InlineData (-2, true, 27)]
+    [InlineData (-2, false, 27)]
+    public void DimFill_Offset (int offset, bool width, int expected)
+    {
+        var super = new View { Width = 25, Height = 25 };
+
+        var view = new View
+        {
+            X = width ? offset : 0,
+            Y = width ? 0 : offset,
+            Width = width ? Dim.Fill () : 1,
+            Height = width ? 1 : Dim.Fill ()
+        };
+
+        super.Add (view);
+        super.BeginInit ();
+        super.EndInit ();
+        super.LayoutSubviews ();
+
+        Assert.Equal (25, super.Frame.Width);
+        Assert.Equal (25, super.Frame.Height);
+
+        if (width)
+        {
+            Assert.Equal (expected, view.Frame.Width);
+            Assert.Equal (1, view.Frame.Height);
+        }
+        else
+        {
+            Assert.Equal (1, view.Frame.Width);
+            Assert.Equal (expected, view.Frame.Height);
+        }
+    }
+
+    // TODO: Other Dim.Height tests (e.g. Equal?)
+
+    [Fact]
+    public void DimFill_SetsValue ()
+    {
+        var testMargin = 0;
+        Dim dim = Dim.Fill ();
+        Assert.Equal ($"Fill({testMargin})", dim.ToString ());
+
+        testMargin = 0;
+        dim = Dim.Fill (testMargin);
+        Assert.Equal ($"Fill({testMargin})", dim.ToString ());
+
+        testMargin = 5;
+        dim = Dim.Fill (testMargin);
+        Assert.Equal ($"Fill({testMargin})", dim.ToString ());
+    }
+
+    [Fact]
+    public void DimFill_Calculate_ReturnsCorrectValue ()
+    {
+        var dim = Dim.Fill ();
+        var result = dim.Calculate (0, 100, null, Dim.Dimension.None);
+        Assert.Equal (100, result);
+    }
+
+}

+ 48 - 0
UnitTests/View/Layout/Dim.FunctionTests.cs

@@ -0,0 +1,48 @@
+using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
+
+namespace Terminal.Gui.PosDimTests;
+
+public class DimFunctionTests (ITestOutputHelper output)
+{
+    private readonly ITestOutputHelper _output = output;
+
+
+    [Fact]
+    public void DimFunction_Equal ()
+    {
+        Func<int> f1 = () => 0;
+        Func<int> f2 = () => 0;
+
+        Dim dim1 = Dim.Function (f1);
+        Dim dim2 = Dim.Function (f2);
+        Assert.Equal (dim1, dim2);
+
+        f2 = () => 1;
+        dim2 = Dim.Function (f2);
+        Assert.NotEqual (dim1, dim2);
+    }
+
+    [Fact]
+    public void DimFunction_SetsValue ()
+    {
+        var text = "Test";
+        Dim dim = Dim.Function (() => text.Length);
+        Assert.Equal ("DimFunc(4)", dim.ToString ());
+
+        text = "New Test";
+        Assert.Equal ("DimFunc(8)", dim.ToString ());
+
+        text = "";
+        Assert.Equal ("DimFunc(0)", dim.ToString ());
+    }
+
+
+    [Fact]
+    public void DimFunction_Calculate_ReturnsCorrectValue ()
+    {
+        var dim = new DimFunc (() => 10);
+        var result = dim.Calculate (0, 100, null, Dim.Dimension.None);
+        Assert.Equal (10, result);
+    }
+}

+ 175 - 0
UnitTests/View/Layout/Dim.PercentTests.cs

@@ -0,0 +1,175 @@
+using System.Globalization;
+using System.Text;
+using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
+
+namespace Terminal.Gui.PosDimTests;
+
+public class DimPercentTests
+{
+    private readonly ITestOutputHelper _output;
+
+    [Fact]
+    public void DimFactor_Calculate_ReturnsCorrectValue ()
+    {
+        var dim = new DimFactor (0.5f);
+        var result = dim.Calculate (0, 100, null, Dim.Dimension.None);
+        Assert.Equal (50, result);
+    }
+
+
+    [Fact]
+    public void DimPercent_Equals ()
+    {
+        float n1 = 0;
+        float n2 = 0;
+        Dim dim1 = Dim.Percent (n1);
+        Dim dim2 = Dim.Percent (n2);
+        Assert.Equal (dim1, dim2);
+
+        n1 = n2 = 1;
+        dim1 = Dim.Percent (n1);
+        dim2 = Dim.Percent (n2);
+        Assert.Equal (dim1, dim2);
+
+        n1 = n2 = 0.5f;
+        dim1 = Dim.Percent (n1);
+        dim2 = Dim.Percent (n2);
+        Assert.Equal (dim1, dim2);
+
+        n1 = n2 = 100f;
+        dim1 = Dim.Percent (n1);
+        dim2 = Dim.Percent (n2);
+        Assert.Equal (dim1, dim2);
+
+        n1 = n2 = 0.3f;
+        dim1 = Dim.Percent (n1, true);
+        dim2 = Dim.Percent (n2, true);
+        Assert.Equal (dim1, dim2);
+
+        n1 = n2 = 0.3f;
+        dim1 = Dim.Percent (n1);
+        dim2 = Dim.Percent (n2, true);
+        Assert.NotEqual (dim1, dim2);
+
+        n1 = 0;
+        n2 = 1;
+        dim1 = Dim.Percent (n1);
+        dim2 = Dim.Percent (n2);
+        Assert.NotEqual (dim1, dim2);
+
+        n1 = 0.5f;
+        n2 = 1.5f;
+        dim1 = Dim.Percent (n1);
+        dim2 = Dim.Percent (n2);
+        Assert.NotEqual (dim1, dim2);
+    }
+
+    [Fact]
+    public void DimPercent_Invalid_Throws ()
+    {
+        Dim dim = Dim.Percent (0);
+        Assert.Throws<ArgumentException> (() => dim = Dim.Percent (-1));
+        Assert.Throws<ArgumentException> (() => dim = Dim.Percent (101));
+        Assert.Throws<ArgumentException> (() => dim = Dim.Percent (100.0001F));
+        Assert.Throws<ArgumentException> (() => dim = Dim.Percent (1000001));
+    }
+
+    [Theory]
+    [InlineData (0, false, true, 12)]
+    [InlineData (0, false, false, 12)]
+    [InlineData (1, false, true, 12)]
+    [InlineData (1, false, false, 12)]
+    [InlineData (2, false, true, 12)]
+    [InlineData (2, false, false, 12)]
+
+    [InlineData (0, true, true, 12)]
+    [InlineData (0, true, false, 12)]
+    [InlineData (1, true, true, 12)]
+    [InlineData (1, true, false, 12)]
+    [InlineData (2, true, true, 11)]
+    [InlineData (2, true, false, 11)]
+    public void DimPercent_Position (int position, bool usePosition, bool width, int expected)
+    {
+        var super = new View { Width = 25, Height = 25 };
+
+        var view = new View
+        {
+            X = width ? position : 0,
+            Y = width ? 0 : position,
+            Width = width ? Dim.Percent (50, usePosition) : 1,
+            Height = width ? 1 : Dim.Percent (50, usePosition)
+        };
+
+        super.Add (view);
+        super.BeginInit ();
+        super.EndInit ();
+        super.LayoutSubviews ();
+
+        Assert.Equal (25, super.Frame.Width);
+        Assert.Equal (25, super.Frame.Height);
+
+        if (width)
+        {
+            Assert.Equal (expected, view.Frame.Width);
+            Assert.Equal (1, view.Frame.Height);
+        }
+        else
+        {
+            Assert.Equal (1, view.Frame.Width);
+            Assert.Equal (expected, view.Frame.Height);
+        }
+    }
+
+    [Theory]
+    [InlineData (0, true)]
+    [InlineData (0, false)]
+    [InlineData (50, true)]
+    [InlineData (50, false)]
+    public void DimPercent_PlusOne (int startingDistance, bool testHorizontal)
+    {
+        var super = new View { Width = 100, Height = 100 };
+
+        var view = new View
+        {
+            X = testHorizontal ? startingDistance : 0,
+            Y = testHorizontal ? 0 : startingDistance,
+            Width = testHorizontal ? Dim.Percent (50) + 1 : 1,
+            Height = testHorizontal ? 1 : Dim.Percent (50) + 1
+        };
+
+        super.Add (view);
+        super.BeginInit ();
+        super.EndInit ();
+        super.LayoutSubviews ();
+
+        Assert.Equal (100, super.Frame.Width);
+        Assert.Equal (100, super.Frame.Height);
+
+        if (testHorizontal)
+        {
+            Assert.Equal (51, view.Frame.Width);
+            Assert.Equal (1, view.Frame.Height);
+        }
+        else
+        {
+            Assert.Equal (1, view.Frame.Width);
+            Assert.Equal (51, view.Frame.Height);
+        }
+    }
+
+    [Fact]
+    public void DimPercent_SetsValue ()
+    {
+        float f = 0;
+        Dim dim = Dim.Percent (f);
+        Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
+        f = 0.5F;
+        dim = Dim.Percent (f);
+        Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
+        f = 100;
+        dim = Dim.Percent (f);
+        Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
+    }
+
+}

+ 10 - 534
UnitTests/View/Layout/DimTests.cs → UnitTests/View/Layout/Dim.Tests.cs

@@ -7,7 +7,7 @@ using static Terminal.Gui.Dim;
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.PosDimTests;
 
 public class DimTests
 {
@@ -32,39 +32,6 @@ public class DimTests
         Assert.Equal (10, result);
     }
 
-    [Fact]
-    public void DimCombine_Calculate_ReturnsCorrectValue ()
-    {
-        var dim1 = new DimAbsolute (10);
-        var dim2 = new DimAbsolute (20);
-        var dim = dim1 + dim2;
-        var result = dim.Calculate (0, 100, null, Dim.Dimension.None);
-        Assert.Equal (30, result);
-    }
-
-    [Fact]
-    public void DimFactor_Calculate_ReturnsCorrectValue ()
-    {
-        var dim = new DimFactor (0.5f);
-        var result = dim.Calculate (0, 100, null, Dim.Dimension.None);
-        Assert.Equal (50, result);
-    }
-
-    [Fact]
-    public void DimFill_Calculate_ReturnsCorrectValue ()
-    {
-        var dim = Dim.Fill ();
-        var result = dim.Calculate (0, 100, null, Dim.Dimension.None);
-        Assert.Equal (100, result);
-    }
-
-    [Fact]
-    public void DimFunc_Calculate_ReturnsCorrectValue ()
-    {
-        var dim = new DimFunc (() => 10);
-        var result = dim.Calculate (0, 100, null, Dim.Dimension.None);
-        Assert.Equal (10, result);
-    }
 
     [Fact]
     public void DimView_Calculate_ReturnsCorrectValue ()
@@ -80,7 +47,7 @@ public class DimTests
     // A new test that does not depend on Application is needed.
     [Fact]
     [AutoInitShutdown]
-    public void Add_Operator ()
+    public void Dim_Add_Operator ()
     {
         Toplevel top = new ();
 
@@ -296,57 +263,6 @@ public class DimTests
         t.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 DimCombine_ObtuseScenario_Does_Not_Throw_If_Two_SubViews_Refs_The_Same_SuperView ()
-    {
-        var t = new View { Width = 80, Height = 25, Text = "top" };
-
-        var w = new Window
-        {
-            Width = Dim.Width (t) - 2, // 78
-            Height = Dim.Height (t) - 2 // 23
-        };
-        var f = new FrameView ();
-
-        var v1 = new View
-        {
-            Width = Dim.Width (w) - 2, // 76
-            Height = Dim.Height (w) - 2 // 21
-        };
-
-        var v2 = new View
-        {
-            Width = Dim.Width (v1) - 2, // 74
-            Height = Dim.Height (v1) - 2 // 19
-        };
-
-        f.Add (v1, v2);
-        w.Add (f);
-        t.Add (w);
-        t.BeginInit ();
-        t.EndInit ();
-
-        f.Width = Dim.Width (t) - Dim.Width (w) + 4; // 80 - 74 = 6
-        f.Height = Dim.Height (t) - Dim.Height (w) + 4; // 25 - 19 = 6
-
-        // BUGBUG: v2 - f references t and w here; t is f's super-superview and w is f's superview. This is supported!
-        Exception exception = Record.Exception (t.LayoutSubviews);
-        Assert.Null (exception);
-        Assert.Equal (80, t.Frame.Width);
-        Assert.Equal (25, t.Frame.Height);
-        Assert.Equal (78, w.Frame.Width);
-        Assert.Equal (23, w.Frame.Height);
-        Assert.Equal (6, f.Frame.Width);
-        Assert.Equal (6, f.Frame.Height);
-        Assert.Equal (76, v1.Frame.Width);
-        Assert.Equal (21, v1.Frame.Height);
-        Assert.Equal (74, v2.Frame.Width);
-        Assert.Equal (19, v2.Frame.Height);
-        t.Dispose ();
-    }
 
     // See #2461
     //[Fact]
@@ -367,88 +283,6 @@ public class DimTests
     //	Assert.Throws<InvalidOperationException> (() => super.LayoutSubviews ());
     //}
 
-    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
-    // TODO: A new test that calls SetRelativeLayout directly is needed.
-
-    /// <summary>This is an intentionally obtuse test. See https://github.com/gui-cs/Terminal.Gui/issues/2461</summary>
-    [Fact]
-    [TestRespondersDisposed]
-    public void Combine_ObtuseScenario_Throw_If_SuperView_Refs_SubView ()
-    {
-        var t = new View { Width = 80, Height = 25 };
-
-        var w = new Window
-        {
-            Width = Dim.Width (t) - 2, // 78
-            Height = Dim.Height (t) - 2 // 23
-        };
-        var f = new FrameView ();
-
-        var v1 = new View
-        {
-            Width = Dim.Width (w) - 2, // 76
-            Height = Dim.Height (w) - 2 // 21
-        };
-
-        var v2 = new View
-        {
-            Width = Dim.Width (v1) - 2, // 74
-            Height = Dim.Height (v1) - 2 // 19
-        };
-
-        f.Add (v1, v2);
-        w.Add (f);
-        t.Add (w);
-        t.BeginInit ();
-        t.EndInit ();
-
-        f.Width = Dim.Width (t) - Dim.Width (v2); // 80 - 74 = 6
-        f.Height = Dim.Height (t) - Dim.Height (v2); // 25 - 19 = 6
-
-        Assert.Throws<InvalidOperationException> (t.LayoutSubviews);
-        Assert.Equal (80, t.Frame.Width);
-        Assert.Equal (25, t.Frame.Height);
-        Assert.Equal (78, w.Frame.Width);
-        Assert.Equal (23, w.Frame.Height);
-        Assert.Equal (6, f.Frame.Width);
-        Assert.Equal (6, f.Frame.Height);
-        Assert.Equal (76, v1.Frame.Width);
-        Assert.Equal (21, v1.Frame.Height);
-        Assert.Equal (74, v2.Frame.Width);
-        Assert.Equal (19, v2.Frame.Height);
-        t.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 Combine_View_Not_Added_Throws ()
-    {
-        var t = new View { Width = 80, Height = 50 };
-
-        var super = new View { Width = Dim.Width (t) - 2, Height = Dim.Height (t) - 2 };
-        t.Add (super);
-
-        var sub = new View ();
-        super.Add (sub);
-
-        var v1 = new View { Width = Dim.Width (super) - 2, Height = Dim.Height (super) - 2 };
-        var v2 = new View { Width = Dim.Width (v1) - 2, Height = Dim.Height (v1) - 2 };
-        sub.Add (v1);
-
-        // v2 not added to sub; should cause exception on Layout since it's referenced by sub.
-        sub.Width = Dim.Fill () - Dim.Width (v2);
-        sub.Height = Dim.Fill () - Dim.Height (v2);
-
-        t.BeginInit ();
-        t.EndInit ();
-
-        Assert.Throws<InvalidOperationException> (() => t.LayoutSubviews ());
-        t.Dispose ();
-        v2.Dispose ();
-    }
-
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
     // TODO: A new test that calls SetRelativeLayout directly is needed.
     [Fact]
@@ -482,149 +316,9 @@ public class DimTests
         t.Dispose ();
     }
 
-    [Fact]
-    public void Fill_Equal ()
-    {
-        var margin1 = 0;
-        var margin2 = 0;
-        Dim dim1 = Dim.Fill (margin1);
-        Dim dim2 = Dim.Fill (margin2);
-        Assert.Equal (dim1, dim2);
-    }
-
-    // Tests that Dim.Fill honors the margin parameter correctly
-    [Theory]
-    [InlineData (0, true, 25)]
-    [InlineData (0, false, 25)]
-    [InlineData (1, true, 24)]
-    [InlineData (1, false, 24)]
-    [InlineData (2, true, 23)]
-    [InlineData (2, false, 23)]
-    [InlineData (-2, true, 27)]
-    [InlineData (-2, false, 27)]
-    public void Fill_Margin (int margin, bool width, int expected)
-    {
-        var super = new View { Width = 25, Height = 25 };
-
-        var view = new View
-        {
-            X = 0,
-            Y = 0,
-            Width = width ? Dim.Fill (margin) : 1,
-            Height = width ? 1 : Dim.Fill (margin)
-        };
-
-        super.Add (view);
-        super.BeginInit ();
-        super.EndInit ();
-        super.LayoutSubviews ();
-
-        Assert.Equal (25, super.Frame.Width);
-        Assert.Equal (25, super.Frame.Height);
-
-        if (width)
-        {
-            Assert.Equal (expected, view.Frame.Width);
-            Assert.Equal (1, view.Frame.Height);
-        }
-        else
-        {
-            Assert.Equal (1, view.Frame.Width);
-            Assert.Equal (expected, view.Frame.Height);
-        }
-    }
-
-    // Tests that Dim.Fill fills the dimension REMAINING from the View's X position to the end of the super view's width
-    [Theory]
-    [InlineData (0, true, 25)]
-    [InlineData (0, false, 25)]
-    [InlineData (1, true, 24)]
-    [InlineData (1, false, 24)]
-    [InlineData (2, true, 23)]
-    [InlineData (2, false, 23)]
-    [InlineData (-2, true, 27)]
-    [InlineData (-2, false, 27)]
-    public void Fill_Offset (int offset, bool width, int expected)
-    {
-        var super = new View { Width = 25, Height = 25 };
-
-        var view = new View
-        {
-            X = width ? offset : 0,
-            Y = width ? 0 : offset,
-            Width = width ? Dim.Fill () : 1,
-            Height = width ? 1 : Dim.Fill ()
-        };
-
-        super.Add (view);
-        super.BeginInit ();
-        super.EndInit ();
-        super.LayoutSubviews ();
-
-        Assert.Equal (25, super.Frame.Width);
-        Assert.Equal (25, super.Frame.Height);
-
-        if (width)
-        {
-            Assert.Equal (expected, view.Frame.Width);
-            Assert.Equal (1, view.Frame.Height);
-        }
-        else
-        {
-            Assert.Equal (1, view.Frame.Width);
-            Assert.Equal (expected, view.Frame.Height);
-        }
-    }
-
-    // TODO: Other Dim.Height tests (e.g. Equal?)
-
-    [Fact]
-    public void Fill_SetsValue ()
-    {
-        var testMargin = 0;
-        Dim dim = Dim.Fill ();
-        Assert.Equal ($"Fill({testMargin})", dim.ToString ());
-
-        testMargin = 0;
-        dim = Dim.Fill (testMargin);
-        Assert.Equal ($"Fill({testMargin})", dim.ToString ());
-
-        testMargin = 5;
-        dim = Dim.Fill (testMargin);
-        Assert.Equal ($"Fill({testMargin})", dim.ToString ());
-    }
-
-    [Fact]
-    public void Function_Equal ()
-    {
-        Func<int> f1 = () => 0;
-        Func<int> f2 = () => 0;
-
-        Dim dim1 = Dim.Function (f1);
-        Dim dim2 = Dim.Function (f2);
-        Assert.Equal (dim1, dim2);
-
-        f2 = () => 1;
-        dim2 = Dim.Function (f2);
-        Assert.NotEqual (dim1, dim2);
-    }
 
     [Fact]
-    public void Function_SetsValue ()
-    {
-        var text = "Test";
-        Dim dim = Dim.Function (() => text.Length);
-        Assert.Equal ("DimFunc(4)", dim.ToString ());
-
-        text = "New Test";
-        Assert.Equal ("DimFunc(8)", dim.ToString ());
-
-        text = "";
-        Assert.Equal ("DimFunc(0)", dim.ToString ());
-    }
-
-    [Fact]
-    public void Height_Set_To_Null_Throws ()
+    public void DimHeight_Set_To_Null_Throws ()
     {
         Dim dim = Dim.Height (null);
         Assert.Throws<NullReferenceException> (() => dim.ToString ());
@@ -632,7 +326,7 @@ public class DimTests
 
     [Fact]
     [TestRespondersDisposed]
-    public void Height_SetsValue ()
+    public void DimHeight_SetsValue ()
     {
         var testVal = Rectangle.Empty;
         var testValview = new View { Frame = testVal };
@@ -928,160 +622,6 @@ public class DimTests
         Application.Run (t);
     }
 
-    [Fact]
-    public void Percent_Equals ()
-    {
-        float n1 = 0;
-        float n2 = 0;
-        Dim dim1 = Dim.Percent (n1);
-        Dim dim2 = Dim.Percent (n2);
-        Assert.Equal (dim1, dim2);
-
-        n1 = n2 = 1;
-        dim1 = Dim.Percent (n1);
-        dim2 = Dim.Percent (n2);
-        Assert.Equal (dim1, dim2);
-
-        n1 = n2 = 0.5f;
-        dim1 = Dim.Percent (n1);
-        dim2 = Dim.Percent (n2);
-        Assert.Equal (dim1, dim2);
-
-        n1 = n2 = 100f;
-        dim1 = Dim.Percent (n1);
-        dim2 = Dim.Percent (n2);
-        Assert.Equal (dim1, dim2);
-
-        n1 = n2 = 0.3f;
-        dim1 = Dim.Percent (n1, true);
-        dim2 = Dim.Percent (n2, true);
-        Assert.Equal (dim1, dim2);
-
-        n1 = n2 = 0.3f;
-        dim1 = Dim.Percent (n1);
-        dim2 = Dim.Percent (n2, true);
-        Assert.NotEqual (dim1, dim2);
-
-        n1 = 0;
-        n2 = 1;
-        dim1 = Dim.Percent (n1);
-        dim2 = Dim.Percent (n2);
-        Assert.NotEqual (dim1, dim2);
-
-        n1 = 0.5f;
-        n2 = 1.5f;
-        dim1 = Dim.Percent (n1);
-        dim2 = Dim.Percent (n2);
-        Assert.NotEqual (dim1, dim2);
-    }
-
-    [Fact]
-    public void Percent_Invalid_Throws ()
-    {
-        Dim dim = Dim.Percent (0);
-        Assert.Throws<ArgumentException> (() => dim = Dim.Percent (-1));
-        Assert.Throws<ArgumentException> (() => dim = Dim.Percent (101));
-        Assert.Throws<ArgumentException> (() => dim = Dim.Percent (100.0001F));
-        Assert.Throws<ArgumentException> (() => dim = Dim.Percent (1000001));
-    }
-
-    [Theory]
-    [InlineData (0, false, true, 12)]
-    [InlineData (0, false, false, 12)]
-    [InlineData (1, false, true, 12)]
-    [InlineData (1, false, false, 12)]
-    [InlineData (2, false, true, 12)]
-    [InlineData (2, false, false, 12)]
-
-    [InlineData (0, true, true, 12)]
-    [InlineData (0, true, false, 12)]
-    [InlineData (1, true, true, 12)]
-    [InlineData (1, true, false, 12)]
-    [InlineData (2, true, true, 11)]
-    [InlineData (2, true, false, 11)]
-    public void Percent_Position (int position, bool usePosition, bool width, int expected)
-    {
-        var super = new View { Width = 25, Height = 25 };
-
-        var view = new View
-        {
-            X = width ? position : 0,
-            Y = width ? 0 : position,
-            Width = width ? Dim.Percent (50, usePosition) : 1,
-            Height = width ? 1 : Dim.Percent (50, usePosition)
-        };
-
-        super.Add (view);
-        super.BeginInit ();
-        super.EndInit ();
-        super.LayoutSubviews ();
-
-        Assert.Equal (25, super.Frame.Width);
-        Assert.Equal (25, super.Frame.Height);
-
-        if (width)
-        {
-            Assert.Equal (expected, view.Frame.Width);
-            Assert.Equal (1, view.Frame.Height);
-        }
-        else
-        {
-            Assert.Equal (1, view.Frame.Width);
-            Assert.Equal (expected, view.Frame.Height);
-        }
-    }
-
-    [Theory]
-    [InlineData (0, true)]
-    [InlineData (0, false)]
-    [InlineData (50, true)]
-    [InlineData (50, false)]
-    public void Percent_PlusOne (int startingDistance, bool testHorizontal)
-    {
-        var super = new View { Width = 100, Height = 100 };
-
-        var view = new View
-        {
-            X = testHorizontal ? startingDistance : 0,
-            Y = testHorizontal ? 0 : startingDistance,
-            Width = testHorizontal ? Dim.Percent (50) + 1 : 1,
-            Height = testHorizontal ? 1 : Dim.Percent (50) + 1
-        };
-
-        super.Add (view);
-        super.BeginInit ();
-        super.EndInit ();
-        super.LayoutSubviews ();
-
-        Assert.Equal (100, super.Frame.Width);
-        Assert.Equal (100, super.Frame.Height);
-
-        if (testHorizontal)
-        {
-            Assert.Equal (51, view.Frame.Width);
-            Assert.Equal (1, view.Frame.Height);
-        }
-        else
-        {
-            Assert.Equal (1, view.Frame.Width);
-            Assert.Equal (51, view.Frame.Height);
-        }
-    }
-
-    [Fact]
-    public void Percent_SetsValue ()
-    {
-        float f = 0;
-        Dim dim = Dim.Percent (f);
-        Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
-        f = 0.5F;
-        dim = Dim.Percent (f);
-        Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
-        f = 100;
-        dim = Dim.Percent (f);
-        Assert.Equal ($"Factor({f / 100:0.###},{false})", dim.ToString ());
-    }
-
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
     // TODO: A new test that calls SetRelativeLayout directly is needed.
     [Fact]
@@ -1107,7 +647,7 @@ public class DimTests
     }
 
     [Fact]
-    public void Sized_Equals ()
+    public void DimSized_Equals ()
     {
         var n1 = 0;
         var n2 = 0;
@@ -1133,7 +673,7 @@ public class DimTests
     }
 
     [Fact]
-    public void Sized_SetsValue ()
+    public void DimSized_SetsValue ()
     {
         Dim dim = Dim.Sized (0);
         Assert.Equal ("Absolute(0)", dim.ToString ());
@@ -1146,71 +686,7 @@ public class DimTests
         dim = Dim.Sized (testVal);
         Assert.Equal ($"Absolute({testVal})", dim.ToString ());
     }
-
-    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
-    // TODO: A new test that calls SetRelativeLayout directly is needed.
-    [Fact]
-    [AutoInitShutdown]
-    public void Subtract_Operator ()
-    {
-        Toplevel top = new Toplevel ();
-
-        var view = new View { X = 0, Y = 0, Width = 20, Height = 0 };
-        var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
-        var count = 20;
-        List<Label> listLabels = new ();
-
-        for (var i = 0; i < count; i++)
-        {
-            field.Text = $"Label {i}";
-            var label = new Label { X = 0, Y = view.Viewport.Height, /*Width = 20,*/ Text = field.Text };
-            view.Add (label);
-            Assert.Equal ($"Label {i}", label.Text);
-            Assert.Equal ($"Absolute({i})", label.Y.ToString ());
-            listLabels.Add (label);
-
-            Assert.Equal ($"Absolute({i})", view.Height.ToString ());
-            view.Height += 1;
-            Assert.Equal ($"Absolute({i + 1})", view.Height.ToString ());
-        }
-
-        field.KeyDown += (s, k) =>
-                         {
-                             if (k.KeyCode == KeyCode.Enter)
-                             {
-                                 Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
-                                 view.Remove (listLabels [count - 1]);
-                                 listLabels [count - 1].Dispose ();
-
-                                 Assert.Equal ($"Absolute({count})", view.Height.ToString ());
-                                 view.Height -= 1;
-                                 count--;
-                                 Assert.Equal ($"Absolute({count})", view.Height.ToString ());
-                             }
-                         };
-
-        Application.Iteration += (s, a) =>
-                                 {
-                                     while (count > 0)
-                                     {
-                                         field.NewKeyDownEvent (new Key (KeyCode.Enter));
-                                     }
-
-                                     Application.RequestStop ();
-                                 };
-
-        var win = new Window ();
-        win.Add (view);
-        win.Add (field);
-
-        top.Add (win);
-
-        Application.Run (top);
-        top.Dispose ();
-
-        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]
@@ -1262,7 +738,7 @@ public class DimTests
 
     [Fact]
     [TestRespondersDisposed]
-    public void Width_Equals ()
+    public void DimWidth_Equals ()
     {
         var testRect1 = Rectangle.Empty;
         var view1 = new View { Frame = testRect1 };
@@ -1312,7 +788,7 @@ public class DimTests
     }
 
     [Fact]
-    public void Width_Set_To_Null_Throws ()
+    public void DimWidth_Set_To_Null_Throws ()
     {
         Dim dim = Dim.Width (null);
         Assert.Throws<NullReferenceException> (() => dim.ToString ());
@@ -1320,7 +796,7 @@ public class DimTests
 
     [Fact]
     [TestRespondersDisposed]
-    public void Width_SetsValue ()
+    public void DimWidth_SetsValue ()
     {
         var testVal = Rectangle.Empty;
         var testValView = new View { Frame = testVal };

+ 1 - 1
UnitTests/View/Layout/FrameTests.cs

@@ -1,6 +1,6 @@
 using Xunit.Abstractions;
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.LayoutTests;
 
 public class FrameTests (ITestOutputHelper output)
 {

+ 3 - 508
UnitTests/View/Layout/LayoutTests.cs

@@ -1,414 +1,10 @@
 using Xunit.Abstractions;
-using static Unix.Terminal.Curses;
 
-// Alias Console to MockConsole so we don't accidentally use Console
+namespace Terminal.Gui.LayoutTests;
 
-namespace Terminal.Gui.ViewTests;
-
-public class LayoutTests
+public class LayoutTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public LayoutTests (ITestOutputHelper output) { _output = output; }
-
-    // Tested in AbsoluteLayoutTests.cs
-    // public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
-
-    [Theory]
-    [AutoInitShutdown]
-    [InlineData (1)]
-    [InlineData (2)]
-    [InlineData (3)]
-    [InlineData (4)]
-    [InlineData (5)]
-    [InlineData (6)]
-    [InlineData (7)]
-    [InlineData (8)]
-    [InlineData (9)]
-    [InlineData (10)]
-    public void Dim_CenteredSubView_85_Percent_Height (int height)
-    {
-        var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
-
-        var subview = new Window
-        {
-            X = Pos.Center (), Y = Pos.Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
-        };
-
-        win.Add (subview);
-
-        RunState rs = Application.Begin (win);
-        var firstIteration = false;
-
-        ((FakeDriver)Application.Driver).SetBufferSize (20, height);
-        Application.RunIteration (ref rs, ref firstIteration);
-        var expected = string.Empty;
-
-        switch (height)
-        {
-            case 1:
-                //Assert.Equal (new (0, 0, 17, 0), subview.Frame);
-                expected = @"
-────────────────────";
-
-                break;
-            case 2:
-                //Assert.Equal (new (0, 0, 17, 1), subview.Frame);
-                expected = @"
-┌──────────────────┐
-└──────────────────┘
-";
-
-                break;
-            case 3:
-                //Assert.Equal (new (0, 0, 17, 2), subview.Frame);
-                expected = @"
-┌──────────────────┐
-│                  │
-└──────────────────┘
-";
-
-                break;
-            case 4:
-                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
-                expected = @"
-┌──────────────────┐
-│ ───────────────  │
-│                  │
-└──────────────────┘";
-
-                break;
-            case 5:
-                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
-                expected = @"
-┌──────────────────┐
-│ ┌─────────────┐  │
-│ └─────────────┘  │
-│                  │
-└──────────────────┘";
-
-                break;
-            case 6:
-                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
-                expected = @"
-┌──────────────────┐
-│ ┌─────────────┐  │
-│ │             │  │
-│ └─────────────┘  │
-│                  │
-└──────────────────┘";
-
-                break;
-            case 7:
-                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
-                expected = @"
-┌──────────────────┐
-│ ┌─────────────┐  │
-│ │             │  │
-│ │             │  │
-│ └─────────────┘  │
-│                  │
-└──────────────────┘";
-
-                break;
-            case 8:
-                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
-                expected = @"
-┌──────────────────┐
-│ ┌─────────────┐  │
-│ │             │  │
-│ │             │  │
-│ │             │  │
-│ └─────────────┘  │
-│                  │
-└──────────────────┘";
-
-                break;
-            case 9:
-                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
-                expected = @"
-┌──────────────────┐
-│                  │
-│ ┌─────────────┐  │
-│ │             │  │
-│ │             │  │
-│ │             │  │
-│ └─────────────┘  │
-│                  │
-└──────────────────┘";
-
-                break;
-            case 10:
-                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
-                expected = @"
-┌──────────────────┐
-│                  │
-│ ┌─────────────┐  │
-│ │             │  │
-│ │             │  │
-│ │             │  │
-│ │             │  │
-│ └─────────────┘  │
-│                  │
-└──────────────────┘";
-
-                break;
-        }
-
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Application.End (rs);
-    }
-
-    [Theory]
-    [AutoInitShutdown]
-    [InlineData (1)]
-    [InlineData (2)]
-    [InlineData (3)]
-    [InlineData (4)]
-    [InlineData (5)]
-    [InlineData (6)]
-    [InlineData (7)]
-    [InlineData (8)]
-    [InlineData (9)]
-    [InlineData (10)]
-    public void Dim_CenteredSubView_85_Percent_Width (int width)
-    {
-        var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
-
-        var subview = new Window
-        {
-            X = Pos.Center (), Y = Pos.Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
-        };
-
-        win.Add (subview);
-
-        RunState rs = Application.Begin (win);
-        var firstIteration = false;
-
-        ((FakeDriver)Application.Driver).SetBufferSize (width, 7);
-        Application.RunIteration (ref rs, ref firstIteration);
-        var expected = string.Empty;
-
-        switch (width)
-        {
-            case 1:
-                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
-
-                expected = @"
-│
-│
-│
-│
-│
-│
-│";
-
-                break;
-            case 2:
-                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
-
-                expected = @"
-┌┐
-││
-││
-││
-││
-││
-└┘";
-
-                break;
-            case 3:
-                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
-
-                expected = @"
-┌─┐
-│ │
-│ │
-│ │
-│ │
-│ │
-└─┘";
-
-                break;
-            case 4:
-                Assert.Equal (new Rectangle (0, 0, 1, 4), subview.Frame);
-
-                expected = @"
-┌──┐
-││ │
-││ │
-││ │
-││ │
-│  │
-└──┘";
-
-                break;
-            case 5:
-                Assert.Equal (new Rectangle (0, 0, 2, 4), subview.Frame);
-
-                expected = @"
-┌───┐
-│┌┐ │
-│││ │
-│││ │
-│└┘ │
-│   │
-└───┘";
-
-                break;
-            case 6:
-                Assert.Equal (new Rectangle (0, 0, 3, 4), subview.Frame);
-
-                expected = @"
-┌────┐
-│┌─┐ │
-││ │ │
-││ │ │
-│└─┘ │
-│    │
-└────┘";
-
-                break;
-            case 7:
-                Assert.Equal (new Rectangle (0, 0, 4, 4), subview.Frame);
-
-                expected = @"
-┌─────┐
-│┌──┐ │
-││  │ │
-││  │ │
-│└──┘ │
-│     │
-└─────┘";
-
-                break;
-            case 8:
-                Assert.Equal (new Rectangle (0, 0, 5, 4), subview.Frame);
-
-                expected = @"
-┌──────┐
-│┌───┐ │
-││   │ │
-││   │ │
-│└───┘ │
-│      │
-└──────┘";
-
-                break;
-            case 9:
-                Assert.Equal (new Rectangle (1, 0, 5, 4), subview.Frame);
-
-                expected = @"
-┌───────┐
-│ ┌───┐ │
-│ │   │ │
-│ │   │ │
-│ └───┘ │
-│       │
-└───────┘";
-
-                break;
-            case 10:
-                Assert.Equal (new Rectangle (1, 0, 6, 4), subview.Frame);
-
-                expected = @"
-┌────────┐
-│ ┌────┐ │
-│ │    │ │
-│ │    │ │
-│ └────┘ │
-│        │
-└────────┘";
-
-                break;
-        }
-
-        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
-        Application.End (rs);
-    }
-
-    [Fact]
-    [AutoInitShutdown]
-    public void DimFill_SizedCorrectly ()
-    {
-        var view = new View { Width = Dim.Fill (), Height = Dim.Fill (), BorderStyle = LineStyle.Single };
-        var top = new Toplevel ();
-        top.Add (view);
-        RunState rs = Application.Begin (top);
-        ((FakeDriver)Application.Driver).SetBufferSize (32, 5);
-
-        //view.SetNeedsLayout ();
-        top.LayoutSubviews ();
-
-        //view.SetRelativeLayout (new (0, 0, 32, 5));
-        Assert.Equal (32, view.Frame.Width);
-        Assert.Equal (5, view.Frame.Height);
-    }
-
-    [Fact]
-    [TestRespondersDisposed]
-    public void Draw_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
-    {
-        Application.Init (new FakeDriver ());
-
-        Toplevel top = new ();
-
-        var view = new View { X = -2, Text = "view" };
-        top.Add (view);
-
-        Application.Iteration += (s, a) =>
-                                 {
-                                     Assert.Equal (-2, view.X);
-
-                                     Application.RequestStop ();
-                                 };
-
-        try
-        {
-            Application.Run (top);
-        }
-        catch (IndexOutOfRangeException ex)
-        {
-            // After the fix this exception will not be caught.
-            Assert.IsType<IndexOutOfRangeException> (ex);
-        }
-
-        top.Dispose ();
-        // Shutdown must be called to safely clean up Application if Init has been called
-        Application.Shutdown ();
-    }
-
-    [Fact]
-    [TestRespondersDisposed]
-    public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
-    {
-        Application.Init (new FakeDriver ());
-
-        Toplevel top = new ();
-
-        var view = new View { Y = -2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight, Text = "view" };
-        top.Add (view);
-
-        Application.Iteration += (s, a) =>
-                                 {
-                                     Assert.Equal (-2, view.Y);
-
-                                     Application.RequestStop ();
-                                 };
-
-        try
-        {
-            Application.Run (top);
-        }
-        catch (IndexOutOfRangeException ex)
-        {
-            // After the fix this exception will not be caught.
-            Assert.IsType<IndexOutOfRangeException> (ex);
-        }
-
-        top.Dispose ();
-        // Shutdown must be called to safely clean up Application if Init has been called
-        Application.Shutdown ();
-    }
+    private readonly ITestOutputHelper _output = output;
 
     [Fact]
     public void LayoutSubviews_No_SuperView ()
@@ -483,107 +79,6 @@ public class LayoutTests
         super.Dispose ();
     }
 
-    // Was named AutoSize_Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
-    // but doesn't actually have anything to do with AutoSize.
-    [Fact]
-    public void
-        Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
-    {
-        Application.Init (new FakeDriver ());
-
-        Toplevel t = new ();
-
-        var w = new Window { X = Pos.Left (t) + 2, Y = Pos.At (2) };
-
-        var v = new View { X = Pos.Center (), Y = Pos.Percent (10) };
-
-        w.Add (v);
-        t.Add (w);
-
-        t.Ready += (s, e) =>
-                   {
-                       v.Frame = new Rectangle (2, 2, 10, 10);
-                       Assert.Equal (2, v.X = 2);
-                       Assert.Equal (2, v.Y = 2);
-                   };
-
-        Application.Iteration += (s, a) => Application.RequestStop ();
-
-        Application.Run (t);
-        t.Dispose ();
-        Application.Shutdown ();
-    }
-
-    [Fact]
-    [SetupFakeDriver]
-    public void PosCombine_DimCombine_View_With_SubViews ()
-    {
-        var clicked = false;
-        Toplevel top = new Toplevel() { Width = 80, Height = 25 };
-        var win1 = new Window { Id = "win1", Width = 20, Height = 10 };
-        var view1 = new View { Text = "view1", AutoSize = true }; // BUGBUG: AutoSize or Width must be set
-        var win2 = new Window { Id = "win2", Y = Pos.Bottom (view1) + 1, Width = 10, Height = 3 };
-        var view2 = new View { Id = "view2", Width = Dim.Fill (), Height = 1, CanFocus = true };
-        view2.MouseClick += (sender, e) => clicked = true;
-        var view3 = new View { Id = "view3", Width = Dim.Fill (1), Height = 1, CanFocus = true };
-
-        view2.Add (view3);
-        win2.Add (view2);
-        win1.Add (view1, win2);
-        top.Add (win1);
-        top.BeginInit();
-        top.EndInit();
-
-        Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
-        Assert.Equal (new Rectangle (0, 0, 5, 1), view1.Frame);
-        Assert.Equal (new Rectangle (0, 0, 20, 10), win1.Frame);
-        Assert.Equal (new Rectangle (0, 2, 10, 3), win2.Frame);
-        Assert.Equal (new Rectangle (0, 0, 8, 1), view2.Frame);
-        Assert.Equal (new Rectangle (0, 0, 7, 1), view3.Frame);
-        var foundView = View.FindDeepestView (top, 9, 4);
-        Assert.Equal (foundView, view2);
-    }
-
-    [Fact]
-    public void PosCombine_Refs_SuperView_Throws ()
-    {
-        Application.Init (new FakeDriver ());
-
-        var top = new Toplevel ();
-        var w = new Window { X = Pos.Left (top) + 2, Y = Pos.Top (top) + 2 };
-        var f = new FrameView ();
-        var v1 = new View { X = Pos.Left (w) + 2, Y = Pos.Top (w) + 2 };
-        var v2 = new View { X = Pos.Left (v1) + 2, Y = Pos.Top (v1) + 2 };
-
-        f.Add (v1, v2);
-        w.Add (f);
-        top.Add (w);
-        Application.Begin (top);
-
-        f.X = Pos.X (Application.Top) + Pos.X (v2) - Pos.X (v1);
-        f.Y = Pos.Y (Application.Top) + Pos.Y (v2) - Pos.Y (v1);
-
-        Application.Top.LayoutComplete += (s, e) =>
-                                          {
-                                              Assert.Equal (0, Application.Top.Frame.X);
-                                              Assert.Equal (0, Application.Top.Frame.Y);
-                                              Assert.Equal (2, w.Frame.X);
-                                              Assert.Equal (2, w.Frame.Y);
-                                              Assert.Equal (2, f.Frame.X);
-                                              Assert.Equal (2, f.Frame.Y);
-                                              Assert.Equal (4, v1.Frame.X);
-                                              Assert.Equal (4, v1.Frame.Y);
-                                              Assert.Equal (6, v2.Frame.X);
-                                              Assert.Equal (6, v2.Frame.Y);
-                                          };
-
-        Application.Iteration += (s, a) => Application.RequestStop ();
-
-        Assert.Throws<InvalidOperationException> (() => Application.Run ());
-        top.Dispose ();
-        Application.Shutdown ();
-    }
-
     [Fact]
     public void TopologicalSort_Missing_Add ()
     {

+ 22 - 13
UnitTests/View/Layout/AnchorEndTests.cs → UnitTests/View/Layout/Pos.AnchorEndTests.cs

@@ -1,9 +1,10 @@
 using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
 using static Terminal.Gui.Pos;
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.PosDimTests;
 
-public class AnchorEndTests (ITestOutputHelper output)
+public class PosAnchorEndTests (ITestOutputHelper output)
 {
     [Fact]
     public void PosAnchorEnd_Constructor ()
@@ -55,14 +56,14 @@ public class AnchorEndTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void AnchorEnd_CreatesCorrectInstance ()
+    public void  PosAnchorEnd_CreatesCorrectInstance ()
     {
         var pos = Pos.AnchorEnd (10);
         Assert.IsType<PosAnchorEnd> (pos);
     }
 
     [Fact]
-    public void AnchorEnd_Negative_Throws ()
+    public void  PosAnchorEnd_Negative_Throws ()
     {
         Pos pos;
         int n = -1;
@@ -72,7 +73,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     [Theory]
     [InlineData (0)]
     [InlineData (1)]
-    public void AnchorEnd_SetsValue_Anchor_Is_Negative (int offset)
+    public void  PosAnchorEnd_SetsValue_Anchor_Is_Negative (int offset)
     {
         Pos pos = Pos.AnchorEnd (offset);
         Assert.Equal (offset, -pos.Anchor (0));
@@ -86,7 +87,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     [InlineData (20, 10, 5)]
     [InlineData (25, 10, 0)]
     [InlineData (26, 10, -1)]
-    public void AnchorEnd_With_Offset_PositionsViewOffsetFromRight (int offset, int width, int expectedXPosition)
+    public void  PosAnchorEnd_With_Offset_PositionsViewOffsetFromRight (int offset, int width, int expectedXPosition)
     {
         // Arrange
         var superView = new View { Width = 25, Height = 25 };
@@ -110,7 +111,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     // UseDimForOffset tests
 
     [Fact]
-    public void AnchorEnd_UseDimForOffset_CreatesCorrectInstance ()
+    public void  PosAnchorEnd_UseDimForOffset_CreatesCorrectInstance ()
     {
         var pos = Pos.AnchorEnd ();
         Assert.IsType<PosAnchorEnd> (pos);
@@ -118,7 +119,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void AnchorEnd_UseDimForOffset_SetsValue_Anchor_Is_Negative ()
+    public void  PosAnchorEnd_UseDimForOffset_SetsValue_Anchor_Is_Negative ()
     {
         Pos pos = Pos.AnchorEnd ();
         Assert.Equal (-10, -pos.Anchor (10));
@@ -131,7 +132,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     [InlineData (11, 14)]
     [InlineData (25, 0)]
     [InlineData (26, -1)]
-    public void AnchorEnd_UseDimForOffset_PositionsViewOffsetByDim (int dim, int expectedXPosition)
+    public void  PosAnchorEnd_UseDimForOffset_PositionsViewOffsetByDim (int dim, int expectedXPosition)
     {
         // Arrange
         var superView = new View { Width = 25, Height = 25 };
@@ -157,7 +158,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     [InlineData (10, 23)]
     [InlineData (50, 13)]
     [InlineData (100, 0)]
-    public void AnchorEnd_UseDimForOffset_DimPercent_PositionsViewOffsetByDim (int percent, int expectedXPosition)
+    public void  PosAnchorEnd_UseDimForOffset_DimPercent_PositionsViewOffsetByDim (int percent, int expectedXPosition)
     {
         // Arrange
         var superView = new View { Width = 25, Height = 25 };
@@ -181,7 +182,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     // This test used to be Dialog_In_Window_With_TextField_And_Button_AnchorEnd in DialogTests.
     [Fact]
     [SetupFakeDriver]
-    public void AnchorEnd_View_And_Button ()
+    public void  PosAnchorEnd_View_And_Button ()
     {
         ((FakeDriver)Application.Driver).SetBufferSize (20, 5);
 
@@ -237,7 +238,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     // TODO: A new test that calls SetRelativeLayout directly is needed.
     [Fact]
     [AutoInitShutdown]
-    public void AnchorEnd_Equal_Inside_Window ()
+    public void  PosAnchorEnd_Equal_Inside_Window ()
     {
         var viewWidth = 10;
         var viewHeight = 1;
@@ -265,7 +266,7 @@ public class AnchorEndTests (ITestOutputHelper output)
     // TODO: A new test that calls SetRelativeLayout directly is needed.
     [Fact]
     [AutoInitShutdown]
-    public void AnchorEnd_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
+    public void  PosAnchorEnd_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
     {
         var viewWidth = 10;
         var viewHeight = 1;
@@ -294,4 +295,12 @@ public class AnchorEndTests (ITestOutputHelper output)
         Application.End (rs);
     }
 
+    [Fact]
+    public void PosAnchorEnd_Calculate_ReturnsExpectedValue ()
+    {
+        var posAnchorEnd = new PosAnchorEnd (5);
+        var result = posAnchorEnd.Calculate (10, new DimAbsolute (2), null, Dimension.None);
+        Assert.Equal (5, result);
+    }
+
 }

+ 378 - 0
UnitTests/View/Layout/Pos.CenterTests.cs

@@ -0,0 +1,378 @@
+using Microsoft.VisualStudio.TestPlatform.Utilities;
+using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
+using static Terminal.Gui.Pos;
+
+namespace Terminal.Gui.PosDimTests;
+
+public class PosCenterTests (ITestOutputHelper output)
+{
+    private readonly ITestOutputHelper _output = output;
+
+    [Fact]
+    public void PosCenter_Constructor ()
+    {
+        var posCenter = new PosCenter ();
+        Assert.NotNull (posCenter);
+    }
+
+
+    [Fact]
+    public void PosCenter_Equals ()
+    {
+        var posCenter1 = new PosCenter ();
+        var posCenter2 = new PosCenter ();
+
+        Assert.False (posCenter1.Equals (posCenter2));
+        Assert.False (posCenter2.Equals (posCenter1));
+    }
+
+
+    [Fact]
+    public void PosCenter_ToString ()
+    {
+        var posCenter = new PosCenter ();
+        var expectedString = "Center";
+
+        Assert.Equal (expectedString, posCenter.ToString ());
+    }
+
+    [Fact]
+    public void PosCenter_Anchor ()
+    {
+        var posCenter = new PosCenter ();
+        var width = 50;
+        var expectedAnchor = width / 2;
+
+        Assert.Equal (expectedAnchor, posCenter.Anchor (width));
+    }
+
+    [Fact]
+    public void PosCenter_CreatesCorrectInstance ()
+    {
+        var pos = Pos.Center ();
+        Assert.IsType<PosCenter> (pos);
+    }
+
+
+    [Fact]
+    public void PosCenter_Calculate_ReturnsExpectedValue ()
+    {
+        var posCenter = new PosCenter ();
+        var result = posCenter.Calculate (10, new DimAbsolute (2), null, Dimension.None);
+        Assert.Equal (4, result);
+    }
+
+    [Theory]
+    [AutoInitShutdown]
+    [InlineData (1)]
+    [InlineData (2)]
+    [InlineData (3)]
+    [InlineData (4)]
+    [InlineData (5)]
+    [InlineData (6)]
+    [InlineData (7)]
+    [InlineData (8)]
+    [InlineData (9)]
+    [InlineData (10)]
+    public void PosCenter_SubView_85_Percent_Height (int height)
+    {
+        var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
+
+        var subview = new Window
+        {
+            X = Pos.Center (), Y = Pos.Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
+        };
+
+        win.Add (subview);
+
+        RunState rs = Application.Begin (win);
+        var firstIteration = false;
+
+        ((FakeDriver)Application.Driver).SetBufferSize (20, height);
+        Application.RunIteration (ref rs, ref firstIteration);
+        var expected = string.Empty;
+
+        switch (height)
+        {
+            case 1:
+                //Assert.Equal (new (0, 0, 17, 0), subview.Frame);
+                expected = @"
+────────────────────";
+
+                break;
+            case 2:
+                //Assert.Equal (new (0, 0, 17, 1), subview.Frame);
+                expected = @"
+┌──────────────────┐
+└──────────────────┘
+";
+
+                break;
+            case 3:
+                //Assert.Equal (new (0, 0, 17, 2), subview.Frame);
+                expected = @"
+┌──────────────────┐
+│                  │
+└──────────────────┘
+";
+
+                break;
+            case 4:
+                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
+                expected = @"
+┌──────────────────┐
+│ ───────────────  │
+│                  │
+└──────────────────┘";
+
+                break;
+            case 5:
+                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
+                expected = @"
+┌──────────────────┐
+│ ┌─────────────┐  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+
+                break;
+            case 6:
+                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
+                expected = @"
+┌──────────────────┐
+│ ┌─────────────┐  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+
+                break;
+            case 7:
+                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
+                expected = @"
+┌──────────────────┐
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+
+                break;
+            case 8:
+                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
+                expected = @"
+┌──────────────────┐
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+
+                break;
+            case 9:
+                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
+                expected = @"
+┌──────────────────┐
+│                  │
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘";
+
+                break;
+            case 10:
+                //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
+                expected = @"
+┌──────────────────┐
+│                  │
+│ ┌─────────────┐  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ │             │  │
+│ └─────────────┘  │
+│                  │
+└──────────────────┘"
+                ;
+                break;
+        }
+
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Application.End (rs);
+    }
+
+    [Theory]
+    [AutoInitShutdown]
+    [InlineData (1)]
+    [InlineData (2)]
+    [InlineData (3)]
+    [InlineData (4)]
+    [InlineData (5)]
+    [InlineData (6)]
+    [InlineData (7)]
+    [InlineData (8)]
+    [InlineData (9)]
+    [InlineData (10)]
+    public void PosCenter_SubView_85_Percent_Width (int width)
+    {
+        var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
+
+        var subview = new Window
+        {
+            X = Pos.Center (), Y = Pos.Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
+        };
+
+        win.Add (subview);
+
+        RunState rs = Application.Begin (win);
+        var firstIteration = false;
+
+        ((FakeDriver)Application.Driver).SetBufferSize (width, 7);
+        Application.RunIteration (ref rs, ref firstIteration);
+        var expected = string.Empty;
+
+        switch (width)
+        {
+            case 1:
+                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
+
+                expected = @"
+│
+│
+│
+│
+│
+│
+│";
+
+                break;
+            case 2:
+                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
+
+                expected = @"
+┌┐
+││
+││
+││
+││
+││
+└┘";
+
+                break;
+            case 3:
+                Assert.Equal (new Rectangle (0, 0, 0, 4), subview.Frame);
+
+                expected = @"
+┌─┐
+│ │
+│ │
+│ │
+│ │
+│ │
+└─┘";
+
+                break;
+            case 4:
+                Assert.Equal (new Rectangle (0, 0, 1, 4), subview.Frame);
+
+                expected = @"
+┌──┐
+││ │
+││ │
+││ │
+││ │
+│  │
+└──┘";
+
+                break;
+            case 5:
+                Assert.Equal (new Rectangle (0, 0, 2, 4), subview.Frame);
+
+                expected = @"
+┌───┐
+│┌┐ │
+│││ │
+│││ │
+│└┘ │
+│   │
+└───┘";
+
+                break;
+            case 6:
+                Assert.Equal (new Rectangle (0, 0, 3, 4), subview.Frame);
+
+                expected = @"
+┌────┐
+│┌─┐ │
+││ │ │
+││ │ │
+│└─┘ │
+│    │
+└────┘";
+
+                break;
+            case 7:
+                Assert.Equal (new Rectangle (0, 0, 4, 4), subview.Frame);
+
+                expected = @"
+┌─────┐
+│┌──┐ │
+││  │ │
+││  │ │
+│└──┘ │
+│     │
+└─────┘";
+
+                break;
+            case 8:
+                Assert.Equal (new Rectangle (0, 0, 5, 4), subview.Frame);
+
+                expected = @"
+┌──────┐
+│┌───┐ │
+││   │ │
+││   │ │
+│└───┘ │
+│      │
+└──────┘";
+
+                break;
+            case 9:
+                Assert.Equal (new Rectangle (1, 0, 5, 4), subview.Frame);
+
+                expected = @"
+┌───────┐
+│ ┌───┐ │
+│ │   │ │
+│ │   │ │
+│ └───┘ │
+│       │
+└───────┘";
+
+                break;
+            case 10:
+                Assert.Equal (new Rectangle (1, 0, 6, 4), subview.Frame);
+
+                expected = @"
+┌────────┐
+│ ┌────┐ │
+│ │    │ │
+│ │    │ │
+│ └────┘ │
+│        │
+└────────┘"
+                ;
+                break;
+        }
+
+        _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        Application.End (rs);
+    }
+}

+ 63 - 0
UnitTests/View/Layout/Pos.CombineTests.cs

@@ -0,0 +1,63 @@
+using Microsoft.VisualStudio.TestPlatform.Utilities;
+using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
+using static Terminal.Gui.Pos;
+
+namespace Terminal.Gui.PosDimTests;
+
+public class PosCombineTests (ITestOutputHelper output)
+{
+    private readonly ITestOutputHelper _output = output;
+
+    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
+    // TODO: A new test that calls SetRelativeLayout directly is needed.
+    [Fact]
+    public void PosCombine_Referencing_Same_View ()
+    {
+        var super = new View { Width = 10, Height = 10, Text = "super" };
+        var view1 = new View { Width = 2, Height = 2, Text = "view1" };
+        var view2 = new View { Width = 2, Height = 2, Text = "view2" };
+        view2.X = Pos.AnchorEnd (0) - (Pos.Right (view2) - Pos.Left (view2));
+
+        super.Add (view1, view2);
+        super.BeginInit ();
+        super.EndInit ();
+
+        Exception exception = Record.Exception (super.LayoutSubviews);
+        Assert.Null (exception);
+        Assert.Equal (new (0, 0, 10, 10), super.Frame);
+        Assert.Equal (new (0, 0, 2, 2), view1.Frame);
+        Assert.Equal (new (8, 0, 2, 2), view2.Frame);
+
+        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 PosCombine_Will_Throws ()
+    {
+        Application.Init (new FakeDriver ());
+
+        Toplevel t = new ();
+
+        var w = new Window { X = Pos.Left (t) + 2, Y = Pos.Top (t) + 2 };
+        var f = new FrameView ();
+        var v1 = new View { X = Pos.Left (w) + 2, Y = Pos.Top (w) + 2 };
+        var v2 = new View { X = Pos.Left (v1) + 2, Y = Pos.Top (v1) + 2 };
+
+        f.Add (v1); // v2 not added
+        w.Add (f);
+        t.Add (w);
+
+        f.X = Pos.X (v2) - Pos.X (v1);
+        f.Y = Pos.Y (v2) - Pos.Y (v1);
+
+        Assert.Throws<InvalidOperationException> (() => Application.Run (t));
+        t.Dispose ();
+        Application.Shutdown ();
+
+        v2.Dispose ();
+    }
+}

+ 74 - 0
UnitTests/View/Layout/Pos.PercentTests.cs

@@ -0,0 +1,74 @@
+using Microsoft.VisualStudio.TestPlatform.Utilities;
+using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
+using static Terminal.Gui.Pos;
+
+namespace Terminal.Gui.PosDimTests;
+
+public class PosPercentTests (ITestOutputHelper output)
+{
+    private readonly ITestOutputHelper _output = output;
+
+    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
+    // TODO: A new test that calls SetRelativeLayout directly is needed.
+    [Theory]
+    [AutoInitShutdown]
+    [InlineData (true)]
+    [InlineData (false)]
+    public void PosPercent_PlusOne (bool testHorizontal)
+    {
+        var container = new View { Width = 100, Height = 100 };
+
+        var view = new View
+        {
+            X = testHorizontal ? Pos.Percent (50) + Pos.Percent (10) + 1 : 1,
+            Y = testHorizontal ? 1 : Pos.Percent (50) + Pos.Percent (10) + 1,
+            Width = 10,
+            Height = 10
+        };
+
+        container.Add (view);
+        var top = new Toplevel ();
+        top.Add (container);
+        top.LayoutSubviews ();
+
+        Assert.Equal (100, container.Frame.Width);
+        Assert.Equal (100, container.Frame.Height);
+
+        if (testHorizontal)
+        {
+            Assert.Equal (61, view.Frame.X);
+            Assert.Equal (1, view.Frame.Y);
+        }
+        else
+        {
+            Assert.Equal (1, view.Frame.X);
+            Assert.Equal (61, view.Frame.Y);
+        }
+    }
+
+    [Fact]
+    public void PosPercent_SetsValue ()
+    {
+        float f = 0;
+        Pos pos = Pos.Percent (f);
+        Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
+        f = 0.5F;
+        pos = Pos.Percent (f);
+        Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
+        f = 100;
+        pos = Pos.Percent (f);
+        Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
+    }
+
+    [Fact]
+    public void PosPercent_ThrowsOnIvalid ()
+    {
+        Pos pos = Pos.Percent (0);
+        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (-1));
+        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (101));
+        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (100.0001F));
+        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (1000001));
+    }
+
+}

+ 112 - 168
UnitTests/View/Layout/PosTests.cs → UnitTests/View/Layout/Pos.Tests.cs

@@ -2,32 +2,47 @@
 using static Terminal.Gui.Dim;
 using static Terminal.Gui.Pos;
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.PosDimTests;
 
 public class PosTests (ITestOutputHelper output)
 {
+    // Was named AutoSize_Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
+    // but doesn't actually have anything to do with AutoSize.
     [Fact]
-    public void PosAbsolute_Calculate_ReturnsExpectedValue ()
+    public void
+        Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
     {
-        var posAbsolute = new PosAbsolute (5);
-        var result = posAbsolute.Calculate (10, new DimAbsolute (2), null, Dimension.None);
-        Assert.Equal (5, result);
-    }
+        Application.Init (new FakeDriver ());
 
-    [Fact]
-    public void PosAnchorEnd_Calculate_ReturnsExpectedValue ()
-    {
-        var posAnchorEnd = new PosAnchorEnd (5);
-        var result = posAnchorEnd.Calculate (10, new DimAbsolute (2), null, Dimension.None);
-        Assert.Equal (5, result);
+        Toplevel t = new ();
+
+        var w = new Window { X = Pos.Left (t) + 2, Y = Pos.At (2) };
+
+        var v = new View { X = Pos.Center (), Y = Pos.Percent (10) };
+
+        w.Add (v);
+        t.Add (w);
+
+        t.Ready += (s, e) =>
+                   {
+                       v.Frame = new Rectangle (2, 2, 10, 10);
+                       Assert.Equal (2, v.X = 2);
+                       Assert.Equal (2, v.Y = 2);
+                   };
+
+        Application.Iteration += (s, a) => Application.RequestStop ();
+
+        Application.Run (t);
+        t.Dispose ();
+        Application.Shutdown ();
     }
 
     [Fact]
-    public void PosCenter_Calculate_ReturnsExpectedValue ()
+    public void PosAbsolute_Calculate_ReturnsExpectedValue ()
     {
-        var posCenter = new PosCenter ();
-        var result = posCenter.Calculate (10, new DimAbsolute (2), null, Dimension.None);
-        Assert.Equal (4, result);
+        var posAbsolute = new PosAbsolute (5);
+        var result = posAbsolute.Calculate (10, new DimAbsolute (2), null, Dimension.None);
+        Assert.Equal (5, result);
     }
 
     [Fact]
@@ -63,7 +78,7 @@ public class PosTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void At_Equal ()
+    public void PosAt_Equal ()
     {
         var n1 = 0;
         var n2 = 0;
@@ -74,7 +89,7 @@ public class PosTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void At_SetsValue ()
+    public void PosAt_SetsValue ()
     {
         Pos pos = Pos.At (0);
         Assert.Equal ("Absolute(0)", pos.ToString ());
@@ -86,42 +101,12 @@ public class PosTests (ITestOutputHelper output)
         Assert.Equal ("Absolute(-1)", pos.ToString ());
     }
 
-    [Fact]
-    public void Center_SetsValue ()
-    {
-        Pos pos = Pos.Center ();
-        Assert.Equal ("Center", pos.ToString ());
-    }
-
-    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
-    // TODO: A new test that calls SetRelativeLayout directly is needed.
-    [Fact]
-    public void Combine_Referencing_Same_View ()
-    {
-        var super = new View { Width = 10, Height = 10, Text = "super" };
-        var view1 = new View { Width = 2, Height = 2, Text = "view1" };
-        var view2 = new View { Width = 2, Height = 2, Text = "view2" };
-        view2.X = Pos.AnchorEnd () - (Pos.Right (view2) - Pos.Left (view2));
-
-        super.Add (view1, view2);
-        super.BeginInit ();
-        super.EndInit ();
-
-        Exception exception = Record.Exception (super.LayoutSubviews);
-        Assert.Null (exception);
-        Assert.Equal (new Rectangle (0, 0, 10, 10), super.Frame);
-        Assert.Equal (new Rectangle (0, 0, 2, 2), view1.Frame);
-        // AnchorEnd (0) would be 10. AnchorEnd () is 10 - 2 = 8. Right (view2) - Left (view2) = 2. 8 - 2 = 6
-        Assert.Equal (new Rectangle (6,0, 2, 2), view2.Frame);
-
-        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 Combine_WHY_Throws ()
+    public void PosCombine_WHY_Throws ()
     {
         Application.Init (new FakeDriver ());
 
@@ -147,7 +132,7 @@ public class PosTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void DoesNotReturnPosCombine ()
+    public void PosCombine_DoesNotReturn ()
     {
         var v = new View { Id = "V" };
 
@@ -195,7 +180,7 @@ public class PosTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void Function_Equal ()
+    public void PosFunction_Equal ()
     {
         Func<int> f1 = () => 0;
         Func<int> f2 = () => 0;
@@ -210,7 +195,7 @@ public class PosTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void Function_SetsValue ()
+    public void PosFunction_SetsValue ()
     {
         var text = "Test";
         Pos pos = Pos.Function (() => text.Length);
@@ -355,7 +340,7 @@ public class PosTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void Percent_Equal ()
+    public void PosPercent_Equal ()
     {
         float n1 = 0;
         float n2 = 0;
@@ -543,126 +528,13 @@ public class PosTests (ITestOutputHelper output)
         Application.Shutdown ();
     }
 
-    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
-    // TODO: A new test that calls SetRelativeLayout directly is needed.
-    [Fact]
-    public void PosCombine_Referencing_Same_View ()
-    {
-        var super = new View { Width = 10, Height = 10, Text = "super" };
-        var view1 = new View { Width = 2, Height = 2, Text = "view1" };
-        var view2 = new View { Width = 2, Height = 2, Text = "view2" };
-        view2.X = Pos.AnchorEnd (0) - (Pos.Right (view2) - Pos.Left (view2));
-
-        super.Add (view1, view2);
-        super.BeginInit ();
-        super.EndInit ();
-
-        Exception exception = Record.Exception (super.LayoutSubviews);
-        Assert.Null (exception);
-        Assert.Equal (new (0, 0, 10, 10), super.Frame);
-        Assert.Equal (new (0, 0, 2, 2), view1.Frame);
-        Assert.Equal (new (8, 0, 2, 2), view2.Frame);
-
-        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 PosCombine_Will_Throws ()
-    {
-        Application.Init (new FakeDriver ());
-
-        Toplevel t = new ();
-
-        var w = new Window { X = Pos.Left (t) + 2, Y = Pos.Top (t) + 2 };
-        var f = new FrameView ();
-        var v1 = new View { X = Pos.Left (w) + 2, Y = Pos.Top (w) + 2 };
-        var v2 = new View { X = Pos.Left (v1) + 2, Y = Pos.Top (v1) + 2 };
-
-        f.Add (v1); // v2 not added
-        w.Add (f);
-        t.Add (w);
-
-        f.X = Pos.X (v2) - Pos.X (v1);
-        f.Y = Pos.Y (v2) - Pos.Y (v1);
-
-        Assert.Throws<InvalidOperationException> (() => Application.Run (t));
-        t.Dispose ();
-        Application.Shutdown ();
-
-        v2.Dispose ();
-    }
-
-    // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
-    // TODO: A new test that calls SetRelativeLayout directly is needed.
-    [Theory]
-    [AutoInitShutdown]
-    [InlineData (true)]
-    [InlineData (false)]
-    public void Percent_PlusOne (bool testHorizontal)
-    {
-        var container = new View { Width = 100, Height = 100 };
-
-        var view = new View
-        {
-            X = testHorizontal ? Pos.Percent (50) + Pos.Percent (10) + 1 : 1,
-            Y = testHorizontal ? 1 : Pos.Percent (50) + Pos.Percent (10) + 1,
-            Width = 10,
-            Height = 10
-        };
-
-        container.Add (view);
-        var top = new Toplevel ();
-        top.Add (container);
-        top.LayoutSubviews ();
-
-        Assert.Equal (100, container.Frame.Width);
-        Assert.Equal (100, container.Frame.Height);
-
-        if (testHorizontal)
-        {
-            Assert.Equal (61, view.Frame.X);
-            Assert.Equal (1, view.Frame.Y);
-        }
-        else
-        {
-            Assert.Equal (1, view.Frame.X);
-            Assert.Equal (61, view.Frame.Y);
-        }
-    }
-
-    [Fact]
-    public void Percent_SetsValue ()
-    {
-        float f = 0;
-        Pos pos = Pos.Percent (f);
-        Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
-        f = 0.5F;
-        pos = Pos.Percent (f);
-        Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
-        f = 100;
-        pos = Pos.Percent (f);
-        Assert.Equal ($"Factor({f / 100:0.###})", pos.ToString ());
-    }
-
-    [Fact]
-    public void Percent_ThrowsOnIvalid ()
-    {
-        Pos pos = Pos.Percent (0);
-        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (-1));
-        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (101));
-        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (100.0001F));
-        Assert.Throws<ArgumentException> (() => pos = Pos.Percent (1000001));
-    }
 
     // TODO: Test Left, Top, Right bottom Equal
 
     /// <summary>Tests Pos.Left, Pos.X, Pos.Top, Pos.Y, Pos.Right, and Pos.Bottom set operations</summary>
     [Fact]
     [TestRespondersDisposed]
-    public void Side_SetsValue ()
+    public void PosView_Side_SetsValue ()
     {
         string side; // used in format string
         var testRect = Rectangle.Empty;
@@ -887,7 +759,7 @@ public class PosTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void Side_SetToNull_Throws ()
+    public void PosView_Side_SetToNull_Throws ()
     {
         Pos pos = Pos.Left (null);
         Assert.Throws<NullReferenceException> (() => pos.ToString ());
@@ -1000,4 +872,76 @@ public class PosTests (ITestOutputHelper output)
         t.Dispose ();
         Application.Shutdown ();
     }
+
+
+    [Fact]
+    [SetupFakeDriver]
+    public void PosCombine_DimCombine_View_With_SubViews ()
+    {
+        var clicked = false;
+        Toplevel top = new Toplevel () { Width = 80, Height = 25 };
+        var win1 = new Window { Id = "win1", Width = 20, Height = 10 };
+        var view1 = new View { Text = "view1", AutoSize = true }; // BUGBUG: AutoSize or Width must be set
+        var win2 = new Window { Id = "win2", Y = Pos.Bottom (view1) + 1, Width = 10, Height = 3 };
+        var view2 = new View { Id = "view2", Width = Dim.Fill (), Height = 1, CanFocus = true };
+        view2.MouseClick += (sender, e) => clicked = true;
+        var view3 = new View { Id = "view3", Width = Dim.Fill (1), Height = 1, CanFocus = true };
+
+        view2.Add (view3);
+        win2.Add (view2);
+        win1.Add (view1, win2);
+        top.Add (win1);
+        top.BeginInit ();
+        top.EndInit ();
+
+        Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
+        Assert.Equal (new Rectangle (0, 0, 5, 1), view1.Frame);
+        Assert.Equal (new Rectangle (0, 0, 20, 10), win1.Frame);
+        Assert.Equal (new Rectangle (0, 2, 10, 3), win2.Frame);
+        Assert.Equal (new Rectangle (0, 0, 8, 1), view2.Frame);
+        Assert.Equal (new Rectangle (0, 0, 7, 1), view3.Frame);
+        var foundView = View.FindDeepestView (top, 9, 4);
+        Assert.Equal (foundView, view2);
+    }
+
+    [Fact]
+    public void PosCombine_Refs_SuperView_Throws ()
+    {
+        Application.Init (new FakeDriver ());
+
+        var top = new Toplevel ();
+        var w = new Window { X = Pos.Left (top) + 2, Y = Pos.Top (top) + 2 };
+        var f = new FrameView ();
+        var v1 = new View { X = Pos.Left (w) + 2, Y = Pos.Top (w) + 2 };
+        var v2 = new View { X = Pos.Left (v1) + 2, Y = Pos.Top (v1) + 2 };
+
+        f.Add (v1, v2);
+        w.Add (f);
+        top.Add (w);
+        Application.Begin (top);
+
+        f.X = Pos.X (Application.Top) + Pos.X (v2) - Pos.X (v1);
+        f.Y = Pos.Y (Application.Top) + Pos.Y (v2) - Pos.Y (v1);
+
+        Application.Top.LayoutComplete += (s, e) =>
+        {
+            Assert.Equal (0, Application.Top.Frame.X);
+            Assert.Equal (0, Application.Top.Frame.Y);
+            Assert.Equal (2, w.Frame.X);
+            Assert.Equal (2, w.Frame.Y);
+            Assert.Equal (2, f.Frame.X);
+            Assert.Equal (2, f.Frame.Y);
+            Assert.Equal (4, v1.Frame.X);
+            Assert.Equal (4, v1.Frame.Y);
+            Assert.Equal (6, v2.Frame.X);
+            Assert.Equal (6, v2.Frame.Y);
+        };
+
+        Application.Iteration += (s, a) => Application.RequestStop ();
+
+        Assert.Throws<InvalidOperationException> (() => Application.Run ());
+        top.Dispose ();
+        Application.Shutdown ();
+    }
+
 }

+ 1 - 1
UnitTests/View/Layout/ScreenToTests.cs

@@ -1,6 +1,6 @@
 using Xunit.Abstractions;
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.LayoutTests;
 
 /// <summary>Tests for view coordinate mapping (e.g. <see cref="View.ScreenToFrame"/> etc...).</summary>
 public class ScreenToTests

+ 1 - 1
UnitTests/View/Layout/SetRelativeLayoutTests.cs

@@ -1,6 +1,6 @@
 using Xunit.Abstractions;
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.LayoutTests;
 
 public class SetRelativeLayoutTests
 {

+ 1 - 1
UnitTests/View/Layout/ToScreenTests.cs

@@ -1,6 +1,6 @@
 using Xunit.Abstractions;
 
-namespace Terminal.Gui.ViewTests;
+namespace Terminal.Gui.LayoutTests;
 
 /// <summary>
 /// Test the <see cref="View.FrameToScreen"/> and <see cref="View.ViewportToScreen"/> methods.