소스 검색

Fixed ScrollBarViewTests

Tig 1 년 전
부모
커밋
31b6efe7c1
2개의 변경된 파일77개의 추가작업 그리고 41개의 파일을 삭제
  1. 28 30
      UnitTests/Views/RuneCellTests.cs
  2. 49 11
      UnitTests/Views/ScrollBarViewTests.cs

+ 28 - 30
UnitTests/Views/RuneCellTests.cs

@@ -3,11 +3,8 @@ using Xunit.Abstractions;
 
 namespace Terminal.Gui.ViewsTests;
 
-public class RuneCellTests
+public class RuneCellTests (ITestOutputHelper output)
 {
-    private readonly ITestOutputHelper _output;
-    public RuneCellTests (ITestOutputHelper output) { _output = output; }
-
     [Fact]
     public void Constructor_Defaults ()
     {
@@ -24,13 +21,13 @@ public class RuneCellTests
 
         var rc2 = new RuneCell
         {
-            Rune = new Rune ('a'), ColorScheme = new ColorScheme { Normal = new Attribute (Color.Red) }
+            Rune = new ('a'), ColorScheme = new() { Normal = new (Color.Red) }
         };
         Assert.False (rc1.Equals (rc2));
         Assert.False (rc2.Equals (rc1));
 
-        rc1.Rune = new Rune ('a');
-        rc1.ColorScheme = new ColorScheme ();
+        rc1.Rune = new ('a');
+        rc1.ColorScheme = new ();
         Assert.Equal (rc1.Rune, rc2.Rune);
         Assert.False (rc1.Equals (rc2));
         Assert.False (rc2.Equals (rc1));
@@ -44,10 +41,10 @@ public class RuneCellTests
         Assert.True (rc1.Equals (rc2));
         Assert.True (rc2.Equals (rc1));
 
-        rc1.Rune = new Rune ('a');
-        rc1.ColorScheme = new ColorScheme ();
-        rc2.Rune = new Rune ('a');
-        rc2.ColorScheme = new ColorScheme ();
+        rc1.Rune = new ('a');
+        rc1.ColorScheme = new ();
+        rc2.Rune = new ('a');
+        rc2.ColorScheme = new ();
         Assert.True (rc1.Equals (rc2));
         Assert.True (rc2.Equals (rc1));
     }
@@ -64,10 +61,10 @@ public class RuneCellTests
 
             foreach (Rune rune in csName.EnumerateRunes ())
             {
-                runeCells.Add (new RuneCell { Rune = rune, ColorScheme = color.Value });
+                runeCells.Add (new() { Rune = rune, ColorScheme = color.Value });
             }
 
-            runeCells.Add (new RuneCell { Rune = (Rune)'\n', ColorScheme = color.Value });
+            runeCells.Add (new() { Rune = (Rune)'\n', ColorScheme = color.Value });
         }
 
         TextView tv = CreateTextView ();
@@ -83,7 +80,7 @@ Base
 Dialog  
 Menu    
 Error   ";
-        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output);
 
         Attribute [] attributes =
         {
@@ -113,16 +110,16 @@ Error   ";
 
         tv.WordWrap = true;
         Application.Refresh ();
-        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output);
         TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes);
 
-        tv.CursorPosition = new Point (6, 2);
+        tv.CursorPosition = new (6, 2);
         tv.SelectionStartColumn = 0;
         tv.SelectionStartRow = 0;
         Assert.Equal ($"TopLevel{Environment.NewLine}Base{Environment.NewLine}Dialog", tv.SelectedText);
         tv.Copy ();
         tv.Selecting = false;
-        tv.CursorPosition = new Point (2, 4);
+        tv.CursorPosition = new (2, 4);
         tv.Paste ();
         Application.Refresh ();
 
@@ -134,7 +131,7 @@ Menu
 ErTopLevel
 Base      
 Dialogror ";
-        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output);
 
         expectedColor = @"
 0000000000
@@ -147,7 +144,7 @@ Dialogror ";
         TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes);
 
         tv.Undo ();
-        tv.CursorPosition = new Point (0, 3);
+        tv.CursorPosition = new (0, 3);
         tv.SelectionStartColumn = 0;
         tv.SelectionStartRow = 0;
 
@@ -157,7 +154,7 @@ Dialogror ";
                      );
         tv.Copy ();
         tv.Selecting = false;
