123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using Xunit.Abstractions;
- namespace Terminal.Gui.LayoutTests;
- public class LayoutTests (ITestOutputHelper output)
- {
- private readonly ITestOutputHelper _output = output;
- [Fact]
- public void LayoutSubviews_No_SuperView ()
- {
- var root = new View ();
- var first = new View
- {
- Id = "first",
- X = 1,
- Y = 2,
- Height = 3,
- Width = 4
- };
- root.Add (first);
- var second = new View { Id = "second" };
- root.Add (second);
- second.X = Pos.Right (first) + 1;
- root.LayoutSubviews ();
- Assert.Equal (6, second.Frame.X);
- root.Dispose ();
- first.Dispose ();
- second.Dispose ();
- }
- [Fact]
- public void LayoutSubviews_RootHas_SuperView ()
- {
- var top = new View ();
- var root = new View ();
- top.Add (root);
- var first = new View
- {
- Id = "first",
- X = 1,
- Y = 2,
- Height = 3,
- Width = 4
- };
- root.Add (first);
- var second = new View { Id = "second" };
- root.Add (second);
- second.X = Pos.Right (first) + 1;
- root.LayoutSubviews ();
- Assert.Equal (6, second.Frame.X);
- root.Dispose ();
- top.Dispose ();
- first.Dispose ();
- second.Dispose ();
- }
- [Fact]
- public void LayoutSubviews_ViewThatRefsSubView_Throws ()
- {
- var root = new View ();
- var super = new View ();
- root.Add (super);
- var sub = new View ();
- super.Add (sub);
- super.Width = Dim.Width (sub);
- Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
- root.Dispose ();
- 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]
- //[AutoInitShutdown]
- //public void TrySetHeight_ForceValidatePosDim ()
- //{
- // var top = new View { X = 0, Y = 0, Height = 20 };
- // var v = new View { Height = Dim.Fill (), ValidatePosDim = true };
- // top.Add (v);
- // Assert.False (v.TrySetHeight (10, out int rHeight));
- // Assert.Equal (10, rHeight);
- // v.Height = Dim.Fill (1);
- // Assert.False (v.TrySetHeight (10, out rHeight));
- // Assert.Equal (9, rHeight);
- // v.Height = 0;
- // Assert.True (v.TrySetHeight (10, out rHeight));
- // Assert.Equal (10, rHeight);
- // Assert.False (v.IsInitialized);
- // var toplevel = new Toplevel ();
- // toplevel.Add (top);
- // Application.Begin (toplevel);
- // Assert.True (v.IsInitialized);
- // v.Height = 15;
- // Assert.True (v.TrySetHeight (5, out rHeight));
- // Assert.Equal (5, rHeight);
- //}
- //[Fact]
- //[AutoInitShutdown]
- //public void TrySetWidth_ForceValidatePosDim ()
- //{
- // var top = new View { X = 0, Y = 0, Width = 80 };
- // var v = new View { Width = Dim.Fill (), ValidatePosDim = true };
- // top.Add (v);
- // Assert.False (v.TrySetWidth (70, out int rWidth));
- // Assert.Equal (70, rWidth);
- // v.Width = Dim.Fill (1);
- // Assert.False (v.TrySetWidth (70, out rWidth));
- // Assert.Equal (69, rWidth);
- // v.Width = 0;
- // Assert.True (v.TrySetWidth (70, out rWidth));
- // Assert.Equal (70, rWidth);
- // Assert.False (v.IsInitialized);
- // var toplevel = new Toplevel ();
- // toplevel.Add (top);
- // Application.Begin (toplevel);
- // Assert.True (v.IsInitialized);
- // v.Width = 75;
- // Assert.True (v.TrySetWidth (60, out rWidth));
- // Assert.Equal (60, rWidth);
- //}
- }
|