Ver Fonte

Add SetScreenSize to IConsoleDriver and fix test issues

- Added SetScreenSize(int, int) method to IConsoleDriver interface
- Implemented in ConsoleDriver base class to throw NotImplementedException
- Implemented in ConsoleDriverFacade to throw NotImplementedException
- Overridden in FakeDriver to call SetBufferSize for testing
- Updated all test files to use Application.Driver.SetScreenSize() instead of casting to FakeDriver
- Fixed FakeDriver_MockKeyPresses_Stack_Works test by clearing stack before use
- All tests now pass without casting (21 UnitTests + 16 Parallelizable FakeDriver tests)

Co-authored-by: tig <[email protected]>
copilot-swe-agent[bot] há 1 mês atrás
pai
commit
c4a73d71c7

+ 5 - 0
Terminal.Gui/Drivers/ConsoleDriver.cs

@@ -738,4 +738,9 @@ public abstract class ConsoleDriver : IConsoleDriver
         return _scheduler ??= new (GetParser ());
     }
 
+    /// <inheritdoc/>
+    public virtual void SetScreenSize (int width, int height)
+    {
+        throw new NotImplementedException ("SetScreenSize is only supported by FakeDriver for testing purposes.");
+    }
 }

+ 6 - 0
Terminal.Gui/Drivers/ConsoleDriverFacade.cs

@@ -423,6 +423,12 @@ internal class ConsoleDriverFacade<T> : IConsoleDriver, IConsoleDriverFacade
 
     public AnsiRequestScheduler GetRequestScheduler () { return _ansiRequestScheduler; }
 
