Bläddra i källkod

Fix driver color tests to set Driver.Force16Colors before driver creation

- Updated DriverColorTests.Force16Colors_Sets to set static property before creating driver
- Updated ToAnsiTests test methods to set Driver.Force16Colors before creating driver
- Added cleanup to reset Driver.Force16Colors to false after tests
- All driver color tests now passing

Co-authored-by: tig <[email protected]>
copilot-swe-agent[bot] 1 vecka sedan
förälder
incheckning
00fa3100e8

+ 6 - 1
Tests/UnitTestsParallelizable/Drivers/DriverColorTests.cs

@@ -9,11 +9,16 @@ public class DriverColorTests : FakeDriverBase
     [Fact]
     public void Force16Colors_Sets ()
     {
+        // Set the static property before creating the driver
+        Terminal.Gui.Drivers.Driver.Force16Colors = true;
         IDriver driver = CreateFakeDriver ();
 
-        driver.Force16Colors = true;
         Assert.True (driver.Force16Colors);
+        Assert.True (driver.GetForce16Colors ());
 
         driver.End ();
+        
+        // Reset for other tests
+        Terminal.Gui.Drivers.Driver.Force16Colors = false;
     }
 }

+ 20 - 8
Tests/UnitTestsParallelizable/Drivers/ToAnsiTests.cs

@@ -45,8 +45,9 @@ public class ToAnsiTests : FakeDriverBase
     [InlineData (false, "\u001b[38;2;255;0;0m", "\u001b[38;2;0;0;255")]
     public void ToAnsi_With_Colors (bool force16Colors, string expectedRed, string expectedBue)
     {
+        // Set the static property before creating the driver
+        Terminal.Gui.Drivers.Driver.Force16Colors = force16Colors;
         IDriver driver = CreateFakeDriver (10, 2);
-        driver.Force16Colors = force16Colors;
 
         // Set red foreground
         driver.CurrentAttribute = new Attribute (Color.Red, Color.Black);
@@ -65,6 +66,9 @@ public class ToAnsiTests : FakeDriverBase
         Assert.Contains (expectedBue, ansi); // Blue foreground
         Assert.Contains ("Red", ansi);
         Assert.Contains ("Blue", ansi);
+        
+        // Reset for other tests
+        Terminal.Gui.Drivers.Driver.Force16Colors = false;
     }
 
     [Theory (Skip = "Uses Application.")]
@@ -82,13 +86,13 @@ public class ToAnsiTests : FakeDriverBase
         string ansi = driver.ToAnsi ();
 
         /*
-         The ANSI escape sequence for red background (8-color) is ESC[41m  where ESC is \x1b (or \u001b).
+         The ANSI escape sequence for red background (8-color) is ESC[41m � where ESC is \x1b (or \u001b).
            Examples:
-           	C# string: "\u001b[41m" or "\x1b[41m"
-           	Reset (clear attributes): "\u001b[0m"
+           �	C# string: "\u001b[41m" or "\x1b[41m"
+           �	Reset (clear attributes): "\u001b[0m"
            Notes:
-           	Bright/red background (16-color bright variant) uses ESC[101m ("\u001b[101m").
-           	For 24-bit RGB background use ESC[48;2;<r>;<g>;<b>m, e.g. "\u001b[48;2;255;0;0m" for pure red.
+           �	Bright/red background (16-color bright variant) uses ESC[101m ("\u001b[101m").
+           �	For 24-bit RGB background use ESC[48;2;<r>;<g>;<b>m, e.g. "\u001b[48;2;255;0;0m" for pure red.
          */
 
         Assert.True (driver.Force16Colors == force16Colors);
@@ -162,8 +166,9 @@ public class ToAnsiTests : FakeDriverBase
     [InlineData (false, "\u001b[38;2;", "\u001b[48;2;")]
     public void ToAnsi_Attribute_Changes_Within_Line (bool force16Colors, string expectedRed, string expectedBlue)
     {
+        // Set the static property before creating the driver
+        Terminal.Gui.Drivers.Driver.Force16Colors = force16Colors;
         IDriver driver = CreateFakeDriver (20, 1);
-        driver.Force16Colors = force16Colors;
 
         driver.AddStr ("Normal");
         driver.CurrentAttribute = new Attribute (Color.Red, Color.Black);
@@ -178,6 +183,9 @@ public class ToAnsiTests : FakeDriverBase
         Assert.Contains ("Normal", ansi);
         Assert.Contains (expectedRed, ansi); // Red
         Assert.Contains (expectedBlue, ansi); // Blue
+        
+        // Reset for other tests
+        Terminal.Gui.Drivers.Driver.Force16Colors = false;
     }
 
     [Fact]
@@ -259,8 +267,9 @@ public class ToAnsiTests : FakeDriverBase
         string expectedCyan
     )
     {
+        // Set the static property before creating the driver
+        Terminal.Gui.Drivers.Driver.Force16Colors = force16Colors;
         IDriver driver = CreateFakeDriver (50, 1);
-        driver.Force16Colors = force16Colors;
 
         // Create a line with many attribute changes
         string [] colors = { "Red", "Green", "Blue", "Yellow", "Magenta", "Cyan" };
@@ -292,6 +301,9 @@ public class ToAnsiTests : FakeDriverBase
         Assert.Contains (expectedYellow, ansi); // Yellow
         Assert.Contains (expectedMagenta, ansi); // Magenta
         Assert.Contains (expectedCyan, ansi); // Cyan
+        
+        // Reset for other tests
+        Terminal.Gui.Drivers.Driver.Force16Colors = false;
     }
 
     [Fact]