Sfoglia il codice sorgente

Add tests for resizing splitter 2 and ensuring splitter does not go too far

tznind 2 anni fa
parent
commit
2caab5d410
2 ha cambiato i file con 126 aggiunte e 8 eliminazioni
  1. 6 3
      Terminal.Gui/Views/TileView.cs
  2. 120 5
      UnitTests/TileViewTests.cs

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

@@ -500,9 +500,6 @@ namespace Terminal.Gui {
 			if (isGettingBigger) {
 				var spaceForNext = nextSplitterOrBorder - newSize;
 
-				// space required for the line itself
-				spaceForNext--;
-
 				// don't grow if it would take us below min size of right panel
 				if (spaceForNext < tiles [idx + 1].MinSize) {
 					return false;
@@ -510,6 +507,12 @@ namespace Terminal.Gui {
 			} else {
 				var spaceForLast = newSize - lastSplitterOrBorder;
 
+				// space required for the line itself
+				if(idx > 0) {
+					spaceForLast--;
+				}
+					
+
 				// don't shrink if it would take us below min size of left panel
 				if (spaceForLast < tiles [idx].MinSize) {
 					return false;

+ 120 - 5
UnitTests/TileViewTests.cs

@@ -907,15 +907,11 @@ namespace UnitTests {
 		}
 
 		[Fact,AutoInitShutdown]
-		public void Test5Panel_MinSizes_VerticalSplitters_ResizeTile1()
+		public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1()
 		{
 			var tv = Get5x1TilesView();
 
 			tv.Tiles.ElementAt(0).MinSize = int.MaxValue;
-			tv.SetNeedsDisplay();
-			tv.LayoutSubviews();
-
-			Assert.True(tv.IsInitialized);
 
 			tv.Redraw (tv.Bounds);
 
@@ -960,6 +956,125 @@ namespace UnitTests {
 
 		}
 
+		[Fact, AutoInitShutdown]
+		public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOverNeighbours ()
+		{
+			var tv = Get5x1TilesView ();
+
+			tv.Redraw (tv.Bounds);
+
+			var looksLike =
+@"
+┌────┬────┬────┬────┬───┐
+│1111│2222│3333│4444│555│
+│    │    │    │    │   │
+└────┴────┴────┴────┴───┘
+";
+			TestHelpers.AssertDriverContentsAre (looksLike, output);
+
+			for (int x = 10; x > 5; x--) {
+				Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
+			}
+
+			for (int x = 5; x > 0; x--) {
+				Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
+			}
+
+			tv.Redraw (tv.Bounds);
+
+			looksLike =
+@"
+┌────┬┬────────┬────┬───┐
+│1111││33333333│4444│555│
+│    ││        │    │   │
+└────┴┴────────┴────┴───┘
+";
+			TestHelpers.AssertDriverContentsAre (looksLike, output);
+
+
+			for (int x = 10; x < 15; x++) {
+				Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
+			}
+
+
+			for (int x = 15; x < 25; x++) {
+				Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
+			}
+
+			tv.Redraw (tv.Bounds);
+
+			looksLike =
+@"
+┌────┬────────┬┬────┬───┐
+│1111│22222222││4444│555│
+│    │        ││    │   │
+└────┴────────┴┴────┴───┘
+";
+			TestHelpers.AssertDriverContentsAre (looksLike, output);
+
+		}
+
+		[Fact, AutoInitShutdown]
+		public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 ()
+		{
+			var tv = Get5x1TilesView ();
+
+			tv.Tiles.ElementAt (1).MinSize = 2;
+			tv.Tiles.ElementAt (2).MinSize = 3;
+
+			tv.Redraw (tv.Bounds);
+
+			var looksLike =
+@"
+┌────┬────┬────┬────┬───┐
+│1111│2222│3333│4444│555│
+│    │    │    │    │   │
+└────┴────┴────┴────┴───┘
+";
+			TestHelpers.AssertDriverContentsAre (looksLike, output);
+
+			for (int x = 10; x > 7; x--) {
+				Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
+			}
+
+			for (int x = 7; x > 0; x--) {
+				Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
+			}
+
+			tv.Redraw (tv.Bounds);
+
+			looksLike =
+@"
+┌────┬──┬──────┬────┬───┐
+│1111│22│333333│4444│555│
+│    │  │      │    │   │
+└────┴──┴──────┴────┴───┘
+";
+			TestHelpers.AssertDriverContentsAre (looksLike, output);
+
+
+			for (int x = 10; x < 13; x++) {
+				Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
+			}
+
+
+			for (int x = 13; x < 25; x++) {
+				Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
+			}
+
+			tv.Redraw (tv.Bounds);
+
+			looksLike =
+@"
+┌────┬──────┬──┬────┬───┐
+│1111│222222│33│4444│555│
+│    │      │  │    │   │
+└────┴──────┴──┴────┴───┘
+";
+			TestHelpers.AssertDriverContentsAre (looksLike, output);
+
+		}
+
 		[Fact, AutoInitShutdown]
 		public void TestNestedNonRoots_OnlyOneRoot_OnlyRootCanHaveBorders ()
 		{