-        tv.CursorPosition = new Point (2, 4);
+        tv.CursorPosition = new (2, 4);
         tv.Paste ();
         Application.Refresh ();
 
@@ -170,7 +167,7 @@ ErTopLevel
 Base      
 Dialog    
 ror       ";
-        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
+        TestHelpers.AssertDriverContentsWithFrameAre (expectedText, output);
 
         expectedColor = @"
 0000000000
@@ -184,18 +181,18 @@ ror       ";
         TestHelpers.AssertDriverAttributesAre (expectedColor, Application.Driver, attributes);
 
         Application.End (rs);
+        top.Dispose ();
     }
 
     [Fact]
-    [AutoInitShutdown]
     public void RuneCell_LoadRuneCells_Without_ColorScheme_Is_Never_Null ()
     {
         List<RuneCell> cells = new ()
         {
-            new RuneCell { Rune = new Rune ('T') },
-            new RuneCell { Rune = new Rune ('e') },
-            new RuneCell { Rune = new Rune ('s') },
-            new RuneCell { Rune = new Rune ('t') }
+            new() { Rune = new ('T') },
+            new() { Rune = new ('e') },
+            new() { Rune = new ('s') },
+            new() { Rune = new ('t') }
         };
         TextView tv = CreateTextView ();
         var top = new Toplevel ();
@@ -250,7 +247,7 @@ ror       ";
                                                       @"
 This is the first line. 
 This is the second line.",
-                                                      _output
+                                                      output
                                                      );
 
         tv.Width = 10;
@@ -268,10 +265,11 @@ This is
 the    
 second 
 line.  ",
-                                                      _output
+                                                      output
                                                      );
 
         Assert.Equal (eventCount, (text [0].Count + text [1].Count) * 2);
+        top.Dispose ();
     }
 
     [Fact]
@@ -281,7 +279,7 @@ line.  ",
 
         var rc2 = new RuneCell
         {
-            Rune = new Rune ('a'), ColorScheme = new ColorScheme { Normal = new Attribute (Color.Red) }
+            Rune = new ('a'), ColorScheme = new() { Normal = new (Color.Red) }
         };
         Assert.Equal ("U+0000 '\0'; null", rc1.ToString ());
 
@@ -292,5 +290,5 @@ line.  ",
     }
 
     // TODO: Move the tests below to View or Color - they test ColorScheme, not RuneCell primitives.
-    private TextView CreateTextView () { return new TextView { Width = 30, Height = 10 }; }
+    private TextView CreateTextView () { return new() { Width = 30, Height = 10 }; }
 }

+ 49 - 11
UnitTests/Views/ScrollBarViewTests.cs

@@ -15,7 +15,8 @@ public class ScrollBarViewTests
     [ScrollBarAutoInitShutdown]
     public void AutoHideScrollBars_Check ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -132,6 +133,7 @@ public class ScrollBarViewTests
         Assert.Equal (79, _scrollBar.OtherScrollBarView.Viewport.Width);
         Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
         Assert.Equal (1, _scrollBar.OtherScrollBarView.Viewport.Height);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -214,13 +216,15 @@ public class ScrollBarViewTests
 │▼│
 └─┘";
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        top.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void ChangedPosition_Negative_Value ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -231,13 +235,16 @@ public class ScrollBarViewTests
         _scrollBar.OtherScrollBarView.Position = -50;
         Assert.Equal (0, _scrollBar.OtherScrollBarView.Position);
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
+
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void ChangedPosition_Scrolling ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -264,13 +271,15 @@ public class ScrollBarViewTests
             _scrollBar.OtherScrollBarView.Position -= 1;
             Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
         }
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void ChangedPosition_Update_The_Hosted_View ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -279,6 +288,7 @@ public class ScrollBarViewTests
 
         _scrollBar.OtherScrollBarView.Position = 5;
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -355,6 +365,7 @@ This is a tes
 ",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -605,6 +616,7 @@ This is a tes▼
 ",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -654,13 +666,15 @@ This is a test
 ",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void DrawContent_Update_The_ScrollBarView_Position ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
@@ -671,6 +685,7 @@ This is a test
         _hostView.Left = 6;
         _hostView.Draw ();
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -694,6 +709,7 @@ This is a test
 │◄├────────────────┤░░░░░░░░░░░░░░░░░░►│
 └──────────────────────────────────────┘";
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        top.Dispose ();
     }
 
     [Fact]
