From 9b66ad5cfdc8dfb8049a7b53e4d1f29ad74dc31e Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 7 Aug 2020 16:16:27 +0100 Subject: [PATCH] Added more unit tests to Pos and Dim. --- UnitTests/DimTests.cs | 62 ++++++++++++++++++++++++++++++++++++++----- UnitTests/PosTests.cs | 60 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 109 insertions(+), 13 deletions(-) diff --git a/UnitTests/DimTests.cs b/UnitTests/DimTests.cs index 90e02423d..d8c2bc8b4 100644 --- a/UnitTests/DimTests.cs +++ b/UnitTests/DimTests.cs @@ -248,28 +248,76 @@ namespace Terminal.Gui { Width = Dim.Width (w) - 2, Height = Dim.Percent (10) }; - var vn = new View (new Rect (1, 2, 3, 3)); - w.Add (v, vn); + w.Add (v); t.Add (w); t.Ready += () => { - w.Width = 2; Assert.Equal (2, w.Width = 2); - w.Height = 2; - Assert.Equal (2, w.Height); + Assert.Equal (2, w.Height = 2); Assert.Throws (() => v.Width = 2); Assert.Throws (() => v.Height = 2); - Assert.Equal (4, vn.Height = 4); }; Application.Iteration += () => Application.RequestStop (); Application.Run (); Application.Shutdown (); - } + [Fact] + public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Null () + { + Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true))); + + var t = Application.Top; + + var w = new Window (new Rect (1, 2, 4, 5), "w"); + t.Add (w); + + t.Ready += () => { + Assert.Equal (3, w.Width = 3); + Assert.Equal (4, w.Height = 4); + }; + + Application.Iteration += () => Application.RequestStop (); + + Application.Run (); + Application.Shutdown (); + } + + [Fact] + public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute () + { + Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true))); + + var t = Application.Top; + + var w = new Window ("w") { + Width = Dim.Fill (0), + Height = Dim.Sized (10) + }; + var v = new View ("v") { + Width = Dim.Width (w) - 2, + Height = Dim.Percent (10) + }; + + w.Add (v); + t.Add (w); + + t.Ready += () => { + v.LayoutStyle = LayoutStyle.Absolute; + Assert.Equal (2, v.Width = 2); + Assert.Equal (2, v.Height = 2); + }; + + Application.Iteration += () => Application.RequestStop (); + + Application.Run (); + Application.Shutdown (); + } + + // TODO: Test operators } } diff --git a/UnitTests/PosTests.cs b/UnitTests/PosTests.cs index f16c05ba5..e076384d3 100644 --- a/UnitTests/PosTests.cs +++ b/UnitTests/PosTests.cs @@ -387,19 +387,36 @@ namespace Terminal.Gui { X = Pos.Center (), Y = Pos.Percent (10) }; - var vn = new View (new Rect (1, 3, 3, 4)); - w.Add (v, vn); + w.Add (v); t.Add (w); t.Ready += () => { - w.X = 2; Assert.Equal (2, w.X = 2); - w.Y = 2; - Assert.Equal (2, w.Y); + Assert.Equal (2, w.Y = 2); Assert.Throws (() => v.X = 2); Assert.Throws (() => v.Y = 2); - Assert.Equal (2, vn.Y = 2); + }; + + Application.Iteration += () => Application.RequestStop (); + + Application.Run (); + Application.Shutdown (); + } + + [Fact] + public void Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Null () + { + Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true))); + + var t = Application.Top; + + var w = new Window (new Rect (1, 2, 4, 5), "w"); + t.Add (w); + + t.Ready += () => { + Assert.Equal (2, w.X = 2); + Assert.Equal (2, w.Y = 2); }; Application.Iteration += () => Application.RequestStop (); @@ -409,6 +426,37 @@ namespace Terminal.Gui { } + [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 (), new NetMainLoop (() => FakeConsole.ReadKey (true))); + + var t = Application.Top; + + var w = new Window ("w") { + X = Pos.Left (t) + 2, + Y = Pos.At (2) + }; + var v = new View ("v") { + X = Pos.Center (), + Y = Pos.Percent (10) + }; + + w.Add (v); + t.Add (w); + + t.Ready += () => { + v.LayoutStyle = LayoutStyle.Absolute; + Assert.Equal (2, v.X = 2); + Assert.Equal (2, v.Y = 2); + }; + + Application.Iteration += () => Application.RequestStop (); + + Application.Run (); + Application.Shutdown (); + } + // TODO: Test PosCombine