mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Improves robustness of Dim, Pos, and SetRelativeLayout (#3077)
* Updated overview docs * Updated toc * Updated docs more * Updated yml via dependabot * Initial work in progress * Fixed some autosize things * Revamped Pos / Dim API docs * Removed margin * horiz->width * Updated MessageBoxes and Dialogs Scenarios to use AutoSize * AutoSize->Auxo * Adds validation * prep for Dialog to use Dim.Auto - Simplify unit tests to not depend on things not important to the unit test (like Dialog) * prep for Dialog to use Dim.Auto - Simplify unit tests * prep for Dialog to use Dim.Auto - Simplify unit tests * prep for Dialog to use Dim.Auto - Make Dialog tests not depend on MessageBox * Started on DimAuto unit tests * started impl on min/max. * started impl on min/max. * Added DimAutoStyle * Added arg checking for not implemented features * Temporarily made DimAutoStyle.Subviews default * Removed unneeded override of Anchor * Fixed GethashCode warning * Implemented DimAuto(min) * Fixed unit tests * renamed scenario * WIP * Moved ViewLayout.cs into Layout folder * Clean up cocde formatting * Renamed and moved SetFrameToFitText * Fixed API docs for SetRelativeLayout * Factored out SetRelativeLayout tests * Better documented existing SetRelativeLayout behavior + unit tess * Debugging Pos.Center + x in SetRelativeLayout - WIP * Progress on low level unit tess * Initial commit * Restored unmodified scenarios * Bump deps
This commit is contained in:
@@ -2,338 +2,374 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using Microsoft.VisualStudio.TestPlatform.Utilities;
|
||||
|
||||
namespace Terminal.Gui.ViewsTests {
|
||||
public class DrawTests {
|
||||
readonly ITestOutputHelper output;
|
||||
namespace Terminal.Gui.ViewsTests;
|
||||
|
||||
public DrawTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
public class DrawTests {
|
||||
readonly ITestOutputHelper _output;
|
||||
|
||||
// TODO: The tests below that use Label should use View instead.
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Non_Bmp_ConsoleWidth_ColumnWidth_Equal_Two ()
|
||||
{
|
||||
string us = "\U0001d539";
|
||||
Rune r = (Rune)0x1d539;
|
||||
public DrawTests (ITestOutputHelper output) => _output = output;
|
||||
|
||||
Assert.Equal ("𝔹", us);
|
||||
Assert.Equal ("𝔹", r.ToString ());
|
||||
Assert.Equal (us, r.ToString ());
|
||||
[Fact] [AutoInitShutdown]
|
||||
public void Clipping_AddRune_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space ()
|
||||
{
|
||||
var tv = new TextView () {
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
Text = @"これは広いルーンラインです。
|
||||
これは広いルーンラインです。
|
||||
これは広いルーンラインです。
|
||||
これは広いルーンラインです。
|
||||
これは広いルーンラインです。
|
||||
これは広いルーンラインです。
|
||||
これは広いルーンラインです。
|
||||
これは広いルーンラインです。"
|
||||
};
|
||||
var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (tv);
|
||||
Application.Top.Add (win);
|
||||
var lbl = new Label ("ワイドルーン。");
|
||||
// Don't have unit tests use things that aren't absolutely critical for the test, like Dialog
|
||||
var dg = new Window () { X = 2, Y = 2, Width = 14, Height = 3 };
|
||||
dg.Add (lbl);
|
||||
Application.Begin (Application.Top);
|
||||
Application.Begin (dg);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (30, 10);
|
||||
|
||||
Assert.Equal (1, us.GetColumns ());
|
||||
Assert.Equal (1, r.GetColumns ());
|
||||
string expected = @$"
|
||||
┌────────────────────────────┐
|
||||
│これは広いルーンラインです。│
|
||||
│<EFBFBD>┌────────────┐<EFBFBD>ラインです。│
|
||||
│<EFBFBD>│ワイドルーン│<EFBFBD>ラインです。│
|
||||
│<EFBFBD>└────────────┘<EFBFBD>ラインです。│
|
||||
│これは広いルーンラインです。│
|
||||
│これは広いルーンラインです。│
|
||||
│これは広いルーンラインです。│
|
||||
│これは広いルーンラインです。│
|
||||
└────────────────────────────┘";
|
||||
|
||||
var win = new Window () { Title = us };
|
||||
var label = new Label (r.ToString ());
|
||||
var tf = new TextField (us) { Y = 1, Width = 3 };
|
||||
win.Add (label, tf);
|
||||
var top = Application.Top;
|
||||
top.Add (win);
|
||||
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
||||
Assert.Equal (new Rect (0, 0, 30, 10), pos);
|
||||
}
|
||||
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
|
||||
// TODO: The tests below that use Label should use View instead.
|
||||
[Fact] [AutoInitShutdown]
|
||||
public void Non_Bmp_ConsoleWidth_ColumnWidth_Equal_Two ()
|
||||
{
|
||||
string us = "\U0001d539";
|
||||
var r = (Rune)0x1d539;
|
||||
|
||||
var expected = @"
|
||||
Assert.Equal ("𝔹", us);
|
||||
Assert.Equal ("𝔹", r.ToString ());
|
||||
Assert.Equal (us, r.ToString ());
|
||||
|
||||
Assert.Equal (1, us.GetColumns ());
|
||||
Assert.Equal (1, r.GetColumns ());
|
||||
|
||||
var win = new Window () { Title = us };
|
||||
var label = new Label (r.ToString ());
|
||||
var tf = new TextField (us) { Y = 1, Width = 3 };
|
||||
win.Add (label, tf);
|
||||
var top = Application.Top;
|
||||
top.Add (win);
|
||||
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
|
||||
|
||||
string expected = @"
|
||||
┌┤𝔹├─────┐
|
||||
│𝔹 │
|
||||
│𝔹 │
|
||||
└────────┘";
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
||||
|
||||
TestHelpers.AssertDriverContentsAre (expected, output);
|
||||
TestHelpers.AssertDriverContentsAre (expected, _output);
|
||||
|
||||
var expectedColors = new Attribute [] {
|
||||
// 0
|
||||
Colors.Base.Normal,
|
||||
// 1
|
||||
Colors.Base.Focus,
|
||||
// 2
|
||||
Colors.Base.HotNormal
|
||||
};
|
||||
var expectedColors = new Attribute [] {
|
||||
// 0
|
||||
Colors.Base.Normal,
|
||||
// 1
|
||||
Colors.Base.Focus,
|
||||
// 2
|
||||
Colors.Base.HotNormal
|
||||
};
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
0020000000
|
||||
0000000000
|
||||
0111000000
|
||||
0000000000", driver: Application.Driver, expectedColors);
|
||||
}
|
||||
0000000000", Application.Driver, expectedColors);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void CJK_Compatibility_Ideographs_ConsoleWidth_ColumnWidth_Equal_Two ()
|
||||
{
|
||||
string us = "\U0000f900";
|
||||
Rune r = (Rune)0xf900;
|
||||
[Fact] [AutoInitShutdown]
|
||||
public void CJK_Compatibility_Ideographs_ConsoleWidth_ColumnWidth_Equal_Two ()
|
||||
{
|
||||
string us = "\U0000f900";
|
||||
var r = (Rune)0xf900;
|
||||
|
||||
Assert.Equal ("豈", us);
|
||||
Assert.Equal ("豈", r.ToString ());
|
||||
Assert.Equal (us, r.ToString ());
|
||||
Assert.Equal ("豈", us);
|
||||
Assert.Equal ("豈", r.ToString ());
|
||||
Assert.Equal (us, r.ToString ());
|
||||
|
||||
Assert.Equal (2, us.GetColumns ());
|
||||
Assert.Equal (2, r.GetColumns ());
|
||||
Assert.Equal (2, us.GetColumns ());
|
||||
Assert.Equal (2, r.GetColumns ());
|
||||
|
||||
var win = new Window () { Title = us };
|
||||
var label = new Label (r.ToString ());
|
||||
var tf = new TextField (us) { Y = 1, Width = 3 };
|
||||
win.Add (label, tf);
|
||||
var top = Application.Top;
|
||||
top.Add (win);
|
||||
var win = new Window () { Title = us };
|
||||
var label = new Label (r.ToString ());
|
||||
var tf = new TextField (us) { Y = 1, Width = 3 };
|
||||
win.Add (label, tf);
|
||||
var top = Application.Top;
|
||||
top.Add (win);
|
||||
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
|
||||
|
||||
var expected = @"
|
||||
string expected = @"
|
||||
┌┤豈├────┐
|
||||
│豈 │
|
||||
│豈 │
|
||||
└────────┘";
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
||||
|
||||
TestHelpers.AssertDriverContentsAre (expected, output);
|
||||
TestHelpers.AssertDriverContentsAre (expected, _output);
|
||||
|
||||
var expectedColors = new Attribute [] {
|
||||
// 0
|
||||
Colors.Base.Normal,
|
||||
// 1
|
||||
Colors.Base.Focus,
|
||||
// 2
|
||||
Colors.Base.HotNormal
|
||||
};
|
||||
var expectedColors = new Attribute [] {
|
||||
// 0
|
||||
Colors.Base.Normal,
|
||||
// 1
|
||||
Colors.Base.Focus,
|
||||
// 2
|
||||
Colors.Base.HotNormal
|
||||
};
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
0022000000
|
||||
0000000000
|
||||
0111000000
|
||||
0000000000", driver: Application.Driver, expectedColors);
|
||||
}
|
||||
0000000000", Application.Driver, expectedColors);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Colors_On_TextAlignment_Right_And_Bottom ()
|
||||
{
|
||||
var labelRight = new Label ("Test") {
|
||||
Width = 6,
|
||||
Height = 1,
|
||||
TextAlignment = TextAlignment.Right,
|
||||
ColorScheme = Colors.Base
|
||||
};
|
||||
var labelBottom = new Label ("Test", TextDirection.TopBottom_LeftRight) {
|
||||
Y = 1,
|
||||
Width = 1,
|
||||
Height = 6,
|
||||
VerticalTextAlignment = VerticalTextAlignment.Bottom,
|
||||
ColorScheme = Colors.Base
|
||||
};
|
||||
var top = Application.Top;
|
||||
top.Add (labelRight, labelBottom);
|
||||
[Fact] [AutoInitShutdown]
|
||||
public void Colors_On_TextAlignment_Right_And_Bottom ()
|
||||
{
|
||||
var labelRight = new Label ("Test") {
|
||||
Width = 6,
|
||||
Height = 1,
|
||||
TextAlignment = TextAlignment.Right,
|
||||
ColorScheme = Colors.Base
|
||||
};
|
||||
var labelBottom = new Label ("Test", TextDirection.TopBottom_LeftRight) {
|
||||
Y = 1,
|
||||
Width = 1,
|
||||
Height = 6,
|
||||
VerticalTextAlignment = VerticalTextAlignment.Bottom,
|
||||
ColorScheme = Colors.Base
|
||||
};
|
||||
var top = Application.Top;
|
||||
top.Add (labelRight, labelBottom);
|
||||
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (7, 7);
|
||||
Application.Begin (top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (7, 7);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
Test
|
||||
|
||||
|
||||
T
|
||||
e
|
||||
s
|
||||
t ", output);
|
||||
t ", _output);
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
000000
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0", driver: Application.Driver, new Attribute [] { Colors.Base.Normal });
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Draw_Negative_Bounds_Horizontal_Without_New_Lines ()
|
||||
{
|
||||
// BUGBUG: This previously assumed the default height of a View was 1.
|
||||
var subView = new View () { Id = "subView", Y = 1, Width = 7, Height = 1, Text = "subView" };
|
||||
var view = new View () { Id = "view", Width = 20, Height = 2, Text = "01234567890123456789" };
|
||||
view.Add (subView);
|
||||
var content = new View () { Id = "content", Width = 20, Height = 20 };
|
||||
content.Add (view);
|
||||
var container = new View () { Id = "container", X = 1, Y = 1, Width = 5, Height = 5 };
|
||||
container.Add (content);
|
||||
var top = Application.Top;
|
||||
top.Add (container);
|
||||
// BUGBUG: v2 - it's bogus to reference .Frame before BeginInit. And why is the clip being set anyway???
|
||||
|
||||
void Top_LayoutComplete (object sender, LayoutEventArgs e)
|
||||
{
|
||||
Application.Driver.Clip = container.Frame;
|
||||
}
|
||||
top.LayoutComplete += Top_LayoutComplete;
|
||||
Application.Begin (top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
01234
|
||||
subVi", output);
|
||||
|
||||
content.X = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
12345
|
||||
ubVie", output);
|
||||
|
||||
content.Y = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
ubVie", output);
|
||||
|
||||
content.Y = -2;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
|
||||
|
||||
content.X = -20;
|
||||
content.Y = 0;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Draw_Negative_Bounds_Horizontal_With_New_Lines ()
|
||||
{
|
||||
var subView = new View () { Id = "subView", X = 1, Width = 1, Height = 7, Text = "s\nu\nb\nV\ni\ne\nw" };
|
||||
var view = new View () { Id = "view", Width = 2, Height = 20, Text = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9" };
|
||||
view.Add (subView);
|
||||
var content = new View () { Id = "content", Width = 20, Height = 20 };
|
||||
content.Add (view);
|
||||
var container = new View () { Id = "container", X = 1, Y = 1, Width = 5, Height = 5 };
|
||||
container.Add (content);
|
||||
var top = Application.Top;
|
||||
top.Add (container);
|
||||
Application.Driver.Clip = container.Frame;
|
||||
Application.Begin (top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
0s
|
||||
1u
|
||||
2b
|
||||
3V
|
||||
4i", output);
|
||||
|
||||
content.X = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
s
|
||||
u
|
||||
b
|
||||
V
|
||||
i", output);
|
||||
|
||||
content.X = -2;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
|
||||
|
||||
content.X = 0;
|
||||
content.Y = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
1u
|
||||
2b
|
||||
3V
|
||||
4i
|
||||
5e", output);
|
||||
|
||||
content.Y = -6;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
6w
|
||||
7
|
||||
8
|
||||
9
|
||||
0 ", output);
|
||||
|
||||
content.Y = -19;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
9", output);
|
||||
|
||||
content.Y = -20;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
|
||||
|
||||
content.X = -2;
|
||||
content.Y = 0;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Draw_Negative_Bounds_Vertical ()
|
||||
{
|
||||
var subView = new View () { Id = "subView", X = 1, Width = 1, Height = 7, Text = "subView", TextDirection = TextDirection.TopBottom_LeftRight };
|
||||
var view = new View () { Id = "view", Width = 2, Height = 20, Text = "01234567890123456789", TextDirection = TextDirection.TopBottom_LeftRight };
|
||||
view.Add (subView);
|
||||
var content = new View () { Id = "content", Width = 20, Height = 20 };
|
||||
content.Add (view);
|
||||
var container = new View () { Id = "container", X = 1, Y = 1, Width = 5, Height = 5 };
|
||||
container.Add (content);
|
||||
var top = Application.Top;
|
||||
top.Add (container);
|
||||
Application.Driver.Clip = container.Frame;
|
||||
Application.Begin (top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
0s
|
||||
1u
|
||||
2b
|
||||
3V
|
||||
4i", output);
|
||||
|
||||
content.X = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
s
|
||||
u
|
||||
b
|
||||
V
|
||||
i", output);
|
||||
|
||||
content.X = -2;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
|
||||
|
||||
content.X = 0;
|
||||
content.Y = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
1u
|
||||
2b
|
||||
3V
|
||||
4i
|
||||
5e", output);
|
||||
|
||||
content.Y = -6;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
6w
|
||||
7
|
||||
8
|
||||
9
|
||||
0 ", output);
|
||||
|
||||
content.Y = -19;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
9", output);
|
||||
|
||||
content.Y = -20;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
|
||||
|
||||
content.X = -2;
|
||||
content.Y = 0;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
|
||||
}
|
||||
0", Application.Driver, new Attribute [] { Colors.Base.Normal });
|
||||
}
|
||||
}
|
||||
|
||||
[Fact] [AutoInitShutdown]
|
||||
public void Draw_Negative_Bounds_Horizontal_Without_New_Lines ()
|
||||
{
|
||||
// BUGBUG: This previously assumed the default height of a View was 1.
|
||||
var subView = new View () { Id = "subView", Y = 1, Width = 7, Height = 1, Text = "subView" };
|
||||
var view = new View () { Id = "view", Width = 20, Height = 2, Text = "01234567890123456789" };
|
||||
view.Add (subView);
|
||||
var content = new View () { Id = "content", Width = 20, Height = 20 };
|
||||
content.Add (view);
|
||||
var container = new View () { Id = "container", X = 1, Y = 1, Width = 5, Height = 5 };
|
||||
container.Add (content);
|
||||
var top = Application.Top;
|
||||
top.Add (container);
|
||||
// BUGBUG: v2 - it's bogus to reference .Frame before BeginInit. And why is the clip being set anyway???
|
||||
|
||||
void Top_LayoutComplete (object sender, LayoutEventArgs e) => Application.Driver.Clip = container.Frame;
|
||||
top.LayoutComplete += Top_LayoutComplete;
|
||||
Application.Begin (top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
01234
|
||||
subVi", _output);
|
||||
|
||||
content.X = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
12345
|
||||
ubVie", _output);
|
||||
|
||||
content.Y = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
ubVie", _output);
|
||||
|
||||
content.Y = -2;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
|
||||
|
||||
content.X = -20;
|
||||
content.Y = 0;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
|
||||
}
|
||||
|
||||
[Fact] [AutoInitShutdown]
|
||||
public void Draw_Negative_Bounds_Horizontal_With_New_Lines ()
|
||||
{
|
||||
var subView = new View () { Id = "subView", X = 1, Width = 1, Height = 7, Text = "s\nu\nb\nV\ni\ne\nw" };
|
||||
var view = new View () { Id = "view", Width = 2, Height = 20, Text = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9" };
|
||||
view.Add (subView);
|
||||
var content = new View () { Id = "content", Width = 20, Height = 20 };
|
||||
content.Add (view);
|
||||
var container = new View () { Id = "container", X = 1, Y = 1, Width = 5, Height = 5 };
|
||||
container.Add (content);
|
||||
var top = Application.Top;
|
||||
top.Add (container);
|
||||
Application.Driver.Clip = container.Frame;
|
||||
Application.Begin (top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
0s
|
||||
1u
|
||||
2b
|
||||
3V
|
||||
4i", _output);
|
||||
|
||||
content.X = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
s
|
||||
u
|
||||
b
|
||||
V
|
||||
i", _output);
|
||||
|
||||
content.X = -2;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
|
||||
|
||||
content.X = 0;
|
||||
content.Y = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
1u
|
||||
2b
|
||||
3V
|
||||
4i
|
||||
5e", _output);
|
||||
|
||||
content.Y = -6;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
6w
|
||||
7
|
||||
8
|
||||
9
|
||||
0 ", _output);
|
||||
|
||||
content.Y = -19;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
9", _output);
|
||||
|
||||
content.Y = -20;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
|
||||
|
||||
content.X = -2;
|
||||
content.Y = 0;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
|
||||
}
|
||||
|
||||
[Fact] [AutoInitShutdown]
|
||||
public void Draw_Negative_Bounds_Vertical ()
|
||||
{
|
||||
var subView = new View () { Id = "subView", X = 1, Width = 1, Height = 7, Text = "subView", TextDirection = TextDirection.TopBottom_LeftRight };
|
||||
var view = new View () { Id = "view", Width = 2, Height = 20, Text = "01234567890123456789", TextDirection = TextDirection.TopBottom_LeftRight };
|
||||
view.Add (subView);
|
||||
var content = new View () { Id = "content", Width = 20, Height = 20 };
|
||||
content.Add (view);
|
||||
var container = new View () { Id = "container", X = 1, Y = 1, Width = 5, Height = 5 };
|
||||
container.Add (content);
|
||||
var top = Application.Top;
|
||||
top.Add (container);
|
||||
Application.Driver.Clip = container.Frame;
|
||||
Application.Begin (top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
0s
|
||||
1u
|
||||
2b
|
||||
3V
|
||||
4i", _output);
|
||||
|
||||
content.X = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
s
|
||||
u
|
||||
b
|
||||
V
|
||||
i", _output);
|
||||
|
||||
content.X = -2;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
|
||||
|
||||
content.X = 0;
|
||||
content.Y = -1;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
1u
|
||||
2b
|
||||
3V
|
||||
4i
|
||||
5e", _output);
|
||||
|
||||
content.Y = -6;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
6w
|
||||
7
|
||||
8
|
||||
9
|
||||
0 ", _output);
|
||||
|
||||
content.Y = -19;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
9", _output);
|
||||
|
||||
content.Y = -20;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
|
||||
|
||||
content.X = -2;
|
||||
content.Y = 0;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
456
UnitTests/View/Layout/SetRelativeLayoutTests.cs
Normal file
456
UnitTests/View/Layout/SetRelativeLayoutTests.cs
Normal file
@@ -0,0 +1,456 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using static Terminal.Gui.SpinnerStyle;
|
||||
|
||||
namespace Terminal.Gui.ViewTests;
|
||||
|
||||
public class SetRelativeLayoutTests {
|
||||
readonly ITestOutputHelper _output;
|
||||
|
||||
public SetRelativeLayoutTests (ITestOutputHelper output) => _output = output;
|
||||
|
||||
[Fact]
|
||||
public void Null_Pos_Is_Same_As_PosAbsolute0 ()
|
||||
{
|
||||
var view = new View () {
|
||||
X = null,
|
||||
Y = null,
|
||||
};
|
||||
|
||||
// Default layout style is Computed
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.Null (view.X);
|
||||
Assert.Null (view.Y);
|
||||
|
||||
view.BeginInit(); view.EndInit();
|
||||
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.Null (view.X);
|
||||
Assert.Null (view.Y);
|
||||
|
||||
view.SetRelativeLayout (new Rect (5, 5, 10, 10));
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.Null (view.X);
|
||||
Assert.Null (view.Y);
|
||||
|
||||
Assert.Equal (0, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (1, 1)]
|
||||
[InlineData (0, 0)]
|
||||
public void NonNull_Pos (int pos, int expectedPos)
|
||||
{
|
||||
var view = new View () {
|
||||
X = pos,
|
||||
Y = pos,
|
||||
};
|
||||
|
||||
// Default layout style is Computed
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.NotNull (view.X);
|
||||
Assert.NotNull (view.Y);
|
||||
|
||||
view.BeginInit (); view.EndInit ();
|
||||
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.NotNull (view.X);
|
||||
Assert.NotNull (view.Y);
|
||||
|
||||
view.SetRelativeLayout (new Rect (5, 5, 10, 10));
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.NotNull (view.X);
|
||||
Assert.NotNull (view.Y);
|
||||
|
||||
Assert.Equal (expectedPos, view.Frame.X);
|
||||
Assert.Equal (expectedPos, view.Frame.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Null_Dim_Is_Same_As_DimFill0 ()
|
||||
{
|
||||
var view = new View () {
|
||||
Width = null,
|
||||
Height = null,
|
||||
};
|
||||
|
||||
// Default layout style is Computed
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.Null (view.Width);
|
||||
Assert.Null (view.Height);
|
||||
view.BeginInit (); view.EndInit ();
|
||||
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.Null (view.Width);
|
||||
Assert.Null (view.Height);
|
||||
|
||||
view.SetRelativeLayout (new Rect (5, 5, 10, 10));
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.Null (view.Width);
|
||||
Assert.Null (view.Height);
|
||||
|
||||
Assert.Equal (0, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
|
||||
Assert.Equal (10, view.Frame.Width);
|
||||
Assert.Equal (10, view.Frame.Height);
|
||||
|
||||
view.Width = Dim.Fill (0);
|
||||
view.Height = Dim.Fill (0);
|
||||
view.SetRelativeLayout (new Rect (5, 5, 10, 10));
|
||||
Assert.Equal (10, view.Frame.Width);
|
||||
Assert.Equal (10, view.Frame.Height);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1)]
|
||||
[InlineData (0, 0)]
|
||||
public void NonNull_Dim (int dim, int expectedDim)
|
||||
{
|
||||
var view = new View () {
|
||||
Width = dim,
|
||||
Height = dim,
|
||||
};
|
||||
|
||||
// Default layout style is Computed
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.NotNull (view.Width);
|
||||
Assert.NotNull (view.Height);
|
||||
view.BeginInit (); view.EndInit ();
|
||||
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.NotNull (view.Width);
|
||||
Assert.NotNull (view.Height);
|
||||
|
||||
view.SetRelativeLayout (new Rect (5, 5, 10, 10));
|
||||
Assert.Equal (LayoutStyle.Computed, view.LayoutStyle);
|
||||
Assert.NotNull (view.Width);
|
||||
Assert.NotNull (view.Height);
|
||||
|
||||
Assert.Equal (0, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
// BUGBUG: Width == null is same as Dim.Absolute (0) (or should be). Thus this is a bug.
|
||||
Assert.Equal (expectedDim, view.Frame.Width);
|
||||
Assert.Equal (expectedDim, view.Frame.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Fill_Pos_Within_Bounds ()
|
||||
{
|
||||
var screen = new Rect (0, 0, 80, 25);
|
||||
var view = new View () {
|
||||
X = 1,
|
||||
Y = 1,
|
||||
Width = 5,
|
||||
Height = 4
|
||||
};
|
||||
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (1, view.Frame.X);
|
||||
Assert.Equal (1, view.Frame.Y);
|
||||
Assert.Equal (5, view.Frame.Width);
|
||||
Assert.Equal (4, view.Frame.Height);
|
||||
|
||||
view.Width = 80;
|
||||
view.Height = 25;
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (1, view.Frame.X);
|
||||
Assert.Equal (1, view.Frame.Y);
|
||||
Assert.Equal (80, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.Width = Dim.Fill ();
|
||||
view.Height = Dim.Fill ();
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (1, view.Frame.X);
|
||||
Assert.Equal (1, view.Frame.Y);
|
||||
Assert.Equal (79, view.Frame.Width); // proof (80 - 1)
|
||||
Assert.Equal (24, view.Frame.Height); // proof (25 - 1)
|
||||
|
||||
view.X = 79;
|
||||
view.Width = Dim.Fill ();
|
||||
view.Height = Dim.Fill ();
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (79, view.Frame.X);
|
||||
Assert.Equal (1, view.Frame.Y);
|
||||
Assert.Equal (1, view.Frame.Width); // proof (80 - 79)
|
||||
Assert.Equal (24, view.Frame.Height);
|
||||
|
||||
view.X = 80;
|
||||
view.Width = Dim.Fill ();
|
||||
view.Height = Dim.Fill ();
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (80, view.Frame.X);
|
||||
Assert.Equal (1, view.Frame.Y);
|
||||
Assert.Equal (0, view.Frame.Width); // proof (80 - 80)
|
||||
Assert.Equal (24, view.Frame.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FIll_Pos_Outside_Bounds ()
|
||||
{
|
||||
var screen = new Rect (0, 0, 80, 25);
|
||||
var view = new View () {
|
||||
X = 90, // outside of screen +10
|
||||
Y = -10, // outside of screen -10
|
||||
Width = 15,
|
||||
Height = 15
|
||||
};
|
||||
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (90, view.Frame.X);
|
||||
Assert.Equal (-10, view.Frame.Y);
|
||||
Assert.Equal (15, view.Frame.Width);
|
||||
Assert.Equal (15, view.Frame.Height);
|
||||
|
||||
// prove Width=Height= same as screen size
|
||||
view.Width = 80;
|
||||
view.Height = 25;
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (90, view.Frame.X);
|
||||
Assert.Equal (-10, view.Frame.Y);
|
||||
Assert.Equal (80, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.Width = Dim.Fill ();
|
||||
view.Height = Dim.Fill ();
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (90, view.Frame.X);
|
||||
Assert.Equal (-10, view.Frame.Y);
|
||||
Assert.Equal (0, view.Frame.Width); // proof: 15x15 view is placed beyond right side of screen, so fill width is 0
|
||||
Assert.Equal (35, view.Frame.Height); // proof: 15x15 view is placed beyond top of screen 10 rows, screen is 25 rows. so fill height is 25 + 10 = 35
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PosCombine_PosCenter_Minus_Absolute ()
|
||||
{
|
||||
// This test used to be in ViewTests.cs Internal_Tests. It was moved here because it is testing
|
||||
// SetRelativeLayout. In addition, the old test was bogus because it was testing the wrong thing (and
|
||||
// because in v1 Pos.Center was broken in this regard!
|
||||
|
||||
var screen = new Rect (0, 0, 80, 25);
|
||||
var view = new View () {
|
||||
X = Pos.Center () - 41, // -2 off left edge of screen
|
||||
Y = Pos.Center () - 13, // -1 off top edge of screen
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (-2, view.Frame.X); // proof: 1x1 view centered in 80x25 screen has x of 39, so -41 is -2
|
||||
Assert.Equal (-1, view.Frame.Y); // proof: 1x1 view centered in 80x25 screen has y of 12, so -13 is -1
|
||||
|
||||
view.Width = 80;
|
||||
view.Height = 25;
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (-41, view.Frame.X);
|
||||
Assert.Equal (-13, view.Frame.Y);
|
||||
Assert.Equal (80, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.Width = Dim.Fill ();
|
||||
view.Height = Dim.Fill ();
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (-41, view.Frame.X);
|
||||
Assert.Equal (-13, view.Frame.Y);
|
||||
Assert.Equal (121, view.Frame.Width); // 121 = screen.Width - (-Center - 41)
|
||||
Assert.Equal (38, view.Frame.Height);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FIll_And_PosCenter ()
|
||||
{
|
||||
var screen = new Rect (0, 0, 80, 25);
|
||||
var view = new View () {
|
||||
X = Pos.Center (),
|
||||
Y = Pos.Center (),
|
||||
Width = Dim.Fill(),
|
||||
Height = Dim.Fill()
|
||||
};
|
||||
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (0, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
Assert.Equal (80, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.X = Pos.Center () + 1;
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (1, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
Assert.Equal (79, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.X = Pos.Center () + 79;
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (79, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
Assert.Equal (1, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.X = Pos.Center () + 80;
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (80, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
Assert.Equal (0, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.X = Pos.Center () - 1;
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (-1, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
Assert.Equal (81, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.X = Pos.Center () - 2; // Fill means all the way to right. So width will be 82. (dim gets calc'd before pos).
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (-2, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
Assert.Equal (82, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.X = Pos.Center () - 3; // Fill means all the way to right. So width will be 83. (dim gets calc'd before pos).
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (-3, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
Assert.Equal (83, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
view.X = Pos.Center () - 41; // Fill means all the way to right. So width will be . (dim gets calc'd before pos).
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (-41, view.Frame.X);
|
||||
Assert.Equal (0, view.Frame.Y);
|
||||
Assert.Equal (121, view.Frame.Width);
|
||||
Assert.Equal (25, view.Frame.Height);
|
||||
|
||||
}
|
||||
[Fact]
|
||||
public void PosCombine_PosCenter_Plus_Absolute ()
|
||||
{
|
||||
var screen = new Rect (0, 0, 80, 25);
|
||||
var view = new View () {
|
||||
X = Pos.Center () + 41, // ((80 / 2) - (5 / 2)) + 41 = (40 - 3 + 41) = 78
|
||||
Y = Pos.Center () + 13, // ((25 / 2) - (4 / 2)) + 13 = (12 - 2 + 13) = 23
|
||||
Width = 5,
|
||||
Height = 4
|
||||
};
|
||||
|
||||
view.SetRelativeLayout (screen);
|
||||
Assert.Equal (78, view.Frame.X);
|
||||
Assert.Equal (23, view.Frame.Y);
|
||||
}
|
||||
|
||||
[Fact] [TestRespondersDisposed]
|
||||
public void PosCombine_Plus_Absolute ()
|
||||
{
|
||||
var superView = new View () {
|
||||
AutoSize = false,
|
||||
Width = 10,
|
||||
Height = 10
|
||||
};
|
||||
|
||||
var testView = new View () {
|
||||
AutoSize = false,
|
||||
X = Pos.Center (),
|
||||
Y = Pos.Center (),
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
superView.Add (testView);
|
||||
testView.SetRelativeLayout (superView.Frame);
|
||||
Assert.Equal (4, testView.Frame.X);
|
||||
Assert.Equal (4, testView.Frame.Y);
|
||||
|
||||
testView = new View () {
|
||||
AutoSize = false,
|
||||
X = Pos.Center () + 1, // ((10 / 2) - (1 / 2)) + 1 = 5 - 1 + 1 = 5
|
||||
Y = Pos.Center () + 1,
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
superView.Add (testView);
|
||||
testView.SetRelativeLayout (superView.Frame);
|
||||
Assert.Equal (5, testView.Frame.X);
|
||||
Assert.Equal (5, testView.Frame.Y);
|
||||
|
||||
testView = new View () {
|
||||
AutoSize = false,
|
||||
X = 1 + Pos.Center (),
|
||||
Y = 1 + Pos.Center (),
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
superView.Add (testView);
|
||||
testView.SetRelativeLayout (superView.Frame);
|
||||
Assert.Equal (5, testView.Frame.X);
|
||||
Assert.Equal (5, testView.Frame.Y);
|
||||
|
||||
testView = new View () {
|
||||
AutoSize = false,
|
||||
X = 1 + Pos.Percent (50),
|
||||
Y = Pos.Percent (50) + 1,
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
superView.Add (testView);
|
||||
testView.SetRelativeLayout (superView.Frame);
|
||||
Assert.Equal (6, testView.Frame.X);
|
||||
Assert.Equal (6, testView.Frame.Y);
|
||||
|
||||
testView = new View () {
|
||||
AutoSize = false,
|
||||
X = Pos.Percent (10) + Pos.Percent (40),
|
||||
Y = Pos.Percent (10) + Pos.Percent (40),
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
superView.Add (testView);
|
||||
testView.SetRelativeLayout (superView.Frame);
|
||||
Assert.Equal (5, testView.Frame.X);
|
||||
Assert.Equal (5, testView.Frame.Y);
|
||||
|
||||
testView = new View () {
|
||||
AutoSize = false,
|
||||
X = 1 + Pos.Percent (10) + Pos.Percent (40) - 1,
|
||||
Y = 5 + Pos.Percent (10) + Pos.Percent (40) - 5,
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
superView.Add (testView);
|
||||
testView.SetRelativeLayout (superView.Frame);
|
||||
Assert.Equal (5, testView.Frame.X);
|
||||
Assert.Equal (5, testView.Frame.Y);
|
||||
|
||||
testView = new View () {
|
||||
AutoSize = false,
|
||||
X = Pos.Left (testView),
|
||||
Y = Pos.Left (testView),
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
superView.Add (testView);
|
||||
testView.SetRelativeLayout (superView.Frame);
|
||||
Assert.Equal (5, testView.Frame.X);
|
||||
Assert.Equal (5, testView.Frame.Y);
|
||||
|
||||
testView = new View () {
|
||||
AutoSize = false,
|
||||
X = 1 + Pos.Left (testView),
|
||||
Y = Pos.Top (testView) + 1,
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
superView.Add (testView);
|
||||
testView.SetRelativeLayout (superView.Frame);
|
||||
Assert.Equal (6, testView.Frame.X);
|
||||
Assert.Equal (6, testView.Frame.Y);
|
||||
|
||||
superView.Dispose ();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -504,6 +504,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
|
||||
var runState = Application.Begin (top);
|
||||
|
||||
// BUGBUG: This is a SetRelativeLayout test. It should be moved to SetRelativeLayoutTests.cs
|
||||
view.Width = Dim.Fill ();
|
||||
view.Height = Dim.Fill ();
|
||||
Assert.Equal (10, view.Bounds.Width);
|
||||
@@ -519,6 +520,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
Assert.Equal (79, view.Bounds.Width);
|
||||
Assert.Equal (24, view.Bounds.Height);
|
||||
|
||||
// BUGBUG: This is a SetRelativeLayout test. It should be moved to SetRelativeLayoutTests.cs
|
||||
view.X = 0;
|
||||
view.Y = 0;
|
||||
Assert.Equal ("Absolute(0)", view.X.ToString ());
|
||||
@@ -532,6 +534,8 @@ namespace Terminal.Gui.ViewTests {
|
||||
Assert.Equal (0, view.Bounds.Y);
|
||||
Assert.Equal (80, view.Bounds.Width);
|
||||
Assert.Equal (25, view.Bounds.Height);
|
||||
|
||||
// BUGBUG: This is a layout test. It should be moved to LayoutTests.cs
|
||||
bool layoutStarted = false;
|
||||
view.LayoutStarted += (s, e) => layoutStarted = true;
|
||||
view.OnLayoutStarted (null);
|
||||
@@ -539,6 +543,10 @@ namespace Terminal.Gui.ViewTests {
|
||||
view.LayoutComplete += (s, e) => layoutStarted = false;
|
||||
view.OnLayoutComplete (null);
|
||||
Assert.False (layoutStarted);
|
||||
|
||||
// This test has been moved to SetRlativeLayoutTests because it is testing
|
||||
// SetRelativeLayout. In addition, the old test was bogus because it was testing the wrong thing (and
|
||||
// because in v1 Pos.Center was broken in this regard!
|
||||
view.X = Pos.Center () - 41;
|
||||
view.Y = Pos.Center () - 13;
|
||||
view.SetRelativeLayout (top.Bounds);
|
||||
@@ -546,7 +554,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
view.BoundsToScreen (0, 0, out rcol, out rrow);
|
||||
Assert.Equal (-41, rcol);
|
||||
Assert.Equal (-13, rrow);
|
||||
|
||||
|
||||
Application.End (runState);
|
||||
}
|
||||
|
||||
@@ -1340,16 +1348,15 @@ At 0,0
|
||||
var frame = new FrameView ();
|
||||
|
||||
var label = new Label ("This should be the first line.") {
|
||||
TextAlignment = Terminal.Gui.TextAlignment.Centered,
|
||||
ColorScheme = Colors.Menu,
|
||||
Width = Dim.Fill (),
|
||||
X = Pos.Center (),
|
||||
Y = Pos.Center () - 2 // center minus 2 minus two lines top and bottom borders equal to zero (4-2-2=0)
|
||||
X = 0, // don't overcomplicate unit tests
|
||||
Y = 0
|
||||
};
|
||||
|
||||
var button = new Button ("Press me!") {
|
||||
X = Pos.Center (),
|
||||
Y = Pos.Center ()
|
||||
X = 0, // don't overcomplicate unit tests
|
||||
Y = 1
|
||||
};
|
||||
|
||||
frame.Add (label, button);
|
||||
@@ -1388,19 +1395,7 @@ At 0,0
|
||||
frame.Frame.Left, frame.Frame.Top,
|
||||
frame.Frame.Right, frame.Frame.Bottom));
|
||||
Assert.Equal (new Rect (0, 0, 38, 1), label.Frame);
|
||||
Assert.Equal (new Rect (12, 2, 13, 1), button.Frame);
|
||||
var expected = @$"
|
||||
┌──────────────────────────────────────┐
|
||||
│ This should be the first line. │
|
||||
│ │
|
||||
│ {CM.Glyphs.LeftBracket} Press me! {CM.Glyphs.RightBracket} │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└──────────────────────────────────────┘
|
||||
";
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 1, 13, 1), button.Frame); // this proves frame was set
|
||||
Application.End (runState);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user