Fixed BorderTests

This commit is contained in:
Tig
2024-05-30 10:47:52 -06:00
parent 349f1f6459
commit 94ce28012e
8 changed files with 191 additions and 196 deletions

View File

@@ -2,11 +2,8 @@
namespace Terminal.Gui.ViewTests;
public class BorderTests
public class BorderTests (ITestOutputHelper output)
{
private readonly ITestOutputHelper _output;
public BorderTests (ITestOutputHelper output) { _output = output; }
[Fact]
[SetupFakeDriver]
public void Border_Parent_HasFocus_Title_Uses_FocusAttribute ()
@@ -18,13 +15,13 @@ public class BorderTests
var view = new View { Title = "A", Height = 2, Width = 5 };
superView.Add (view);
view.Border.Thickness = new Thickness (0, 1, 0, 0);
view.Border.Thickness = new (0, 1, 0, 0);
view.Border.LineStyle = LineStyle.Single;
view.ColorScheme = new ColorScheme
view.ColorScheme = new()
{
Normal = new Attribute (Color.Red, Color.Green),
Focus = new Attribute (Color.Green, Color.Red)
Normal = new (Color.Red, Color.Green),
Focus = new (Color.Green, Color.Red)
};
Assert.NotEqual (view.ColorScheme.Normal.Foreground, view.ColorScheme.Focus.Foreground);
Assert.Equal (ColorName.Red, view.Border.GetNormalColor ().Foreground.GetClosestNamedColor ());
@@ -36,7 +33,7 @@ public class BorderTests
superView.Draw ();
var expected = @"─┤A├─";
TestHelpers.AssertDriverContentsAre (expected, _output);
TestHelpers.AssertDriverContentsAre (expected, output);
TestHelpers.AssertDriverAttributesAre ("00000", null, view.ColorScheme.Normal);
view.CanFocus = true;
@@ -53,12 +50,12 @@ public class BorderTests
public void Border_Uses_Parent_ColorScheme ()
{
var view = new View { Title = "A", Height = 2, Width = 5 };
view.Border.Thickness = new Thickness (0, 1, 0, 0);
view.Border.Thickness = new (0, 1, 0, 0);
view.Border.LineStyle = LineStyle.Single;
view.ColorScheme = new ColorScheme
view.ColorScheme = new()
{
Normal = new Attribute (Color.Red, Color.Green), Focus = new Attribute (Color.Green, Color.Red)
Normal = new (Color.Red, Color.Green), Focus = new (Color.Green, Color.Red)
};
Assert.Equal (ColorName.Red, view.Border.GetNormalColor ().Foreground.GetClosestNamedColor ());
Assert.Equal (ColorName.Green, view.Border.GetFocusColor ().Foreground.GetClosestNamedColor ());
@@ -70,7 +67,7 @@ public class BorderTests
view.Draw ();
var expected = @"─┤A├─";
TestHelpers.AssertDriverContentsAre (expected, _output);
TestHelpers.AssertDriverContentsAre (expected, output);
TestHelpers.AssertDriverAttributesAre ("00000", null, view.ColorScheme.Normal);
}
@@ -105,7 +102,7 @@ public class BorderTests
switch (width)
{
case 1:
Assert.Equal (new Rectangle (0, 0, 1, 5), win.Frame);
Assert.Equal (new (0, 0, 1, 5), win.Frame);
expected = @"
@@ -114,7 +111,7 @@ public class BorderTests
break;
case 2:
Assert.Equal (new Rectangle (0, 0, 2, 5), win.Frame);
Assert.Equal (new (0, 0, 2, 5), win.Frame);
expected = @"
╔╗
@@ -123,7 +120,7 @@ public class BorderTests
break;
case 3:
Assert.Equal (new Rectangle (0, 0, 3, 5), win.Frame);
Assert.Equal (new (0, 0, 3, 5), win.Frame);
expected = @"
╔═╗
@@ -132,7 +129,7 @@ public class BorderTests
break;
case 4:
Assert.Equal (new Rectangle (0, 0, 4, 5), win.Frame);
Assert.Equal (new (0, 0, 4, 5), win.Frame);
expected = @"
╒╕
@@ -142,7 +139,7 @@ public class BorderTests
break;
case 5:
Assert.Equal (new Rectangle (0, 0, 5, 5), win.Frame);
Assert.Equal (new (0, 0, 5, 5), win.Frame);
expected = @"
╒═╕
@@ -152,7 +149,7 @@ public class BorderTests
break;
case 6:
Assert.Equal (new Rectangle (0, 0, 6, 5), win.Frame);
Assert.Equal (new (0, 0, 6, 5), win.Frame);
expected = @"
╒══╕
@@ -162,7 +159,7 @@ public class BorderTests
break;
case 7:
Assert.Equal (new Rectangle (0, 0, 7, 5), win.Frame);
Assert.Equal (new (0, 0, 7, 5), win.Frame);
expected = @"
╒═══╕
@@ -172,7 +169,7 @@ public class BorderTests
break;
case 8:
Assert.Equal (new Rectangle (0, 0, 8, 5), win.Frame);
Assert.Equal (new (0, 0, 8, 5), win.Frame);
expected = @"
╒════╕
@@ -182,7 +179,7 @@ public class BorderTests
break;
case 9:
Assert.Equal (new Rectangle (0, 0, 9, 5), win.Frame);
Assert.Equal (new (0, 0, 9, 5), win.Frame);
expected = @"
╒════╕
@@ -192,7 +189,7 @@ public class BorderTests
break;
case 10:
Assert.Equal (new Rectangle (0, 0, 10, 5), win.Frame);
Assert.Equal (new (0, 0, 10, 5), win.Frame);
expected = @"
╒════╕
@@ -203,8 +200,9 @@ public class BorderTests
break;
}
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Application.End (rs);
win.Dispose ();
}
[Theory]
@@ -238,7 +236,7 @@ public class BorderTests
switch (width)
{
case 1:
Assert.Equal (new Rectangle (0, 0, 1, 4), win.Frame);
Assert.Equal (new (0, 0, 1, 4), win.Frame);
expected = @"
@@ -247,7 +245,7 @@ public class BorderTests
break;
case 2:
Assert.Equal (new Rectangle (0, 0, 2, 4), win.Frame);
Assert.Equal (new (0, 0, 2, 4), win.Frame);
expected = @"
╔╗
@@ -256,7 +254,7 @@ public class BorderTests
break;
case 3:
Assert.Equal (new Rectangle (0, 0, 3, 4), win.Frame);
Assert.Equal (new (0, 0, 3, 4), win.Frame);
expected = @"
╔═╗
@@ -265,7 +263,7 @@ public class BorderTests
break;
case 4:
Assert.Equal (new Rectangle (0, 0, 4, 4), win.Frame);
Assert.Equal (new (0, 0, 4, 4), win.Frame);
expected = @"
╒╕
@@ -275,7 +273,7 @@ public class BorderTests
break;
case 5:
Assert.Equal (new Rectangle (0, 0, 5, 4), win.Frame);
Assert.Equal (new (0, 0, 5, 4), win.Frame);
expected = @"
╒═╕
@@ -285,7 +283,7 @@ public class BorderTests
break;
case 6:
Assert.Equal (new Rectangle (0, 0, 6, 4), win.Frame);
Assert.Equal (new (0, 0, 6, 4), win.Frame);
expected = @"
╒══╕
@@ -295,7 +293,7 @@ public class BorderTests
break;
case 7:
Assert.Equal (new Rectangle (0, 0, 7, 4), win.Frame);
Assert.Equal (new (0, 0, 7, 4), win.Frame);
expected = @"
╒═══╕
@@ -305,7 +303,7 @@ public class BorderTests
break;
case 8:
Assert.Equal (new Rectangle (0, 0, 8, 4), win.Frame);
Assert.Equal (new (0, 0, 8, 4), win.Frame);
expected = @"
╒════╕
@@ -315,7 +313,7 @@ public class BorderTests
break;
case 9:
Assert.Equal (new Rectangle (0, 0, 9, 4), win.Frame);
Assert.Equal (new (0, 0, 9, 4), win.Frame);
expected = @"
╒════╕
@@ -325,7 +323,7 @@ public class BorderTests
break;
case 10:
Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame);
Assert.Equal (new (0, 0, 10, 4), win.Frame);
expected = @"
╒════╕
@@ -336,8 +334,9 @@ public class BorderTests
break;
}
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Application.End (rs);
win.Dispose ();
}
[Theory]
@@ -371,7 +370,7 @@ public class BorderTests
switch (width)
{
case 1:
Assert.Equal (new Rectangle (0, 0, 1, 4), win.Frame);
Assert.Equal (new (0, 0, 1, 4), win.Frame);
expected = @"
@@ -380,7 +379,7 @@ public class BorderTests
break;
case 2:
Assert.Equal (new Rectangle (0, 0, 2, 4), win.Frame);
Assert.Equal (new (0, 0, 2, 4), win.Frame);
expected = @"
╔╗
@@ -389,7 +388,7 @@ public class BorderTests
break;
case 3:
Assert.Equal (new Rectangle (0, 0, 3, 4), win.Frame);
Assert.Equal (new (0, 0, 3, 4), win.Frame);
expected = @"
╔═╗
@@ -398,7 +397,7 @@ public class BorderTests
break;
case 4:
Assert.Equal (new Rectangle (0, 0, 4, 4), win.Frame);
Assert.Equal (new (0, 0, 4, 4), win.Frame);
expected = @"
╒╕
@@ -408,7 +407,7 @@ public class BorderTests
break;
case 5:
Assert.Equal (new Rectangle (0, 0, 5, 4), win.Frame);
Assert.Equal (new (0, 0, 5, 4), win.Frame);
expected = @"
╒═╕
@@ -418,7 +417,7 @@ public class BorderTests
break;
case 6:
Assert.Equal (new Rectangle (0, 0, 6, 4), win.Frame);
Assert.Equal (new (0, 0, 6, 4), win.Frame);
expected = @"
╒══╕
@@ -428,7 +427,7 @@ public class BorderTests
break;
case 7:
Assert.Equal (new Rectangle (0, 0, 7, 4), win.Frame);
Assert.Equal (new (0, 0, 7, 4), win.Frame);
expected = @"
╒═══╕
@@ -438,7 +437,7 @@ public class BorderTests
break;
case 8:
Assert.Equal (new Rectangle (0, 0, 8, 4), win.Frame);
Assert.Equal (new (0, 0, 8, 4), win.Frame);
expected = @"
╒════╕
@@ -448,7 +447,7 @@ public class BorderTests
break;
case 9:
Assert.Equal (new Rectangle (0, 0, 9, 4), win.Frame);
Assert.Equal (new (0, 0, 9, 4), win.Frame);
expected = @"
╒════╕
@@ -458,7 +457,7 @@ public class BorderTests
break;
case 10:
Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame);
Assert.Equal (new (0, 0, 10, 4), win.Frame);
expected = @"
╒════╕
@@ -469,8 +468,9 @@ public class BorderTests
break;
}
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Application.End (rs);
win.Dispose ();
}
[Theory]
@@ -523,8 +523,9 @@ public class BorderTests
break;
}
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Application.End (rs);
win.Dispose ();
}
[Theory]
@@ -636,7 +637,8 @@ public class BorderTests
break;
}
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
win.Dispose ();
}
[Theory]
@@ -736,8 +738,9 @@ public class BorderTests
║└─┘║
╚═══╝";
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Application.End (rs);
top.Dispose ();
}
[Fact]
@@ -762,8 +765,9 @@ public class BorderTests
║└──────┘║
╚════════╝";
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Application.End (rs);
top.Dispose ();
}
[Fact]
@@ -783,7 +787,8 @@ public class BorderTests
│ │
└─┘";
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
win.Dispose ();
}
[Fact]
@@ -801,11 +806,11 @@ public class BorderTests
var view = new View ();
view.BorderStyle = LineStyle.Single;
Assert.Equal (LineStyle.Single, view.BorderStyle);
Assert.Equal (new Thickness (1), view.Border.Thickness);
Assert.Equal (new (1), view.Border.Thickness);
view.BorderStyle = LineStyle.Double;
Assert.Equal (LineStyle.Double, view.BorderStyle);
Assert.Equal (new Thickness (1), view.Border.Thickness);
Assert.Equal (new (1), view.Border.Thickness);
view.BorderStyle = LineStyle.None;
Assert.Equal (LineStyle.None, view.BorderStyle);