+    /// <inheritdoc/>
+    public void SetScreenSize (int width, int height)
+    {
+        throw new NotImplementedException ("SetScreenSize is only supported by FakeDriver for testing purposes.");
+    }
+
     /// <inheritdoc/>
     public void Refresh ()
     {

+ 6 - 0
Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs

@@ -378,6 +378,12 @@ public class FakeDriver : ConsoleDriver
     /// <inheritdoc />
     internal override IAnsiResponseParser GetParser () => _parser;
 
+    /// <inheritdoc/>
+    public override void SetScreenSize (int width, int height)
+    {
+        SetBufferSize (width, height);
+    }
+
     public void SetBufferSize (int width, int height)
     {
         FakeConsole.SetBufferSize (width, height);

+ 8 - 0
Terminal.Gui/Drivers/IConsoleDriver.cs

@@ -259,4 +259,12 @@ public interface IConsoleDriver
     /// </summary>
     /// <returns></returns>
     public AnsiRequestScheduler GetRequestScheduler ();
+
+    /// <summary>
+    ///     Sets the size of the terminal screen. Only supported by FakeDriver for testing.
+    /// </summary>
+    /// <param name="width">The new width of the screen in columns.</param>
+    /// <param name="height">The new height of the screen in rows.</param>
+    /// <exception cref="NotImplementedException">Thrown by all drivers except FakeDriver.</exception>
+    void SetScreenSize (int width, int height);
 }

+ 2 - 2
Tests/UnitTests/Text/TextFormatterTests.cs

@@ -3828,7 +3828,7 @@ ssb
     [SetupFakeDriver]
     public void FillRemaining_True_False ()
     {
-        ((FakeDriver)Application.Driver!).SetBufferSize (22, 5);
+        Application.Driver!.SetScreenSize (22, 5);
 
         Attribute [] attrs =
         {
@@ -4050,7 +4050,7 @@ Nice       Work")]
         Size tfSize = tf.FormatAndGetSize ();
         Assert.Equal (new (59, 13), tfSize);
 
-        ((FakeDriver)Application.Driver).SetBufferSize (tfSize.Width, tfSize.Height);
+        Application.Driver!.SetScreenSize (tfSize.Width, tfSize.Height);
 
         Application.Driver.FillRect (Application.Screen, (Rune)'*');
         tf.Draw (Application.Screen, Attribute.Default, Attribute.Default);

+ 2 - 2
Tests/UnitTests/View/Adornment/ShadowStyleTests.cs

@@ -30,7 +30,7 @@ public class ShadowStyleTests (ITestOutputHelper output)
     [SetupFakeDriver]
     public void ShadowView_Colors (ShadowStyle style, string expectedAttrs)
     {
-        ((FakeDriver)Application.Driver!).SetBufferSize (5, 5);
+        Application.Driver!.SetScreenSize (5, 5);
         Color fg = Color.Red;
         Color bg = Color.Green;
 
@@ -100,7 +100,7 @@ public class ShadowStyleTests (ITestOutputHelper output)
     [SetupFakeDriver]
     public void Visual_Test (ShadowStyle style, string expected)
     {
-        ((FakeDriver)Application.Driver!).SetBufferSize (5, 5);
+        Application.Driver!.SetScreenSize (5, 5);
 
         var superView = new Toplevel
         {

+ 1 - 1
Tests/UnitTests/View/TextTests.cs

@@ -998,7 +998,7 @@ w ";
     [SetupFakeDriver]
     public void Narrow_Wide_Runes ()
     {
-        ((FakeDriver)Application.Driver!).SetBufferSize (32, 32);
+        Application.Driver!.SetScreenSize (32, 32);
         var top = new View { Width = 32, Height = 32 };
 
         var text = $"First line{Environment.NewLine}Second line";

+ 1 - 1
Tests/UnitTests/Views/LabelTests.cs

@@ -892,7 +892,7 @@ e
     [SetupFakeDriver]
     public void Label_Height_Zero_Stays_Zero ()
     {
-        ((FakeDriver)Application.Driver!).SetBufferSize (10, 4);
+        Application.Driver!.SetScreenSize (10, 4);
         var text = "Label";
 
         var label = new Label

+ 1 - 1
Tests/UnitTests/Views/TableViewTests.cs

@@ -2206,7 +2206,7 @@ public class TableViewTests (ITestOutputHelper output)
     [SetupFakeDriver]
     public void TestEnumerableDataSource_BasicTypes ()
     {
-        ((FakeDriver)Application.Driver!).SetBufferSize (100, 100);
+        Application.Driver!.SetScreenSize (100, 100);
         var tv = new TableView ();
         tv.SchemeName = "TopLevel";
         tv.Viewport = new (0, 0, 50, 6);

+ 2 - 2
Tests/UnitTests/Views/ToplevelTests.cs

@@ -507,10 +507,10 @@ public class ToplevelTests
         top.BeginInit ();
         top.EndInit ();
 
-        Exception exception = Record.Exception (() => ((FakeDriver)Application.Driver!).SetBufferSize (0, 10));
+        Exception exception = Record.Exception (() => Application.Driver!.SetScreenSize (0, 10));
         Assert.Null (exception);
 
-        exception = Record.Exception (() => ((FakeDriver)Application.Driver!).SetBufferSize (10, 0));
+        exception = Record.Exception (() => Application.Driver!.SetScreenSize (10, 0));
         Assert.Null (exception);
     }
 

+ 2 - 2
Tests/UnitTests/Views/TreeTableSourceTests.cs

@@ -30,7 +30,7 @@ public class TreeTableSourceTests : IDisposable
     [SetupFakeDriver]
     public void TestTreeTableSource_BasicExpanding_WithKeyboard ()
     {
-        ((FakeDriver)Application.Driver!).SetBufferSize (100, 100);
+        Application.Driver!.SetScreenSize (100, 100);
         TableView tv = GetTreeTable (out _);
 
         tv.Style.GetOrCreateColumnStyle (1).MinAcceptableWidth = 1;
@@ -91,7 +91,7 @@ public class TreeTableSourceTests : IDisposable
     [SetupFakeDriver]
     public void TestTreeTableSource_BasicExpanding_WithMouse ()
     {
-        ((FakeDriver)Application.Driver!).SetBufferSize (100, 100);
+        Application.Driver!.SetScreenSize (100, 100);
 
         TableView tv = GetTreeTable (out _);
 

+ 3 - 0
Tests/UnitTestsParallelizable/Drivers/FakeDriverInputTests.cs

@@ -36,6 +36,9 @@ public class FakeDriverInputTests (ITestOutputHelper output)
         var driver = new FakeDriver ();
         driver.Init ();
 
+        // Clear any previous state from other tests
+        FakeConsole.MockKeyPresses.Clear ();
+
         // Act - Push multiple keys
         FakeConsole.PushMockKeyPress (KeyCode.A);
         FakeConsole.PushMockKeyPress (KeyCode.B);