Bläddra i källkod

Fixed a bunch of unit test issues. Fixed color stuff I broke

Tig 10 månader sedan
förälder
incheckning
aed37f9b54

+ 1 - 1
Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs

@@ -93,7 +93,7 @@ public class FakeDriver : ConsoleDriver
         FakeConsole.Clear ();
         ResizeScreen ();
         CurrentAttribute = new Attribute (Color.White, Color.Black);
-        ClearContents ();
+        //ClearContents ();
 
         _mainLoopDriver = new FakeMainLoop (this);
         _mainLoopDriver.MockKeyPressed = MockKeyPressedHandler;

+ 20 - 10
Terminal.Gui/Drawing/Color.ColorExtensions.cs

@@ -1,4 +1,5 @@
 using System.Collections.Frozen;
+using ColorHelper;
 
 namespace Terminal.Gui;
 
@@ -32,17 +33,26 @@ internal static class ColorExtensions
         };
         ColorName16ToAnsiColorMap = nameToCodeMap.ToFrozenDictionary ();
 
-        var colorToNameDict = new Dictionary<Color, ColorName16> ();
-
-        foreach (ColorName16 colorName in Enum.GetValues<ColorName16> ())
+        ColorToName16Map = new Dictionary<Color, ColorName16>
         {
-            if (ColorStrings.TryParseW3CColorName (Enum.GetName<ColorName16> (colorName), out Color color))
-            {
-                colorToNameDict [color] = colorName;
-            }
-        }
-
-        ColorToName16Map = colorToNameDict.ToFrozenDictionary ();
+            // These match the values in Strings.resx, which are the W3C colors.
+            { new Color(0, 0, 0), ColorName16.Black },
+            { new Color(0, 0, 255), ColorName16.Blue },
+            { new Color(0, 128, 0), ColorName16.Green },
+            { new Color(0, 255, 255), ColorName16.Cyan },
+            { new Color(255, 0, 0), ColorName16.Red },
+            { new Color(255, 0, 255), ColorName16.Magenta },
+            { new Color(255, 255, 0), ColorName16.Yellow },
+            { new Color(128, 128, 128), ColorName16.Gray },
+            { new Color(118, 118, 118), ColorName16.DarkGray },
+            { new Color(59, 120, 255), ColorName16.BrightBlue },
+            { new Color(22, 198, 12), ColorName16.BrightGreen },
+            { new Color(97, 214, 214), ColorName16.BrightCyan },
+            { new Color(231, 72, 86), ColorName16.BrightRed },
+            { new Color(180, 0, 158), ColorName16.BrightMagenta },
+            { new Color(249, 241, 165), ColorName16.BrightYellow },
+            { new Color(255, 255, 255), ColorName16.White }
+        }.ToFrozenDictionary ();
     }
 
     /// <summary>Defines the 16 legacy color names and their corresponding ANSI color codes.</summary>

+ 1 - 14
Terminal.Gui/Drawing/Color.cs

@@ -109,20 +109,7 @@ public readonly partial record struct Color : ISpanParsable<Color>, IUtf8SpanPar
 
     /// <summary>Initializes a new instance of the <see cref="Color"/> color from a legacy 16-color named value.</summary>
     /// <param name="colorName">The 16-color value.</param>
-    public Color (in ColorName16 colorName)
-    {
-        string? name = Enum.GetName<ColorName16> (colorName);
-
-        if (name is null)
-        {
-            return;
-        }
-
-        if (ColorStrings.TryParseW3CColorName (name, out Color color))
-        {
-            this = color;
-        }
-    }
+    public Color (in ColorName16 colorName) { this = ColorExtensions.ColorName16ToColorMap [colorName]; }
 
     /// <summary>
     ///     Initializes a new instance of the <see cref="Color"/> color from string. See

+ 1 - 1
UnitTests/View/ViewTests.cs

@@ -136,7 +136,7 @@ public class ViewTests (ITestOutputHelper output)
     }
 
     [Theory]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     [InlineData (true)]
     [InlineData (false)]
     public void Clear_Does_Not_Spillover_Its_Parent (bool label)

+ 1 - 1
UnitTests/Views/ComboBoxTests.cs

