Browse Source

unit tests

Tigger Kindel 2 years ago
parent
commit
482b6764ff
2 changed files with 230 additions and 35 deletions
  1. 3 0
      UnitTests/Application/ApplicationTests.cs
  2. 227 35
      UnitTests/Drawing/RulerTests.cs

+ 3 - 0
UnitTests/Application/ApplicationTests.cs

@@ -468,6 +468,9 @@ namespace Terminal.Gui.ApplicationTests {
 
 			((FakeDriver)Application.Driver).SetBufferSize (5, 5);
 			Application.Begin (Application.Top);
+			// BUGBUG: v2 - 
+			Assert.Equal (new Rect (0, 0, 80, 25), Application.Top.Frame);
+			((FakeDriver)Application.Driver).SetBufferSize (5, 5);
 			Assert.Equal (new Rect (0, 0, 5, 5), Application.Top.Frame);
 		}
 

+ 227 - 35
UnitTests/Drawing/RulerTests.cs

@@ -53,7 +53,7 @@ namespace Terminal.Gui.DrawingTests {
 		[Fact ()]
 		public void Template_set ()
 		{
-			var newTemplate = ")!@#$$%^&*(";
+			var newTemplate = "|123456789";
 
 			var r = new Ruler ();
 			Assert.Equal ("0123456789", r.Template);
@@ -86,7 +86,6 @@ namespace Terminal.Gui.DrawingTests {
 		public void Draw_Horizontal ()
 		{
 			var len = 15;
-			((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
 
 			// Add a frame so we can see the ruler
 			var f = new FrameView () {
@@ -97,6 +96,7 @@ namespace Terminal.Gui.DrawingTests {
 			};
 			Application.Top.Add (f);
 			Application.Begin (Application.Top);
+			((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
 			Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
 			
 			var r = new Ruler ();
@@ -104,56 +104,248 @@ namespace Terminal.Gui.DrawingTests {
 
 			r.Length = len;
 			r.Draw (new Point(0,0));
-			TestHelpers.AssertDriverContentsWithFrameAre (@"012345678901234", output);
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+012345678901234────┐
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
 
 			// Postive offset
-			((FakeDriver)Application.Driver).FillRect (new Rect (0, 0, len * 2, len * 2), ' ');
+			Application.Refresh ();
 			r.Draw (new Point (1, 1));
 			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│012345678901234   │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			// Negative offset
+			Application.Refresh ();
+			r.Draw (new Point (-1, 1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+12345678901234     │
+│                  │
+│                  │
+└──────────────────┘", output);
+
+			// Clip
+			Application.Refresh ();
+			r.Draw (new Point (10, 1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌──────────────────┐
+│         0123456789
+│                  │
+│                  │
+└──────────────────┘", output);
+		}
+
+		[Fact (), AutoInitShutdown]
+		public void Draw_Horizontal_Template ()
+		{
+			var len = 15;
+
+			// Add a frame so we can see the ruler
+			var f = new FrameView () {
+				X = 0,
+				Y = 0,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
 
-012345678901234", output);
+		
+			Application.Top.Add (f);
+			Application.Begin (Application.Top);
+			((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
+			Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
+
+			var r = new Ruler ();
+			r.Length = len;
+
+			var newTemplate = "|123456789";
+			r.Template = newTemplate;
+
+			r.Draw (new Point (0, 0));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+|123456789|1234────┐
+│                  │
+│                  │
+│                  │
+└──────────────────┘", output);
 		}
 
 		[Fact (), AutoInitShutdown]
 		public void Draw_Vertical ()
 		{
-			var len = 25;
-			((FakeDriver)Application.Driver).SetBufferSize (len * 2, len * 2);
+			var len = 15;
+
+			// Add a frame so we can see the ruler
+			var f = new FrameView () {
+				X = 0,
+				Y = 0,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
+
+
+			Application.Top.Add (f);
+			Application.Begin (Application.Top);
+			((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
+			Assert.Equal (new Rect (0, 0, 5, len + 5), f.Frame);
 
 			var r = new Ruler ();
 			r.Orientation = Orientation.Vertical;
-			Assert.Equal (Orientation.Vertical, r.Orientation);
-
 			r.Length = len;
 			r.Draw (new Point (0, 0));
 			TestHelpers.AssertDriverContentsWithFrameAre (@"
-0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-0
-1
-2
-3
-4", output);
+0───┐
+1   │
+2   │
+3   │
+4   │
+5   │
+6   │
+7   │
+8   │
+9   │
+0   │
+1   │
+2   │
+3   │
+4   │
+│   │
+│   │
+│   │
+│   │
+└───┘", output);
+
+			// Postive offset
+			Application.Refresh ();
+			r.Draw (new Point (1, 1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌───┐
+│0  │
+│1  │
+│2  │
+│3  │
+│4  │
+│5  │
+│6  │
+│7  │
+│8  │
+│9  │
+│0  │
+│1  │
+│2  │
+│3  │
+│4  │
+│   │
+│   │
+│   │
+└───┘", output);
+
+			// Negative offset
+			Application.Refresh ();
+			r.Draw (new Point (1, -1));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌1──┐
+│2  │
+│3  │
+│4  │
+│5  │
+│6  │
+│7  │
+│8  │
+│9  │
+│0  │
+│1  │
+│2  │
+│3  │
+│4  │
+│   │
+│   │
+│   │
+│   │
+│   │
+└───┘", output);
+
+			// Clip
+			Application.Refresh ();
+			r.Draw (new Point (1, 10));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+┌───┐
+│   │
+│   │
+│   │
+│   │
+│   │
+│   │
+│   │
+│   │
+│   │
+│0  │
+│1  │
+│2  │
+│3  │
+│4  │
+│5  │
+│6  │
+│7  │
+│8  │
+└9──┘", output);
 		}
-		
+
+		[Fact (), AutoInitShutdown]
+		public void Draw_Vertical_Template ()
+		{
+			var len = 15;
+
+			// Add a frame so we can see the ruler
+			var f = new FrameView () {
+				X = 0,
+				Y = 0,
+				Width = Dim.Fill (),
+				Height = Dim.Fill (),
+			};
+
+
+			Application.Top.Add (f);
+			Application.Begin (Application.Top);
+			((FakeDriver)Application.Driver).SetBufferSize (5, len + 5);
+			Assert.Equal (new Rect (0, 0, 5, len + 5), f.Frame);
+
+			var r = new Ruler ();
+			r.Orientation = Orientation.Vertical;
+			r.Length = len;
+
+			var newTemplate = ")!@#$$%^&*(";
+			r.Template = newTemplate;
+
+			r.Draw (new Point (0, 0));
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+)───┐
+!   │
+@   │
+#   │
+$   │
+$   │
+%   │
+^   │
+&   │
+*   │
+(   │
+)   │
+!   │
+@   │
+#   │
+│   │
+│   │
+│   │
+│   │
+└───┘", output);
+		}		
 	}
 }