View File

@@ -4,11 +4,8 @@ using Xunit.Abstractions;
namespace Terminal.Gui.ViewTests;
public class ViewTests
public class ViewTests (ITestOutputHelper output)
{
private readonly ITestOutputHelper _output;
public ViewTests (ITestOutputHelper output) { _output = output; }
[Fact]
[AutoInitShutdown]
public void Clear_Viewport_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
@@ -18,7 +15,7 @@ public class ViewTests
view.DrawContent += (s, e) =>
{
Rectangle savedClip = Application.Driver.Clip;
Application.Driver.Clip = new Rectangle (1, 1, view.Viewport.Width, view.Viewport.Height);
Application.Driver.Clip = new (1, 1, view.Viewport.Width, view.Viewport.Height);
for (var row = 0; row < view.Viewport.Height; row++)
{
@@ -51,8 +48,8 @@ public class ViewTests
└──────────────────┘
";
Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rectangle (0, 0, 20, 10), pos);
Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new (0, 0, 20, 10), pos);
view.FillRect (view.Viewport);
@@ -69,7 +66,7 @@ public class ViewTests
└──────────────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
top.Dispose ();
}
@@ -82,7 +79,7 @@ public class ViewTests
view.DrawContent += (s, e) =>
{
Rectangle savedClip = Application.Driver.Clip;
Application.Driver.Clip = new Rectangle (1, 1, view.Viewport.Width, view.Viewport.Height);
Application.Driver.Clip = new (1, 1, view.Viewport.Width, view.Viewport.Height);
for (var row = 0; row < view.Viewport.Height; row++)
{
@@ -115,8 +112,8 @@ public class ViewTests
└──────────────────┘
";
Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rectangle (0, 0, 20, 10), pos);
Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new (0, 0, 20, 10), pos);
view.FillRect (view.Viewport);
@@ -133,7 +130,7 @@ public class ViewTests
└──────────────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
top.Dispose ();
}
@@ -147,8 +144,8 @@ public class ViewTests
var root = new View { Width = 20, Height = 10, ColorScheme = Colors.ColorSchemes ["Base"] };
View v = label
? new Label { Text = new string ('c', 100) }
: new TextView { Height = 1, Text = new string ('c', 100), Width = Dim.Fill () };
? new Label { Text = new ('c', 100) }
: new TextView { Height = 1, Text = new ('c', 100), Width = Dim.Fill () };
root.Add (v);
@@ -159,18 +156,19 @@ public class ViewTests
if (label)
{
Assert.False (v.CanFocus);
//Assert.Equal (new Rectangle (0, 0, 20, 1), v.Frame);
}
else
{
Assert.True (v.CanFocus);
Assert.Equal (new Rectangle (0, 0, 20, 1), v.Frame);
Assert.Equal (new (0, 0, 20, 1), v.Frame);
}
TestHelpers.AssertDriverContentsWithFrameAre (
@"
cccccccccccccccccccc",
_output
output
);
Attribute [] attributes =
@@ -220,6 +218,7 @@ cccccccccccccccccccc",
}
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -246,13 +245,13 @@ At 0,0
A text with some long width
and also with two lines. ",
_output
output
);
view.Frame = new Rectangle (3, 3, 10, 1);
Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame);
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect);
view.Frame = new (3, 3, 10, 1);
Assert.Equal (new (3, 3, 10, 1), view.Frame);
Assert.Equal (new (0, 0, 10, 1), view.Viewport);
Assert.Equal (new (0, 0, 10, 1), view._needsDisplayRect);
top.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (
@@ -261,9 +260,10 @@ At 0,0
A text wit",
_output
output
);
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -292,16 +292,16 @@ At 0,0
A text with some long width
and also with two lines. ",
_output
output
);
view.X = 3;
view.Y = 3;
view.Width = 10;
view.Height = 1;
Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame);
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect);
Assert.Equal (new (3, 3, 10, 1), view.Frame);
Assert.Equal (new (0, 0, 10, 1), view.Viewport);
Assert.Equal (new (0, 0, 30, 2), view._needsDisplayRect);
top.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (
@@ -310,9 +310,10 @@ At 0,0
A text wit",
_output
output
);
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -341,22 +342,23 @@ At 0,0
A text with some long width
and also with two lines. ",
_output
output
);
view.Frame = new Rectangle (1, 1, 10, 1);
Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame);
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect);
view.Frame = new (1, 1, 10, 1);
Assert.Equal (new (1, 1, 10, 1), view.Frame);
Assert.Equal (new (0, 0, 10, 1), view.Viewport);
Assert.Equal (new (0, 0, 10, 1), view._needsDisplayRect);
top.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (
@"
At 0,0
A text wit",
_output
output
);
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -385,25 +387,26 @@ At 0,0
A text with some long width
and also with two lines. ",
_output
output
);
view.X = 1;
view.Y = 1;
view.Width = 10;
view.Height = 1;
Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame);
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect);
Assert.Equal (new (1, 1, 10, 1), view.Frame);
Assert.Equal (new (0, 0, 10, 1), view.Viewport);
Assert.Equal (new (0, 0, 30, 2), view._needsDisplayRect);
top.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (
@"
At 0,0
A text wit",
_output
output
);
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -443,6 +446,7 @@ At 0,0
Assert.True (viewCalled);
Assert.True (tvCalled);
top.Dispose ();
}
[Fact]
@@ -476,33 +480,33 @@ At 0,0
RunState runState = Application.Begin (top);
top.LayoutComplete += (s, e) => { Assert.Equal (new Rectangle (0, 0, 80, 25), top._needsDisplayRect); };
top.LayoutComplete += (s, e) => { Assert.Equal (new (0, 0, 80, 25), top._needsDisplayRect); };
frame.LayoutComplete += (s, e) => { Assert.Equal (new Rectangle (0, 0, 40, 8), frame._needsDisplayRect); };
frame.LayoutComplete += (s, e) => { Assert.Equal (new (0, 0, 40, 8), frame._needsDisplayRect); };
label.LayoutComplete += (s, e) => { Assert.Equal (new Rectangle (0, 0, 38, 1), label._needsDisplayRect); };
label.LayoutComplete += (s, e) => { Assert.Equal (new (0, 0, 38, 1), label._needsDisplayRect); };
button.LayoutComplete += (s, e) => { Assert.Equal (new Rectangle (0, 0, 13, 1), button._needsDisplayRect); };
button.LayoutComplete += (s, e) => { Assert.Equal (new (0, 0, 13, 1), button._needsDisplayRect); };
Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
Assert.Equal (new Rectangle (20, 8, 40, 8), frame.Frame);
Assert.Equal (new (0, 0, 80, 25), top.Frame);
Assert.Equal (new (20, 8, 40, 8), frame.Frame);
Assert.Equal (
new Rectangle (20, 8, 60, 16),
new (20, 8, 60, 16),
new Rectangle (
frame.Frame.Left,
frame.Frame.Top,
frame.Frame.Right,
frame.Frame.Bottom
)
frame.Frame.Left,
frame.Frame.Top,
frame.Frame.Right,
frame.Frame.Bottom
)
);
Assert.Equal (new Rectangle (0, 0, 30, 1), label.Frame);
Assert.Equal (new Rectangle (0, 1, 13, 1), button.Frame); // this proves frame was set
Assert.Equal (new (0, 0, 30, 1), label.Frame);
Assert.Equal (new (0, 1, 13, 1), button.Frame); // this proves frame was set
Application.End (runState);
top.Dispose ();
}
[Fact]
[AutoInitShutdown]
public void GetHotNormalColor_ColorScheme ()
{
var view = new View { ColorScheme = Colors.ColorSchemes ["Base"] };
@@ -515,7 +519,6 @@ At 0,0
}
[Fact]
[AutoInitShutdown]
public void GetNormalColor_ColorScheme ()
{
var view = new View { ColorScheme = Colors.ColorSchemes ["Base"] };
@@ -553,12 +556,12 @@ At 0,0
A text with some long width
and also with two lines. ",
_output
output
);
view.Frame = new Rectangle (3, 3, 10, 1);
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect);
view.Frame = new (3, 3, 10, 1);
Assert.Equal (new (0, 0, 10, 1), view.Viewport);
Assert.Equal (new (0, 0, 10, 1), view._needsDisplayRect);
view.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (
@@ -567,9 +570,10 @@ At 0,0
A text with some long width
A text witith two lines. ",
_output
output
);
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -598,16 +602,16 @@ At 0,0
A text with some long width
and also with two lines. ",
_output
output
);
view.X = 3;
view.Y = 3;
view.Width = 10;
view.Height = 1;
Assert.Equal (new Rectangle (3, 3, 10, 1), view.Frame);
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect);
Assert.Equal (new (3, 3, 10, 1), view.Frame);
Assert.Equal (new (0, 0, 10, 1), view.Viewport);
Assert.Equal (new (0, 0, 30, 2), view._needsDisplayRect);
view.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (
@@ -616,9 +620,10 @@ At 0,0
A text with some long width
A text witith two lines. ",
_output
output
);
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -647,13 +652,13 @@ At 0,0
A text with some long width
and also with two lines. ",
_output
output
);
view.Frame = new Rectangle (1, 1, 10, 1);
Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame);
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
Assert.Equal (new Rectangle (0, 0, 10, 1), view._needsDisplayRect);
view.Frame = new (1, 1, 10, 1);
Assert.Equal (new (1, 1, 10, 1), view.Frame);
Assert.Equal (new (0, 0, 10, 1), view.Viewport);
Assert.Equal (new (0, 0, 10, 1), view._needsDisplayRect);
view.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (
@@ -662,9 +667,10 @@ At 0,0
A text wit
A text with some long width
and also with two lines. ",
_output
output
);
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -693,16 +699,16 @@ At 0,0
A text with some long width
and also with two lines. ",
_output
output
);
view.X = 1;
view.Y = 1;
view.Width = 10;
view.Height = 1;
Assert.Equal (new Rectangle (1, 1, 10, 1), view.Frame);
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Viewport);
Assert.Equal (new Rectangle (0, 0, 30, 2), view._needsDisplayRect);
Assert.Equal (new (1, 1, 10, 1), view.Frame);
Assert.Equal (new (0, 0, 10, 1), view.Viewport);
Assert.Equal (new (0, 0, 30, 2), view._needsDisplayRect);
view.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (
@@ -711,9 +717,10 @@ At 0,0
A text wit
A text with some long width
and also with two lines. ",
_output
output
);
Application.End (runState);
top.Dispose ();
}
[Fact]
@@ -735,7 +742,7 @@ At 0,0
view.EndInit ();
view.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (text, _output);
TestHelpers.AssertDriverContentsWithFrameAre (text, output);
}
[Fact]
@@ -751,8 +758,8 @@ At 0,0
Assert.Equal ($"View(){r.Viewport}", r.ToString ());
Assert.False (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rectangle (0, 0, 0, 0), r.Viewport);
Assert.Equal (new Rectangle (0, 0, 0, 0), r.Frame);
Assert.Equal (new (0, 0, 0, 0), r.Viewport);
Assert.Equal (new (0, 0, 0, 0), r.Frame);
Assert.Null (r.Focused);
Assert.Null (r.ColorScheme);
Assert.Equal (0, r.Width);
@@ -770,13 +777,13 @@ At 0,0
r.Dispose ();
// Empty Rect
r = new View { Frame = Rectangle.Empty };
r = new() { Frame = Rectangle.Empty };
Assert.NotNull (r);
Assert.Equal ($"View(){r.Viewport}", r.ToString ());
Assert.False (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rectangle (0, 0, 0, 0), r.Viewport);
Assert.Equal (new Rectangle (0, 0, 0, 0), r.Frame);
Assert.Equal (new (0, 0, 0, 0), r.Viewport);
Assert.Equal (new (0, 0, 0, 0), r.Frame);
Assert.Null (r.Focused);
Assert.Null (r.ColorScheme);
Assert.Equal (0, r.Width);
@@ -794,13 +801,13 @@ At 0,0
r.Dispose ();
// Rect with values
r = new View { Frame = new Rectangle (1, 2, 3, 4) };
r = new() { Frame = new (1, 2, 3, 4) };
Assert.NotNull (r);
Assert.Equal ($"View(){r.Frame}", r.ToString ());
Assert.False (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rectangle (0, 0, 3, 4), r.Viewport);
Assert.Equal (new Rectangle (1, 2, 3, 4), r.Frame);
Assert.Equal (new (0, 0, 3, 4), r.Viewport);
Assert.Equal (new (1, 2, 3, 4), r.Frame);
Assert.Null (r.Focused);
Assert.Null (r.ColorScheme);
Assert.Equal (3, r.Width);
@@ -818,7 +825,7 @@ At 0,0
r.Dispose ();
// Initializes a view with a vertical direction
r = new View
r = new()
{
Text = "Vertical View",
TextDirection = TextDirection.TopBottom_LeftRight,
@@ -832,8 +839,8 @@ At 0,0
r.EndInit ();
Assert.False (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rectangle (0, 0, 1, 13), r.Viewport);
Assert.Equal (new Rectangle (0, 0, 1, 13), r.Frame);
Assert.Equal (new (0, 0, 1, 13), r.Viewport);
Assert.Equal (new (0, 0, 1, 13), r.Frame);
Assert.Null (r.Focused);
Assert.Null (r.ColorScheme);
Assert.False (r.IsCurrentTop);
@@ -857,13 +864,13 @@ At 0,0
{
var r = new View ();
Assert.False (r.OnKeyDown (new Key { KeyCode = KeyCode.Null }));
Assert.False (r.OnKeyDown (new() { KeyCode = KeyCode.Null }));
//Assert.False (r.OnKeyDown (new KeyEventArgs () { Key = Key.Unknown }));
Assert.False (r.OnKeyUp (new Key { KeyCode = KeyCode.Null }));
Assert.False (r.NewMouseEvent (new MouseEvent { Flags = MouseFlags.AllEvents }));
Assert.False (r.NewMouseEnterEvent (new MouseEvent { Flags = MouseFlags.AllEvents }));
Assert.False (r.NewMouseLeaveEvent (new MouseEvent { Flags = MouseFlags.AllEvents }));
Assert.False (r.OnKeyUp (new() { KeyCode = KeyCode.Null }));
Assert.False (r.NewMouseEvent (new() { Flags = MouseFlags.AllEvents }));
Assert.False (r.NewMouseEnterEvent (new() { Flags = MouseFlags.AllEvents }));
Assert.False (r.NewMouseLeaveEvent (new() { Flags = MouseFlags.AllEvents }));
var v1 = new View ();
Assert.False (r.OnEnter (v1));
@@ -882,7 +889,7 @@ At 0,0
[AutoInitShutdown]
public void Test_Nested_Views_With_Height_Equal_To_One ()
{
var v = new View { Width = 11, Height = 3, ColorScheme = new ColorScheme () };
var v = new View { Width = 11, Height = 3, ColorScheme = new () };
var top = new View { Width = Dim.Fill (), Height = 1 };
var bottom = new View { Width = Dim.Fill (), Height = 1, Y = 2 };
@@ -903,7 +910,7 @@ At 0,0
111
───────────
222";
TestHelpers.AssertDriverContentsAre (looksLike, _output);
TestHelpers.AssertDriverContentsAre (looksLike, output);
v.Dispose ();
top.Dispose ();
bottom.Dispose ();
@@ -917,7 +924,7 @@ At 0,0
var view = new View { X = 1, Y = 2, Width = 3, Height = 4 };
// Object Initializer Absolute
var super = new View { Frame = new Rectangle (0, 0, 10, 10) };
var super = new View { Frame = new (0, 0, 10, 10) };
super.Add (view);
super.BeginInit ();
super.EndInit ();
@@ -928,9 +935,9 @@ At 0,0
Assert.Equal (3, view.Width);
Assert.Equal (4, view.Height);
Assert.False (view.Frame.IsEmpty);
Assert.Equal (new Rectangle (1, 2, 3, 4), view.Frame);
Assert.Equal (new (1, 2, 3, 4), view.Frame);
Assert.False (view.Viewport.IsEmpty);
Assert.Equal (new Rectangle (0, 0, 3, 4), view.Viewport);
Assert.Equal (new (0, 0, 3, 4), view.Viewport);
view.LayoutSubviews ();
@@ -947,7 +954,7 @@ At 0,0
#endif
// Default Constructor
view = new View ();
view = new ();
Assert.Equal (0, view.X);
Assert.Equal (0, view.Y);
Assert.Equal (0, view.Width);
@@ -957,7 +964,7 @@ At 0,0
view.Dispose ();
// Object Initializer
view = new View { X = 1, Y = 2, Text = "" };
view = new() { X = 1, Y = 2, Text = "" };
Assert.Equal (1, view.X);
Assert.Equal (2, view.Y);
Assert.Equal (0, view.Width);
@@ -967,12 +974,12 @@ At 0,0
view.Dispose ();
// Default Constructor and post assignment equivalent to Object Initializer
view = new View ();
view = new ();
view.X = 1;
view.Y = 2;
view.Width = 3;
view.Height = 4;
super = new View { Frame = new Rectangle (0, 0, 10, 10) };
super = new() { Frame = new (0, 0, 10, 10) };
super.Add (view);
super.BeginInit ();
super.EndInit ();
@@ -982,9 +989,9 @@ At 0,0
Assert.Equal (3, view.Width);
Assert.Equal (4, view.Height);
Assert.False (view.Frame.IsEmpty);
Assert.Equal (new Rectangle (1, 2, 3, 4), view.Frame);
Assert.Equal (new (1, 2, 3, 4), view.Frame);
Assert.False (view.Viewport.IsEmpty);
Assert.Equal (new Rectangle (0, 0, 3, 4), view.Viewport);
Assert.Equal (new (0, 0, 3, 4), view.Viewport);
super.Dispose ();
}
@@ -1017,7 +1024,7 @@ At 0,0
│ │
└────────────────────────────┘
",
_output
output
);
view.Visible = false;
@@ -1033,9 +1040,10 @@ At 0,0
│ │
└────────────────────────────┘
",
_output
output
);
Application.End (rs);
top.Dispose ();
}
[Fact]
@@ -1089,7 +1097,7 @@ At 0,0
};
Application.Run (top);
top.Dispose ();
Assert.Equal (1, iterations);
int RunesCount ()
@@ -1187,6 +1195,7 @@ At 0,0
Assert.True (accepted);
return;
void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; }
}
@@ -1198,11 +1207,12 @@ At 0,0
view.Accept += ViewOnAccept;
var ret = view.InvokeCommand (Command.Accept);
bool? ret = view.InvokeCommand (Command.Accept);
Assert.True (ret);
Assert.True (acceptInvoked);
return;
void ViewOnAccept (object sender, CancelEventArgs e)
{
acceptInvoked = true;
@@ -1222,6 +1232,7 @@ At 0,0
Assert.True (accepted);
return;
void ViewOnAccept (object sender, CancelEventArgs e) { accepted = true; }
}

