mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Fixing unit tests 3
This commit is contained in:
@@ -18,35 +18,4 @@ public class DimCombineTests (ITestOutputHelper output)
|
||||
Assert.Equal (30, result);
|
||||
}
|
||||
|
||||
|
||||
// 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 DimCombine_View_Not_Added_Throws ()
|
||||
{
|
||||
var t = new View { Width = 80, Height = 50 };
|
||||
|
||||
var super = new View { Width = Dim.Width (t) - 2, Height = Dim.Height (t) - 2 };
|
||||
t.Add (super);
|
||||
|
||||
var sub = new View ();
|
||||
super.Add (sub);
|
||||
|
||||
var v1 = new View { Width = Dim.Width (super) - 2, Height = Dim.Height (super) - 2 };
|
||||
var v2 = new View { Width = Dim.Width (v1) - 2, Height = Dim.Height (v1) - 2 };
|
||||
sub.Add (v1);
|
||||
|
||||
// v2 not added to sub; should cause exception on Layout since it's referenced by sub.
|
||||
sub.Width = Dim.Fill () - Dim.Width (v2);
|
||||
sub.Height = Dim.Fill () - Dim.Height (v2);
|
||||
|
||||
t.BeginInit ();
|
||||
t.EndInit ();
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => t.LayoutSubviews ());
|
||||
t.Dispose ();
|
||||
v2.Dispose ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -256,23 +256,12 @@ public class PosViewTests (ITestOutputHelper output)
|
||||
[Fact]
|
||||
public void PosView_Side_SetToNull_Throws ()
|
||||
{
|
||||
Pos pos = Left (null);
|
||||
Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
||||
|
||||
pos = X (null);
|
||||
Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
||||
|
||||
pos = Top (null);
|
||||
Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
||||
|
||||
pos = Y (null);
|
||||
Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
||||
|
||||
pos = Bottom (null);
|
||||
Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
||||
|
||||
pos = Right (null);
|
||||
Assert.Throws<NullReferenceException> (() => pos.ToString ());
|
||||
Assert.Throws<ArgumentNullException> (() => X (null));
|
||||
Assert.Throws<ArgumentNullException> (() => Y (null));
|
||||
Assert.Throws<ArgumentNullException> (() => Left (null));
|
||||
Assert.Throws<ArgumentNullException> (() => Right (null));
|
||||
Assert.Throws<ArgumentNullException> (() => Bottom (null));
|
||||
Assert.Throws<ArgumentNullException> (() => Top (null));
|
||||
}
|
||||
|
||||
// TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Terminal.Gui.LayoutTests;
|
||||
|
||||
public class LayoutTests (ITestOutputHelper output)
|
||||
public class SetLayoutTests (ITestOutputHelper output)
|
||||
{
|
||||
private readonly ITestOutputHelper _output = output;
|
||||
|
||||
@@ -173,42 +173,6 @@ public class LayoutTests (ITestOutputHelper output)
|
||||
super.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TopologicalSort_Missing_Add ()
|
||||
{
|
||||
var root = new View ();
|
||||
var sub1 = new View ();
|
||||
root.Add (sub1);
|
||||
var sub2 = new View ();
|
||||
sub1.Width = Dim.Width (sub2);
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
|
||||
|
||||
sub2.Width = Dim.Width (sub1);
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
|
||||
root.Dispose ();
|
||||
sub1.Dispose ();
|
||||
sub2.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TopologicalSort_Recursive_Ref ()
|
||||
{
|
||||
var root = new View ();
|
||||
var sub1 = new View ();
|
||||
root.Add (sub1);
|
||||
var sub2 = new View ();
|
||||
root.Add (sub2);
|
||||
sub2.Width = Dim.Width (sub2);
|
||||
|
||||
Exception exception = Record.Exception (root.LayoutSubviews);
|
||||
Assert.Null (exception);
|
||||
root.Dispose ();
|
||||
sub1.Dispose ();
|
||||
sub2.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LayoutSubviews_Uses_ContentSize ()
|
||||
{
|
||||
@@ -695,25 +659,4 @@ public class LayoutTests (ITestOutputHelper output)
|
||||
Assert.Equal (19, v2.Frame.Height);
|
||||
t.Dispose ();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>This is an intentionally obtuse test. See https://github.com/gui-cs/Terminal.Gui/issues/2461</summary>
|
||||
[Fact]
|
||||
[TestRespondersDisposed]
|
||||
public void Throw_If_SuperView_Refs_SubView ()
|
||||
{
|
||||
var superView = new View { Width = 80, Height = 25 };
|
||||
|
||||
var subViewThatRefsSuperView = new View ()
|
||||
{
|
||||
Width = Dim.Width (superView),
|
||||
Height = Dim.Height (superView)
|
||||
};
|
||||
|
||||
superView.Add (subViewThatRefsSuperView);
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => superView.LayoutSubviews ());
|
||||
superView.Dispose ();
|
||||
}
|
||||
|
||||
}
|
||||
82
UnitTests/View/Layout/TopologicalSortTests.cs
Normal file
82
UnitTests/View/Layout/TopologicalSortTests.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.LayoutTests;
|
||||
|
||||
public class TopologicalSortTests (ITestOutputHelper output)
|
||||
{
|
||||
private readonly ITestOutputHelper _output = output;
|
||||
|
||||
[Fact]
|
||||
public void TopologicalSort_Missing_Add ()
|
||||
{
|
||||
var root = new View ();
|
||||
var sub1 = new View ();
|
||||
root.Add (sub1);
|
||||
var sub2 = new View ();
|
||||
sub1.Width = Dim.Width (sub2);
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
|
||||
|
||||
sub2.Width = Dim.Width (sub1);
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
|
||||
root.Dispose ();
|
||||
sub1.Dispose ();
|
||||
sub2.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TopologicalSort_Recursive_Ref_Does_Not_Throw ()
|
||||
{
|
||||
var root = new View ();
|
||||
var sub1 = new View ();
|
||||
root.Add (sub1);
|
||||
var sub2 = new View ();
|
||||
root.Add (sub2);
|
||||
sub2.Width = Dim.Width (sub2);
|
||||
|
||||
Exception exception = Record.Exception (root.LayoutSubviews);
|
||||
Assert.Null (exception);
|
||||
root.Dispose ();
|
||||
sub1.Dispose ();
|
||||
sub2.Dispose ();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TopologicalSort_Throws_If_SuperView_Refs_SubView ()
|
||||
{
|
||||
var top = new View ();
|
||||
var superView = new View ();
|
||||
top.Add (superView);
|
||||
|
||||
var subView = new View ();
|
||||
superView.Y = Pos.Top (subView);
|
||||
superView.Add (subView);
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => top.LayoutSubviews ());
|
||||
superView.Dispose ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TopologicalSort_View_Not_Added_Throws ()
|
||||
{
|
||||
var top = new View { Width = 80, Height = 50 };
|
||||
|
||||
var super = new View { Width = Dim.Width (top) - 2, Height = Dim.Height (top) - 2 };
|
||||
top.Add (super);
|
||||
|
||||
var sub = new View ();
|
||||
super.Add (sub);
|
||||
|
||||
var v1 = new View { Width = Dim.Width (super) - 2, Height = Dim.Height (super) - 2 };
|
||||
var v2 = new View { Width = Dim.Width (v1) - 2, Height = Dim.Height (v1) - 2 };
|
||||
sub.Add (v1);
|
||||
|
||||
// v2 not added to sub; should cause exception on Layout since it's referenced by sub.
|
||||
sub.Width = Dim.Fill () - Dim.Width (v2);
|
||||
sub.Height = Dim.Fill () - Dim.Height (v2);
|
||||
|
||||
Assert.Throws<InvalidOperationException> (() => top.Layout ());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user