Fixes #3127 - View Layout improvements - Redefines how LayoutStyle works. Fixes AutoSize etc... (#3130)

* Removes CheckAbsoulte and updates unit tests to match

* Fixed code that was dependent on ToString behavior vs. direct test for null

* Dim/Pos != null WIP

* Moved AutoSize specific tests out of Pos/Dim tests

* Broke out AutoSize = false tests to new file

* Commented test TODOs

* New test

* Removed unused API and cleaned up code

* Removed unused API and cleaned up code

* Cleaned up code

* Cleaned up code

* reorg'd Toplevel tests

* Fixed Create and related unit tests

* Added test from #3136

* Removed TopLevel.Create

* Fixed SetCurrentOverlappedAsTop

* Updated pull request template

* Updated pull request template

* Revert "Updated pull request template"

This reverts commit d807190dd9.

* reverting

* re-reverting

* Fixed every thing but autosize scenarios??

* Fixed hexview

* Fixed contextmenu

* Fixed more minor issues in tests

* Fixed more minor issues in tests

* Debugging Dialog test failure

* Fixed bad Dialog test. Was cleary invalid

* Fixed OnResizeNeeded bug

* Fixed OnResizeNeeded bug

* Fixed UICatalog to not eat exceptions

* Fixed TextView

* Removed Frame overrides

* Made Frame non-virtual

* Fixed radioGroup

* Fixed TabView

* Hcked ScrolLBarView unit tests to pass

* All AutoSize tests pass!

* All tests pass!!!!!!!

* Updated API docs. Cleaned up code.

* Fixed ColorPicker

* Added 'Bounds =' unit tests

* Refactored TextFormatter.Size setting logic

* Cleaned up OnResizeNeeded (api docs and usages)

* Merges in #3019 changes. Makes OnResizeNeeded non-virtual. If we find a use-case where someone wants to override it we can change this back.

* Fixed FileDialog bounds warning

* Removed resharper settings from editorconfig

* Added Pos.Center test to AllViewsTests.cs.
Modernized RadioGroup.
Fixed ProgressBar.

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Reverted formatting
This commit is contained in:
Tig
2024-01-12 17:43:35 -07:00
committed by GitHub
parent 4cc6339192
commit d2ad11248f
78 changed files with 21739 additions and 20765 deletions

View File