@@ -492,7 +492,7 @@ public class ComboBoxTests (ITestOutputHelper output)
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     public void HideDropdownListOnClick_True_Highlight_Current_Item ()
     {
         var selected = "";

+ 2 - 2
UnitTests/Views/MenuBarTests.cs

@@ -290,7 +290,7 @@ public class MenuBarTests (ITestOutputHelper output)
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     public void Disabled_MenuBar_Is_Never_Opened ()
     {
         Toplevel top = new ();
@@ -316,7 +316,7 @@ public class MenuBarTests (ITestOutputHelper output)
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     public void Disabled_MenuItem_Is_Never_Selected ()
     {
         var menu = new MenuBar

+ 1 - 1
UnitTests/Views/RuneCellTests.cs

@@ -50,7 +50,7 @@ public class RuneCellTests (ITestOutputHelper output)
     }
 
     [Fact]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     public void RuneCell_LoadRuneCells_InheritsPreviousColorScheme ()
     {
         List<RuneCell> runeCells = new ();

+ 1 - 1
UnitTests/Views/ScrollViewTests.cs

@@ -174,7 +174,7 @@ public class ScrollViewTests (ITestOutputHelper output)
 
     // There are still issue with the lower right corner of the scroll view
     [Fact]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     public void Clear_Window_Inside_ScrollView ()
     {
         var topLabel = new Label { X = 15, Text = "At 15,0" };

+ 3 - 3
UnitTests/Views/TableViewTests.cs

@@ -1035,7 +1035,7 @@ public class TableViewTests (ITestOutputHelper output)
     }
 
     [Theory]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     [InlineData (false)]
     [InlineData (true)]
     public void TableView_ColorsTest_ColorGetter (bool focused)
@@ -1132,7 +1132,7 @@ public class TableViewTests (ITestOutputHelper output)
     }
 
     [Theory]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     [InlineData (false)]
     [InlineData (true)]
     public void TableView_ColorsTest_RowColorGetter (bool focused)
@@ -1223,7 +1223,7 @@ public class TableViewTests (ITestOutputHelper output)
     }
 
     [Theory]
-    [AutoInitShutdown]
+    [AutoInitShutdown (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly)]
     [InlineData (false)]
     [InlineData (true)]
     public void TableView_ColorTests_FocusedOrNot (bool focused)

+ 41 - 1
UnitTests/Views/TextViewTests.cs

@@ -106,6 +106,7 @@ public class TextViewTests
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -155,6 +156,7 @@ public class TextViewTests
         Assert.False (tv.HasFocus);
         Assert.False (fv.CanFocus);
         Assert.False (fv.HasFocus);
+        top.Dispose ();
     }
 
     [Fact]
@@ -248,6 +250,7 @@ public class TextViewTests
         top.Add (tv);
         Application.Begin (top);
         Assert.Equal (1, eventcount);
+        top.Dispose ();
     }
 
     [Fact]
@@ -340,6 +343,8 @@ public class TextViewTests
         expectedCol = 0;
         tv.Text = "defg";
         Assert.Equal (2, eventcount); // for set Text = "defg"
+        top.Dispose ();
+
     }
 
     [Fact]
@@ -374,6 +379,8 @@ public class TextViewTests
         tv.NewKeyDownEvent (Key.Y.WithShift);
         Assert.Equal (3, eventcount);
         Assert.Equal ("Yay", tv.Text);
+        top.Dispose ();
+
     }
 
     [Fact]
@@ -775,6 +782,7 @@ This is the second line.
         Assert.Equal (envText, tv.Text);
         Assert.Equal (new Point (3, 0), tv.CursorPosition);
         Assert.False (tv.IsDirty);
+        top.Dispose ();
     }
 
     [Fact]
@@ -846,6 +854,7 @@ This is the second line.
         Assert.Equal (envText, tv.Text);
         Assert.Equal (new Point (3, 0), tv.CursorPosition);
         Assert.False (tv.IsDirty);
+        top.Dispose ();
     }
 
     [Fact]
@@ -917,6 +926,7 @@ This is the second line.
         Assert.Equal (envText, tv.Text);
         Assert.Equal (new Point (2, 0), tv.CursorPosition);
         Assert.False (tv.IsDirty);
+        top.Dispose ();
     }
 
     [Fact]
@@ -988,6 +998,7 @@ This is the second line.
         Assert.Equal (envText, tv.Text);
         Assert.Equal (new Point (2, 0), tv.CursorPosition);
         Assert.False (tv.IsDirty);
+        top.Dispose ();
     }
 
     [Fact]
@@ -2288,6 +2299,7 @@ This is the second line.
                      );
         Assert.Equal (3, tv.Lines);
         Assert.Equal (new Point (4, 2), tv.CursorPosition);
+        top.Dispose ();
     }
 
     [Fact]
@@ -2421,6 +2433,7 @@ This is the second line.
                      );
         Assert.Equal (3, tv.Lines);
         Assert.Equal (new Point (7, 2), tv.CursorPosition);
+        top.Dispose ();
     }
 
     [Fact]
@@ -2542,6 +2555,7 @@ This is the second line.
                      );
         Assert.Equal (3, tv.Lines);
         Assert.Equal (new Point (13, 2), tv.CursorPosition);
+        top.Dispose ();
     }
 
     [Fact]
@@ -3030,6 +3044,7 @@ This is the second line.
         Assert.Equal (11, tv.SelectionStartColumn);
         Assert.Equal (2, tv.SelectionStartRow);
         Assert.Equal (0, tv.SelectedLength);
+        top.Dispose ();
     }
 
     [Fact]
@@ -3093,6 +3108,7 @@ This is the second line.
         Assert.Equal (new Point (2, 0), tv.CursorPosition);
         Assert.Equal (0, tv.SelectedLength);
         Assert.True (tv.IsDirty);
