Explorar o código

Added more unit tests to Pos and Dim.

BDisp %!s(int64=5) %!d(string=hai) anos
pai
achega
9b66ad5cfd
Modificáronse 2 ficheiros con 108 adicións e 12 borrados
  1. 54 6
      UnitTests/DimTests.cs
  2. 54 6
      UnitTests/PosTests.cs

+ 54 - 6
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<ArgumentException> (() => v.Width = 2);
 				Assert.Throws<ArgumentException> (() => 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
 	}
 }

+ 54 - 6
UnitTests/PosTests.cs

@@ -387,26 +387,74 @@ 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<ArgumentException> (() => v.X = 2);
 				Assert.Throws<ArgumentException> (() => 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 ();
+
+			Application.Run ();
+			Application.Shutdown ();
+
+		}
+
+		[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