Browse Source

Back to all unit tests passing

Tig 9 months ago
parent
commit
fe2497ef25

+ 1 - 0
Terminal.Gui/Views/HexView.cs

@@ -272,6 +272,7 @@ public class HexView : View, IDesignable
 
             _addressWidth = value;
             SetNeedsDisplay ();
+            SetLayoutNeeded ();
         }
     }
 

+ 4 - 0
Terminal.Gui/Views/TileView.cs

@@ -355,6 +355,8 @@ public class TileView : View
             // BUGBUG: This should not be needed:
             tile.TitleChanged += (s, e) => SetLayoutNeeded ();
         }
+
+        SetLayoutNeeded ();
     }
 
     /// <summary>
@@ -423,6 +425,7 @@ public class TileView : View
 
         _splitterDistances [idx] = value;
         OnSplitterMoved (idx);
+        SetLayoutNeeded ();
 
         return true;
     }
@@ -1017,6 +1020,7 @@ public class TileView : View
         /// <param name="newValue"></param>
         private bool FinalisePosition (Pos oldValue, Pos newValue)
         {
+            SetLayoutNeeded ();
             if (oldValue is PosPercent)
             {
                 if (Orientation == Orientation.Horizontal)

+ 8 - 0
UnitTests/Views/ComboBoxTests.cs

@@ -297,6 +297,8 @@ public class ComboBoxTests (ITestOutputHelper output)
         Assert.Equal (0, cb.SelectedItem);
         Assert.Equal ("One", cb.Text);
 
+        cb.Layout ();
+
         Assert.True (
                      cb.Subviews [1]
                        .NewMouseEvent (
@@ -522,6 +524,9 @@ public class ComboBoxTests (ITestOutputHelper output)
         Assert.True (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
+
+        cb.Layout ();
+
         cb.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -897,6 +902,9 @@ Three ",
         Assert.Equal (0, cb.SelectedItem);
         Assert.Equal ("One", cb.Text);
         Assert.True (Application.RaiseKeyDownEvent (Key.CursorUp));
+
+        cb.Layout ();
+
         Assert.True (cb.IsShow);
         Assert.Equal (0, cb.SelectedItem);
         Assert.Equal ("One", cb.Text);

+ 4 - 0
UnitTests/Views/TextFieldTests.cs

@@ -14,6 +14,7 @@ public class TextFieldTests (ITestOutputHelper output)
     public void Accented_Letter_With_Three_Combining_Unicode_Chars ()
     {
         var tf = new TextField { Width = 3, Text = "ắ" };
+        tf.Layout ();
         tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -23,6 +24,7 @@ public class TextFieldTests (ITestOutputHelper output)
                                                      );
 
         tf.Text = "\u1eaf";
+        tf.Layout ();
         tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -32,6 +34,7 @@ public class TextFieldTests (ITestOutputHelper output)
                                                      );
 
         tf.Text = "\u0103\u0301";
+        tf.Layout ();
         tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -41,6 +44,7 @@ public class TextFieldTests (ITestOutputHelper output)
                                                      );
 
         tf.Text = "\u0061\u0306\u0301";
+        tf.Layout ();
         tf.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (

+ 2 - 2
UnitTests/Views/TextViewTests.cs

@@ -8322,7 +8322,7 @@ Line 2.",
 
         var top = new Toplevel ();
         top.Add (tv);
-        top.LayoutSubviews ();
+        top.Layout();
         tv.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (
@@ -8427,7 +8427,7 @@ line.
         var top = new Toplevel ();
         top.Add (tv);
 
-        tv.LayoutSubviews ();
+        top.Layout ();
         tv.Draw ();
 
         TestHelpers.AssertDriverContentsWithFrameAre (

+ 67 - 31
UnitTests/Views/TileViewTests.cs

@@ -58,6 +58,7 @@ public class TileViewTests
 
         tv.Tiles.ElementAt (0).MinSize = int.MaxValue;
 
+        Application.Top!.Layout ();
         tv.Draw ();
 
         var looksLike =
@@ -90,8 +91,8 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
-        tv.Draw ();
+        Application.Top!.Layout ();
+        Application.Top!.Draw ();
 
         looksLike =
             @"
@@ -111,6 +112,7 @@ public class TileViewTests
 
         tv.Tiles.ElementAt (0).MinSize = int.MaxValue;
 
+        Application.Top!.Layout ();
         tv.Draw ();
 
         var looksLike =
@@ -143,7 +145,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -187,7 +189,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -209,7 +211,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -252,7 +254,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -276,7 +278,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -320,7 +322,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -343,7 +345,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -386,7 +388,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -408,7 +410,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -445,7 +447,7 @@ public class TileViewTests
 
         Assert.False (tv.SetSplitterPos (0, 0));
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -469,7 +471,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -504,7 +506,7 @@ public class TileViewTests
             Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -528,7 +530,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -569,7 +571,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -591,7 +593,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -631,7 +633,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -654,7 +656,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -694,7 +696,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -716,7 +718,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -756,7 +758,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -779,7 +781,7 @@ public class TileViewTests
             Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
         }
 
-        tv.SetNeedsDisplay ();
+        Application.Top!.Layout ();
         tv.Draw ();
 
         looksLike =
@@ -1412,6 +1414,7 @@ public class TileViewTests
         Assert.Same (toRemove, removed);
         Assert.DoesNotContain (removed, tileView.Tiles);
 
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1432,6 +1435,7 @@ public class TileViewTests
         Assert.Null (tileView.RemoveTile (2));
         tileView.RemoveTile (0);
 
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1450,6 +1454,7 @@ public class TileViewTests
 
         Assert.NotNull (tileView.RemoveTile (0));
 
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1678,6 +1683,7 @@ public class TileViewTests
     {
         TileView tileView = Get11By3TileView (out LineView line);
         tileView.Orientation = Orientation.Horizontal;
+        tileView.Layout ();
         tileView.Draw ();
 
         var looksLike =
@@ -1706,6 +1712,7 @@ public class TileViewTests
 
         Assert.True (line.HasFocus);
 
+        tileView.Layout ();
         tileView.Draw ();
 
         var looksLike =
@@ -1718,6 +1725,7 @@ public class TileViewTests
         // Now move splitter line down
         tileView.NewKeyDownEvent (Key.CursorDown);
 
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1729,8 +1737,10 @@ public class TileViewTests
 
         // And 2 up
         line.NewKeyDownEvent (Key.CursorUp);
+        tileView.Layout ();
+
         line.NewKeyDownEvent (Key.CursorUp);
-        tileView.SetNeedsDisplay ();
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1757,6 +1767,7 @@ public class TileViewTests
         // position should remain where it was, at 50%
         Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
 
+        tileView.Layout ();
         tileView.Draw ();
 
         var looksLike =
@@ -1768,6 +1779,7 @@ public class TileViewTests
 
         // Now move splitter line down (allowed
         line.NewKeyDownEvent (Key.CursorDown);
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1782,6 +1794,7 @@ public class TileViewTests
         line.NewKeyDownEvent (Key.CursorUp);
 
         tileView.SetNeedsDisplay ();
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1841,6 +1854,7 @@ public class TileViewTests
         TileView tileView = Get11By3TileView (out LineView line, true);
         tileView.InsertTile (2);
 
+        tileView.Layout ();
         tileView.Draw ();
 
         // so should ignore the 2 distance and stick to 6
@@ -1859,6 +1873,7 @@ public class TileViewTests
         TileView tileView = Get11By3TileView (out LineView line, true);
         tileView.InsertTile (0);
 
+        tileView.Layout ();
         tileView.Draw ();
 
         // so should ignore the 2 distance and stick to 6
@@ -1877,6 +1892,7 @@ public class TileViewTests
         TileView tileView = Get11By3TileView (out LineView line, true);
         tileView.InsertTile (1);
 
+        tileView.Layout ();
         tileView.Draw ();
 
         // so should ignore the 2 distance and stick to 6
@@ -1894,6 +1910,7 @@ public class TileViewTests
     {
         TileView tileView = Get11By3TileView (out LineView line);
 
+        tileView.Layout ();
         tileView.Draw ();
 
         var looksLike =
@@ -1917,6 +1934,7 @@ public class TileViewTests
         TileView tileView = Get11By3TileView (out LineView line);
         tileView.NewKeyDownEvent (new Key (tileView.ToggleResizable));
 
+        tileView.Layout ();
         tileView.Draw ();
 
         var looksLike =
@@ -1928,6 +1946,7 @@ public class TileViewTests
 
         // Now while focused move the splitter 1 unit right
         line.NewKeyDownEvent (Key.CursorRight);
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1939,7 +1958,9 @@ public class TileViewTests
 
         // and 2 to the left
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1958,7 +1979,7 @@ public class TileViewTests
         tileView.SetSplitterPos (0, Pos.Percent (50));
         Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
         tileView.NewKeyDownEvent (new Key (tileView.ToggleResizable));
-
+        tileView.Layout ();
         tileView.Draw ();
 
         var looksLike =
@@ -1970,6 +1991,7 @@ public class TileViewTests
 
         // Now while focused move the splitter 1 unit right
         line.NewKeyDownEvent (Key.CursorRight);
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -1984,7 +2006,9 @@ public class TileViewTests
 
         // and 2 to the left
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -2004,7 +2028,7 @@ public class TileViewTests
     {
         TileView tileView = Get11By3TileView (out LineView line, true);
         tileView.NewKeyDownEvent (new Key (tileView.ToggleResizable));
-
+        tileView.Layout ();
         tileView.Draw ();
 
         var looksLike =
@@ -2016,6 +2040,7 @@ public class TileViewTests
 
         // Now while focused move the splitter 1 unit right
         line.NewKeyDownEvent (Key.CursorRight);
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -2027,7 +2052,9 @@ public class TileViewTests
 
         // and 2 to the left
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         tileView.Draw ();
 
         looksLike =
@@ -2066,11 +2093,13 @@ public class TileViewTests
         // would take us below the minimum splitter size
         line.NewKeyDownEvent (Key.CursorLeft);
         tileView.SetNeedsDisplay ();
+        tileView.Layout ();
         tileView.Draw ();
         TestHelpers.AssertDriverContentsAre (looksLike, _output);
 
         // but we can continue to move the splitter right if we want
         line.NewKeyDownEvent (Key.CursorRight);
+        tileView.Layout ();
         tileView.SetNeedsDisplay ();
         tileView.Draw ();
 
@@ -2096,7 +2125,7 @@ public class TileViewTests
 
         // Should stay where it was originally at (50%)
         Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
-
+        tileView.Layout ();
         tileView.Draw ();
 
         // so should ignore the 2 distance and stick to 5
@@ -2110,12 +2139,14 @@ public class TileViewTests
         // Keyboard movement on splitter should have no effect because it
         // would take us below the minimum splitter size
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         tileView.SetNeedsDisplay ();
         tileView.Draw ();
         TestHelpers.AssertDriverContentsAre (looksLike, _output);
 
         // but we can continue to move the splitter right if we want
         line.NewKeyDownEvent (Key.CursorRight);
+        tileView.Layout ();
         tileView.SetNeedsDisplay ();
         tileView.Draw ();
 
@@ -2135,7 +2166,7 @@ public class TileViewTests
         TileView tileView = Get11By3TileView (out LineView line);
         tileView.NewKeyDownEvent (new Key (tileView.ToggleResizable));
         tileView.Tiles.ElementAt (1).MinSize = 6;
-
+        tileView.Layout ();
         // distance leaves too little space for view2 (less than 6 would remain)
         Assert.False (tileView.SetSplitterPos (0, 8));
 
@@ -2155,12 +2186,14 @@ public class TileViewTests
         // Keyboard movement on splitter should have no effect because it
         // would take us below the minimum splitter size
         line.NewKeyDownEvent (Key.CursorRight);
+        tileView.Layout ();
         tileView.SetNeedsDisplay ();
         tileView.Draw ();
         TestHelpers.AssertDriverContentsAre (looksLike, _output);
 
         // but we can continue to move the splitter left if we want
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         tileView.SetNeedsDisplay ();
         tileView.Draw ();
 
@@ -2183,6 +2216,7 @@ public class TileViewTests
 
         // distance leaves too little space for view2 (less than 5 would remain)
         Assert.False (tileView.SetSplitterPos (0, 8));
+        tileView.Layout ();
 
         //  Should stay where it was originally at (50%)
         Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
@@ -2200,12 +2234,14 @@ public class TileViewTests
         // Keyboard movement on splitter should have no effect because it
         // would take us below the minimum splitter size
         line.NewKeyDownEvent (Key.CursorRight);
+        tileView.Layout ();
         tileView.SetNeedsDisplay ();
         tileView.Draw ();
         TestHelpers.AssertDriverContentsAre (looksLike, _output);
 
         // but we can continue to move the splitter left if we want
         line.NewKeyDownEvent (Key.CursorLeft);
+        tileView.Layout ();
         tileView.SetNeedsDisplay ();
         tileView.Draw ();
 
@@ -2302,11 +2338,11 @@ public class TileViewTests
                             new Label { Width = Dim.Fill (), Height = 1, Text = new string ('5', 100) }
                            );
 
-        var top = new Toplevel ();
-        top.Add (tv);
+        Application.Top = new Toplevel ();
+        Application.Top.Add (tv);
         tv.BeginInit ();
         tv.EndInit ();
-        tv.LayoutSubviews ();
+        tv.Layout ();
 
         return tv;
     }

+ 5 - 0
UnitTests/Views/TimeFieldTests.cs

@@ -6,6 +6,7 @@ public class TimeFieldTests
     public void Constructors_Defaults ()
     {
         var tf = new TimeField ();
+        tf.Layout ();
         Assert.False (tf.IsShortFormat);
         Assert.Equal (TimeSpan.MinValue, tf.Time);
         Assert.Equal (1, tf.CursorPosition);
@@ -13,24 +14,28 @@ public class TimeFieldTests
 
         TimeSpan time = DateTime.Now.TimeOfDay;
         tf = new TimeField { Time = time };
+        tf.Layout ();
         Assert.False (tf.IsShortFormat);
         Assert.Equal (time, tf.Time);
         Assert.Equal (1, tf.CursorPosition);
         Assert.Equal (new Rectangle (0, 0, 10, 1), tf.Frame);
 
         tf = new TimeField { X = 1, Y = 2, Time = time };
+        tf.Layout ();
         Assert.False (tf.IsShortFormat);
         Assert.Equal (time, tf.Time);
         Assert.Equal (1, tf.CursorPosition);
         Assert.Equal (new Rectangle (1, 2, 10, 1), tf.Frame);
 
         tf = new TimeField { X = 3, Y = 4, Time = time, IsShortFormat = true };
+        tf.Layout ();
         Assert.True (tf.IsShortFormat);
         Assert.Equal (time, tf.Time);
         Assert.Equal (1, tf.CursorPosition);
         Assert.Equal (new Rectangle (3, 4, 7, 1), tf.Frame);
 
         tf.IsShortFormat = false;
+        tf.Layout ();
         Assert.Equal (new Rectangle (3, 4, 10, 1), tf.Frame);
         Assert.Equal (10, tf.Width);
     }