|
@@ -1,9 +1,7 @@
|
|
|
using System.Globalization;
|
|
|
using System.Text;
|
|
|
using Xunit.Abstractions;
|
|
|
-
|
|
|
-// Alias Console to MockConsole so we don't accidentally use Console
|
|
|
-using Console = Terminal.Gui.FakeConsole;
|
|
|
+using static Terminal.Gui.Dim;
|
|
|
|
|
|
namespace Terminal.Gui.ViewTests;
|
|
|
|
|
@@ -26,7 +24,7 @@ public class DimTests
|
|
|
// A new test that does not depend on Application is needed.
|
|
|
[Fact]
|
|
|
[AutoInitShutdown]
|
|
|
- public void Dim_Add_Operator ()
|
|
|
+ public void Add_Operator ()
|
|
|
{
|
|
|
Toplevel top = Application.Top;
|
|
|
|
|
@@ -76,176 +74,7 @@ public class DimTests
|
|
|
// 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]
|
|
|
- [AutoInitShutdown]
|
|
|
- public void Dim_Subtract_Operator ()
|
|
|
- {
|
|
|
- Toplevel top = Application.Top;
|
|
|
-
|
|
|
- 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.Bounds.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);
|
|
|
-
|
|
|
- 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]
|
|
|
- [TestRespondersDisposed]
|
|
|
- public void
|
|
|
- Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
|
|
|
- {
|
|
|
- var t = new View { Width = 80, Height = 25, Text = "top" };
|
|
|
-
|
|
|
- var w = new Window { Width = Dim.Fill (), Height = Dim.Sized (10) };
|
|
|
- var v = new View { Width = Dim.Width (w) - 2, Height = Dim.Percent (10), Text = "v" };
|
|
|
-
|
|
|
- w.Add (v);
|
|
|
- t.Add (w);
|
|
|
-
|
|
|
- Assert.Equal (LayoutStyle.Absolute, t.LayoutStyle);
|
|
|
- Assert.Equal (LayoutStyle.Computed, w.LayoutStyle);
|
|
|
- Assert.Equal (LayoutStyle.Computed, v.LayoutStyle);
|
|
|
-
|
|
|
- t.LayoutSubviews ();
|
|
|
- Assert.Equal (2, v.Width = 2);
|
|
|
- Assert.Equal (2, v.Height = 2);
|
|
|
-
|
|
|
- // Force v to be LayoutStyle.Absolute;
|
|
|
- v.Frame = new Rect (0, 1, 3, 4);
|
|
|
- Assert.Equal (LayoutStyle.Absolute, v.LayoutStyle);
|
|
|
- t.LayoutSubviews ();
|
|
|
-
|
|
|
- Assert.Equal (2, v.Width = 2);
|
|
|
- Assert.Equal (2, v.Height = 2);
|
|
|
- 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 Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Null ()
|
|
|
- {
|
|
|
- var t = new View { Width = 80, Height = 25, Text = "top" };
|
|
|
-
|
|
|
- var w = new Window
|
|
|
- {
|
|
|
- X = 1,
|
|
|
- Y = 2,
|
|
|
- Width = 4,
|
|
|
- Height = 5,
|
|
|
- Title = "w"
|
|
|
- };
|
|
|
- t.Add (w);
|
|
|
- t.LayoutSubviews ();
|
|
|
-
|
|
|
- Assert.Equal (3, w.Width = 3);
|
|
|
- Assert.Equal (4, w.Height = 4);
|
|
|
- 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 ()
|
|
|
+ public void Combine_ObtuseScenario_Does_Not_Throw_If_Two_SubViews_Refs_The_Same_SuperView ()
|
|
|
{
|
|
|
var t = new View { Width = 80, Height = 25, Text = "top" };
|
|
|
|
|
@@ -318,7 +147,7 @@ public class DimTests
|
|
|
/// <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 ()
|
|
|
+ public void Combine_ObtuseScenario_Throw_If_SuperView_Refs_SubView ()
|
|
|
{
|
|
|
var t = new View { Width = 80, Height = 25 };
|
|
|
|
|
@@ -366,54 +195,159 @@ public class DimTests
|
|
|
|
|
|
// 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]
|
|
|
+ [TestRespondersDisposed]
|
|
|
+ public void
|
|
|
+ Dim_Validation_Does_Not_Throw_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
|
|
|
+ {
|
|
|
+ var t = new View { Width = 80, Height = 25, Text = "top" };
|
|
|
+
|
|
|
+ var w = new Window { Width = Dim.Fill (), Height = Dim.Sized (10) };
|
|
|
+ var v = new View { Width = Dim.Width (w) - 2, Height = Dim.Percent (10), Text = "v" };
|
|
|
+
|
|
|
+ w.Add (v);
|
|
|
+ t.Add (w);
|
|
|
+
|
|
|
+ Assert.Equal (LayoutStyle.Absolute, t.LayoutStyle);
|
|
|
+ Assert.Equal (LayoutStyle.Computed, w.LayoutStyle);
|
|
|
+ Assert.Equal (LayoutStyle.Computed, v.LayoutStyle);
|
|
|
+
|
|
|
+ t.LayoutSubviews ();
|
|
|
+ Assert.Equal (2, v.Width = 2);
|
|
|
+ Assert.Equal (2, v.Height = 2);
|
|
|
+
|
|
|
+ // Force v to be LayoutStyle.Absolute;
|
|
|
+ v.Frame = new Rect (0, 1, 3, 4);
|
|
|
+ Assert.Equal (LayoutStyle.Absolute, v.LayoutStyle);
|
|
|
+ t.LayoutSubviews ();
|
|
|
+
|
|
|
+ Assert.Equal (2, v.Width = 2);
|
|
|
+ Assert.Equal (2, v.Height = 2);
|
|
|
+ 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]
|
|
|
- [AutoInitShutdown]
|
|
|
- [InlineData (0, true)]
|
|
|
- [InlineData (0, false)]
|
|
|
- [InlineData (50, true)]
|
|
|
- [InlineData (50, false)]
|
|
|
- public void DimPercentPlusOne (int startingDistance, bool testHorizontal)
|
|
|
+ [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 container = new View { Width = 100, Height = 100 };
|
|
|
+ var super = new View { Width = 25, Height = 25 };
|
|
|
|
|
|
- var label = new Label
|
|
|
+ var view = new View
|
|
|
{
|
|
|
- AutoSize = false,
|
|
|
- X = testHorizontal ? startingDistance : 0,
|
|
|
- Y = testHorizontal ? 0 : startingDistance,
|
|
|
- Width = testHorizontal ? Dim.Percent (50) + 1 : 1,
|
|
|
- Height = testHorizontal ? 1 : Dim.Percent (50) + 1
|
|
|
+ X = 0,
|
|
|
+ Y = 0,
|
|
|
+ Width = width ? Dim.Fill (margin) : 1,
|
|
|
+ Height = width ? 1 : Dim.Fill (margin)
|
|
|
};
|
|
|
|
|
|
- container.Add (label);
|
|
|
- Application.Top.Add (container);
|
|
|
- Application.Top.BeginInit ();
|
|
|
- Application.Top.EndInit ();
|
|
|
- Application.Top.LayoutSubviews ();
|
|
|
+ super.Add (view);
|
|
|
+ super.BeginInit ();
|
|
|
+ super.EndInit ();
|
|
|
+ super.LayoutSubviews ();
|
|
|
|
|
|
- Assert.Equal (100, container.Frame.Width);
|
|
|
- Assert.Equal (100, container.Frame.Height);
|
|
|
+ Assert.Equal (25, super.Frame.Width);
|
|
|
+ Assert.Equal (25, super.Frame.Height);
|
|
|
|
|
|
- if (testHorizontal)
|
|
|
+ if (width)
|
|
|
{
|
|
|
- Assert.Equal (51, label.Frame.Width);
|
|
|
- Assert.Equal (1, label.Frame.Height);
|
|
|
+ Assert.Equal (expected, view.Frame.Width);
|
|
|
+ Assert.Equal (1, view.Frame.Height);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Assert.Equal (1, label.Frame.Width);
|
|
|
- Assert.Equal (51, label.Frame.Height);
|
|
|
+ Assert.Equal (1, view.Frame.Width);
|
|
|
+ Assert.Equal (expected, view.Frame.Height);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- [Fact]
|
|
|
- public void Fill_Equal ()
|
|
|
+ // 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 margin1 = 0;
|
|
|
- var margin2 = 0;
|
|
|
- Dim dim1 = Dim.Fill (margin1);
|
|
|
- Dim dim2 = Dim.Fill (margin2);
|
|
|
- Assert.Equal (dim1, dim2);
|
|
|
+ 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?)
|
|
@@ -506,9 +440,9 @@ public class DimTests
|
|
|
Assert.Equal (20, dimCombine.Anchor (100));
|
|
|
|
|
|
var view = new View { Frame = new Rect (20, 10, 20, 1) };
|
|
|
- var dimViewHeight = new Dim.DimView (view, 0);
|
|
|
+ var dimViewHeight = new Dim.DimView (view, Side.Height);
|
|
|
Assert.Equal (1, dimViewHeight.Anchor (0));
|
|
|
- var dimViewWidth = new Dim.DimView (view, 1);
|
|
|
+ var dimViewWidth = new Dim.DimView (view, Side.Width);
|
|
|
Assert.Equal (20, dimViewWidth.Anchor (0));
|
|
|
|
|
|
view.Dispose ();
|
|
@@ -814,6 +748,89 @@ public class DimTests
|
|
|
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 ()
|
|
|
{
|
|
@@ -832,47 +849,24 @@ public class DimTests
|
|
|
// TODO: A new test that calls SetRelativeLayout directly is needed.
|
|
|
[Fact]
|
|
|
[TestRespondersDisposed]
|
|
|
- public void PosCombine_View_Not_Added_Throws ()
|
|
|
+ public void Referencing_SuperView_Does_Not_Throw ()
|
|
|
{
|
|
|
- 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 ();
|
|
|
+ var super = new View { Width = 10, Height = 10, Text = "super" };
|
|
|
|
|
|
- Assert.Throws<InvalidOperationException> (() => t.LayoutSubviews ());
|
|
|
- t.Dispose ();
|
|
|
- v2.Dispose ();
|
|
|
- }
|
|
|
+ var view = new View
|
|
|
+ {
|
|
|
+ Width = Dim.Width (super), // this is allowed
|
|
|
+ Height = Dim.Height (super), // this is allowed
|
|
|
+ Text = "view"
|
|
|
+ };
|
|
|
|
|
|
- [Fact]
|
|
|
- [TestRespondersDisposed]
|
|
|
- public void SetsValue ()
|
|
|
- {
|
|
|
- var testVal = Rect.Empty;
|
|
|
- var testValView = new View { Frame = testVal };
|
|
|
- Dim dim = Dim.Width (testValView);
|
|
|
- Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
|
|
|
- testValView.Dispose ();
|
|
|
+ super.Add (view);
|
|
|
+ super.BeginInit ();
|
|
|
+ super.EndInit ();
|
|
|
|
|
|
- testVal = new Rect (1, 2, 3, 4);
|
|
|
- testValView = new View { Frame = testVal };
|
|
|
- dim = Dim.Width (testValView);
|
|
|
- Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
|
|
|
- testValView.Dispose ();
|
|
|
+ Exception exception = Record.Exception (super.LayoutSubviews);
|
|
|
+ Assert.Null (exception);
|
|
|
+ super.Dispose ();
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
@@ -916,6 +910,118 @@ public class DimTests
|
|
|
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 = Application.Top;
|
|
|
+
|
|
|
+ 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.Bounds.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);
|
|
|
+
|
|
|
+ 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 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]
|
|
|
+ [TestRespondersDisposed]
|
|
|
+ public void Validation_Does_Not_Throw_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Null ()
|
|
|
+ {
|
|
|
+ var t = new View { Width = 80, Height = 25, Text = "top" };
|
|
|
+
|
|
|
+ var w = new Window
|
|
|
+ {
|
|
|
+ X = 1,
|
|
|
+ Y = 2,
|
|
|
+ Width = 4,
|
|
|
+ Height = 5,
|
|
|
+ Title = "w"
|
|
|
+ };
|
|
|
+ t.Add (w);
|
|
|
+ t.LayoutSubviews ();
|
|
|
+
|
|
|
+ Assert.Equal (3, w.Width = 3);
|
|
|
+ Assert.Equal (4, w.Height = 4);
|
|
|
+ t.Dispose ();
|
|
|
+ }
|
|
|
+
|
|
|
[Fact]
|
|
|
[TestRespondersDisposed]
|
|
|
public void Width_Equals ()
|
|
@@ -973,4 +1079,21 @@ public class DimTests
|
|
|
Dim dim = Dim.Width (null);
|
|
|
Assert.Throws<NullReferenceException> (() => dim.ToString ());
|
|
|
}
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ [TestRespondersDisposed]
|
|
|
+ public void Width_SetsValue ()
|
|
|
+ {
|
|
|
+ var testVal = Rect.Empty;
|
|
|
+ var testValView = new View { Frame = testVal };
|
|
|
+ Dim dim = Dim.Width (testValView);
|
|
|
+ Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
|
|
|
+ testValView.Dispose ();
|
|
|
+
|
|
|
+ testVal = new Rect (1, 2, 3, 4);
|
|
|
+ testValView = new View { Frame = testVal };
|
|
|
+ dim = Dim.Width (testValView);
|
|
|
+ Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
|
|
|
+ testValView.Dispose ();
|
|
|
+ }
|
|
|
}
|