Bläddra i källkod

Merge pull request #661 from tig/more_dimpos_tests

Thanks Miguel! Fixes #504 + More DimPos Unit Tests
Charlie Kindel 5 år sedan
förälder
incheckning
299d70718a
4 ändrade filer med 372 tillägg och 81 borttagningar
  1. 10 10
      Terminal.Gui/Core/PosDim.cs
  2. 19 11
      Terminal.Gui/Views/Button.cs
  3. 111 9
      UnitTests/DimTests.cs
  4. 232 51
      UnitTests/PosTests.cs

+ 10 - 10
Terminal.Gui/Core/PosDim.cs

@@ -279,7 +279,7 @@ namespace Terminal.Gui {
 			}
 			internal override int Anchor (int width)
 			{
-				switch(side) {
+				switch (side) {
 				case 0: return Target.Frame.X;
 				case 1: return Target.Frame.Y;
 				case 2: return Target.Frame.Right;
@@ -292,7 +292,7 @@ namespace Terminal.Gui {
 			public override string ToString ()
 			{
 				string tside;
-				switch(side) {
+				switch (side) {
 				case 0: tside = "x"; break;
 				case 1: tside = "y"; break;
 				case 2: tside = "right"; break;
@@ -308,42 +308,42 @@ namespace Terminal.Gui {
 		/// </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) => new PosView (view, 0);
+		public static Pos Left (View view) => new PosCombine (true, new PosView (view, 0), new Pos.PosAbsolute (0));
 
 		/// <summary>
 		/// Returns a <see cref="Pos"/> object 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) => new PosView (view, 0);
+		public static Pos X (View view) => new PosCombine (true, new PosView (view, 0), new Pos.PosAbsolute (0));
 
 		/// <summary>
 		/// Returns a <see cref="Pos"/> object 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) => new PosView (view, 1);
+		public static Pos Top (View view) => new PosCombine (true, new PosView (view, 1), new Pos.PosAbsolute (0));
 
 		/// <summary>
 		/// Returns a <see cref="Pos"/> object 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) => new PosView (view, 1);
+		public static Pos Y (View view) => new PosCombine (true, new PosView (view, 1), new Pos.PosAbsolute (0));
 
 		/// <summary>
 		/// Returns a <see cref="Pos"/> object tracks the Right (X+Width) coordinate 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 Right (View view) => new PosView (view, 2);
+		public static Pos Right (View view) => new PosCombine (true, new PosView (view, 2), new Pos.PosAbsolute (0));
 
 		/// <summary>
 		/// Returns a <see cref="Pos"/> object tracks the Bottom (Y+Height) coordinate 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 Bottom (View view) => new PosView (view, 3);
+		public static Pos Bottom (View view) => new PosCombine (true, new PosView (view, 3), new Pos.PosAbsolute (0));
 	}
 
 	/// <summary>
@@ -546,7 +546,7 @@ namespace Terminal.Gui {
 			public override string ToString ()
 			{
 				string tside;
-				switch(side) {
+				switch (side) {
 				case 0: tside = "Height"; break;
 				case 1: tside = "Width"; break;
 				default: tside = "unknown"; break;
@@ -556,7 +556,7 @@ namespace Terminal.Gui {
 
 			internal override int Anchor (int width)
 			{
-				switch(side) {
+				switch (side) {
 				case 0: return Target.Frame.Height;
 				case 1: return Target.Frame.Width;
 				default:

+ 19 - 11
Terminal.Gui/Views/Button.cs

@@ -62,7 +62,7 @@ namespace Terminal.Gui {
 		///   The width of the <see cref="Button"/> is computed based on the
 		///   text length. The height will always be 1.
 		/// </remarks>
-		public Button () : this (string.Empty) { }
+		public Button () : this (text: string.Empty, is_default: false) { }
 
 		/// <summary>
 		///   Initializes a new instance of <see cref="Button"/> using <see cref="LayoutStyle.Computed"/> layout.
@@ -78,11 +78,7 @@ namespace Terminal.Gui {
 		/// </param>
 		public Button (ustring text, bool is_default = false) : base ()
 		{
-			CanFocus = true;
-			Text = text ?? string.Empty;
-			this.IsDefault = is_default;
-			int w = SetWidthHeight (text, is_default);
-			Frame = new Rect (Frame.Location, new Size (w, 1));
+			Init (text, is_default);
 		}
 
 		/// <summary>
@@ -114,9 +110,26 @@ namespace Terminal.Gui {
 		public Button (int x, int y, ustring text, bool is_default)
 		    : base (new Rect (x, y, text.Length + 4 + (is_default ? 2 : 0), 1))
 		{
+			Init (text, is_default);
+		}
+
+		Rune _leftBracket;
+		Rune _rightBracket;
+		Rune _leftDefault;
+		Rune _rightDefault;
+
+		void Init (ustring text, bool is_default)
+		{
+			_leftBracket = new Rune (Driver != null ? Driver.LeftBracket : '[');
+			_rightBracket = new Rune (Driver != null ? Driver.RightBracket : ']');
+			_leftDefault = new Rune (Driver != null ? Driver.LeftDefaultIndicator : '<');
+			_rightDefault = new Rune (Driver != null ? Driver.RightDefaultIndicator : '>');
+
 			CanFocus = true;
 			Text = text ?? string.Empty;
 			this.IsDefault = is_default;
+			int w = SetWidthHeight (text, is_default);
+			Frame = new Rect (Frame.Location, new Size (w, 1));
 		}
 
 		int SetWidthHeight (ustring text, bool is_default)
@@ -154,11 +167,6 @@ namespace Terminal.Gui {
 			}
 		}
 
-		Rune _leftBracket = new Rune (Driver != null ? Driver.LeftBracket : '[');
-		Rune _rightBracket = new Rune (Driver != null ? Driver.RightBracket : ']');
-		Rune _leftDefault = new Rune (Driver != null ? Driver.LeftDefaultIndicator : '<');
-		Rune _rightDefault = new Rune (Driver != null ? Driver.RightDefaultIndicator : '>');
-
 		internal void Update ()
 		{
 			if (IsDefault)

+ 111 - 9
UnitTests/DimTests.cs

@@ -27,9 +27,37 @@ namespace Terminal.Gui {
 			int testVal = 5;
 			dim = Dim.Sized (testVal);
 			Assert.Equal ($"Dim.Absolute({testVal})", dim.ToString ());
+
+			testVal = -1;
+			dim = Dim.Sized (testVal);
+			Assert.Equal ($"Dim.Absolute({testVal})", dim.ToString ());
 		}
 
-		// TODO: Other Dim.Sized tests (e.g. Equal?)
+		[Fact]
+		public void Sized_Equals ()
+		{
+			int n1 = 0;
+			int n2 = 0;
+			var dim1 = Dim.Sized (n1);
+			var dim2 = Dim.Sized (n2);
+			Assert.Equal (dim1, dim2);
+
+			n1 = n2 = 1;
+			dim1 = Dim.Sized (n1);
+			dim2 = Dim.Sized (n2);
+			Assert.Equal (dim1, dim2);
+
+			n1 = n2 = -1;
+			dim1 = Dim.Sized (n1);
+			dim2 = Dim.Sized (n2);
+			Assert.Equal (dim1, dim2);
+
+			n1 = 0;
+			n2 = 1;
+			dim1 = Dim.Sized (n1);
+			dim2 = Dim.Sized (n2);
+			Assert.NotEqual (dim1, dim2);
+		}
 
 		[Fact]
 		public void Width_SetsValue ()
@@ -47,7 +75,46 @@ namespace Terminal.Gui {
 			Assert.Equal ($"DimView(side=Width, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", dim.ToString ());
 		}
 
-		// TODO: Other Dim.Width tests (e.g. Equal?)
+		[Fact]
+		public void Width_Equals ()
+		{
+			var testRect1 = Rect.Empty;
+			var view1 = new View (testRect1);
+			var testRect2 = Rect.Empty;
+			var view2 = new View (testRect2);
+
+			var dim1 = Dim.Width (view1);
+			var dim2 = Dim.Width (view1);
+			// BUGBUG: Dim.Width should support Equals() and this should change to Euqal.
+			Assert.NotEqual (dim1, dim2);
+
+			dim2 = Dim.Width (view2);
+			Assert.NotEqual (dim1, dim2);
+
+			testRect1 = new Rect (0, 1, 2, 3);
+			view1 = new View (testRect1);
+			testRect2 = new Rect (0, 1, 2, 3);
+			dim1 = Dim.Width (view1);
+			dim2 = Dim.Width (view1);
+			// BUGBUG: Dim.Width should support Equals() and this should change to Euqal.
+			Assert.NotEqual (dim1, dim2);
+
+			testRect1 = new Rect (0, -1, -2, -3);
+			view1 = new View (testRect1);
+			testRect2 = new Rect (0, -1, -2, -3);
+			dim1 = Dim.Width (view1);
+			dim2 = Dim.Width (view1);
+			// BUGBUG: Dim.Width should support Equals() and this should change to Euqal.
+			Assert.NotEqual (dim1, dim2);
+
+			testRect1 = new Rect (0, -1, -2, -3);
+			view1 = new View (testRect1);
+			testRect2 = Rect.Empty;
+			view2 = new View (testRect2);
+			dim1 = Dim.Width (view1);
+			dim2 = Dim.Width (view2);
+			Assert.NotEqual (dim1, dim2);
+		}
 
 		[Fact]
 		public void Height_SetsValue ()
@@ -72,7 +139,7 @@ namespace Terminal.Gui {
 		{
 			var testMargin = 0;
 			var dim = Dim.Fill ();
-			Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString());
+			Assert.Equal ($"Dim.Fill(margin={testMargin})", dim.ToString ());
 
 			testMargin = 0;
 			dim = Dim.Fill (testMargin);
@@ -85,7 +152,7 @@ namespace Terminal.Gui {
 
 
 		[Fact]
-		public void Fill_Equal()
+		public void Fill_Equal ()
 		{
 			var margin1 = 0;
 			var margin2 = 0;
@@ -99,19 +166,54 @@ namespace Terminal.Gui {
 		{
 			float f = 0;
 			var dim = Dim.Percent (f);
-			Assert.Equal ($"Dim.Factor({f/100:0.###})", dim.ToString ());
+			Assert.Equal ($"Dim.Factor({f / 100:0.###})", dim.ToString ());
 			f = 0.5F;
 			dim = Dim.Percent (f);
-			Assert.Equal ($"Dim.Factor({f/100:0.###})", dim.ToString ());
+			Assert.Equal ($"Dim.Factor({f / 100:0.###})", dim.ToString ());
 			f = 100;
 			dim = Dim.Percent (f);
-			Assert.Equal ($"Dim.Factor({f/100:0.###})", dim.ToString ());
+			Assert.Equal ($"Dim.Factor({f / 100:0.###})", dim.ToString ());
 		}
 
-		// TODO: Other Dim.Percent tests (e.g. Equal?)
+		[Fact]
+		public void Percent_Equals ()
+		{
+			float n1 = 0;
+			float n2 = 0;
+			var dim1 = Dim.Percent (n1);
+			var dim2 = Dim.Percent (n2);
+			Assert.Equal (dim1, dim2);
+
+			n1 = n2 = 1;
+			dim1 = Dim.Percent (n1);
+			dim2 = Dim.Percent (n2);
+			Assert.Equal (dim1, dim2);
+
+			n1 = n2 = 0.5f;
+			dim1 = Dim.Percent (n1);
+			dim2 = Dim.Percent (n2);
+			Assert.Equal (dim1, dim2);
+
+			n1 = n2 = 100f;
+			dim1 = Dim.Percent (n1);
+			dim2 = Dim.Percent (n2);
+			Assert.Equal (dim1, dim2);
+
+			n1 = 0;
+			n2 = 1;
+			dim1 = Dim.Percent (n1);
+			dim2 = Dim.Percent (n2);
+			Assert.NotEqual (dim1, dim2);
+
+			n1 = 0.5f;
+			n2 = 1.5f;
+			dim1 = Dim.Percent (n1);
+			dim2 = Dim.Percent (n2);
+			Assert.NotEqual (dim1, dim2);
+		}
 
 		[Fact]
-		public void Percent_ThrowsOnIvalid()
+		public void Percent_ThrowsOnIvalid ()
 		{
 			var dim = Dim.Percent (0);
 			Assert.Throws<ArgumentException> (() => dim = Dim.Percent (-1));

+ 232 - 51
UnitTests/PosTests.cs

@@ -1,8 +1,10 @@
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Data;
 using System.IO;
 using System.Linq;
+using System.Runtime.InteropServices.WindowsRuntime;
 using Terminal.Gui;
 using Xunit;
 
@@ -46,6 +48,14 @@ namespace Terminal.Gui {
 			Assert.NotEqual (pos1, pos2);
 		}
 
+		[Fact]
+		public void AnchorEnd_Negative_Throws ()
+		{
+			Pos pos;
+			var n = -1;
+			Assert.Throws<ArgumentException> (() => pos = Pos.AnchorEnd (n));
+		}
+
 		[Fact]
 		public void At_SetsValue ()
 		{
@@ -55,7 +65,8 @@ namespace Terminal.Gui {
 			pos = Pos.At (5);
 			Assert.Equal ("Pos.Absolute(5)", pos.ToString ());
 
-			//Assert.Throws<ArgumentException> (() => pos = Pos.At (-1));
+			pos = Pos.At (-1);
+			Assert.Equal ("Pos.Absolute(-1)", pos.ToString ());
 		}
 
 		[Fact]
@@ -69,79 +80,246 @@ namespace Terminal.Gui {
 			Assert.Equal (pos1, pos2);
 		}
 
-		[Fact]
-		public void Left_SetsValue ()
+		[Fact] 
+		public void SetSide_Null_Throws ()
 		{
 			var pos = Pos.Left (null);
 			Assert.Throws<NullReferenceException> (() => pos.ToString ());
 
-			var testVal = Rect.Empty;
-			pos = Pos.Left (new View ());
-			Assert.Equal ($"Pos.View(side=x, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
+			pos = Pos.X (null);
+			Assert.Throws<NullReferenceException> (() => pos.ToString ());
 
-			pos = Pos.Left (new View (testVal));
-			Assert.Equal ($"Pos.View(side=x, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
+			pos = Pos.Top (null);
+			Assert.Throws<NullReferenceException> (() => pos.ToString ());
+
+			pos = Pos.Y(null);
+			Assert.Throws<NullReferenceException> (() => pos.ToString ());
 
-			testVal = new Rect (1, 2, 3, 4);
-			pos = Pos.Left (new View (testVal));
-			Assert.Equal ($"Pos.View(side=x, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
+			pos = Pos.Bottom (null);
+			Assert.Throws<NullReferenceException> (() => pos.ToString ());
+
+			pos = Pos.Right (null);
+			Assert.Throws<NullReferenceException> (() => pos.ToString ());
 		}
 
 		// TODO: Test Left, Top, Right bottom Equal
 
+		/// <summary>
+		/// Tests Pos.Left, Pos.X, Pos.Top, Pos.Y, Pos.Right, and Pos.Bottom set operations
+		/// </summary>
 		[Fact]
-		public void Top_SetsValue ()
+		public void PosSide_SetsValue ()
 		{
-			var pos = Pos.Top (null);
-			Assert.Throws<NullReferenceException> (() => pos.ToString ());
-
-			var testVal = Rect.Empty;
+			string side; // used in format string
+			var testRect = Rect.Empty;
+			var testInt = 0;
+			Pos pos; 
+
+			// Pos.Left
+			side = "x";
+			testInt = 0;
+			testRect = Rect.Empty;
+			pos = Pos.Left (new View ());
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			pos = Pos.Left (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testRect = new Rect (1, 2, 3, 4);
+			pos = Pos.Left (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			// Pos.Left(win) + 0
+			pos = Pos.Left (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testInt = 1;
+			// Pos.Left(win) +1
+			pos = Pos.Left (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testInt = -1;
+			// Pos.Left(win) -1
+			pos = Pos.Left (new View (testRect)) - testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			// Pos.X
+			side = "x";
+			testInt = 0;
+			testRect = Rect.Empty;
+			pos = Pos.X (new View ());
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			pos = Pos.X (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testRect = new Rect (1, 2, 3, 4);
+			pos = Pos.X (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			// Pos.X(win) + 0
+			pos = Pos.X (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testInt = 1;
+			// Pos.X(win) +1
+			pos = Pos.X (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testInt = -1;
+			// Pos.X(win) -1
+			pos = Pos.X (new View (testRect)) - testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			// Pos.Top
+			side = "y";
+			testInt = 0;
+			testRect = Rect.Empty;
 			pos = Pos.Top (new View ());
-			Assert.Equal ($"Pos.View(side=y, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			pos = Pos.Top (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testRect = new Rect (1, 2, 3, 4);
+			pos = Pos.Top (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			// Pos.Top(win) + 0
+			pos = Pos.Top (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testInt = 1;
+			// Pos.Top(win) +1
+			pos = Pos.Top (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testInt = -1;
+			// Pos.Top(win) -1
+			pos = Pos.Top (new View (testRect)) - testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			// Pos.Y
+			side = "y";
+			testInt = 0;
+			testRect = Rect.Empty;
+			pos = Pos.Y (new View ());
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			pos = Pos.Y (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testRect = new Rect (1, 2, 3, 4);
+			pos = Pos.Y (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			// Pos.Y(win) + 0
+			pos = Pos.Y (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testInt = 1;
+			// Pos.Y(win) +1
+			pos = Pos.Y (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			testInt = -1;
+			// Pos.Y(win) -1
+			pos = Pos.Y (new View (testRect)) - testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
+
+			// Pos.Bottom
+			side = "bottom";
+			testRect = Rect.Empty;
+			testInt = 0;
+			pos = Pos.Bottom (new View ());
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
 
-			testVal = new Rect (1, 2, 3, 4);
-			pos = Pos.Top (new View (testVal));
-			Assert.Equal ($"Pos.View(side=y, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
-		}
+			pos = Pos.Bottom (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
 
-		[Fact]
-		public void Right_SetsValue ()
-		{
-			var pos = Pos.Right (null);
-			Assert.Throws<NullReferenceException> (() => pos.ToString ());
+			testRect = new Rect (1, 2, 3, 4);
+			pos = Pos.Bottom (new View (testRect));
+			Assert.Equal ($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
 
-			var testVal = Rect.Empty;
-			pos = Pos.Right (new View ());
-			Assert.Equal ($"Pos.View(side=right, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
+			// Pos.Bottom(win) + 0
+			pos = Pos.Bottom (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
 
-			testVal = Rect.Empty;
-			pos = Pos.Right (new View (testVal));
-			Assert.Equal ($"Pos.View(side=right, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
+			testInt = 1;
+			// Pos.Bottom(win) +1
+			pos = Pos.Bottom (new View (testRect)) + testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
 
-			testVal = new Rect (1, 2, 3, 4);
-			pos = Pos.Right (new View (testVal));
-			Assert.Equal ($"Pos.View(side=right, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
+			testInt = -1;
+			// Pos.Bottom(win) -1
+			pos = Pos.Bottom (new View (testRect)) - testInt;
+			Assert.Equal ($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString ());
 		}
 
+		// See: https://github.com/migueldeicaza/gui.cs/issues/504
 		[Fact]
-		public void Bottom_SetsValue ()
+		public void LeftTopBottomRight_Win_ShouldNotThrow ()
 		{
-			var pos = Pos.Bottom (null);
-			Assert.Throws<NullReferenceException> (() => pos.ToString ());
-
-			var testVal = Rect.Empty;
-			pos = Pos.Bottom (new View ());
-			Assert.Equal ($"Pos.View(side=bottom, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
-
-			testVal = Rect.Empty;
-			pos = Pos.Bottom (new View (testVal));
-			Assert.Equal ($"Pos.View(side=bottom, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
+			// Setup Fake driver
+			(Window win, Button button) setup ()
+			{
+				Application.Init (new FakeDriver (), new NetMainLoop (() => FakeConsole.ReadKey (true)));
+				Application.Iteration = () => {
+					Application.RequestStop ();
+				};
+				var win = new Window ("window") {
+					X = 0,
+					Y = 0,
+					Width = Dim.Fill (),
+					Height = Dim.Fill (),
+				};
+				Application.Top.Add (win);
+
+				var button = new Button ("button") {
+					X = Pos.Center (),
+				};
+				win.Add (button);
+
+				return (win, button);
+			}
+
+			void cleanup ()
+			{
+				// Cleanup
+				Application.Shutdown ();
+			}
+
+			// Test cases:
+			var app = setup ();
+			app.button.Y = Pos.Left (app.win);
+			Application.Run ();
+			cleanup ();
+
+			app = setup ();
+			app.button.Y = Pos.X (app.win);
+			Application.Run ();
+			cleanup ();
+
+			app = setup ();
+			app.button.Y = Pos.Top (app.win);
+			Application.Run ();
+			cleanup ();
+
+			app = setup ();
+			app.button.Y = Pos.Y (app.win);
+			Application.Run ();
+			cleanup ();
+
+			app = setup ();
+			app.button.Y = Pos.Bottom (app.win);
+			Application.Run ();
+			cleanup ();
+
+			app = setup ();
+			app.button.Y = Pos.Right (app.win);
+			Application.Run ();
+			cleanup ();
 
-			testVal = new Rect (1, 2, 3, 4);
-			pos = Pos.Bottom (new View (testVal));
-			Assert.Equal ($"Pos.View(side=bottom, target=View()({{X={testVal.X},Y={testVal.Y},Width={testVal.Width},Height={testVal.Height}}}))", pos.ToString ());
-
-			//Assert.Throws<ArgumentException> (() => pos = Pos.Bottom (new View (new Rect (0, 0, -3, -4))));
 		}
 
 		[Fact]
@@ -186,6 +364,9 @@ namespace Terminal.Gui {
 			Assert.Throws<ArgumentException> (() => pos = Pos.Percent (1000001));
 		}
 
+		// TODO: Test PosCombine
+
+
 		// TODO: Test operators
 	}
 }