mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
New unit tests. Lots of fixes
This commit is contained in:
@@ -394,7 +394,7 @@ public class DrawTests (ITestOutputHelper _output)
|
||||
var view = new View { Width = 2, Height = 2, BorderStyle = LineStyle.Single };
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
view.SetRelativeLayout (Application.Driver.Screen.Size);
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
|
||||
Assert.Equal (new (0, 0, 2, 2), view.Frame);
|
||||
Assert.Equal (Rectangle.Empty, view.Viewport);
|
||||
@@ -419,7 +419,7 @@ public class DrawTests (ITestOutputHelper _output)
|
||||
view.Border.Thickness = new Thickness (1, 1, 1, 0);
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
view.SetRelativeLayout (Application.Driver.Screen.Size);
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
|
||||
Assert.Equal (new (0, 0, 2, 1), view.Frame);
|
||||
Assert.Equal (Rectangle.Empty, view.Viewport);
|
||||
@@ -437,7 +437,7 @@ public class DrawTests (ITestOutputHelper _output)
|
||||
view.Border.Thickness = new Thickness (0, 1, 1, 1);
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
view.SetRelativeLayout (Application.Driver.Screen.Size);
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
|
||||
Assert.Equal (new (0, 0, 1, 2), view.Frame);
|
||||
Assert.Equal (Rectangle.Empty, view.Viewport);
|
||||
@@ -462,7 +462,7 @@ public class DrawTests (ITestOutputHelper _output)
|
||||
view.Border.Thickness = new Thickness (1, 1, 0, 1);
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
view.SetRelativeLayout (Application.Driver.Screen.Size);
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
|
||||
Assert.Equal (new (0, 0, 1, 2), view.Frame);
|
||||
Assert.Equal (Rectangle.Empty, view.Viewport);
|
||||
@@ -488,7 +488,7 @@ public class DrawTests (ITestOutputHelper _output)
|
||||
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
view.SetRelativeLayout (Application.Driver.Screen.Size);
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
|
||||
Assert.Equal (new (0, 0, 2, 1), view.Frame);
|
||||
Assert.Equal (Rectangle.Empty, view.Viewport);
|
||||
|
||||
@@ -976,8 +976,9 @@ public class DimAutoTests (ITestOutputHelper output)
|
||||
public void DimAutoStyle_Content_IgnoresSubviews_When_ContentSize_Is_Set ()
|
||||
{
|
||||
var view = new View ();
|
||||
var subview = new View () {
|
||||
Frame = new Rectangle (50, 50, 1, 1)
|
||||
var subview = new View ()
|
||||
{
|
||||
Frame = new Rectangle (50, 50, 1, 1)
|
||||
};
|
||||
view.SetContentSize (new (10, 5));
|
||||
|
||||
@@ -1045,27 +1046,34 @@ public class DimAutoTests (ITestOutputHelper output)
|
||||
[InlineData (1, 50, 51)]
|
||||
[InlineData (0, 25, 25)]
|
||||
[InlineData (-1, 50, 49)]
|
||||
public void With_Subview_Using_DimFactor (int subViewOffset, int dimFactor, int expectedSize)
|
||||
public void With_Subview_Using_DimPercent (int subViewOffset, int percent, int expectedSize)
|
||||
{
|
||||
var view = new View () { Width = 100, Height = 100 };
|
||||
var view = new View ()
|
||||
{
|
||||
Width = 100, Height = 100
|
||||
};
|
||||
var subview = new View ()
|
||||
{
|
||||
X = subViewOffset,
|
||||
Y = subViewOffset,
|
||||
Width = Dim.Percent (dimFactor),
|
||||
Height = Dim.Percent (dimFactor)
|
||||
Width = Dim.Percent (percent),
|
||||
Height = Dim.Percent (percent)
|
||||
};
|
||||
view.Add (subview);
|
||||
|
||||
subview.SetRelativeLayout (new (100, 100));
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
|
||||
var dim = Dim.Auto (DimAutoStyle.Content);
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedX = subview.X.Calculate (100, subview.Width, subview, Dimension.Width);
|
||||
int calculatedY = subview.Y.Calculate (100, subview.Height, subview, Dimension.Height);
|
||||
int calculatedWidth = subview.Width.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = subview.Height.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
Assert.Equal (expectedSize, calculatedWidth);
|
||||
Assert.Equal (expectedSize, calculatedHeight);
|
||||
Assert.Equal (20, calculatedWidth); // subview's width
|
||||
Assert.Equal (10, calculatedHeight); // subview's height
|
||||
Assert.Equal (50, calculatedX); // 50% of 100 (Width)
|
||||
Assert.Equal (50, calculatedY); // 50% of 100 (Height)
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -1090,7 +1098,7 @@ public class DimAutoTests (ITestOutputHelper output)
|
||||
};
|
||||
view.Add (subview);
|
||||
//view.LayoutSubviews ();
|
||||
view.SetRelativeLayout(new (200,200));
|
||||
view.SetRelativeLayout (new (200, 200));
|
||||
|
||||
Assert.Equal (expectedSize, view.Frame.Width);
|
||||
}
|
||||
@@ -1136,72 +1144,226 @@ public class DimAutoTests (ITestOutputHelper output)
|
||||
|
||||
// Testing all Pos combinations
|
||||
|
||||
[Fact]
|
||||
public void With_Subview_At_PosAt ()
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 19, 0, 9, 19, 9)]
|
||||
[InlineData (0, 20, 0, 10, 20, 10)]
|
||||
[InlineData (0, 21, 0, 11, 21, 11)]
|
||||
[InlineData (1, 21, 1, 11, 21, 11)]
|
||||
[InlineData (100, 21, 100, 11, 21, 11)]
|
||||
public void With_Subview_Using_PosAbsolute (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var view = new View ();
|
||||
var subview = new View () { X = Pos.Absolute (10), Y = Pos.Absolute (5), Width = 20, Height = 10 };
|
||||
view.Add (subview);
|
||||
|
||||
var dimWidth = Dim.Auto ();
|
||||
var dimHeight = Dim.Auto ();
|
||||
|
||||
int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
// Expecting the size to include the subview's position and size
|
||||
Assert.Equal (30, calculatedWidth); // 10 (X position) + 20 (Width)
|
||||
Assert.Equal (15, calculatedHeight); // 5 (Y position) + 10 (Height)
|
||||
}
|
||||
|
||||
[Fact (Skip = "TextOnly")]
|
||||
public void With_Subview_At_PosPercent ()
|
||||
{
|
||||
var view = new View () { Width = 100, Height = 100 };
|
||||
var subview = new View () { X = Pos.Percent (50), Y = Pos.Percent (50), Width = 20, Height = 10 };
|
||||
view.Add (subview);
|
||||
|
||||
var dimWidth = Dim.Auto ();
|
||||
var dimHeight = Dim.Auto ();
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
// Expecting the size to include the subview's position as a percentage of the parent view's size plus the subview's size
|
||||
Assert.Equal (70, calculatedWidth); // 50% of 100 (Width) + 20
|
||||
Assert.Equal (60, calculatedHeight); // 50% of 100 (Height) + 10
|
||||
}
|
||||
|
||||
[Fact (Skip = "TextOnly")]
|
||||
public void With_Subview_At_PosCenter ()
|
||||
{
|
||||
var view = new View () { Width = 100, Height = 100 };
|
||||
var subview = new View () { X = Pos.Center (), Y = Pos.Center (), Width = 20, Height = 10 };
|
||||
view.Add (subview);
|
||||
|
||||
var dimWidth = Dim.Auto ();
|
||||
var dimHeight = Dim.Auto ();
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
// Expecting the size to include the subview's position at the center of the parent view plus the subview's size
|
||||
Assert.Equal (70, calculatedWidth); // Centered in 100 (Width) + 20
|
||||
Assert.Equal (60, calculatedHeight); // Centered in 100 (Height) + 10
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void With_Subview_At_PosAnchorEnd ()
|
||||
{
|
||||
var dimWidth = Dim.Auto ();
|
||||
var dimHeight = Dim.Auto ();
|
||||
|
||||
var view = new View ()
|
||||
{
|
||||
Width = dimWidth,
|
||||
Height = dimHeight
|
||||
Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
|
||||
Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
|
||||
};
|
||||
var subview = new View ()
|
||||
{
|
||||
X = Pos.Absolute (10),
|
||||
Y = Pos.Absolute (5),
|
||||
Width = 20,
|
||||
Height = 10
|
||||
};
|
||||
view.Add (subview);
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
|
||||
int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
|
||||
int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
Assert.Equal (expectedWidth, calculatedWidth);
|
||||
Assert.Equal (expectedHeight, calculatedHeight);
|
||||
|
||||
Assert.Equal (0, calculatedX);
|
||||
Assert.Equal (0, calculatedY);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 19, 0, 9, 19, 9)]
|
||||
[InlineData (0, 20, 0, 10, 20, 10)]
|
||||
[InlineData (0, 21, 0, 11, 20, 10)]
|
||||
[InlineData (1, 21, 1, 11, 20, 10)]
|
||||
[InlineData (100, 21, 100, 11, 21, 11)]
|
||||
public void With_Subview_Using_PosPercent (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var view = new View ()
|
||||
{
|
||||
Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
|
||||
Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
|
||||
};
|
||||
var subview = new View ()
|
||||
{
|
||||
X = Pos.Percent (50),
|
||||
Y = Pos.Percent (50),
|
||||
Width = 20,
|
||||
Height = 10
|
||||
};
|
||||
view.Add (subview);
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
|
||||
int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
|
||||
int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
Assert.Equal (expectedWidth, calculatedWidth);
|
||||
Assert.Equal (expectedHeight, calculatedHeight);
|
||||
|
||||
Assert.Equal (0, calculatedX);
|
||||
Assert.Equal (0, calculatedY);
|
||||
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
// subview should be at 50% in the parent view
|
||||
Assert.Equal ((int)(view.Viewport.Width * .50), subview.Frame.X);
|
||||
Assert.Equal ((int)(view.Viewport.Height * .50), subview.Frame.Y);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 19, 0, 9, 19, 9)]
|
||||
[InlineData (0, 20, 0, 10, 20, 10)]
|
||||
[InlineData (0, 21, 0, 11, 21, 11)]
|
||||
[InlineData (1, 21, 1, 11, 21, 11)]
|
||||
[InlineData (100, 21, 100, 11, 21, 11)]
|
||||
public void With_Subview_Using_PosPercent_Combine (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var view = new View ()
|
||||
{
|
||||
Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
|
||||
Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
|
||||
};
|
||||
var subview = new View ()
|
||||
{
|
||||
X = Pos.Percent (50) + 1,
|
||||
Y = 1 + Pos.Percent (50),
|
||||
Width = 20,
|
||||
Height = 10
|
||||
};
|
||||
view.Add (subview);
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
|
||||
int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
|
||||
int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
Assert.Equal (expectedWidth, calculatedWidth);
|
||||
Assert.Equal (expectedHeight, calculatedHeight);
|
||||
|
||||
Assert.Equal (0, calculatedX);
|
||||
Assert.Equal (0, calculatedY);
|
||||
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
// subview should be at 50% in the parent view
|
||||
Assert.Equal ((int)(view.Viewport.Width * .50) + 1, subview.Frame.X);
|
||||
Assert.Equal ((int)(view.Viewport.Height * .50) + 1, subview.Frame.Y);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 19, 0, 9, 19, 9)]
|
||||
[InlineData (0, 20, 0, 10, 20, 10)]
|
||||
[InlineData (0, 21, 0, 11, 21, 11)]
|
||||
[InlineData (1, 21, 1, 11, 21, 11)]
|
||||
[InlineData (100, 21, 100, 11, 21, 11)]
|
||||
public void With_Subview_Using_PosCenter (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var view = new View ()
|
||||
{
|
||||
Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
|
||||
Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
|
||||
};
|
||||
var subview = new View ()
|
||||
{
|
||||
X = Pos.Center (),
|
||||
Y = Pos.Center (),
|
||||
Width = 20,
|
||||
Height = 10
|
||||
};
|
||||
view.Add (subview);
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
|
||||
int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
|
||||
int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
Assert.Equal (expectedWidth, calculatedWidth);
|
||||
Assert.Equal (expectedHeight, calculatedHeight);
|
||||
|
||||
Assert.Equal (0, calculatedX);
|
||||
Assert.Equal (0, calculatedY);
|
||||
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
// subview should be centered in the parent view + 1
|
||||
Assert.Equal (view.Viewport.Width / 2 - subview.Frame.Width / 2, subview.Frame.X);
|
||||
Assert.Equal (view.Viewport.Height / 2 - subview.Frame.Height / 2, subview.Frame.Y);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 19, 0, 9, 19, 9)]
|
||||
[InlineData (0, 18, 0, 8, 18, 8)]
|
||||
[InlineData (0, 20, 0, 10, 20, 10)]
|
||||
[InlineData (0, 21, 0, 11, 21, 11)]
|
||||
[InlineData (1, 21, 1, 11, 21, 11)]
|
||||
[InlineData (100, 21, 100, 11, 21, 11)]
|
||||
public void With_Subview_Using_PosCenter_Combine (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var view = new View ()
|
||||
{
|
||||
Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
|
||||
Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
|
||||
};
|
||||
|
||||
var subview = new View ()
|
||||
{
|
||||
X = Pos.Center () + 1,
|
||||
Y = 1 + Pos.Center (),
|
||||
Width = 20,
|
||||
Height = 10
|
||||
};
|
||||
view.Add (subview);
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
|
||||
int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
|
||||
int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
Assert.Equal (expectedWidth, calculatedWidth);
|
||||
Assert.Equal (expectedHeight, calculatedHeight);
|
||||
|
||||
Assert.Equal (0, calculatedX);
|
||||
Assert.Equal (0, calculatedY);
|
||||
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
// subview should be centered in the parent view + 1
|
||||
Assert.Equal (view.Viewport.Width / 2 - subview.Frame.Width / 2 + 1, subview.Frame.X);
|
||||
Assert.Equal (view.Viewport.Height / 2 - subview.Frame.Height / 2 + 1, subview.Frame.Y);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 0, 0, 0, 0, 0)]
|
||||
[InlineData (0, 19, 0, 9, 19, 9)]
|
||||
[InlineData (0, 18, 0, 8, 18, 8)]
|
||||
[InlineData (0, 20, 0, 10, 20, 10)]
|
||||
[InlineData (0, 21, 0, 11, 20, 10)]
|
||||
[InlineData (1, 21, 1, 11, 20, 10)]
|
||||
[InlineData (100, 21, 100, 11, 21, 11)]
|
||||
public void With_Subview_Using_PosAnchorEnd (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var view = new View ()
|
||||
{
|
||||
Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
|
||||
Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
|
||||
};
|
||||
|
||||
var subview = new View ()
|
||||
@@ -1214,12 +1376,22 @@ public class DimAutoTests (ITestOutputHelper output)
|
||||
view.Add (subview);
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height);
|
||||
int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
|
||||
int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
|
||||
int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
// Expecting the size to include the subview's position at the end of the parent view minus the offset plus the subview's size
|
||||
Assert.Equal (20, calculatedWidth);
|
||||
Assert.Equal (10, calculatedHeight);
|
||||
Assert.Equal (expectedWidth, calculatedWidth);
|
||||
Assert.Equal (expectedHeight, calculatedHeight);
|
||||
|
||||
Assert.Equal (0, calculatedX);
|
||||
Assert.Equal (0, calculatedY);
|
||||
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
// subview should be at the end of the view
|
||||
Assert.Equal (view.Viewport.Width - subview.Frame.Width, subview.Frame.X);
|
||||
Assert.Equal (view.Viewport.Height - subview.Frame.Height, subview.Frame.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -51,12 +51,31 @@ public class PosCenterTests (ITestOutputHelper output)
|
||||
Assert.IsType<PosCenter> (pos);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PosCenter_Calculate_ReturnsExpectedValue ()
|
||||
[Theory]
|
||||
[InlineData (10, 2, 4)]
|
||||
[InlineData (10, 10, 0)]
|
||||
[InlineData (10, 11, 0)]
|
||||
[InlineData (10, 12, -1)]
|
||||
[InlineData (19, 20, -1)]
|
||||
public void PosCenter_Calculate_ReturnsExpectedValue (int superviewDimension, int width, int expectedX)
|
||||
{
|
||||
var posCenter = new PosCenter ();
|
||||
int result = posCenter.Calculate (10, new DimAbsolute (2), null, Dimension.None);
|
||||
Assert.Equal (4, result);
|
||||
int result = posCenter.Calculate (superviewDimension, new DimAbsolute (width), null!, Dimension.Width);
|
||||
Assert.Equal (expectedX, result);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void PosCenter_Bigger_Than_SuperView ()
|
||||
{
|
||||
var superView = new View { Width = 10, Height = 10 };
|
||||
var view = new View { X = Center (), Y = Center (), Width = 20, Height = 20 };
|
||||
superView.Add (view);
|
||||
superView.BeginInit();
|
||||
superView.EndInit();
|
||||
|
||||
Assert.Equal (-5, view.Frame.Left);
|
||||
Assert.Equal (-5, view.Frame.Top);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -7,6 +7,20 @@ public class PosPercentTests (ITestOutputHelper output)
|
||||
{
|
||||
private readonly ITestOutputHelper _output = output;
|
||||
|
||||
[Theory]
|
||||
[InlineData (50, 10, 2, 5)]
|
||||
[InlineData (50, 10, 10, 5)]
|
||||
[InlineData (50, 10, 11, 5)]
|
||||
[InlineData (50, 10, 12, 5)]
|
||||
[InlineData (50, 19, 20, 9)]
|
||||
public void PosPercent_Calculate_ReturnsExpectedValue (int percent, int superviewDimension, int width, int expectedX)
|
||||
{
|
||||
var posPercent = new PosPercent (percent);
|
||||
int result = posPercent.Calculate (superviewDimension, new DimAbsolute (width), null!, Dimension.Width);
|
||||
Assert.Equal (expectedX, result);
|
||||
}
|
||||
|
||||
|
||||
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
|
||||
// TODO: A new test that calls SetRelativeLayout directly is needed.
|
||||
[Theory]
|
||||
|
||||
@@ -778,56 +778,7 @@ Y
|
||||
Application.End (rs);
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
public void GetTextFormatterBoundsSize_GetSizeNeededForText_HotKeySpecifier ()
|
||||
{
|
||||
var text = "Say Hello 你";
|
||||
|
||||
// Frame: 0, 0, 12, 1
|
||||
var horizontalView = new View
|
||||
{
|
||||
Width = Dim.Auto (), Height = Dim.Auto ()
|
||||
};
|
||||
horizontalView.TextFormatter.HotKeySpecifier = (Rune)'_';
|
||||
horizontalView.Text = text;
|
||||
|
||||
// Frame: 0, 0, 1, 12
|
||||
var verticalView = new View
|
||||
{
|
||||
Width = Dim.Auto (), Height = Dim.Auto (), TextDirection = TextDirection.TopBottom_LeftRight
|
||||
};
|
||||
verticalView.Text = text;
|
||||
verticalView.TextFormatter.HotKeySpecifier = (Rune)'_';
|
||||
|
||||
var top = new Toplevel ();
|
||||
top.Add (horizontalView, verticalView);
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (50, 50);
|
||||
|
||||
Assert.Equal (new (0, 0, 12, 1), horizontalView.Frame);
|
||||
Assert.Equal (new (12, 1), horizontalView.GetSizeNeededForTextWithoutHotKey ());
|
||||
Assert.Equal (horizontalView.Frame.Size, horizontalView.GetSizeNeededForTextWithoutHotKey ());
|
||||
|
||||
Assert.Equal (new (0, 0, 2, 11), verticalView.Frame);
|
||||
Assert.Equal (new (2, 11), verticalView.GetSizeNeededForTextWithoutHotKey ());
|
||||
Assert.Equal (verticalView.Frame.Size, verticalView.GetSizeNeededForTextWithoutHotKey ());
|
||||
|
||||
text = "012345678你";
|
||||
horizontalView.Text = text;
|
||||
verticalView.Text = text;
|
||||
|
||||
Assert.Equal (new (0, 0, 11, 1), horizontalView.Frame);
|
||||
Assert.Equal (new (11, 1), horizontalView.GetSizeNeededForTextWithoutHotKey ());
|
||||
Assert.Equal (horizontalView.Frame.Size, horizontalView.GetSizeNeededForTextWithoutHotKey ());
|
||||
|
||||
Assert.Equal (new (0, 0, 2, 10), verticalView.Frame);
|
||||
Assert.Equal (new (2, 10), verticalView.GetSizeNeededForTextWithoutHotKey ());
|
||||
Assert.Equal (verticalView.Frame.Size, verticalView.GetSizeNeededForTextWithoutHotKey ());
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[AutoInitShutdown]
|
||||
[InlineData (true)]
|
||||
|
||||
@@ -833,10 +833,10 @@ At 0,0
|
||||
TextDirection = TextDirection.TopBottom_LeftRight,
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto ()
|
||||
}; // BUGBUG: AutoSize or Height need be set
|
||||
};
|
||||
r.TextFormatter.WordWrap = false;
|
||||
Assert.NotNull (r);
|
||||
|
||||
// BUGBUG: IsInitialized must be true to process calculation
|
||||
r.BeginInit ();
|
||||
r.EndInit ();
|
||||
Assert.False (r.CanFocus);
|
||||
|
||||
Reference in New Issue
Block a user