Browse Source

Add test for Int.Max minwidth

Thomas 2 years ago
parent
commit
61e2faccba
2 changed files with 44 additions and 18 deletions
  1. 3 1
      Terminal.Gui/Views/TileView.cs
  2. 41 17
      UnitTests/TileViewTests.cs

+ 3 - 1
Terminal.Gui/Views/TileView.cs

@@ -704,7 +704,9 @@ namespace Terminal.Gui {
 				if (availableLeft < requiredLeft) {
 				if (availableLeft < requiredLeft) {
 
 
 					// There is not enough space for panel on left
 					// There is not enough space for panel on left
-					var insteadTake = requiredLeft + (HasBorder() ? 1 :0);
+					var insteadTake = requiredLeft == int.MaxValue ?
+						 int.MaxValue :
+						 requiredLeft + (HasBorder() ? 1 :0);
 
 
 					// Don't take more than the available space in view
 					// Don't take more than the available space in view
 					insteadTake = Math.Max(0,Math.Min (fullSpace, insteadTake));
 					insteadTake = Math.Max(0,Math.Min (fullSpace, insteadTake));

+ 41 - 17
UnitTests/TileViewTests.cs

@@ -908,33 +908,26 @@ namespace UnitTests {
 		[Fact,AutoInitShutdown]
 		[Fact,AutoInitShutdown]
 		public void Test5Panel_MinSizes_VerticalSplitters()
 		public void Test5Panel_MinSizes_VerticalSplitters()
 		{
 		{
-			
-			var tv = new TileView (5){ Width = 25, Height = 4, ColorScheme = new ColorScheme (), IntegratedBorder = BorderStyle.Single };
-
-			tv.Tiles.ElementAt (0).View.Add (new Label(new string('1',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
-			tv.Tiles.ElementAt (1).View.Add (new Label(new string('2',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
-			tv.Tiles.ElementAt (2).View.Add (new Label(new string('3',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
-			tv.Tiles.ElementAt (3).View.Add (new Label(new string('4',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
-			tv.Tiles.ElementAt (4).View.Add (new Label(new string('5',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
+			var tv = Get5x1TilesView();
 
 
-			Application.Top.Add (tv);
-			tv.BeginInit ();
-			tv.EndInit ();
-			tv.LayoutSubviews ();
+			tv.Tiles.ElementAt(0).MinSize = int.MaxValue;
+			tv.SetNeedsDisplay();
+			tv.LayoutSubviews();
 
 
+			Assert.True(tv.IsInitialized);
 
 
 			tv.Redraw (tv.Bounds);
 			tv.Redraw (tv.Bounds);
 
 
 			var looksLike =
 			var looksLike =
 @"
 @"
-┌────┬────┬────┬────┬───┐
-│1111│2222│3333│4444│555
-│    │    │    │    │
-└────┴────┴────┴────┴───┘
+┌───────────────────────┐
+│11111111111111111111111
+│                    
+└───────────────────────┘
 ";
 ";
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 			TestHelpers.AssertDriverContentsAre (looksLike, output);
 
 
-			// TODO : Apply min sizes and create test assertions
+
 		}
 		}
 
 
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
@@ -1418,6 +1411,37 @@ namespace UnitTests {
 			Assert.True (line.HasFocus);
 			Assert.True (line.HasFocus);
 		}
 		}
 
 
+
+		private TileView Get5x1TilesView ()
+		{
+			var tv = new TileView (5){ Width = 25, Height = 4, ColorScheme = new ColorScheme (), IntegratedBorder = BorderStyle.Single };
+
+			tv.Tiles.ElementAt (0).View.Add (new Label(new string('1',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
+			tv.Tiles.ElementAt (1).View.Add (new Label(new string('2',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
+			tv.Tiles.ElementAt (2).View.Add (new Label(new string('3',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
+			tv.Tiles.ElementAt (3).View.Add (new Label(new string('4',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
+			tv.Tiles.ElementAt (4).View.Add (new Label(new string('5',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
+
+			Application.Top.Add (tv);
+			tv.BeginInit ();
+			tv.EndInit ();
+			tv.LayoutSubviews ();
+
+
+			tv.Redraw (tv.Bounds);
+
+			var looksLike =
+@"
+┌────┬────┬────┬────┬───┐
+│1111│2222│3333│4444│555│
+│    │    │    │    │   │
+└────┴────┴────┴────┴───┘
+";
+			TestHelpers.AssertDriverContentsAre (looksLike, output);
+
+			return tv;
+		}
+
 		private TileView Get11By3TileView (out LineView line, bool withBorder = false)
 		private TileView Get11By3TileView (out LineView line, bool withBorder = false)
 		{
 		{
 			var split = Get11By3TileView (withBorder);
 			var split = Get11By3TileView (withBorder);