@@ -4,14 +4,16 @@ using Xunit;
using Xunit.Abstractions;
using Microsoft.VisualStudio.TestPlatform.Utilities;
namespace Terminal.Gui.ViewsTests;
namespace Terminal.Gui.ViewsTests;
public class DrawTests {
readonly ITestOutputHelper _output;
public DrawTests (ITestOutputHelper output) => _output = output;
[Fact] [AutoInitShutdown]
// TODO: Refactor this test to not depend on TextView etc... Make it as primitive as possible
[Fact]
[AutoInitShutdown]
public void Clipping_AddRune_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space ()
{
var tv = new TextView () {
@@ -29,7 +31,8 @@ public class DrawTests {
var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
win.Add (tv);
Application.Top.Add (win);
var lbl = new Label ("ワイドルーン。");
// Don't use Label. It sets AutoSize = true which is not what we're testing here.
var lbl = new View ("ワイドルーン。");
// 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);
@@ -54,7 +57,8 @@ public class DrawTests {
}
// TODO: The tests below that use Label should use View instead.
[Fact] [AutoInitShutdown]
[Fact]
[AutoInitShutdown]
public void Non_Bmp_ConsoleWidth_ColumnWidth_Equal_Two ()
{
string us = "\U0001d539";
@@ -102,7 +106,8 @@ public class DrawTests {
0000000000", Application.Driver, expectedColors);
}
[Fact] [AutoInitShutdown]
[Fact]
[AutoInitShutdown]
public void CJK_Compatibility_Ideographs_ConsoleWidth_ColumnWidth_Equal_Two ()
{
string us = "\U0000f900";
@@ -150,7 +155,8 @@ public class DrawTests {
0000000000", Application.Driver, expectedColors);
}
[Fact] [AutoInitShutdown]
[Fact]
[AutoInitShutdown]
public void Colors_On_TextAlignment_Right_And_Bottom ()
{
var labelRight = new Label ("Test") {
@@ -191,7 +197,8 @@ t ", _output);
0", Application.Driver, new Attribute [] { Colors.Base.Normal });
}
[Fact] [AutoInitShutdown]
[Fact]
[AutoInitShutdown]
public void Draw_Negative_Bounds_Horizontal_Without_New_Lines ()
{
// BUGBUG: This previously assumed the default height of a View was 1.
@@ -235,7 +242,8 @@ t ", _output);
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
}
[Fact] [AutoInitShutdown]
[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" };
@@ -304,7 +312,8 @@ t ", _output);
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
}
[Fact] [AutoInitShutdown]
[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 };

View File

@@ -1,5 +1,6 @@
using Xunit;
using Xunit.Abstractions;
//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
// Alias Console to MockConsole so we don't accidentally use Console
@@ -9,95 +10,146 @@ namespace Terminal.Gui.ViewTests;
public class AbsoluteLayoutTests {
readonly ITestOutputHelper _output;
public AbsoluteLayoutTests (ITestOutputHelper output) => this._output = output;
public AbsoluteLayoutTests (ITestOutputHelper output) => _output = output;
[Fact] [TestRespondersDisposed]
[Fact]
[TestRespondersDisposed]
public void AbsoluteLayout_Constructor ()
{
var frame = new Rect (1, 2, 3, 4);
var v = new View (frame);
var v = new View ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Dispose ();
var frame = Rect.Empty;
v = new View (frame);
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (frame, v.Frame);
Assert.Equal (new Rect (0, 0, frame.Width, frame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
Assert.Equal (Pos.At (0), v.X);
Assert.Equal (Pos.At (0), v.Y);
Assert.Equal (Dim.Sized (0), v.Width);
Assert.Equal (Dim.Sized (0), v.Height);
v.Dispose ();
frame = new Rect (1, 2, 3, 4);
v = new View (frame);
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (frame, v.Frame);
Assert.Equal (new Rect (0, 0, frame.Width, frame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (3), v.Width);
Assert.Equal (Dim.Sized (4), v.Height);
v.Dispose ();
v = new View (frame, "v");
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (frame, v.Frame);
Assert.Equal (new Rect (0, 0, frame.Width, frame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (3), v.Width);
Assert.Equal (Dim.Sized (4), v.Height);
v.Dispose ();
v = new View (frame.X, frame.Y, "v");
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
// BUGBUG: v2 - I think the default size should be 0,0
// BUGBUG: v2 - I think the default size should be 0,0 not 1,1
Assert.Equal (new Rect (frame.X, frame.Y, 1, 1), v.Frame);
Assert.Equal (new Rect (0, 0, 1, 1), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (1), v.Width);
Assert.Equal (Dim.Sized (1), v.Height);
v.Dispose ();
v = new View ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (new Rect (0, 0, 0, 0), v.Frame);
Assert.Equal (new Rect (0, 0, 0, 0), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Equal (Pos.At (0), v.X);
Assert.Equal (Pos.At (0), v.Y);
Assert.Equal (Dim.Sized (0), v.Width);
Assert.Equal (Dim.Sized (0), v.Height);
v.Dispose ();
v = new View {
X = frame.X,
Y = frame.Y,
Width = frame.Width,
Height = frame.Height
};
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (new Rect (frame.X, frame.Y, 3, 4), v.Frame);
Assert.Equal (new Rect (0, 0, 3, 4), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (3), v.Width);
Assert.Equal (Dim.Sized (4), v.Height);
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
[Fact]
[TestRespondersDisposed]
public void AbsoluteLayout_Change_Frame ()
{
var frame = new Rect (1, 2, 3, 4);
var newFrame = new Rect (1, 2, 30, 40);
var v = new View (frame);
var v = new View ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Dispose ();
v = new View (frame);
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Frame = newFrame;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (30), v.Width);
Assert.Equal (Dim.Sized (40), v.Height);
v.Dispose ();
v = new View (frame.X, frame.Y, "v");
v.Frame = newFrame;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (30), v.Width);
Assert.Equal (Dim.Sized (40), v.Height);
v.Dispose ();
newFrame = new Rect (10, 20, 30, 40);
v = new View (frame);
v.Frame = newFrame;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
Assert.Equal (Pos.At (10), v.X);
Assert.Equal (Pos.At (20), v.Y);
Assert.Equal (Dim.Sized (30), v.Width);
Assert.Equal (Dim.Sized (40), v.Height);
v.Dispose ();
v = new View (frame.X, frame.Y, "v");
v.Frame = newFrame;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
Assert.Equal (Pos.At (10), v.X);
Assert.Equal (Pos.At (20), v.Y);
Assert.Equal (Dim.Sized (30), v.Width);
Assert.Equal (Dim.Sized (40), v.Height);
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
[Fact]
[TestRespondersDisposed]
public void AbsoluteLayout_Change_Height_or_Width_Absolute ()
{
var frame = new Rect (1, 2, 3, 4);
@@ -109,34 +161,26 @@ public class AbsoluteLayoutTests {
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal ($"Absolute({newFrame.Height})", v.Height.ToString ());
Assert.Equal ($"Absolute({newFrame.Width})", v.Width.ToString ());
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
public void AbsoluteLayout_Change_Height_or_Width_NotAbsolute ()
[Fact]
[TestRespondersDisposed]
public void AbsoluteLayout_Change_Height_or_Width_MakesComputed ()
{
var v = new View (Rect.Empty);
v.Height = Dim.Fill ();
v.Width = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
public void AbsoluteLayout_Change_Height_or_Width_Null ()
{
var v = new View (Rect.Empty);
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
[Fact]
[TestRespondersDisposed]
public void AbsoluteLayout_Change_X_or_Y_Absolute ()
{
var frame = new Rect (1, 2, 3, 4);
@@ -150,52 +194,24 @@ public class AbsoluteLayoutTests {
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Equal ($"Absolute({newFrame.X})", v.X.ToString ());
Assert.Equal ($"Absolute({newFrame.Y})", v.Y.ToString ());
Assert.Null (v.Height);
Assert.Null (v.Width);
Assert.Equal (Dim.Sized (3), v.Width);
Assert.Equal (Dim.Sized (4), v.Height);
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
public void AbsoluteLayout_Change_X_or_Y_NotAbsolute ()
[Fact]
[TestRespondersDisposed]
public void AbsoluteLayout_Change_X_or_Y_MakesComputed ()
{
var v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
public void AbsoluteLayout_Change_X_or_Y_Null ()
{
var v = new View (Rect.Empty);
v.X = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Dispose ();
v = new View (Rect.Empty);
v.X = Pos.Center ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
v.X = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Dispose ();
v = new View (Rect.Empty);
v.Y = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Dispose ();
v = new View (Rect.Empty);
v.Y = Pos.Center ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
v.Y = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
[Fact]
[TestRespondersDisposed]
public void AbsoluteLayout_Change_X_Y_Height_Width_Absolute ()
{
var v = new View (Rect.Empty);
@@ -211,14 +227,7 @@ public class AbsoluteLayoutTests {
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = null;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
v.Dispose ();
v = new View (Rect.Empty);
@@ -226,14 +235,10 @@ public class AbsoluteLayoutTests {
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = 1;
v.Y = null;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
v.Dispose ();
v = new View (Rect.Empty);
@@ -241,14 +246,10 @@ public class AbsoluteLayoutTests {
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = 2;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
v.Dispose ();
v = new View (Rect.Empty);
@@ -256,14 +257,21 @@ public class AbsoluteLayoutTests {
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
v.Width = 3;
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
v.Dispose ();
v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = null;
v.Height = 3;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
v.Dispose ();
v = new View (Rect.Empty);
@@ -271,72 +279,111 @@ public class AbsoluteLayoutTests {
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
Assert.True (v.LayoutStyle == LayoutStyle.Computed);
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = null;
v.Height = null;
v.X = 1;
v.Y = 2;
v.Height = 3;
v.Width = 4;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
public void AbsoluteLayout_Change_X_Y_Height_Width_Null ()
{
var v = new View (Rect.Empty);
v.X = null;
v.Y = null;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Dispose ();
v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = null;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
v.Dispose ();
}
[Fact] [TestRespondersDisposed]
public void AbsoluteLayout_Layout ()
[Fact]
[TestRespondersDisposed]
public void AbsoluteLayout_LayoutSubviews ()
{
var superRect = new Rect (0, 0, 100, 100);
var super = new View (superRect, "super");
Assert.True (super.LayoutStyle == LayoutStyle.Absolute);
var v1 = new View () {
var v1 = new View {
X = 0,
Y = 0,
Width = 10,
Height = 10
};
// BUGBUG: v2 - This should be LayoutStyle.Absolute
Assert.True (v1.LayoutStyle == LayoutStyle.Computed);
Assert.True (v1.LayoutStyle == LayoutStyle.Absolute);
var v2 = new View () {
var v2 = new View {
X = 10,
Y = 10,
Width = 10,
Height = 10
};
// BUGBUG: v2 - This should be LayoutStyle.Absolute
Assert.True (v1.LayoutStyle == LayoutStyle.Computed);
Assert.True (v2.LayoutStyle == LayoutStyle.Absolute);
super.Add (v1, v2);
Assert.True (v1.LayoutStyle == LayoutStyle.Absolute);
Assert.True (v2.LayoutStyle == LayoutStyle.Absolute);
super.LayoutSubviews ();
Assert.Equal (new Rect (0, 0, 10, 10), v1.Frame);
Assert.Equal (new Rect (10, 10, 10, 10), v2.Frame);
super.Dispose ();
}
[Fact]
public void AbsoluteLayout_Setting_Bounds_Location_NotEmpty ()
{
// TODO: Should we enforce Bounds.X/Y == 0? The code currently ignores value.X/Y which is
// TODO: correct behavior, but is silent. Perhaps an exception?
var frame = new Rect (1, 2, 3, 4);
var newBounds = new Rect (10, 20, 30, 40);
var view = new View (frame);
view.Bounds = newBounds;
Assert.Equal (new Rect (0, 0, 30, 40), view.Bounds);
Assert.Equal (new Rect (1, 2, 30, 40), view.Frame);
}
[Fact]
public void AbsoluteLayout_Setting_Bounds_Sets_Frame ()
{
var frame = new Rect (1, 2, 3, 4);
var newBounds = new Rect (0, 0, 30, 40);
var v = new View (frame);
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v.Bounds = newBounds;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newBounds, v.Bounds);
Assert.Equal (new Rect (1, 2, newBounds.Width, newBounds.Height), v.Frame);
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (30), v.Width);
Assert.Equal (Dim.Sized (40), v.Height);
newBounds = new Rect (0, 0, 3, 4);
v.Bounds = newBounds;
Assert.Equal (newBounds, v.Bounds);
Assert.Equal (new Rect (1, 2, newBounds.Width, newBounds.Height), v.Frame);
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (3), v.Width);
Assert.Equal (Dim.Sized (4), v.Height);
v.BorderStyle = LineStyle.Single;
// Bounds should shrink
Assert.Equal (new Rect (0, 0, 1, 2), v.Bounds);
// Frame should not change
Assert.Equal (new Rect (1, 2, 3, 4), v.Frame);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (3), v.Width);
Assert.Equal (Dim.Sized (4), v.Height);
// Now set bounds bigger as before
newBounds = new Rect (0, 0, 3, 4);
v.Bounds = newBounds;
Assert.Equal (newBounds, v.Bounds);
// Frame grows because there's now a border
Assert.Equal (new Rect (1, 2, 5, 6), v.Frame);
Assert.Equal (new Rect (0, 0, newBounds.Width, newBounds.Height), v.Bounds);
Assert.Equal (Pos.At (1), v.X);
Assert.Equal (Pos.At (2), v.Y);
Assert.Equal (Dim.Sized (5), v.Width);
Assert.Equal (Dim.Sized (6), v.Height);
}
}

View File

@@ -1,838 +0,0 @@
using System.Text;
using System;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewTests {
public class AutoSizeTests {
readonly ITestOutputHelper output;
public AutoSizeTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact, AutoInitShutdown]
public void AutoSize_GetAutoSize_Horizontal ()
{
var text = "text";
var view = new View () {
Text = text,
AutoSize = true
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
var size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length, 1), size);
view.Text = $"{text}\n{text}";
size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length, 2), size);
view.Text = $"{text}\n{text}\n{text}+";
size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length + 1, 3), size);
text = string.Empty;
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (0, 0), size);
text = "1";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (1, 1), size);
text = "界";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (2, 1), size);
}
[Fact, AutoInitShutdown]
public void AutoSize_GetAutoSize_Vertical()
{
var text = "text";
var view = new View () {
Text = text,
TextDirection = TextDirection.TopBottom_LeftRight,
AutoSize = true
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
var size = view.GetAutoSize ();
Assert.Equal (new Size (1, text.Length), size);
view.Text = $"{text}\n{text}";
size = view.GetAutoSize ();
Assert.Equal (new Size (2, text.Length), size);
view.Text = $"{text}\n{text}\n{text}+";
size = view.GetAutoSize ();
Assert.Equal (new Size (3, text.Length + 1), size);
text = string.Empty;
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (0, 0), size);
text = "1";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (1, 1), size);
text = "界";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (2, 1), size);
}
[Fact, AutoInitShutdown]
public void AutoSize_GetAutoSize_Left()
{
var text = "This is some text.";
var view = new View () {
Text = text,
TextAlignment = TextAlignment.Left,
AutoSize = true
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
var size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length, 1), size);
view.Text = $"{text}\n{text}";
size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length, 2), size);
view.Text = $"{text}\n{text}\n{text}+";
size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length + 1, 3), size);
text = string.Empty;
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (0, 0), size);
text = "1";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (1, 1), size);
text = "界";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (2, 1), size);
}
[Fact, AutoInitShutdown]
public void AutoSize_GetAutoSize_Right ()
{
var text = "This is some text.";
var view = new View () {
Text = text,
TextAlignment = TextAlignment.Right,
AutoSize = true
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
var size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length, 1), size);
view.Text = $"{text}\n{text}";
size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length, 2), size);
view.Text = $"{text}\n{text}\n{text}+";
size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length + 1, 3), size);
text = string.Empty;
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (0, 0), size);
text = "1";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (1, 1), size);
text = "界";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (2, 1), size);
}
[Fact, AutoInitShutdown]
public void AutoSize_GetAutoSize_Centered ()
{
var text = "This is some text.";
var view = new View () {
Text = text,
TextAlignment = TextAlignment.Centered,
AutoSize = true
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
var size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length, 1), size);
view.Text = $"{text}\n{text}";
size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length, 2), size);
view.Text = $"{text}\n{text}\n{text}+";
size = view.GetAutoSize ();
Assert.Equal (new Size (text.Length + 1, 3), size);
text = string.Empty;
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (0, 0), size);
text = "1";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (1, 1), size);
text = "界";
view.Text = text;
size = view.GetAutoSize ();
Assert.Equal (new Size (2, 1), size);
}
[Fact, AutoInitShutdown]
public void AutoSize_False_View_IsEmpty_False_Return_Null_Lines ()
{
var text = "Views";
var view = new View () {
Width = Dim.Fill () - text.Length,
Height = 1,
Text = text
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.False (view.AutoSize);
Assert.Equal (new Rect (0, 0, 3, 1), view.Frame);
Assert.Equal (new Size (3, 1), view.TextFormatter.Size);
Assert.Equal (new List<string> () { "Vie" }, view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Vie │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 0, 1), view.Frame);
Assert.Equal (new Size (0, 1), view.TextFormatter.Size);
Assert.Equal (new List<string> () { string.Empty }, view.TextFormatter.Lines);
expected = @"
┌────────┐
│ │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_False_View_IsEmpty_True_Minimum_Height ()
{
var text = "Views";
var view = new View () {
Width = Dim.Fill () - text.Length,
Text = text
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.False (view.AutoSize);
Assert.Equal (new Rect (0, 0, 3, 1), view.Frame);
Assert.Equal (new Size (3, 1), view.TextFormatter.Size);
Assert.Single (view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Vie │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 0, 1), view.Frame);
Assert.Equal (new Size (0, 1), view.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> () { string.Empty }, view.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌────────┐
│ │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_True_Label_IsEmpty_False_Never_Return_Null_Lines ()
{
var text = "Label";
var label = new Label () {
Width = Dim.Fill () - text.Length,
Height = 1,
Text = text
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (label);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.True (label.AutoSize);
Assert.Equal (new Rect (0, 0, 5, 1), label.Frame);
Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
Assert.Equal (new List<string> () { "Label" }, label.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Label │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
label.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.True (label.AutoSize);
Assert.Equal (new Rect (0, 0, 5, 1), label.Frame);
Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
Assert.Single (label.TextFormatter.Lines);
expected = @"
┌────────┐
│Label │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_False_Label_IsEmpty_True_Return_Null_Lines ()
{
var text = "Label";
var label = new Label () {
Width = Dim.Fill () - text.Length,
Height = 1,
Text = text,
AutoSize = false
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (label);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.False (label.AutoSize);
Assert.Equal (new Rect (0, 0, 3, 1), label.Frame);
Assert.Equal (new Size (3, 1), label.TextFormatter.Size);
Assert.Equal (new List<string> () { "Lab" }, label.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Lab │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
label.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.False (label.AutoSize);
Assert.Equal (new Rect (0, 0, 0, 1), label.Frame);
Assert.Equal (new Size (0, 1), label.TextFormatter.Size);
Assert.Equal (new List<string> { string.Empty }, label.TextFormatter.Lines);
expected = @"
┌────────┐
│ │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_True_Label_IsEmpty_False_Minimum_Height ()
{
var text = "Label";
var label = new Label () {
Width = Dim.Fill () - text.Length,
Text = text
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (label);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.True (label.AutoSize);
Assert.Equal (new Rect (0, 0, 5, 1), label.Frame);
Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
Assert.Equal (new List<string> () { "Label" }, label.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Label │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
label.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 5, 1), label.Frame);
Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Single (label.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌────────┐
│Label │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_False_Label_Height_Zero_Returns_Minimum_Height ()
{
var text = "Label";
var label = new Label () {
Width = Dim.Fill () - text.Length,
Text = text,
AutoSize = false
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (label);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.False (label.AutoSize);
Assert.Equal (new Rect (0, 0, 3, 1), label.Frame);
Assert.Equal (new Size (3, 1), label.TextFormatter.Size);
Assert.Single (label.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Lab │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
label.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 0, 1), label.Frame);
Assert.Equal (new Size (0, 1), label.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> () { string.Empty }, label.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌────────┐
│ │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_True_View_IsEmpty_False_Minimum_Width ()
{
var text = "Views";
var view = new View () {
TextDirection = TextDirection.TopBottom_LeftRight,
Height = Dim.Fill () - text.Length,
Text = text,
AutoSize = true
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (4, 10);
Assert.Equal (5, text.Length);
Assert.True (view.AutoSize);
Assert.Equal (new Rect (0, 0, 1, 5), view.Frame);
Assert.Equal (new Size (1, 5), view.TextFormatter.Size);
Assert.Equal (new List<string> () { "Views" }, view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 4, 10), win.Frame);
Assert.Equal (new Rect (0, 0, 4, 10), Application.Top.Frame);
var expected = @"
┌──┐
│V │
│i │
│e │
│w │
│s │
│ │
│ │
│ │
└──┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Height = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 1, 5), view.Frame);
Assert.Equal (new Size (1, 5), view.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Single (view.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌──┐
│V │
│i │
│e │
│w │
│s │
│ │
│ │
│ │
└──┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_False_View_Width_Null_Returns_Host_Frame_Width ()
{
var text = "Views";
var view = new View () {
TextDirection = TextDirection.TopBottom_LeftRight,
Height = Dim.Fill () - text.Length,
Text = text
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (4, 10);
Assert.Equal (5, text.Length);
Assert.False (view.AutoSize);
Assert.Equal (new Rect (0, 0, 1, 3), view.Frame);
Assert.Equal (new Size (1, 3), view.TextFormatter.Size);
Assert.Single (view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 4, 10), win.Frame);
Assert.Equal (new Rect (0, 0, 4, 10), Application.Top.Frame);
var expected = @"
┌──┐
│V │
│i │
│e │
│ │
│ │
│ │
│ │
│ │
└──┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Height = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 1, 0), view.Frame);
Assert.Equal (new Size (1, 0), view.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> () { string.Empty }, view.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌──┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_True_View_IsEmpty_False_Minimum_Width_Wide_Rune ()
{
var text = "界View";
var view = new View () {
TextDirection = TextDirection.TopBottom_LeftRight,
Height = Dim.Fill () - text.Length,
Text = text,
AutoSize = true
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (4, 10);
Assert.Equal (5, text.Length);
Assert.True (view.AutoSize);
Assert.Equal (new Rect (0, 0, 2, 5), view.Frame);
Assert.Equal (new Size (2, 5), view.TextFormatter.Size);
Assert.Equal (new List<string> () { "界View" }, view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 4, 10), win.Frame);
Assert.Equal (new Rect (0, 0, 4, 10), Application.Top.Frame);
var expected = @"
┌──┐
│界│
│V │
│i │
│e │
│w │
│ │
│ │
│ │
└──┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Height = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 2, 5), view.Frame);
Assert.Equal (new Size (2, 5), view.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> () { "界View" }, view.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌──┐
│界│
│V │
│i │
│e │
│w │
│ │
│ │
│ │
└──┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_False_View_Width_Zero_Returns_Minimum_Width_With_Wide_Rune ()
{
var text = "界View";
var view = new View () {
TextDirection = TextDirection.TopBottom_LeftRight,
Height = Dim.Fill () - text.Length,
Text = text
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (4, 10);
Assert.Equal (5, text.Length);
Assert.False (view.AutoSize);
Assert.Equal (new Rect (0, 0, 2, 3), view.Frame);
Assert.Equal (new Size (2, 3), view.TextFormatter.Size);
Assert.Single (view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 4, 10), win.Frame);
Assert.Equal (new Rect (0, 0, 4, 10), Application.Top.Frame);
var expected = @"
┌──┐
│界│
│V │
│i │
│ │
│ │
│ │
│ │
│ │
└──┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Height = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 2, 0), view.Frame);
Assert.Equal (new Size (2, 0), view.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> () { string.Empty }, view.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌──┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
}
}
}

View File

@@ -1,22 +1,15 @@
using System;
using System.Text;
using Xunit;
using Xunit;
using Xunit.Abstractions;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui.ViewTests;
/// <summary>
/// Tests for view coordinate mapping (e.g. <see cref="View.ScreenToFrame"/> etc...).
/// </summary>
public class CoordinateTests {
readonly ITestOutputHelper _output;
public CoordinateTests (ITestOutputHelper output)
{
this._output = output;
}
public CoordinateTests (ITestOutputHelper output) => _output = output;
/// <summary>
/// Tests that screen to view mapping works correctly when the view has no superview and there are no Frames on the view.
@@ -32,7 +25,7 @@ public class CoordinateTests {
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
public void ScreenToView_NoSuper_NoFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
{
var view = new View () {
var view = new View {
X = viewX,
Y = viewY,
Width = 10,
@@ -58,7 +51,7 @@ public class CoordinateTests {
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
public void ScreenToView_NoSuper_HasFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
{
var view = new View () {
var view = new View {
X = viewX,
Y = viewY,
Width = 10,
@@ -85,13 +78,13 @@ public class CoordinateTests {
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
public void ScreenToView_SuperHasNoFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
{
var super = new View () {
var super = new View {
X = 0,
Y = 0,
Width = 10,
Height = 10
};
var view = new View () {
var view = new View {
X = viewX,
Y = viewY,
Width = 5,
@@ -118,14 +111,14 @@ public class CoordinateTests {
[InlineData (1, 1, 11, 11, 9, 9)] // it's ok for the view to return coordinates outside of its bounds
public void ScreenToView_SuperHasFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
{
var super = new View () {
var super = new View {
X = 0,
Y = 0,
Width = 10,
Height = 10,
BorderStyle = LineStyle.Single
};
var view = new View () {
var view = new View {
X = viewX,
Y = viewY,
Width = 5,
@@ -154,7 +147,7 @@ public class CoordinateTests {
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
public void ScreenToBounds_NoSuper_NoFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
{
var view = new View () {
var view = new View {
X = viewX,
Y = viewY,
Width = 10,
@@ -173,14 +166,14 @@ public class CoordinateTests {
[InlineData (0, 0, 0, 0, -1, -1)]
[InlineData (0, 0, 1, 1, 0, 0)]
[InlineData (0, 0, 9, 9, 8, 8)]
[InlineData (0, 0, 11, 11, 10, 10)]
[InlineData (0, 0, 11, 11, 10, 10)]
[InlineData (1, 1, 0, 0, -2, -2)]
[InlineData (1, 1, 1, 1, -1, -1)]
[InlineData (1, 1, 9, 9, 7, 7)]
[InlineData (1, 1, 11, 11, 9, 9)]
[InlineData (1, 1, 11, 11, 9, 9)]
public void ScreenToBounds_NoSuper_HasFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
{
var view = new View () {
var view = new View {
X = viewX,
Y = viewY,
Width = 10,
@@ -207,13 +200,13 @@ public class CoordinateTests {
[InlineData (1, 1, 11, 11, 10, 10)] // it's ok for the view to return coordinates outside of its bounds
public void ScreenToBounds_SuperHasNoFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
{
var super = new View () {
var super = new View {
X = 0,
Y = 0,
Width = 10,
Height = 10
};
var view = new View () {
var view = new View {
X = viewX,
Y = viewY,
Width = 5,
@@ -240,14 +233,14 @@ public class CoordinateTests {
[InlineData (1, 1, 11, 11, 9, 9)] // it's ok for the view to return coordinates outside of its bounds
public void ScreenToBounds_SuperHasFrames (int viewX, int viewY, int x, int y, int expectedX, int expectedY)
{
var super = new View () {
var super = new View {
X = 0,
Y = 0,
Width = 10,
Height = 10,
BorderStyle = LineStyle.Single
};
var view = new View () {
var view = new View {
X = viewX,
Y = viewY,
Width = 5,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,7 @@ public class PosTests {
[Fact]
public void AnchorEnd_SetsValue ()
{
int n = 0;
var n = 0;
var pos = Pos.AnchorEnd ();
Assert.Equal ($"AnchorEnd({n})", pos.ToString ());
@@ -34,8 +34,8 @@ public class PosTests {
[Fact]
public void AnchorEnd_Equal ()
{
int n1 = 0;
int n2 = 0;
var n1 = 0;
var n2 = 0;
var pos1 = Pos.AnchorEnd (n1);
var pos2 = Pos.AnchorEnd (n2);
@@ -47,13 +47,15 @@ public class PosTests {
Assert.NotEqual (pos1, pos2);
}
// 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 AnchorEnd_Equal_Inside_Window ()
{
int viewWidth = 10;
int viewHeight = 1;
var tv = new TextView () {
var viewWidth = 10;
var viewHeight = 1;
var tv = new TextView {
X = Pos.AnchorEnd (viewWidth),
Y = Pos.AnchorEnd (viewHeight),
Width = viewWidth,
@@ -74,13 +76,15 @@ public class PosTests {
Application.End (rs);
}
// 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 AnchorEnd_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
{
int viewWidth = 10;
int viewHeight = 1;
var tv = new TextView () {
var viewWidth = 10;
var viewHeight = 1;
var tv = new TextView {
X = Pos.AnchorEnd (viewWidth),
Y = Pos.AnchorEnd (viewHeight),
Width = viewWidth,
@@ -106,212 +110,11 @@ public class PosTests {
Application.End (rs);
}
[Fact]
[AutoInitShutdown]
public void Bottom_Equal_Inside_Window ()
{
var win = new Window ();
var label = new Label ("This should be the last line.") {
ColorScheme = Colors.Menu,
Width = Dim.Fill (),
X = 0,
Y = Pos.Bottom (win) - 3 // two lines top and bottom borders more one line above the bottom border
};
win.Add (label);
var top = Application.Top;
top.Add (win);
var rs = Application.Begin (top);
((FakeDriver)Application.Driver).SetBufferSize (40, 10);
Assert.True (label.AutoSize);
Assert.Equal (new Rect (0, 0, 40, 10), top.Frame);
Assert.Equal (new Rect (0, 0, 40, 10), win.Frame);
Assert.Equal (new Rect (0, 7, 38, 1), label.Frame);
string expected = @"
┌──────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│This should be the last line. │
└──────────────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Application.End (rs);
}
[Fact]
[AutoInitShutdown]
public void AnchorEnd_Better_Than_Bottom_Equal_Inside_Window ()
{
var win = new Window ();
var label = new Label ("This should be the last line.") {
ColorScheme = Colors.Menu,
Width = Dim.Fill (),
X = 0, // keep unit test focused; don't use Center here
Y = Pos.AnchorEnd (1)
};
win.Add (label);
var top = Application.Top;
top.Add (win);
var rs = Application.Begin (top);
((FakeDriver)Application.Driver).SetBufferSize (40, 10);
Assert.True (label.AutoSize);
Assert.Equal (29, label.Text.Length);
Assert.Equal (new Rect (0, 0, 40, 10), top.Frame);
Assert.Equal (new Rect (0, 0, 40, 10), win.Frame);
Assert.Equal (new Rect (0, 7, 38, 1), label.Frame);
string expected = @"
┌──────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│This should be the last line. │
└──────────────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Application.End (rs);
}
[Fact]
[AutoInitShutdown]
public void Bottom_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
{
var win = new Window ();
var label = new Label ("This should be the last line.") {
ColorScheme = Colors.Menu,
Width = Dim.Fill (),
X = 0,
Y = Pos.Bottom (win) - 4 // two lines top and bottom borders more two lines above border
};
win.Add (label);
var menu = new MenuBar (new MenuBarItem [] { new ("Menu", "", null) });
var status = new StatusBar (new StatusItem [] { new (KeyCode.F1, "~F1~ Help", null) });
var top = Application.Top;
top.Add (win, menu, status);
var rs = Application.Begin (top);
Assert.True (label.AutoSize);
Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
Assert.Equal (new Rect (0, 0, 80, 1), menu.Frame);
Assert.Equal (new Rect (0, 24, 80, 1), status.Frame);
Assert.Equal (new Rect (0, 1, 80, 23), win.Frame);
Assert.Equal (new Rect (0, 20, 78, 1), label.Frame);
string expected = @"
Menu
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│This should be the last line. │
└──────────────────────────────────────────────────────────────────────────────┘
F1 Help
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Application.End (rs);
}
[Fact]
[AutoInitShutdown]
public void AnchorEnd_Better_Than_Bottom_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
{
var win = new Window ();
var label = new Label ("This should be the last line.") {
ColorScheme = Colors.Menu,
Width = Dim.Fill (),
X = 0,
Y = Pos.AnchorEnd (1)
};
win.Add (label);
var menu = new MenuBar (new MenuBarItem [] { new ("Menu", "", null) });
var status = new StatusBar (new StatusItem [] { new (KeyCode.F1, "~F1~ Help", null) });
var top = Application.Top;
top.Add (win, menu, status);
var rs = Application.Begin (top);
Assert.True (label.AutoSize);
Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
Assert.Equal (new Rect (0, 0, 80, 1), menu.Frame);
Assert.Equal (new Rect (0, 24, 80, 1), status.Frame);
Assert.Equal (new Rect (0, 1, 80, 23), win.Frame);
Assert.Equal (new Rect (0, 20, 78, 1), label.Frame);
string expected = @"
Menu
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│This should be the last line. │
└──────────────────────────────────────────────────────────────────────────────┘
F1 Help
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Application.End (rs);
}
[Fact]
public void AnchorEnd_Negative_Throws ()
{
Pos pos;
int n = -1;
var n = -1;
Assert.Throws<ArgumentException> (() => pos = Pos.AnchorEnd (n));
}
@@ -331,8 +134,8 @@ public class PosTests {
[Fact]
public void At_Equal ()
{
int n1 = 0;
int n2 = 0;
var n1 = 0;
var n2 = 0;
var pos1 = Pos.At (n1);
var pos2 = Pos.At (n2);
@@ -372,7 +175,7 @@ public class PosTests {
{
string side; // used in format string
var testRect = Rect.Empty;
int testInt = 0;
var testInt = 0;
Pos pos;
// Pos.Left
@@ -521,6 +324,8 @@ public class PosTests {
#endif
}
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
// TODO: A new test that calls SetRelativeLayout directly is needed.
// See: https://github.com/gui-cs/Terminal.Gui/issues/504
[Fact]
[TestRespondersDisposed]
@@ -533,7 +338,7 @@ public class PosTests {
Application.Iteration += (s, a) => {
Application.RequestStop ();
};
var win = new Window () {
var win = new Window {
X = 0,
Y = 0,
Width = Dim.Fill (),
@@ -671,39 +476,8 @@ public class PosTests {
Assert.Throws<ArgumentException> (() => pos = Pos.Percent (1000001));
}
[Fact]
public void ForceValidatePosDim_True_Pos_Validation_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type ()
{
Application.Init (new FakeDriver ());
var t = Application.Top;
var w = new Window () {
X = Pos.Left (t) + 2,
Y = Pos.At (2)
};
var v = new View () {
X = Pos.Center (),
Y = Pos.Percent (10),
ValidatePosDim = true
};
w.Add (v);
t.Add (w);
t.Ready += (s, e) => {
Assert.Equal (2, w.X = 2);
Assert.Equal (2, w.Y = 2);
Assert.Throws<ArgumentException> (() => v.X = 2);
Assert.Throws<ArgumentException> (() => v.Y = 2);
};
Application.Iteration += (s, a) => Application.RequestStop ();
Application.Run ();
Application.Shutdown ();
}
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
// TODO: A new test that calls SetRelativeLayout directly is needed.
[Fact]
public void Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Null ()
{
@@ -726,85 +500,8 @@ public class PosTests {
}
[Fact]
public void Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
{
Application.Init (new FakeDriver ());
var t = Application.Top;
var w = new Window () {
X = Pos.Left (t) + 2,
Y = Pos.At (2)
};
var v = new View () {
X = Pos.Center (),
Y = Pos.Percent (10)
};
w.Add (v);
t.Add (w);
t.Ready += (s, e) => {
v.LayoutStyle = LayoutStyle.Absolute;
Assert.Equal (2, v.X = 2);
Assert.Equal (2, v.Y = 2);
};
Application.Iteration += (s, a) => Application.RequestStop ();
Application.Run ();
Application.Shutdown ();
}
// DONE: Test PosCombine
// DONE: Test operators
// BUGBUG: v2 - This test is bogus. v1 and references it's superview's (f) superview (w).
//[Fact]
//public void PosCombine_Do_Not_Throws ()
//{
// Application.Init (new FakeDriver ());
// var w = new Window () {
// X = Pos.Left (Application.Top) + 2,
// Y = Pos.Top (Application.Top) + 2
// };
// var f = new FrameView ();
// var v1 = new View () {
// X = Pos.Left (w) + 2,
// Y = Pos.Top (w) + 2
// };
// var v2 = new View () {
// X = Pos.Left (v1) + 2,
// Y = Pos.Top (v1) + 2
// };
// f.Add (v1, v2);
// w.Add (f);
// Application.Top.Add (w);
// f.X = Pos.X (Application.Top) + Pos.X (v2) - Pos.X (v1);
// f.Y = Pos.Y (Application.Top) + Pos.Y (v2) - Pos.Y (v1);
// Application.Top.LayoutComplete += (s, e) => {
// Assert.Equal (0, Application.Top.Frame.X);
// Assert.Equal (0, Application.Top.Frame.Y);
// Assert.Equal (2, w.Frame.X);
// Assert.Equal (2, w.Frame.Y);
// Assert.Equal (2, f.Frame.X);
// Assert.Equal (2, f.Frame.Y);
// Assert.Equal (4, v1.Frame.X);
// Assert.Equal (4, v1.Frame.Y);
// Assert.Equal (6, v2.Frame.X);
// Assert.Equal (6, v2.Frame.Y);
// };
// Application.Iteration += (s, a) => Application.RequestStop ();
// Application.Run ();
// Application.Shutdown ();
//}
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
// TODO: A new test that calls SetRelativeLayout directly is needed.
[Fact]
[TestRespondersDisposed]
public void PosCombine_Will_Throws ()
@@ -813,16 +510,16 @@ public class PosTests {
var t = Application.Top;
var w = new Window () {
var w = new Window {
X = Pos.Left (t) + 2,
Y = Pos.Top (t) + 2
};
var f = new FrameView ();
var v1 = new View () {
var v1 = new View {
X = Pos.Left (w) + 2,
Y = Pos.Top (w) + 2
};
var v2 = new View () {
var v2 = new View {
X = Pos.Left (v1) + 2,
Y = Pos.Top (v1) + 2
};
@@ -840,6 +537,8 @@ public class PosTests {
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 Pos_Add_Operator ()
@@ -848,9 +547,9 @@ public class PosTests {
var top = Application.Top;
var view = new View () { X = 0, Y = 0, Width = 20, Height = 20 };
var field = new TextField () { X = 0, Y = 0, Width = 20 };
int count = 0;
var view = new View { X = 0, Y = 0, Width = 20, Height = 20 };
var field = new TextField { X = 0, Y = 0, Width = 20 };
var count = 0;
field.KeyDown += (s, k) => {
if (k.KeyCode == KeyCode.Enter) {
@@ -889,6 +588,8 @@ public class PosTests {
Application.Shutdown ();
}
// 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 Pos_Subtract_Operator ()
@@ -897,12 +598,12 @@ public class PosTests {
var top = Application.Top;
var view = new View () { X = 0, Y = 0, Width = 20, Height = 20 };
var field = new TextField () { X = 0, Y = 0, Width = 20 };
int count = 20;
var view = new View { X = 0, Y = 0, Width = 20, Height = 20 };
var field = new TextField { X = 0, Y = 0, Width = 20 };
var count = 20;
var listLabels = new List<Label> ();
for (int i = 0; i < count; i++) {
for (var i = 0; i < count; i++) {
field.Text = $"Label {i}";
var label = new Label (field.Text) { X = 0, Y = field.Y, Width = 20 };
view.Add (label);
@@ -993,7 +694,7 @@ public class PosTests {
[Fact]
public void Function_SetsValue ()
{
string text = "Test";
var text = "Test";
var pos = Pos.Function (() => text.Length);
Assert.Equal ("PosFunc(4)", pos.ToString ());
@@ -1019,6 +720,8 @@ public class PosTests {
Assert.NotEqual (pos1, pos2);
}
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
// TODO: A new test that calls SetRelativeLayout directly is needed.
[Theory]
[AutoInitShutdown]
[InlineData (true)]
@@ -1053,6 +756,8 @@ public class PosTests {
}
}
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
// TODO: A new test that calls SetRelativeLayout directly is needed.
[Fact]
public void PosCombine_Referencing_Same_View ()
{
@@ -1086,7 +791,7 @@ public class PosTests {
[Fact]
public void DoNotReturnPosCombine ()
{
var v = new View () { Id = "V" };
var v = new View { Id = "V" };
var pos = Pos.Left (v);
Assert.Equal (
@@ -1118,5 +823,5 @@ public class PosTests {
"View(side=bottom,target=View(V)(0,0,0,0))",
pos.ToString ());
}
}
}

View File

@@ -1,8 +1,5 @@
using System;
using System.Text;
using Xunit;
using Xunit;
using Xunit.Abstractions;
using static Terminal.Gui.SpinnerStyle;
namespace Terminal.Gui.ViewTests;
@@ -12,138 +9,49 @@ public class SetRelativeLayoutTests {
public SetRelativeLayoutTests (ITestOutputHelper output) => _output = output;
[Fact]
public void Null_Pos_Is_Same_As_PosAbsolute0 ()
public void ComputedPosDim_StayComputed ()
{
var view = new View () {
X = null,
Y = null,
var screen = new Rect (0, 0, 10, 15);
var view = new View {
X = 1,
Y = 2,
Width = Dim.Fill (),
Height = Dim.Fill ()
};
// 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);
Assert.Equal ("Absolute(1)", view.X.ToString ());
Assert.Equal ("Absolute(2)", view.Y.ToString ());
Assert.Equal ("Fill(0)", view.Width.ToString ());
Assert.Equal ("Fill(0)", view.Height.ToString ());
view.SetRelativeLayout (screen);
Assert.Equal ("Fill(0)", view.Width.ToString ());
Assert.Equal ("Fill(0)", view.Height.ToString ());
}
[Fact]
public void Null_Dim_Is_Same_As_DimFill0 ()
public void AbsolutePosDim_DontChange ()
{
var view = new View () {
Width = null,
Height = null,
var screen = new Rect (0, 0, 10, 15);
var view = new View {
X = 1, // outside of screen +10
Y = 2, // outside of screen -10
Width = 3,
Height = 4
};
// 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);
// Layout is Absolute. So the X and Y are not changed.
view.SetRelativeLayout (screen);
Assert.Equal (1, view.Frame.X);
Assert.Equal (2, view.Frame.Y);
Assert.Equal (3, view.Frame.Width);
Assert.Equal (4, view.Frame.Height);
}
[Fact]
public void Fill_Pos_Within_Bounds ()
{
var screen = new Rect (0, 0, 80, 25);
var view = new View () {
var view = new View {
X = 1,
Y = 1,
Width = 5,
@@ -187,21 +95,22 @@ public class SetRelativeLayoutTests {
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 (0, view.Frame.Width); // proof (80 - 80)
Assert.Equal (24, view.Frame.Height);
}
[Fact]
public void FIll_Pos_Outside_Bounds ()
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
var view = new View {
X = 90, // outside of screen +10
Y = -10, // outside of screen -10
Width = 15,
Height = 15
};
// Layout is Absolute. So the X and Y are not changed.
view.SetRelativeLayout (screen);
Assert.Equal (90, view.Frame.X);
Assert.Equal (-10, view.Frame.Y);
@@ -222,8 +131,8 @@ public class SetRelativeLayoutTests {
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
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]
@@ -234,9 +143,9 @@ public class SetRelativeLayoutTests {
// 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
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
};
@@ -253,28 +162,28 @@ public class SetRelativeLayoutTests {
Assert.Equal (80, view.Frame.Width);
Assert.Equal (25, view.Frame.Height);
view.Width = Dim.Fill ();
view.Width = Dim.Fill ();
view.Height = Dim.Fill ();
view.SetRelativeLayout (screen);
Assert.Equal (-41, view.Frame.X);
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 (121, view.Frame.Width); // 121 = screen.Width - (-Center - 41)
Assert.Equal (38, view.Frame.Height);
}
[Fact]
public void FIll_And_PosCenter ()
public void Fill_And_PosCenter ()
{
var screen = new Rect (0, 0, 80, 25);
var view = new View () {
var view = new View {
X = Pos.Center (),
Y = Pos.Center (),
Width = Dim.Fill(),
Height = Dim.Fill()
Width = Dim.Fill (),
Height = Dim.Fill ()
};
view.SetRelativeLayout (screen);
Assert.Equal (0, view.Frame.X);
Assert.Equal (0, view.Frame.X);
Assert.Equal (0, view.Frame.Y);
Assert.Equal (80, view.Frame.Width);
Assert.Equal (25, view.Frame.Height);
@@ -304,14 +213,14 @@ public class SetRelativeLayoutTests {
view.SetRelativeLayout (screen);
Assert.Equal (-1, view.Frame.X);
Assert.Equal (0, view.Frame.Y);
Assert.Equal (81, view.Frame.Width);
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 (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).
@@ -329,13 +238,14 @@ public class SetRelativeLayoutTests {
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
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
};
@@ -345,16 +255,17 @@ public class SetRelativeLayoutTests {
Assert.Equal (23, view.Frame.Y);
}
[Fact] [TestRespondersDisposed]
[Fact]
[TestRespondersDisposed]
public void PosCombine_Plus_Absolute ()
{
var superView = new View () {
var superView = new View {
AutoSize = false,
Width = 10,
Height = 10
};
var testView = new View () {
var testView = new View {
AutoSize = false,
X = Pos.Center (),
Y = Pos.Center (),
@@ -366,7 +277,7 @@ public class SetRelativeLayoutTests {
Assert.Equal (4, testView.Frame.X);
Assert.Equal (4, testView.Frame.Y);
testView = new View () {
testView = new View {
AutoSize = false,
X = Pos.Center () + 1, // ((10 / 2) - (1 / 2)) + 1 = 5 - 1 + 1 = 5
Y = Pos.Center () + 1,
@@ -378,7 +289,7 @@ public class SetRelativeLayoutTests {
Assert.Equal (5, testView.Frame.X);
Assert.Equal (5, testView.Frame.Y);
testView = new View () {
testView = new View {
AutoSize = false,
X = 1 + Pos.Center (),
Y = 1 + Pos.Center (),
@@ -390,7 +301,7 @@ public class SetRelativeLayoutTests {
Assert.Equal (5, testView.Frame.X);
Assert.Equal (5, testView.Frame.Y);
testView = new View () {
testView = new View {
AutoSize = false,
X = 1 + Pos.Percent (50),
Y = Pos.Percent (50) + 1,
@@ -402,7 +313,7 @@ public class SetRelativeLayoutTests {
Assert.Equal (6, testView.Frame.X);
Assert.Equal (6, testView.Frame.Y);
testView = new View () {
testView = new View {
AutoSize = false,
X = Pos.Percent (10) + Pos.Percent (40),
Y = Pos.Percent (10) + Pos.Percent (40),
@@ -414,7 +325,7 @@ public class SetRelativeLayoutTests {
Assert.Equal (5, testView.Frame.X);
Assert.Equal (5, testView.Frame.Y);
testView = new View () {
testView = new View {
AutoSize = false,
X = 1 + Pos.Percent (10) + Pos.Percent (40) - 1,
Y = 5 + Pos.Percent (10) + Pos.Percent (40) - 5,
@@ -426,7 +337,7 @@ public class SetRelativeLayoutTests {
Assert.Equal (5, testView.Frame.X);
Assert.Equal (5, testView.Frame.Y);
testView = new View () {
testView = new View {
AutoSize = false,
X = Pos.Left (testView),
Y = Pos.Left (testView),
@@ -438,7 +349,7 @@ public class SetRelativeLayoutTests {
Assert.Equal (5, testView.Frame.X);
Assert.Equal (5, testView.Frame.Y);
testView = new View () {
testView = new View {
AutoSize = false,
X = 1 + Pos.Left (testView),
Y = Pos.Top (testView) + 1,
@@ -453,4 +364,37 @@ public class SetRelativeLayoutTests {
superView.Dispose ();
}
[Fact]
public void PosDimFunction ()
{
var screen = new Rect (0, 0, 30, 1);
var view = new View ("abc");
view.X = Pos.AnchorEnd () - Pos.Function (GetViewWidth);
int GetViewWidth ()
{
return view.Frame.Width;
}
// view will be 3 chars wide. It's X will be 27 (30 - 3).
view.SetRelativeLayout (screen);
Assert.Equal (27, view.Frame.X);
Assert.Equal (0, view.Frame.Y);
Assert.Equal (3, view.Frame.Width);
Assert.Equal (1, view.Frame.Height);
var tf = new TextField ("01234567890123456789");
tf.Width = Dim.Fill (1) - Dim.Function (GetViewWidth);
// tf will fill the screen minus 1 minus the width of view (3).
// so it's width will be 26 (30 - 1 - 3).
tf.SetRelativeLayout (screen);
Assert.Equal (0, tf.Frame.X);
Assert.Equal (0, tf.Frame.Y);
Assert.Equal (26, tf.Frame.Width);
Assert.Equal (1, tf.Frame.Height);
}
}

View File

@@ -1001,7 +1001,7 @@ namespace Terminal.Gui.ViewTests {
{
// Arrange
Application.Init ();
using var top = Toplevel.Create ();
using var top = new Toplevel ();
using var view = new View (
x: 0,
y: 1,

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,652 @@
using System;
using System.Collections.Generic;
using Xunit;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewTests;
/// <summary>
/// Tests of the <see cref="View.Text"/> property with <see cref="View.AutoSize"/> set to false.
/// </summary>
public class TextTests {
readonly ITestOutputHelper _output;
public TextTests (ITestOutputHelper output) => _output = output;
[Fact]
[AutoInitShutdown]
public void AutoSize_False_View_IsEmpty_False_Return_Null_Lines ()
{
var text = "Views";
var view = new View {
Width = Dim.Fill () - text.Length,
Height = 1,
Text = text
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.False (view.AutoSize);
Assert.Equal (new Rect (0, 0, 3, 1), view.Frame);
Assert.Equal (new Size (3, 1), view.TextFormatter.Size);
Assert.Equal (new List<string> { "Vie" }, view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Vie │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 0, 1), view.Frame);
Assert.Equal (new Size (0, 1), view.TextFormatter.Size);
Assert.Equal (new List<string> { string.Empty }, view.TextFormatter.Lines);
expected = @"
┌────────┐
│ │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact]
[AutoInitShutdown]
public void AutoSize_False_View_IsEmpty_True_Minimum_Height ()
{
var text = "Views";
var view = new View {
Width = Dim.Fill () - text.Length,
Text = text
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.False (view.AutoSize);
Assert.Equal (new Rect (0, 0, 3, 1), view.Frame);
Assert.Equal (new Size (3, 1), view.TextFormatter.Size);
Assert.Single (view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Vie │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 0, 1), view.Frame);
Assert.Equal (new Size (0, 1), view.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> { string.Empty }, view.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌────────┐
│ │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact]
[AutoInitShutdown]
public void AutoSize_False_Label_IsEmpty_True_Return_Null_Lines ()
{
var text = "Label";
var label = new Label {
Width = Dim.Fill () - text.Length,
Height = 1,
Text = text,
AutoSize = false
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (label);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.False (label.AutoSize);
Assert.Equal (new Rect (0, 0, 3, 1), label.Frame);
Assert.Equal (new Size (3, 1), label.TextFormatter.Size);
Assert.Equal (new List<string> { "Lab" }, label.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Lab │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
label.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.False (label.AutoSize);
Assert.Equal (new Rect (0, 0, 0, 1), label.Frame);
Assert.Equal (new Size (0, 1), label.TextFormatter.Size);
Assert.Equal (new List<string> { string.Empty }, label.TextFormatter.Lines);
expected = @"
┌────────┐
│ │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact]
[AutoInitShutdown]
public void AutoSize_False_Label_Height_Zero_Returns_Minimum_Height ()
{
var text = "Label";
var label = new Label {
Width = Dim.Fill () - text.Length,
Text = text,
AutoSize = false
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (label);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
Assert.Equal (5, text.Length);
Assert.False (label.AutoSize);
Assert.Equal (new Rect (0, 0, 3, 1), label.Frame);
Assert.Equal (new Size (3, 1), label.TextFormatter.Size);
Assert.Single (label.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
var expected = @"
┌────────┐
│Lab │
│ │
└────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
label.Width = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 0, 1), label.Frame);
Assert.Equal (new Size (0, 1), label.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> { string.Empty }, label.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌────────┐
│ │
│ │
└────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 10, 4), pos);
}
[Fact]
[AutoInitShutdown]
public void AutoSize_False_View_Width_Null_Returns_Host_Frame_Width ()
{
var text = "Views";
var view = new View {
TextDirection = TextDirection.TopBottom_LeftRight,
Height = Dim.Fill () - text.Length,
Text = text
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (4, 10);
Assert.Equal (5, text.Length);
Assert.False (view.AutoSize);
Assert.Equal (new Rect (0, 0, 1, 3), view.Frame);
Assert.Equal (new Size (1, 3), view.TextFormatter.Size);
Assert.Single (view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 4, 10), win.Frame);
Assert.Equal (new Rect (0, 0, 4, 10), Application.Top.Frame);
var expected = @"
┌──┐
│V │
│i │
│e │
│ │
│ │
│ │
│ │
│ │
└──┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Height = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 1, 0), view.Frame);
Assert.Equal (new Size (1, 0), view.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> { string.Empty }, view.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌──┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
}
[Fact]
[AutoInitShutdown]
public void AutoSize_False_View_Width_Zero_Returns_Minimum_Width_With_Wide_Rune ()
{
var text = "界View";
var view = new View {
TextDirection = TextDirection.TopBottom_LeftRight,
Height = Dim.Fill () - text.Length,
Text = text
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
win.Add (view);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (4, 10);
Assert.Equal (5, text.Length);
Assert.False (view.AutoSize);
Assert.Equal (new Rect (0, 0, 2, 3), view.Frame);
Assert.Equal (new Size (2, 3), view.TextFormatter.Size);
Assert.Single (view.TextFormatter.Lines);
Assert.Equal (new Rect (0, 0, 4, 10), win.Frame);
Assert.Equal (new Rect (0, 0, 4, 10), Application.Top.Frame);
var expected = @"
┌──┐
│界│
│V │
│i │
│ │
│ │
│ │
│ │
│ │
└──┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
view.Height = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 2, 0), view.Frame);
Assert.Equal (new Size (2, 0), view.TextFormatter.Size);
var exception = Record.Exception (() => Assert.Equal (new List<string> { string.Empty }, view.TextFormatter.Lines));
Assert.Null (exception);
expected = @"
┌──┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 4, 10), pos);
}
[Fact]
public void AutoSize_False_If_Text_Empty ()
{
var view1 = new View ();
var view2 = new View ("");
var view3 = new View { Text = "" };
Assert.False (view1.AutoSize);
Assert.False (view2.AutoSize);
Assert.False (view3.AutoSize);
view1.Dispose ();
view2.Dispose ();
view3.Dispose ();
}
[Fact]
public void AutoSize_False_If_Text_Is_Not_Empty ()
{
var view1 = new View ();
view1.Text = "Hello World";
var view2 = new View ("Hello World");
var view3 = new View { Text = "Hello World" };
Assert.False (view1.AutoSize);
Assert.False (view2.AutoSize);
Assert.False (view3.AutoSize);
view1.Dispose ();
view2.Dispose ();
view3.Dispose ();
}
[Fact]
public void AutoSize_False_ResizeView_Is_Always_False ()
{
var super = new View ();
var label = new Label { AutoSize = false };
super.Add (label);
label.Text = "New text";
super.LayoutSubviews ();
Assert.False (label.AutoSize);
Assert.Equal ("(0,0,0,1)", label.Bounds.ToString ());
super.Dispose ();
}
[Fact]
[AutoInitShutdown]
public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
{
var win = new Window (new Rect (0, 0, 30, 80));
var label = new Label { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill () };
win.Add (label);
Application.Top.Add (win);
Assert.False (label.AutoSize);
Assert.Equal ("(0,0,80,25)", label.Bounds.ToString ());
label.Text = "New text\nNew line";
Application.Top.LayoutSubviews ();
Assert.False (label.AutoSize);
Assert.Equal ("(0,0,28,78)", label.Bounds.ToString ());
Assert.False (label.IsInitialized);
var rs = Application.Begin (Application.Top);
Assert.True (label.IsInitialized);
Assert.False (label.AutoSize);
Assert.Equal ("(0,0,28,78)", label.Bounds.ToString ());
Application.End (rs);
}
[Fact]
[AutoInitShutdown]
public void AutoSize_False_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
{
var view1 = new View { Text = "Say Hello view1 你", AutoSize = false, Width = 10, Height = 5 };
var view2 = new View { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = false };
var view3 = new View { AutoSize = false, Width = 10, Height = 5, Text = "Say Hello view3 你" };
var view4 = new View {
Text = "Say Hello view4 你",
AutoSize = false,
Width = 10,
Height = 5,
TextDirection = TextDirection.TopBottom_LeftRight
};
var view5 = new View {
Text = "Say Hello view5 你",
Width = 10,
Height = 5,
AutoSize = false,
TextDirection = TextDirection.TopBottom_LeftRight
};
var view6 = new View {
AutoSize = false,
Width = 10,
Height = 5,
TextDirection = TextDirection.TopBottom_LeftRight,
Text = "Say Hello view6 你"
};
Application.Top.Add (view1, view2, view3, view4, view5, view6);
Assert.False (view1.IsInitialized);
Assert.False (view2.IsInitialized);
Assert.False (view3.IsInitialized);
Assert.False (view4.IsInitialized);
Assert.False (view5.IsInitialized);
Assert.False (view1.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
Assert.Equal ("Absolute(10)", view1.Width.ToString ());
Assert.Equal ("Absolute(5)", view1.Height.ToString ());
Assert.False (view2.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
Assert.Equal ("Absolute(10)", view2.Width.ToString ());
Assert.Equal ("Absolute(5)", view2.Height.ToString ());
Assert.False (view3.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
Assert.Equal ("Absolute(10)", view3.Width.ToString ());
Assert.Equal ("Absolute(5)", view3.Height.ToString ());
Assert.False (view4.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
Assert.Equal ("Absolute(10)", view4.Width.ToString ());
Assert.Equal ("Absolute(5)", view4.Height.ToString ());
Assert.False (view5.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
Assert.Equal ("Absolute(10)", view5.Width.ToString ());
Assert.Equal ("Absolute(5)", view5.Height.ToString ());
Assert.False (view6.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
Assert.Equal ("Absolute(10)", view6.Width.ToString ());
Assert.Equal ("Absolute(5)", view6.Height.ToString ());
var rs = Application.Begin (Application.Top);
Assert.True (view1.IsInitialized);
Assert.True (view2.IsInitialized);
Assert.True (view3.IsInitialized);
Assert.True (view4.IsInitialized);
Assert.True (view5.IsInitialized);
Assert.False (view1.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
Assert.Equal ("Absolute(10)", view1.Width.ToString ());
Assert.Equal ("Absolute(5)", view1.Height.ToString ());
Assert.False (view2.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
Assert.Equal ("Absolute(10)", view2.Width.ToString ());
Assert.Equal ("Absolute(5)", view2.Height.ToString ());
Assert.False (view3.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
Assert.Equal ("Absolute(10)", view3.Width.ToString ());
Assert.Equal ("Absolute(5)", view3.Height.ToString ());
Assert.False (view4.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
Assert.Equal ("Absolute(10)", view4.Width.ToString ());
Assert.Equal ("Absolute(5)", view4.Height.ToString ());
Assert.False (view5.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
Assert.Equal ("Absolute(10)", view5.Width.ToString ());
Assert.Equal ("Absolute(5)", view5.Height.ToString ());
Assert.False (view6.AutoSize);
Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
Assert.Equal ("Absolute(10)", view6.Width.ToString ());
Assert.Equal ("Absolute(5)", view6.Height.ToString ());
Application.End (rs);
}
[Fact]
[AutoInitShutdown]
public void AutoSize_False_Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
{
string text = $"First line{Environment.NewLine}Second line";
var horizontalView = new View () {
Width = 20,
Height = 1,
Text = text
};
var verticalView = new View () {
Y = 3,
Height = 20,
Width = 1,
Text = text,
TextDirection = TextDirection.TopBottom_LeftRight
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Text = "Window"
};
win.Add (horizontalView, verticalView);
Application.Top.Add (win);
var rs = Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (32, 32);
Assert.False (horizontalView.AutoSize);
Assert.False (verticalView.AutoSize);
Assert.Equal (new Rect (0, 0, 20, 1), horizontalView.Frame);
Assert.Equal (new Rect (0, 3, 1, 20), verticalView.Frame);
string expected = @"
┌──────────────────────────────┐
│First line Second li │
│ │
│ │
│F │
│i │
│r │
│s │
│t │
│ │
│l │
│i │
│n │
│e │
│ │
│S │
│e │
│c │
│o │
│n │
│d │
│ │
│l │
│i │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
verticalView.Text = $"最初の行{Environment.NewLine}二行目";
Application.Top.Draw ();
// BUGBUG: #3127 - If AutoSize == false, setting text should NOT change the size of the view.
Assert.Equal (new Rect (0, 3, 2, 20), verticalView.Frame);
expected = @"
┌──────────────────────────────┐
│First line Second li │
│ │
│ │
│最 │
│初 │
│の │
│行 │
│ │
│二 │
│行 │
│目 │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Application.End (rs);
}
}

View File

@@ -27,13 +27,13 @@ public class ViewKeyBindingTests {
AddCommand (Command.Save, () => ApplicationCommand = true);
AddCommand (Command.Default, () => HotKeyCommand = true);
AddCommand (Command.Left, () => FocusedCommand = true);
KeyBindings.Add (KeyCode.A, KeyBindingScope.Application, Command.Save);
HotKey = KeyCode.H;
KeyBindings.Add (KeyCode.F, KeyBindingScope.Focused, Command.Left);
}
}
[Fact]
[AutoInitShutdown]
public void Focus_KeyBinding ()
@@ -64,7 +64,7 @@ public class ViewKeyBindingTests {
Assert.True (view.HasFocus);
Application.OnKeyDown (new (KeyCode.F));
Assert.True (invoked);
Assert.True (view.ApplicationCommand);
Assert.True (view.HotKeyCommand);
Assert.True (view.FocusedCommand);

File diff suppressed because it is too large Load Diff