mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixing unit tests 3
This commit is contained in:
@@ -202,7 +202,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
|
||||
|
||||
if (PositionCursor ())
|
||||
{
|
||||
Driver.UpdateCursor ();
|
||||
Driver?.UpdateCursor ();
|
||||
}
|
||||
|
||||
NotifyNewRunState?.Invoke (toplevel, new (rs));
|
||||
|
||||
@@ -251,22 +251,22 @@ public abstract record Pos
|
||||
/// <summary>Creates a <see cref="Pos"/> object that tracks the Top (Y) position of the specified <see cref="View"/>.</summary>
|
||||
/// <returns>The <see cref="Pos"/> that depends on the other view.</returns>
|
||||
/// <param name="view">The <see cref="View"/> that will be tracked.</param>
|
||||
public static Pos Top (View? view) { return new PosView (view, Side.Top); }
|
||||
public static Pos Top (View view) { return new PosView (view, Side.Top); }
|
||||
|
||||
/// <summary>Creates a <see cref="Pos"/> object that tracks the Top (Y) position of the specified <see cref="View"/>.</summary>
|
||||
/// <returns>The <see cref="Pos"/> that depends on the other view.</returns>
|
||||
/// <param name="view">The <see cref="View"/> that will be tracked.</param>
|
||||
public static Pos Y (View? view) { return new PosView (view, Side.Top); }
|
||||
public static Pos Y (View view) { return new PosView (view, Side.Top); }
|
||||
|
||||
/// <summary>Creates a <see cref="Pos"/> object that tracks the Left (X) position of the specified <see cref="View"/>.</summary>
|
||||
/// <returns>The <see cref="Pos"/> that depends on the other view.</returns>
|
||||
/// <param name="view">The <see cref="View"/> that will be tracked.</param>
|
||||
public static Pos Left (View? view) { return new PosView (view, Side.Left); }
|
||||
public static Pos Left (View view) { return new PosView (view, Side.Left); }
|
||||
|
||||
/// <summary>Creates a <see cref="Pos"/> object that tracks the Left (X) position of the specified <see cref="View"/>.</summary>
|
||||
/// <returns>The <see cref="Pos"/> that depends on the other view.</returns>
|
||||
/// <param name="view">The <see cref="View"/> that will be tracked.</param>
|
||||
public static Pos X (View? view) { return new PosView (view, Side.Left); }
|
||||
public static Pos X (View view) { return new PosView (view, Side.Left); }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Pos"/> object that tracks the Bottom (Y+Height) coordinate of the specified
|
||||
@@ -274,7 +274,7 @@ public abstract record Pos
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Pos"/> that depends on the other view.</returns>
|
||||
/// <param name="view">The <see cref="View"/> that will be tracked.</param>
|
||||
public static Pos Bottom (View? view) { return new PosView (view, Side.Bottom); }
|
||||
public static Pos Bottom (View view) { return new PosView (view, Side.Bottom); }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Pos"/> object that tracks the Right (X+Width) coordinate of the specified
|
||||
@@ -282,7 +282,7 @@ public abstract record Pos
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Pos"/> that depends on the other view.</returns>
|
||||
/// <param name="view">The <see cref="View"/> that will be tracked.</param>
|
||||
public static Pos Right (View? view) { return new PosView (view, Side.Right); }
|
||||
public static Pos Right (View view) { return new PosView (view, Side.Right); }
|
||||
|
||||
#endregion static Pos creation methods
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ public partial class View // Drawing APIs
|
||||
{
|
||||
if (Move (col, row))
|
||||
{
|
||||
Driver.AddRune (rune);
|
||||
Driver?.AddRune (rune);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public partial class View // Drawing APIs
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The view will only be drawn if it is visible, and has any of <see cref="NeedsDisplay"/>, <see cref="SubViewNeedsDisplay"/>,
|
||||
/// or <see cref="LayoutNeeded"/> set.
|
||||
/// or <see cref="IsLayoutNeeded"/> set.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Always use <see cref="Viewport"/> (view-relative) when calling <see cref="OnDrawContent(Rectangle)"/>, NOT
|
||||
|
||||
@@ -20,8 +20,7 @@ public partial class View // Layout APIs
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If <paramref name="viewToMove"/> does not have a <see cref="View.SuperView"/> or it's SuperView is not
|
||||
/// <see cref="Application.Top"/> the position will be bound by the <see cref="ConsoleDriver.Cols"/> and
|
||||
/// <see cref="ConsoleDriver.Rows"/>.
|
||||
/// <see cref="Application.Top"/> the position will be bound by <see cref="Application.Screen"/>.
|
||||
/// </remarks>
|
||||
/// <param name="viewToMove">The View that is to be moved.</param>
|
||||
/// <param name="targetX">The target x location.</param>
|
||||
@@ -48,7 +47,7 @@ public partial class View // Layout APIs
|
||||
|
||||
if (viewToMove is not Toplevel || viewToMove?.SuperView is null || viewToMove == Application.Top || viewToMove?.SuperView == Application.Top)
|
||||
{
|
||||
maxDimension = Driver.Cols;
|
||||
maxDimension = Application.Screen.Width;
|
||||
superView = Application.Top;
|
||||
}
|
||||
else
|
||||
@@ -135,7 +134,7 @@ public partial class View // Layout APIs
|
||||
|
||||
if (viewToMove?.SuperView is null || viewToMove == Application.Top || viewToMove?.SuperView == Application.Top)
|
||||
{
|
||||
maxDimension = statusVisible ? Driver.Rows - 1 : Driver.Rows;
|
||||
maxDimension = statusVisible ? Application.Screen.Height - 1 : Application.Screen.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -591,7 +590,7 @@ public partial class View // Layout APIs
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception _)
|
||||
{
|
||||
// A Dim/PosFunc threw indicating it could not calculate (typically because a dependent View was not laid out).
|
||||
return false;
|
||||
|
||||
@@ -91,8 +91,8 @@ internal abstract class ColorBar : View, IColorBar
|
||||
if (!string.IsNullOrWhiteSpace (Text))
|
||||
{
|
||||
Move (0, 0);
|
||||
Driver.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
|
||||
Driver.AddStr (Text);
|
||||
Driver?.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
|
||||
Driver?.AddStr (Text);
|
||||
|
||||
// TODO: is there a better method than this? this is what it is in TableView
|
||||
xOffset = Text.EnumerateRunes ().Sum (c => c.GetColumns ());
|
||||
|
||||
@@ -12,7 +12,6 @@ public class TileViewNesting : Scenario
|
||||
private CheckBox _cbHorizontal;
|
||||
private CheckBox _cbTitles;
|
||||
private CheckBox _cbUseLabels;
|
||||
private bool _loaded;
|
||||
private TextField _textField;
|
||||
private int _viewsCreated;
|
||||
private int _viewsToCreate;
|
||||
@@ -70,8 +69,6 @@ public class TileViewNesting : Scenario
|
||||
top.Add (menu);
|
||||
top.Add (win);
|
||||
|
||||
top.Loaded += (s, e) => _loaded = true;
|
||||
|
||||
Application.Run (top);
|
||||
top.Dispose ();
|
||||
Application.Shutdown ();
|
||||
|
||||
@@ -1068,7 +1068,7 @@ public class UICatalogApp
|
||||
|
||||
if (ShVersion is { })
|
||||
{
|
||||
ShVersion.Title = $"{RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}, {Driver.GetVersionInfo ()}";
|
||||
ShVersion.Title = $"{RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}, {Driver!.GetVersionInfo ()}";
|
||||
}
|
||||
|
||||
if (_selectedScenario != null)
|
||||
|
||||
@@ -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