@@ -733,7 +749,6 @@ This is a test
         RemoveHandlers ();
 
         _scrollBar = new ScrollBarView (_hostView, true);
-
         Application.Begin (_hostView.SuperView as Toplevel);
 
         Assert.True (_scrollBar.IsVertical);
@@ -752,6 +767,7 @@ This is a test
         Assert.Equal (_scrollBar.Size, _hostView.Lines);
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
         Assert.Equal (_scrollBar.OtherScrollBarView.Size, _hostView.Cols);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -914,6 +930,7 @@ This is a test
 
         pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
         Assert.Equal (new Rectangle (0, 0, 10, 10), pos);
+        top.Dispose ();
     }
 
     [Fact]
@@ -928,6 +945,8 @@ This is a test
 
         Assert.Throws<ArgumentException> (() => v.OtherScrollBarView = h);
         Assert.Throws<ArgumentException> (() => h.OtherScrollBarView = v);
+        top.Dispose ();
+
     }
 
     [Fact]
@@ -942,6 +961,7 @@ This is a test
 
         Assert.Throws<ArgumentException> (() => v.OtherScrollBarView = h);
         Assert.Throws<ArgumentException> (() => h.OtherScrollBarView = v);
+        top.Dispose ();
     }
 
     [Fact]
@@ -994,15 +1014,19 @@ This is a test
         Assert.Equal (99, max);
         Assert.True (sbv.Visible);
         Assert.True (sbv.OtherScrollBarView.Visible);
+        top.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void KeepContentAlwaysInViewport_False ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
+        _hostView.SuperView.LayoutSubviews ();
+        _hostView.Draw ();
 
         _scrollBar.KeepContentAlwaysInViewport = false;
         _scrollBar.Position = 50;
@@ -1016,16 +1040,20 @@ This is a test
         Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
         Assert.Equal (99, _scrollBar.OtherScrollBarView.Position);
         Assert.Equal (99, _hostView.Left);
+        _hostView.SuperView.Dispose ();
+
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void KeepContentAlwaysInViewport_True ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
-
+        _hostView.SuperView.LayoutSubviews ();
+        _hostView.Draw ();
         Assert.Equal (80, _hostView.Viewport.Width);
         Assert.Equal (25, _hostView.Viewport.Height);
         Assert.Equal (79, _scrollBar.OtherScrollBarView.Viewport.Width);
@@ -1060,19 +1088,22 @@ This is a test
         Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
         Assert.True (_scrollBar.Visible);
         Assert.True (_scrollBar.OtherScrollBarView.Visible);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void OtherScrollBarView_Not_Null ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
 
         Assert.NotNull (_scrollBar.OtherScrollBarView);
         Assert.NotEqual (_scrollBar, _scrollBar.OtherScrollBarView);
         Assert.Equal (_scrollBar.OtherScrollBarView.OtherScrollBarView, _scrollBar);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -1082,18 +1113,23 @@ This is a test
         var sbv = new ScrollBarView { Position = 1 };
         Assert.Equal (1, sbv.Position);
         Assert.NotEqual (0, sbv.Position);
+        sbv.Dispose ();
     }
 
     [Fact]
     [ScrollBarAutoInitShutdown]
     public void ShowScrollIndicator_Check ()
     {
-        Hosting_A_View_To_A_ScrollBarView ();
+        _scrollBar = new ScrollBarView (_hostView, true);
+        Application.Begin (_hostView.SuperView as Toplevel);
 
         AddHandlers ();
+        _hostView.SuperView.LayoutSubviews ();
+        _hostView.Draw ();
 
         Assert.True (_scrollBar.ShowScrollIndicator);
         Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
+        _hostView.SuperView.Dispose ();
     }
 
     [Fact]
@@ -1165,6 +1201,7 @@ This is a test             ",
         Assert.Equal (5, sbv.Size);
         Assert.False (sbv.ShowScrollIndicator);
         Assert.False (sbv.Visible);
+        top.Dispose ();
     }
 
     [Fact]
@@ -1235,6 +1272,7 @@ This is a test             ",
 │▼│
 └─┘";
         _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
+        top.Dispose ();
     }
 
     private void _hostView_DrawContent (object sender, DrawEventArgs e)