|
@@ -4,33 +4,36 @@ using static Terminal.Gui.Dim;
|
|
|
|
|
|
namespace Terminal.Gui.LayoutTests;
|
|
|
|
|
|
+[Trait("Category", "Layout")]
|
|
|
public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
{
|
|
|
private readonly ITestOutputHelper _output = output;
|
|
|
|
|
|
- private class DimAutoTestView : View
|
|
|
+ [SetupFakeDriver]
|
|
|
+ [Fact]
|
|
|
+ public void Change_To_Non_Auto_Resets_ContentSize ()
|
|
|
{
|
|
|
- public DimAutoTestView ()
|
|
|
+ View view = new ()
|
|
|
{
|
|
|
- ValidatePosDim = true;
|
|
|
- Width = Auto ();
|
|
|
- Height = Auto ();
|
|
|
- }
|
|
|
+ Width = Auto (),
|
|
|
+ Height = Auto (),
|
|
|
+ Text = "01234"
|
|
|
+ };
|
|
|
+ view.SetRelativeLayout (new (100, 100));
|
|
|
+ Assert.Equal (new (0, 0, 5, 1), view.Frame);
|
|
|
+ Assert.Equal (new (5, 1), view.GetContentSize ());
|
|
|
|
|
|
- public DimAutoTestView (Dim width, Dim height)
|
|
|
- {
|
|
|
- ValidatePosDim = true;
|
|
|
- Width = width;
|
|
|
- Height = height;
|
|
|
- }
|
|
|
+ // Change text to a longer string
|
|
|
+ view.Text = "0123456789";
|
|
|
|
|
|
- public DimAutoTestView (string text, Dim width, Dim height)
|
|
|
- {
|
|
|
- ValidatePosDim = true;
|
|
|
- Text = text;
|
|
|
- Width = width;
|
|
|
- Height = height;
|
|
|
- }
|
|
|
+ Assert.Equal (new (0, 0, 10, 1), view.Frame);
|
|
|
+ Assert.Equal (new (10, 1), view.GetContentSize ());
|
|
|
+
|
|
|
+ // If ContentSize was reset, these should cause it to update
|
|
|
+ view.Width = 5;
|
|
|
+ view.Height = 1;
|
|
|
+
|
|
|
+ Assert.Equal (new (5, 1), view.GetContentSize ());
|
|
|
}
|
|
|
|
|
|
[Theory]
|
|
@@ -74,6 +77,46 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
Assert.Equal (new (0, 0, 10, expectedHeight), superView.Frame);
|
|
|
}
|
|
|
|
|
|
+ [Theory]
|
|
|
+ [CombinatorialData]
|
|
|
+ public void HotKey_TextFormatter_Height_Correct ([CombinatorialValues ("1234", "_1234", "1_234", "____")] string text)
|
|
|
+ {
|
|
|
+ View view = new ()
|
|
|
+ {
|
|
|
+ HotKeySpecifier = (Rune)'_',
|
|
|
+ Text = text,
|
|
|
+ Width = Auto (),
|
|
|
+ Height = 1
|
|
|
+ };
|
|
|
+ Assert.Equal (4, view.TextFormatter.ConstrainToWidth);
|
|
|
+ Assert.Equal (1, view.TextFormatter.ConstrainToHeight);
|
|
|
+
|
|
|
+ view = new ()
|
|
|
+ {
|
|
|
+ HotKeySpecifier = (Rune)'_',
|
|
|
+ TextDirection = TextDirection.TopBottom_LeftRight,
|
|
|
+ Text = text,
|
|
|
+ Width = 1,
|
|
|
+ Height = Auto ()
|
|
|
+ };
|
|
|
+ Assert.Equal (1, view.TextFormatter.ConstrainToWidth);
|
|
|
+ Assert.Equal (4, view.TextFormatter.ConstrainToHeight);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [CombinatorialData]
|
|
|
+ public void HotKey_TextFormatter_Width_Correct ([CombinatorialValues ("1234", "_1234", "1_234", "____")] string text)
|
|
|
+ {
|
|
|
+ View view = new ()
|
|
|
+ {
|
|
|
+ Text = text,
|
|
|
+ Height = 1,
|
|
|
+ Width = Auto ()
|
|
|
+ };
|
|
|
+ Assert.Equal (4, view.TextFormatter.ConstrainToWidth);
|
|
|
+ Assert.Equal (1, view.TextFormatter.ConstrainToHeight);
|
|
|
+ }
|
|
|
+
|
|
|
[Fact]
|
|
|
public void NoSubViews_Does_Nothing ()
|
|
|
{
|
|
@@ -158,6 +201,122 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
Assert.Equal (new (0, 0, expectedWidth, expectedHeight), superView.Frame);
|
|
|
}
|
|
|
|
|
|
+ [Fact]
|
|
|
+ public void TestEquality ()
|
|
|
+ {
|
|
|
+ var a = new DimAuto (
|
|
|
+ MaximumContentDim: null,
|
|
|
+ MinimumContentDim: 1,
|
|
|
+ Style: DimAutoStyle.Auto
|
|
|
+ );
|
|
|
+
|
|
|
+ var b = new DimAuto (
|
|
|
+ MaximumContentDim: null,
|
|
|
+ MinimumContentDim: 1,
|
|
|
+ Style: DimAutoStyle.Auto
|
|
|
+ );
|
|
|
+
|
|
|
+ var c = new DimAuto(
|
|
|
+ MaximumContentDim: 2,
|
|
|
+ MinimumContentDim: 1,
|
|
|
+ Style: DimAutoStyle.Auto
|
|
|
+ );
|
|
|
+
|
|
|
+ var d = new DimAuto (
|
|
|
+ MaximumContentDim: null,
|
|
|
+ MinimumContentDim: 1,
|
|
|
+ Style: DimAutoStyle.Content
|
|
|
+ );
|
|
|
+
|
|
|
+ var e = new DimAuto (
|
|
|
+ MaximumContentDim: null,
|
|
|
+ MinimumContentDim: 2,
|
|
|
+ Style: DimAutoStyle.Auto
|
|
|
+ );
|
|
|
+
|
|
|
+ // Test equality with same values
|
|
|
+ Assert.True (a.Equals (b));
|
|
|
+ Assert.True (a.GetHashCode () == b.GetHashCode ());
|
|
|
+
|
|
|
+ // Test inequality with different MaximumContentDim
|
|
|
+ Assert.False (a.Equals (c));
|
|
|
+ Assert.False (a.GetHashCode () == c.GetHashCode ());
|
|
|
+
|
|
|
+ // Test inequality with different Style
|
|
|
+ Assert.False (a.Equals (d));
|
|
|
+ Assert.False (a.GetHashCode () == d.GetHashCode ());
|
|
|
+
|
|
|
+ // Test inequality with different MinimumContentDim
|
|
|
+ Assert.False (a.Equals (e));
|
|
|
+ Assert.False (a.GetHashCode () == e.GetHashCode ());
|
|
|
+
|
|
|
+ // Test inequality with null
|
|
|
+ Assert.False (a.Equals (null));
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void TestEquality_Simple ()
|
|
|
+ {
|
|
|
+ Dim a = Auto ();
|
|
|
+ Dim b = Auto ();
|
|
|
+ Assert.True (a.Equals (b));
|
|
|
+ Assert.True (a.GetHashCode () == b.GetHashCode ());
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void TextFormatter_Settings_Change_View_Size ()
|
|
|
+ {
|
|
|
+ View view = new ()
|
|
|
+ {
|
|
|
+ Text = "_1234",
|
|
|
+ Width = Auto ()
|
|
|
+ };
|
|
|
+ Assert.Equal (new (4, 0), view.Frame.Size);
|
|
|
+
|
|
|
+ view.Height = 1;
|
|
|
+ view.SetRelativeLayout (Application.Screen.Size);
|
|
|
+ Assert.Equal (new (4, 1), view.Frame.Size);
|
|
|
+ Size lastSize = view.Frame.Size;
|
|
|
+
|
|
|
+ view.TextAlignment = Alignment.Fill;
|
|
|
+ Assert.Equal (lastSize, view.Frame.Size);
|
|
|
+
|
|
|
+ view = new ()
|
|
|
+ {
|
|
|
+ Text = "_1234",
|
|
|
+ Width = Auto (),
|
|
|
+ Height = 1
|
|
|
+ };
|
|
|
+ view.SetRelativeLayout (Application.Screen.Size);
|
|
|
+
|
|
|
+ lastSize = view.Frame.Size;
|
|
|
+ view.VerticalTextAlignment = Alignment.Center;
|
|
|
+ Assert.Equal (lastSize, view.Frame.Size);
|
|
|
+
|
|
|
+ view = new ()
|
|
|
+ {
|
|
|
+ Text = "_1234",
|
|
|
+ Width = Auto (),
|
|
|
+ Height = 1
|
|
|
+ };
|
|
|
+ view.SetRelativeLayout (Application.Screen.Size);
|
|
|
+ lastSize = view.Frame.Size;
|
|
|
+ view.HotKeySpecifier = (Rune)'*';
|
|
|
+ view.SetRelativeLayout (Application.Screen.Size);
|
|
|
+ Assert.NotEqual (lastSize, view.Frame.Size);
|
|
|
+
|
|
|
+ view = new ()
|
|
|
+ {
|
|
|
+ Text = "_1234",
|
|
|
+ Width = Auto (),
|
|
|
+ Height = 1
|
|
|
+ };
|
|
|
+ view.SetRelativeLayout (Application.Screen.Size);
|
|
|
+ lastSize = view.Frame.Size;
|
|
|
+ view.Text = "*ABCD";
|
|
|
+ Assert.NotEqual (lastSize, view.Frame.Size);
|
|
|
+ }
|
|
|
+
|
|
|
// Test validation
|
|
|
[Fact]
|
|
|
public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims ()
|
|
@@ -419,7 +578,7 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
[InlineData (1, 10, 10)]
|
|
|
[InlineData (9, 10, 10)]
|
|
|
[InlineData (10, 10, 10)]
|
|
|
- public void Width_Auto_Text_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth)
|
|
|
+ public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int subSubViewWidth, int expectedSubWidth)
|
|
|
{
|
|
|
var superView = new View
|
|
|
{
|
|
@@ -432,14 +591,23 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
|
|
|
var subView = new View
|
|
|
{
|
|
|
- Text = new ('*', textLen),
|
|
|
X = subX,
|
|
|
Y = 0,
|
|
|
- Width = Auto (DimAutoStyle.Text),
|
|
|
+ Width = Auto (DimAutoStyle.Content),
|
|
|
Height = 1,
|
|
|
ValidatePosDim = true
|
|
|
};
|
|
|
|
|
|
+ var subSubView = new View
|
|
|
+ {
|
|
|
+ X = 0,
|
|
|
+ Y = 0,
|
|
|
+ Width = subSubViewWidth,
|
|
|
+ Height = 1,
|
|
|
+ ValidatePosDim = true
|
|
|
+ };
|
|
|
+ subView.Add (subSubView);
|
|
|
+
|
|
|
superView.Add (subView);
|
|
|
|
|
|
superView.BeginInit ();
|
|
@@ -459,7 +627,7 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
[InlineData (1, 10, 10)]
|
|
|
[InlineData (9, 10, 10)]
|
|
|
[InlineData (10, 10, 10)]
|
|
|
- public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int subSubViewWidth, int expectedSubWidth)
|
|
|
+ public void Width_Auto_Text_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth)
|
|
|
{
|
|
|
var superView = new View
|
|
|
{
|
|
@@ -472,22 +640,13 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
|
|
|
var subView = new View
|
|
|
{
|
|
|
+ Text = new ('*', textLen),
|
|
|
X = subX,
|
|
|
Y = 0,
|
|
|
- Width = Auto (DimAutoStyle.Content),
|
|
|
- Height = 1,
|
|
|
- ValidatePosDim = true
|
|
|
- };
|
|
|
-
|
|
|
- var subSubView = new View
|
|
|
- {
|
|
|
- X = 0,
|
|
|
- Y = 0,
|
|
|
- Width = subSubViewWidth,
|
|
|
+ Width = Auto (DimAutoStyle.Text),
|
|
|
Height = 1,
|
|
|
ValidatePosDim = true
|
|
|
};
|
|
|
- subView.Add (subSubView);
|
|
|
|
|
|
superView.Add (subView);
|
|
|
|
|
@@ -499,31 +658,29 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
Assert.Equal (expectedSubWidth, subView.Frame.Width);
|
|
|
}
|
|
|
|
|
|
- [SetupFakeDriver]
|
|
|
- [Fact]
|
|
|
- public void Change_To_Non_Auto_Resets_ContentSize ()
|
|
|
+ private class DimAutoTestView : View
|
|
|
{
|
|
|
- View view = new ()
|
|
|
+ public DimAutoTestView ()
|
|
|
{
|
|
|
- Width = Auto (),
|
|
|
- Height = Auto (),
|
|
|
- Text = "01234"
|
|
|
- };
|
|
|
- view.SetRelativeLayout (new (100, 100));
|
|
|
- Assert.Equal (new (0, 0, 5, 1), view.Frame);
|
|
|
- Assert.Equal (new (5, 1), view.GetContentSize ());
|
|
|
-
|
|
|
- // Change text to a longer string
|
|
|
- view.Text = "0123456789";
|
|
|
-
|
|
|
- Assert.Equal (new (0, 0, 10, 1), view.Frame);
|
|
|
- Assert.Equal (new (10, 1), view.GetContentSize ());
|
|
|
+ ValidatePosDim = true;
|
|
|
+ Width = Auto ();
|
|
|
+ Height = Auto ();
|
|
|
+ }
|
|
|
|
|
|
- // If ContentSize was reset, these should cause it to update
|
|
|
- view.Width = 5;
|
|
|
- view.Height = 1;
|
|
|
+ public DimAutoTestView (Dim width, Dim height)
|
|
|
+ {
|
|
|
+ ValidatePosDim = true;
|
|
|
+ Width = width;
|
|
|
+ Height = height;
|
|
|
+ }
|
|
|
|
|
|
- Assert.Equal (new (5, 1), view.GetContentSize ());
|
|
|
+ public DimAutoTestView (string text, Dim width, Dim height)
|
|
|
+ {
|
|
|
+ ValidatePosDim = true;
|
|
|
+ Text = text;
|
|
|
+ Width = width;
|
|
|
+ Height = height;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#region DimAutoStyle.Auto tests
|
|
@@ -544,7 +701,6 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
view.SetRelativeLayout (Application.Screen.Size);
|
|
|
|
|
|
Assert.Equal (new (expectedW, expectedH), view.Frame.Size);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
@@ -653,7 +809,6 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
view.SetRelativeLayout (Application.Screen.Size);
|
|
|
|
|
|
Assert.Equal (new (expectedW, expectedH), view.Frame.Size);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
[Theory]
|
|
@@ -665,15 +820,14 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
public void DimAutoStyle_Text_Sizes_Correctly_With_Min (string text, int minWidth, int minHeight, int expectedW, int expectedH)
|
|
|
{
|
|
|
var view = new View ();
|
|
|
- view.Width = Auto (DimAutoStyle.Text, minimumContentDim: minWidth);
|
|
|
- view.Height = Auto (DimAutoStyle.Text, minimumContentDim: minHeight);
|
|
|
+ view.Width = Auto (DimAutoStyle.Text, minWidth);
|
|
|
+ view.Height = Auto (DimAutoStyle.Text, minHeight);
|
|
|
|
|
|
view.Text = text;
|
|
|
|
|
|
view.SetRelativeLayout (Application.Screen.Size);
|
|
|
|
|
|
Assert.Equal (new (expectedW, expectedH), view.Frame.Size);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
[Theory]
|
|
@@ -699,7 +853,6 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
[InlineData ("01234", 5, 1)]
|
|
|
[InlineData ("01234ABCDE", 10, 1)]
|
|
|
[InlineData ("01234\nABCDE", 5, 2)]
|
|
|
-
|
|
|
public void DimAutoStyle_Text_NoMin_Not_Constrained_By_ContentSize (string text, int expectedW, int expectedH)
|
|
|
{
|
|
|
var view = new View ();
|
|
@@ -711,7 +864,6 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
Assert.Equal (new (expectedW, expectedH), view.Frame.Size);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
[Theory]
|
|
|
[InlineData ("", 0, 0)]
|
|
|
[InlineData (" ", 1, 1)]
|
|
@@ -720,7 +872,7 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
[InlineData ("01234\nABCDE", 5, 2)]
|
|
|
public void DimAutoStyle_Text_NoMin_Not_Constrained_By_SuperView (string text, int expectedW, int expectedH)
|
|
|
{
|
|
|
- var superView = new View ()
|
|
|
+ var superView = new View
|
|
|
{
|
|
|
Width = 1, Height = 1
|
|
|
};
|
|
@@ -870,100 +1022,5 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
|
|
|
|
|
#endregion DimAutoStyle.Content tests
|
|
|
|
|
|
- [Fact]
|
|
|
- public void TextFormatter_Settings_Change_View_Size ()
|
|
|
- {
|
|
|
- View view = new ()
|
|
|
- {
|
|
|
- Text = "_1234",
|
|
|
- Width = Auto ()
|
|
|
- };
|
|
|
- Assert.Equal (new (4, 0), view.Frame.Size);
|
|
|
-
|
|
|
- view.Height = 1;
|
|
|
- view.SetRelativeLayout (Application.Screen.Size);
|
|
|
- Assert.Equal (new (4, 1), view.Frame.Size);
|
|
|
- Size lastSize = view.Frame.Size;
|
|
|
-
|
|
|
- view.TextAlignment = Alignment.Fill;
|
|
|
- Assert.Equal (lastSize, view.Frame.Size);
|
|
|
-
|
|
|
- view = new ()
|
|
|
- {
|
|
|
- Text = "_1234",
|
|
|
- Width = Auto (),
|
|
|
- Height = 1
|
|
|
- };
|
|
|
- view.SetRelativeLayout (Application.Screen.Size);
|
|
|
-
|
|
|
- lastSize = view.Frame.Size;
|
|
|
- view.VerticalTextAlignment = Alignment.Center;
|
|
|
- Assert.Equal (lastSize, view.Frame.Size);
|
|
|
-
|
|
|
- view = new ()
|
|
|
- {
|
|
|
- Text = "_1234",
|
|
|
- Width = Auto (),
|
|
|
- Height = 1
|
|
|
- };
|
|
|
- view.SetRelativeLayout (Application.Screen.Size);
|
|
|
- lastSize = view.Frame.Size;
|
|
|
- view.HotKeySpecifier = (Rune)'*';
|
|
|
- view.SetRelativeLayout (Application.Screen.Size);
|
|
|
- Assert.NotEqual (lastSize, view.Frame.Size);
|
|
|
-
|
|
|
- view = new ()
|
|
|
- {
|
|
|
- Text = "_1234",
|
|
|
- Width = Auto (),
|
|
|
- Height = 1
|
|
|
- };
|
|
|
- view.SetRelativeLayout (Application.Screen.Size);
|
|
|
- lastSize = view.Frame.Size;
|
|
|
- view.Text = "*ABCD";
|
|
|
- Assert.NotEqual (lastSize, view.Frame.Size);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- [Theory]
|
|
|
- [CombinatorialData]
|
|
|
- public void HotKey_TextFormatter_Width_Correct ([CombinatorialValues ("1234", "_1234", "1_234", "____")] string text)
|
|
|
- {
|
|
|
- View view = new ()
|
|
|
- {
|
|
|
- Text = text,
|
|
|
- Height = 1,
|
|
|
- Width = Auto ()
|
|
|
- };
|
|
|
- Assert.Equal (4, view.TextFormatter.ConstrainToWidth);
|
|
|
- Assert.Equal (1, view.TextFormatter.ConstrainToHeight);
|
|
|
- }
|
|
|
-
|
|
|
- [Theory]
|
|
|
- [CombinatorialData]
|
|
|
- public void HotKey_TextFormatter_Height_Correct ([CombinatorialValues ("1234", "_1234", "1_234", "____")] string text)
|
|
|
- {
|
|
|
- View view = new ()
|
|
|
- {
|
|
|
- HotKeySpecifier = (Rune)'_',
|
|
|
- Text = text,
|
|
|
- Width = Auto (),
|
|
|
- Height = 1
|
|
|
- };
|
|
|
- Assert.Equal (4, view.TextFormatter.ConstrainToWidth);
|
|
|
- Assert.Equal (1, view.TextFormatter.ConstrainToHeight);
|
|
|
-
|
|
|
- view = new ()
|
|
|
- {
|
|
|
- HotKeySpecifier = (Rune)'_',
|
|
|
- TextDirection = TextDirection.TopBottom_LeftRight,
|
|
|
- Text = text,
|
|
|
- Width = 1,
|
|
|
- Height = Auto ()
|
|
|
- };
|
|
|
- Assert.Equal (1, view.TextFormatter.ConstrainToWidth);
|
|
|
- Assert.Equal (4, view.TextFormatter.ConstrainToHeight);
|
|
|
- }
|
|
|
-
|
|
|
// Test variations of Frame
|
|
|
}
|