View File

@@ -91,7 +91,6 @@ public class ButtonTests (ITestOutputHelper output)
}
[Fact]
[AutoInitShutdown]
public void Button_HotKeyChanged_EventFires ()
{
var btn = new Button { Text = "_Yar" };
@@ -240,15 +239,11 @@ public class ButtonTests (ITestOutputHelper output)
}
[Fact]
[AutoInitShutdown]
public void HotKeyChange_Works ()
{
var clicked = false;
var btn = new Button { Text = "_Test" };
btn.Accept += (s, e) => clicked = true;
var top = new Toplevel ();
top.Add (btn);
Application.Begin (top);
Assert.Equal (KeyCode.T, btn.HotKey);
Assert.True (btn.NewKeyDownEvent (Key.T));
@@ -262,7 +257,6 @@ public class ButtonTests (ITestOutputHelper output)
btn.HotKey = KeyCode.E;
Assert.True (btn.NewKeyDownEvent (Key.E.WithAlt));
Assert.True (clicked);
top.Dispose ();
}
/// <summary>

View File

@@ -93,13 +93,10 @@ public class CheckBoxTests (ITestOutputHelper output)
}
[Fact]
[AutoInitShutdown]
[SetupFakeDriver]
public void AllowNullChecked_Get_Set ()
{
var checkBox = new CheckBox { Text = "Check this out 你" };
Toplevel top = new ();
top.Add (checkBox);
Application.Begin (top);
Assert.False (checkBox.Checked);
Assert.True (checkBox.NewKeyDownEvent (Key.Space));
@@ -110,7 +107,7 @@ public class CheckBoxTests (ITestOutputHelper output)
checkBox.AllowNullChecked = true;
Assert.True (checkBox.NewKeyDownEvent (Key.Space));
Assert.Null (checkBox.Checked);
Application.Refresh ();
checkBox.Draw();
TestHelpers.AssertDriverContentsWithFrameAre (
@$"
@@ -126,7 +123,6 @@ public class CheckBoxTests (ITestOutputHelper output)
checkBox.AllowNullChecked = false;
Assert.False (checkBox.Checked);
top.Dispose ();
}
[Fact]

View File

@@ -793,7 +793,6 @@ public class TileViewTests
}
[Fact]
[AutoInitShutdown]
public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringInsertTile ()
{
TileView tv = GetTileView (20, 10);
@@ -822,7 +821,6 @@ public class TileViewTests
}
[Fact]
[AutoInitShutdown]
public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRebuildForTileCount ()
{
TileView tv = GetTileView (20, 10);
@@ -850,7 +848,6 @@ public class TileViewTests
}
[Theory]
[AutoInitShutdown]
[InlineData (0)]
[InlineData (1)]
public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRemoveTile (int idx)