+        top.Dispose ();
     }
 
     [Fact]
@@ -3156,6 +3172,7 @@ This is the second line.
         Assert.Equal (new Point (2, 0), tv.CursorPosition);
         Assert.Equal (0, tv.SelectedLength);
         Assert.True (tv.IsDirty);
+        top.Dispose ();
     }
 
     [Fact]
@@ -3511,6 +3528,7 @@ This is the second line.
         Assert.Equal (new Point (2, 0), tv.CursorPosition);
         Assert.Equal (0, tv.SelectedLength);
         Assert.True (tv.IsDirty);
+        top.Dispose ();
     }
 
     [Fact]
@@ -3792,6 +3810,7 @@ This is the second line.
         Assert.Equal (4, tv.Lines);
         Assert.Equal (new Point (0, 3), tv.CursorPosition);
         Assert.True (tv.IsDirty);
+        top.Dispose ();
     }
 
     [Fact]
@@ -4031,6 +4050,7 @@ This is the second line.
                      );
         Assert.Equal (3, tv.Lines);
         Assert.Equal (new Point (4, 1), tv.CursorPosition);
+        top.Dispose ();
     }
 
     [Fact]
@@ -4088,6 +4108,7 @@ This is the second line.
                      );
         Assert.Equal (3, tv.Lines);
         Assert.Equal (new Point (7, 1), tv.CursorPosition);
+        top.Dispose ();
     }
 
     [Fact]
@@ -4141,6 +4162,7 @@ This is the second line.
                      );
         Assert.Equal (3, tv.Lines);
         Assert.Equal (new Point (13, 1), tv.CursorPosition);
+        top.Dispose ();
     }
 
     [Fact]
@@ -4210,6 +4232,7 @@ This is the second line.
         Assert.Equal (11, tv.SelectionStartColumn);
         Assert.Equal (1, tv.SelectionStartRow);
         Assert.Equal (0, tv.SelectedLength);
+        top.Dispose ();
     }
 
     [Fact]
@@ -4279,6 +4302,7 @@ This is the second line.
         Assert.Equal (11, tv.SelectionStartColumn);
         Assert.Equal (1, tv.SelectionStartRow);
         Assert.Equal (0, tv.SelectedLength);
+        top.Dispose ();
     }
 
     [Fact]
@@ -4344,6 +4368,7 @@ This is the second line.
         Assert.Equal (11, tv.SelectionStartColumn);
         Assert.Equal (1, tv.SelectionStartRow);
         Assert.Equal (0, tv.SelectedLength);
+        top.Dispose ();
     }
 
     [Fact]
@@ -5413,6 +5438,7 @@ This is the second line.
 
         Assert.True (tv.NewKeyDownEvent (ContextMenu.DefaultKey));
         Assert.True (tv.ContextMenu != null && tv.ContextMenu.MenuBar.Visible);
+        top.Dispose ();
     }
 
     [Fact]
@@ -6254,6 +6280,7 @@ This is the second line.
 
         //                                             TAB to jump between text fields.
         TestHelpers.AssertDriverAttributesAre ("1111000", Application.Driver, attributes);
+        top.Dispose ();
     }
 
     [Fact]
@@ -6376,6 +6403,7 @@ This is the second line.
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -6418,6 +6446,7 @@ This is the second line.
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -6469,6 +6498,7 @@ This is the second line.
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -6522,6 +6552,7 @@ This is the second line.
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -6591,6 +6622,7 @@ This is the second line.
                                  };
 
         Application.Run (top);
+        top.Dispose ();
     }
 
     [Fact]
@@ -6639,6 +6671,7 @@ TAB to jump between text field",
 TAB to jump between text field",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -6747,6 +6780,7 @@ TAB to jump between text field",
 └─────────────┘",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -6824,6 +6858,7 @@ TAB to jump between text field",
 └─────────────┘",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -6990,6 +7025,7 @@ line.
 ",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -8108,6 +8144,7 @@ a
 ",
                                              _output
                                             );
+        top.Dispose ();
     }
 
     [Theory]
@@ -8147,6 +8184,7 @@ H
 Line 2.",
                                                       _output
                                                      );
+        top.Dispose ();
     }
 
     [Fact]
@@ -8381,10 +8419,12 @@ line.
     // This is necessary because a) Application is a singleton and Init/Shutdown must be called
     // as a pair, and b) all unit test functions should be atomic.
     [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
-    public class TextViewTestsAutoInitShutdown : AutoInitShutdownAttribute
+    public class TextViewTestsAutoInitShutdown : AutoInitShutdownAttribute 
     {
         public static string Txt = "TAB to jump between text fields.";
 
+        public TextViewTestsAutoInitShutdown () : base (configLocation: ConfigurationManager.ConfigLocations.DefaultOnly) { }
+
         public override void After (MethodInfo methodUnderTest)
         {
             _textView = null;