View File

@@ -36,7 +36,7 @@ public class TimeFieldTests
}
[Fact]
[AutoInitShutdown]
[AutoInitShutdown (useFakeClipboard:true)]
public void Copy_Paste ()
{
var tf1 = new TimeField { Time = TimeSpan.Parse ("12:12:19") };

View File

@@ -24,7 +24,6 @@ public class TreeViewTests
}
[Fact]
[SetupFakeDriver]
public void ContentWidth_BiggerAfterExpand ()
{
TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
@@ -51,7 +50,6 @@ public class TreeViewTests
}
[Fact]
[SetupFakeDriver]
public void ContentWidth_VisibleVsAll ()
{
TreeView<object> tree = CreateTree (out Factory f, out Car car1, out Car car2);
@@ -95,7 +93,7 @@ public class TreeViewTests
}
[Fact]
[SetupFakeDriver]
[AutoInitShutdown]
public void CursorVisibility_MultiSelect ()
{
var tv = new TreeView { Width = 20, Height = 10 };
@@ -119,6 +117,7 @@ public class TreeViewTests
Application.Driver.GetCursorVisibility (out CursorVisibility visibility);
Assert.Equal (CursorVisibility.Default, tv.CursorVisibility);
Assert.Equal (CursorVisibility.Default, visibility);
top.Dispose ();
}
[Fact]
@@ -348,7 +347,6 @@ public class TreeViewTests
}
[Fact]
[SetupFakeDriver]
public void ObjectActivated_Called ()
{
TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
@@ -381,7 +379,6 @@ public class TreeViewTests
}
[Fact]
[SetupFakeDriver]
public void ObjectActivated_CustomKey ()
{
@@ -424,7 +421,6 @@ public class TreeViewTests
}
[Fact]
[SetupFakeDriver]
public void ObjectActivationButton_DoubleClick ()
{
TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
@@ -451,7 +447,6 @@ public class TreeViewTests
}
[Fact]
[SetupFakeDriver]
public void ObjectActivationButton_RightClick ()
{
TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);
@@ -485,7 +480,6 @@ public class TreeViewTests
}
[Fact]
[SetupFakeDriver]
public void ObjectActivationButton_SetToNull ()
{
TreeView<object> tree = CreateTree (out Factory f, out Car car1, out _);

View File

@@ -3,13 +3,11 @@ using Xunit.Abstractions;
namespace Terminal.Gui.ViewsTests;
public class ViewDisposalTest
public class ViewDisposalTest (ITestOutputHelper output)
{
private readonly ITestOutputHelper _output;
#nullable enable
private readonly Dictionary<Type, object? []?> _special_params = new ();
#nullable restore
public ViewDisposalTest (ITestOutputHelper output) { _output = output; }
[Fact]
[AutoInitShutdown]
@@ -34,7 +32,7 @@ public class ViewDisposalTest
private WeakReference DoTest ()
{
GetSpecialParams ();
var Container = new View ();
var container = new View ();
Toplevel top = new ();
List<Type> views = GetViews ();
@@ -53,11 +51,11 @@ public class ViewDisposalTest
}
Assert.NotNull (instance);
Container.Add (instance);
_output.WriteLine ($"Added instance of {view}!");
container.Add (instance);
output.WriteLine ($"Added instance of {view}!");
}
top.Add (Container);
top.Add (container);
// make sure the application is doing to the views whatever its supposed to do to the views
for (var i = 0; i < 100; i++)
@@ -65,9 +63,9 @@ public class ViewDisposalTest
Application.Refresh ();
}
top.Remove (Container);
WeakReference reference = new (Container, true);
Container.Dispose ();
top.Remove (container);
WeakReference reference = new (container, true);
container.Dispose ();
return reference;
}
@@ -101,11 +99,11 @@ public class ViewDisposalTest
}
)) //end of body of anonymous check function
{ //body of the foreach loop
_output.WriteLine ($"Found Type {type.Name}");
output.WriteLine ($"Found Type {type.Name}");
Assert.DoesNotContain (type, valid);
Assert.True (type.IsAssignableTo (typeof (IDisposable))); // Just to be safe
valid.Add (type);
_output.WriteLine (" -Added!");
output.WriteLine (" -Added!");
} //end body of foreach loop
return valid;