Fixes #4361 - Consolidate FakeDriver into library and refactor driver architecture (#4362)

* Initial plan

* Add ScreenChanged event, SetScreenSize method, and fix FakeDriver buffer initialization

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add comprehensive tests for ScreenChanged event and buffer integrity

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Replace obsolete SizeChanged usage with ScreenChanged in core and tests

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Refactor terminal size event handling

Replaced `ScreenChanged` with `SizeChanged` across the codebase to standardize naming and improve clarity. Updated event handling logic, including subscriptions, unsubscriptions, and raising methods. Removed deprecated `ScreenChanged` event and backward compatibility code.

Refactored driver initialization to handle legacy `IConsoleDriver` types separately. Updated tests and mock implementations to align with the new `SizeChanged` event. Improved documentation and comments to reflect these changes.

These updates enhance maintainability, consistency, and modernize the architecture.

* Refactor & Code Cleanup: Replace IWindowSizeMonitor with IConsoleSizeMonitor

Renamed `IWindowSizeMonitor` to `IConsoleSizeMonitor` across the codebase, updating all references, method signatures, and event handlers. Replaced the `WindowSizeMonitor` class with the new `ConsoleSizeMonitor` implementation, which includes improved terminal size change handling via the `Poll` method.

Enabled nullable reference types in several files to enhance code safety. Updated test cases to reflect the new `IConsoleSizeMonitor` interface. Removed redundant code, simplified null checks, and corrected minor typos in comments. Streamlined the codebase by removing the obsolete `WindowSizeMonitor` class and its interface.

* Code cleanup - Refactor and enhance ShadowView and FakeDriverTests

Updated ShadowView.cs to use null-conditional operators and added null checks for safer access to `ScreenContents`. Refined XML documentation in View.Layout.cs for clarity and consistency.

Refactored FakeDriverTests.cs to leverage modern C# features, including shorthand object instantiation, inline lambdas, and tuple-like syntax for `Size` and `Rectangle`. Removed redundant tests and improved test readability and reliability.

Enhanced error handling with null checks and ensured backward compatibility for deprecated events. Improved test coverage for resizing, clipboard operations, and invalid coordinates. Verified buffer integrity and screen updates after resizing.

General improvements include replacing explicit type declarations with `var`, removing unused imports, and aligning code formatting for better readability.

Refactor and improve code quality and test coverage

Updated `ShadowView` for null safety using null-conditional operators. Simplified object initializations and modernized syntax across the codebase, including shorthand initializations and inline lambdas. Enhanced event handling logic and ensured compatibility with obsolete members.

Refactored `FakeDriverTests` by removing redundant code, standardizing formatting, and improving test setup. Suppressed obsolete warnings where necessary. Improved XML documentation in `View.Layout.cs` for clarity and removed outdated references.

Performed general cleanup, including removing unused namespaces, redundant comments, and ensuring consistent formatting. These changes enhance readability, maintainability, and runtime safety.

* Code cleanup

Refactor TimedEventsTests for readability and consistency

Improved code readability and maintainability:
- Enabled nullable reference types with `#nullable enable`.
- Removed unused `using System.Diagnostics;`.
- Updated namespace to `UnitTests.ApplicationTests`.
- Replaced `Terminal.Gui.App.TimedEvents` with `TimedEvents`.
- Reformatted XML documentation comments for alignment.
- Used `var` and target-typed new expressions for consistency.
- Reformatted `Parallel.For` loops and lambdas for clarity.
- Added `Thread.Sleep(10)` to prevent excessive CPU usage in tests.
- Improved assertions and event handler formatting in tests.

Aligned with modern C# coding practices.

* Code Cleanup - No more driver warnings.

Refactor codebase and introduce FakeClipboard

- Adjusted `.editorconfig` to change severity levels for CS0612, CS0618, and CS0672 diagnostics.
- Replaced `FakeDriver.FakeClipboard` with a new `FakeClipboard` class for testing purposes, supporting exception handling and clipboard data manipulation.
- Removed redundant methods (`MakeColor`, `MapKey`) and unused classes (`MockConsoleDriver`) to streamline the codebase.
- Refactored `ConsoleDriverFacade` and `FakeDriver` to simplify logic and improve maintainability.
- Updated tests to use `CreateFakeDriver` and removed or commented out obsolete tests.
- Reformatted and cleaned up code for readability across multiple files.

* Refactor FakeDriver - Code Cleanup

Standardized console size management by replacing `WindowSizeMonitor` with `ConsoleSizeMonitor` across the codebase. Updated methods `GetWindowSize` and `SetWindowSize` to `GetSize` and `SetSize` for consistency.

Refactored `FakeDriver` to use `SetScreenSize` and removed redundant methods. Simplified driver initialization by removing legacy `InternalInit` logic.

Standardized ANSI escape sequences by replacing `CSI_ReportTerminalSizeInChars` with `CSI_ReportWindowSizeInChars`.

Updated test cases to align with the new `ConsoleSizeMonitor` and `SetScreenSize` methods. Removed obsolete test utilities like `FakeSizeMonitor` and `FakeWindowSizeMonitor`.

Performed general code cleanup, including removing unused classes, redundant code, and improving formatting. Fixed resizing logic issues and improved exception handling in driver methods.

* Update Terminal.Gui/Drivers/OutputBuffer.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/Drivers/MouseButtonStateEx.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/App/MainLoop/IApplicationMainLoop.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Tests/UnitTests/Views/ToplevelTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/ViewBase/View.Layout.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Moved all Drawing tests to Paralleizable - proving Fakedriver works

Enhanced `Ruler` and `Thickness` classes by adding an optional `IConsoleDriver? driver` parameter to decouple rendering from the default `Application.Driver`, improving flexibility and testability. Updated `DriverAssert` to support nullable drivers and added defensive checks.

Refactored and expanded test cases for `Ruler`, `Thickness`, `LineCanvas`, and `StraightLineExtensions` to ensure comprehensive coverage, including zero-length intersections, line rendering, and exclusion logic. Migrated rendering-dependent tests to a parallelizable namespace.

Removed redundant tests, improved naming conventions, and updated documentation for better maintainability and clarity.

* Fixed Run<T> startup hang.

Refactor: Simplify driver logic and update SetSize methods

Removed FakeDriver safeguard in unit tests to simplify
CreateDriver logic. Updated SetSize methods in NetOutput,
UnixOutput, and WindowsOutput to do nothing instead of
throwing NotImplementedException. Modified SizeChanged
event in ConsoleDriverFacade to call SetScreenSize directly.
Commented out unnecessary debug validation in DimAuto.
These changes improve maintainability and reduce complexity.

* Fixed intermittent unit test bug.

Refactored `_cachedRunStateToplevel` to `CachedRunStateToplevel` as an internal static property, delegating its management to `ApplicationImpl` for improved encapsulation. Updated all references to use the new property and centralized its handling in `ApplicationImpl`.

Removed the `MouseGrabHandler` property from `ApplicationImpl` and simplified driver-related assignments by replacing `Application.ForceDriver` and `Application.Screen` with direct references.

Reset `CachedRunStateToplevel` during cleanup to ensure proper state management. Updated the `Invoke` method to use `Top` directly, aligning with the refactored design. Improved debug assertions and performed general cleanup to enhance code readability and maintainability.

* Fixed intermittent bug an massive code cleanup of warnings.

Refactor and enhance codebase for maintainability

- Applied null-conditional operator (`!`) to improve null-safety.
- Refactored tests for clarity, added new cases, and removed redundancies.
- Introduced `FakeApplicationFactory` and `FakeSizeMonitor` for testing.
- Removed unused code, including legacy `DecodeEscSeq` logic.
- Reformatted code for readability and consistency.
- Updated assertions for more accurate validation in tests.
- Fixed potential null reference issues across multiple files.
- Improved event handling with proper null checks.
- Enhanced documentation for new classes and methods.
- Modernized code with C# features like `record struct` and `nullable enable`.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Copilot
2025-10-27 23:34:14 -06:00
committed by GitHub
parent f3fc20306e
commit e6a0ec64ca
158 changed files with 3359 additions and 7523 deletions

View File

@@ -76,20 +76,20 @@ public class AdornmentTests
Assert.Equal (new (0, 0, 20, 20), view.Viewport);
var marginThickness = 1;
view.Margin.Thickness = new (marginThickness);
view.Margin!.Thickness = new (marginThickness);
Assert.Equal (new (0, 0, 18, 18), view.Viewport);
var borderThickness = 2;
view.Border.Thickness = new (borderThickness);
view.Border!.Thickness = new (borderThickness);
Assert.Equal (new (0, 0, 14, 14), view.Viewport);
var paddingThickness = 3;
view.Padding.Thickness = new (paddingThickness);
view.Padding!.Thickness = new (paddingThickness);
Assert.Equal (new (0, 0, 8, 8), view.Viewport);
Assert.Equal (new (0, 0, view.Margin.Frame.Width, view.Margin.Frame.Height), view.Margin.Viewport);
Assert.Equal (new (0, 0, view.Margin!.Frame.Width, view.Margin!.Frame.Height), view.Margin!.Viewport);
Assert.Equal (new (0, 0, view.Border.Frame.Width, view.Border.Frame.Height), view.Border.Viewport);
Assert.Equal (new (0, 0, view.Border!.Frame.Width, view.Border!.Frame.Height), view.Border!.Viewport);
Assert.Equal (new (0, 0, view.Padding.Frame.Width, view.Padding.Frame.Height), view.Padding.Viewport);
}
@@ -131,7 +131,7 @@ public class AdornmentTests
[InlineData (1, 1, 1, 0, 4)]
public void Viewport_Width_Is_Frame_Width (int thickness, int x, int y, int w, int h)
{
var adornment = new Adornment (null);
var adornment = new Adornment (null!);
adornment.Thickness = new (thickness);
adornment.Frame = new (x, y, w, h);
Assert.Equal (new (x, y, w, h), adornment.Frame);
@@ -151,11 +151,11 @@ public class AdornmentTests
Assert.Equal (new (1, 2, 10, 10), parent.Frame);
Assert.Equal (new (0, 0, 10, 10), parent.Viewport);
Assert.Equal (new (0, 0, 10, 10), parent.Margin.Frame);
Assert.Equal (new (0, 0, 10, 10), parent.Margin.Viewport);
Assert.Equal (new (0, 0, 10, 10), parent.Margin!.Frame);
Assert.Equal (new (0, 0, 10, 10), parent.Margin!.Viewport);
Assert.Null (parent.Margin.SuperView);
Rectangle boundsAsScreen = parent.Margin.ViewportToScreen (new Rectangle (1, 2, 5, 5));
Assert.Null (parent.Margin!.SuperView);
Rectangle boundsAsScreen = parent.Margin!.ViewportToScreen (new Rectangle (1, 2, 5, 5));
Assert.Equal (new (2, 4, 5, 5), boundsAsScreen);
}
@@ -167,8 +167,8 @@ public class AdornmentTests
Assert.Equal (new (1, 2, 10, 20), parent.Frame);
Assert.Equal (new (0, 0, 10, 20), parent.Viewport);
Assert.Equal (new (0, 0, 10, 20), parent.Margin.Frame);
Assert.Equal (new (0, 0, 10, 20), parent.Margin.Viewport);
Assert.Equal (new (0, 0, 10, 20), parent.Margin!.Frame);
Assert.Equal (new (0, 0, 10, 20), parent.Margin!.Viewport);
}
[Fact]
@@ -183,13 +183,13 @@ public class AdornmentTests
};
var marginThickness = 1;
view.Margin.Thickness = new (marginThickness);
view.Margin!.Thickness = new (marginThickness);
var borderThickness = 2;
view.Border.Thickness = new (borderThickness);
view.Border!.Thickness = new (borderThickness);
var paddingThickness = 3;
view.Padding.Thickness = new (paddingThickness);
view.Padding!.Thickness = new (paddingThickness);
view.BeginInit ();
view.EndInit ();
@@ -198,12 +198,12 @@ public class AdornmentTests
Assert.Equal (new (0, 0, 8, 19), view.Viewport);
// Margin.Frame is always the same as the view frame
Assert.Equal (new (0, 0, 20, 31), view.Margin.Frame);
Assert.Equal (new (0, 0, 20, 31), view.Margin!.Frame);
// Border.Frame is View.Frame minus the Margin thickness
Assert.Equal (
new (marginThickness, marginThickness, view.Frame.Width - marginThickness * 2, view.Frame.Height - marginThickness * 2),
view.Border.Frame);
view.Border!.Frame);
// Padding.Frame is View.Frame minus the Border thickness plus Margin thickness
Assert.Equal (
@@ -226,15 +226,15 @@ public class AdornmentTests
public void FrameToScreen_Retains_Frame_Size (int marginThickness, int w, int h)
{
var parent = new View { X = 1, Y = 2, Width = w, Height = h };
parent.Margin.Thickness = new (marginThickness);
parent.Margin!.Thickness = new (marginThickness);
parent.BeginInit ();
parent.EndInit ();
Assert.Equal (new (1, 2, w, h), parent.Frame);
Assert.Equal (new (0, 0, w, h), parent.Margin.Frame);
Assert.Equal (new (0, 0, w, h), parent.Margin!.Frame);
Assert.Equal (parent.Frame, parent.Margin.FrameToScreen ());
Assert.Equal (parent.Frame, parent.Margin!.FrameToScreen ());
}
// Test that Adornment.FrameToScreen override returns Frame if Parent is null
@@ -276,8 +276,8 @@ public class AdornmentTests
Width = 20,
Height = 20
};
superView.Margin.Thickness = new (marginThickness);
superView.Border.Thickness = new (borderThickness);
superView.Margin!.Thickness = new (marginThickness);
superView.Border!.Thickness = new (borderThickness);
var view = new View { X = x, Y = y, Width = 1, Height = 1 };
superView.Add (view);
@@ -285,16 +285,16 @@ public class AdornmentTests
superView.EndInit ();
Assert.Equal (new (x, y, 1, 1), view.Frame);
Assert.Equal (new (0, 0, 20, 20), superView.Margin.Frame);
Assert.Equal (new (0, 0, 20, 20), superView.Margin!.Frame);
Assert.Equal (
new (marginThickness, marginThickness, 20 - marginThickness * 2, 20 - marginThickness * 2),
superView.Border.Frame
superView.Border!.Frame
);
Assert.Equal (
new (superView.Frame.X + marginThickness, superView.Frame.Y + marginThickness, 20 - marginThickness * 2, 20 - marginThickness * 2),
superView.Border.FrameToScreen ()
superView.Border!.FrameToScreen ()
);
}
@@ -309,11 +309,11 @@ public class AdornmentTests
Assert.Equal (new (1, 2, 10, 10), parent.Frame);
Assert.Equal (new (0, 0, 10, 10), parent.Viewport);
Assert.Equal (new (0, 0, 10, 10), parent.Margin.Frame);
Assert.Equal (new (0, 0, 10, 10), parent.Margin.Viewport);
Assert.Equal (new (0, 0, 10, 10), parent.Margin!.Frame);
Assert.Equal (new (0, 0, 10, 10), parent.Margin!.Viewport);
Assert.Null (parent.Margin.SuperView);
Assert.Equal (new (1, 2, 10, 10), parent.Margin.FrameToScreen ());
Assert.Null (parent.Margin!.SuperView);
Assert.Equal (new (1, 2, 10, 10), parent.Margin!.FrameToScreen ());
}
[Fact]
@@ -322,13 +322,13 @@ public class AdornmentTests
var view = new View ();
Assert.Equal (Thickness.Empty, view.GetAdornmentsThickness ());
view.Margin.Thickness = new (1);
view.Margin!.Thickness = new (1);
Assert.Equal (new (1), view.GetAdornmentsThickness ());
view.Border.Thickness = new (1);
view.Border!.Thickness = new (1);
Assert.Equal (new (2), view.GetAdornmentsThickness ());
view.Padding.Thickness = new (1);
view.Padding!.Thickness = new (1);
Assert.Equal (new (3), view.GetAdornmentsThickness ());
view.Padding.Thickness = new (2);
@@ -337,7 +337,7 @@ public class AdornmentTests
view.Padding.Thickness = new (1, 2, 3, 4);
Assert.Equal (new (3, 4, 5, 6), view.GetAdornmentsThickness ());
view.Margin.Thickness = new (1, 2, 3, 4);
view.Margin!.Thickness = new (1, 2, 3, 4);
Assert.Equal (new (3, 5, 7, 9), view.GetAdornmentsThickness ());
view.Dispose ();
}
@@ -345,14 +345,14 @@ public class AdornmentTests
[Fact]
public void Setting_Viewport_Throws ()
{
var adornment = new Adornment (null);
var adornment = new Adornment (null!);
Assert.Throws<InvalidOperationException> (() => adornment.Viewport = new (1, 2, 3, 4));
}
[Fact]
public void Setting_SuperViewRendersLineCanvas_Throws ()
{
var adornment = new Adornment (null);
var adornment = new Adornment (null!);
Assert.Throws<InvalidOperationException> (() => adornment.SuperViewRendersLineCanvas = true);
}
@@ -366,7 +366,7 @@ public class AdornmentTests
Assert.Equal (new (0, 0, 10, 10), parent.Frame);
Assert.Equal (new (0, 0, 10, 10), parent.Viewport);
parent.Margin.Thickness = new (1);
parent.Margin!.Thickness = new (1);
Assert.Equal (new (0, 0, 10, 10), parent.Frame);
Assert.Equal (new (0, 0, 8, 8), parent.Viewport);
}
@@ -374,7 +374,7 @@ public class AdornmentTests
[Fact]
public void Setting_Thickness_Raises_ThicknessChanged ()
{
var adornment = new Adornment (null);
var adornment = new Adornment (null!);
var super = new View ();
var raised = false;
@@ -396,15 +396,15 @@ public class AdornmentTests
parent.EndInit ();
parent.SubViewLayout += LayoutStarted;
parent.Margin.Thickness = new (1, 2, 3, 4);
parent.Margin!.Thickness = new (1, 2, 3, 4);
Assert.True (parent.NeedsLayout);
Assert.True (parent.Margin.NeedsLayout);
Assert.True (parent.Margin!.NeedsLayout);
parent.Layout ();
Assert.True (raised);
return;
void LayoutStarted (object sender, LayoutEventArgs e) { raised = true; }
void LayoutStarted (object? sender, LayoutEventArgs e) { raised = true; }
}
[Fact]
@@ -415,16 +415,16 @@ public class AdornmentTests
parent.BeginInit ();
parent.EndInit ();
parent.Margin.SubViewLayout += LayoutStarted;
parent.Margin.Thickness = new (1, 2, 3, 4);
parent.Margin!.SubViewLayout += LayoutStarted;
parent.Margin!.Thickness = new (1, 2, 3, 4);
Assert.True (parent.NeedsLayout);
Assert.True (parent.Margin.NeedsLayout);
Assert.True (parent.Margin!.NeedsLayout);
parent.Layout ();
Assert.True (raised);
return;
void LayoutStarted (object sender, LayoutEventArgs e) { raised = true; }
void LayoutStarted (object? sender, LayoutEventArgs e) { raised = true; }
}
[Fact]
@@ -434,7 +434,7 @@ public class AdornmentTests
view.BeginInit ();
view.EndInit ();
view.Padding.Thickness = new (2, 2, 2, 2);
view.Padding!.Thickness = new (2, 2, 2, 2);
Assert.Throws<InvalidOperationException> (() => view.Padding.Viewport = view.Padding.Viewport with { Location = new (1, 1) });
}

View File

@@ -28,7 +28,7 @@ public class MarginTests
view.Margin!.Thickness = new Thickness (1, 1, 1, 1);
// Give it Text
view.Margin.Text = "Test";
view.Margin!.Text = "Test";
// Strip off ViewportSettings.Transparent
view.Margin!.ViewportSettings &= ~ViewportSettingsFlags.Transparent;
@@ -50,7 +50,7 @@ public class MarginTests
{
var view = new View { Height = 3, Width = 3, ShadowStyle = ShadowStyle.Transparent };
Assert.Equal (ShadowStyle.Transparent, view.Margin!.ShadowStyle);
Assert.True (view.Margin.ViewportSettings.HasFlag (ViewportSettingsFlags.TransparentMouse), "Margin should be transparent to mouse when ShadowStyle is Transparent.");
Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.TransparentMouse), "Margin should be transparent to mouse when ShadowStyle is Transparent.");
Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.Transparent), "Margin should be transparent when ShadowStyle is Transparent..");
}
@@ -59,7 +59,7 @@ public class MarginTests
{
var view = new View { Height = 3, Width = 3, ShadowStyle = ShadowStyle.Opaque };
Assert.Equal (ShadowStyle.Opaque, view.Margin!.ShadowStyle);
Assert.True (view.Margin.ViewportSettings.HasFlag (ViewportSettingsFlags.TransparentMouse), "Margin should be transparent to mouse when ShadowStyle is Opaque.");
Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.TransparentMouse), "Margin should be transparent to mouse when ShadowStyle is Opaque.");
Assert.True (view.Margin!.ViewportSettings.HasFlag (ViewportSettingsFlags.Transparent), "Margin should be transparent when ShadowStyle is Opaque..");
}

View File

@@ -128,14 +128,14 @@ public class GetViewsUnderLocationTests
containedType = view.GetType ();
}
if (view.Margin.Contains (new (testX, testY)))
if (view.Margin!.Contains (new (testX, testY)))
{
containedType = view.Margin.GetType ();
containedType = view.Margin!.GetType ();
}
if (view.Border.Contains (new (testX, testY)))
if (view.Border!.Contains (new (testX, testY)))
{
containedType = view.Border.GetType ();
containedType = view.Border!.GetType ();
}
if (view.Padding.Contains (new (testX, testY)))

View File

@@ -275,8 +275,8 @@ public class LayoutTests : GlobalTestSetup
view.SubViewLayout += (sender, e) => layoutStartedCount++;
view.SubViewsLaidOut += (sender, e) => layoutCompleteCount++;
view.Border.SubViewLayout += (sender, e) => borderLayoutStartedCount++;
view.Border.SubViewsLaidOut += (sender, e) => borderLayoutCompleteCount++;
view.Border!.SubViewLayout += (sender, e) => borderLayoutStartedCount++;
view.Border!.SubViewsLaidOut += (sender, e) => borderLayoutCompleteCount++;
superView.Add (view);
@@ -300,7 +300,7 @@ public class LayoutTests : GlobalTestSetup
Assert.Equal (2, layoutCompleteCount);
// With Border subview
view.Border.Add (new View ());
view.Border!.Add (new View ());
superView.LayoutSubViews ();
Assert.Equal (1, borderLayoutStartedCount);
Assert.Equal (1, borderLayoutCompleteCount);
@@ -338,8 +338,8 @@ public class LayoutTests : GlobalTestSetup
view.SubViewLayout += (sender, e) => layoutStartedCount++;
view.SubViewsLaidOut += (sender, e) => layoutCompleteCount++;
view.Border.SubViewLayout += (sender, e) => borderLayoutStartedCount++;
view.Border.SubViewsLaidOut += (sender, e) => borderLayoutCompleteCount++;
view.Border!.SubViewLayout += (sender, e) => borderLayoutStartedCount++;
view.Border!.SubViewsLaidOut += (sender, e) => borderLayoutCompleteCount++;
superView.Add (view);
Assert.Equal (0, borderLayoutStartedCount);

View File

@@ -119,7 +119,7 @@ public class ToScreenTests ()
Height = 1
};
view.Border.Add (subviewOfBorder);
view.Border!.Add (subviewOfBorder);
view.BeginInit ();
view.EndInit ();

View File

@@ -55,7 +55,7 @@ public class ViewportTests (ITestOutputHelper output)
Height = 10,
Width = 10,
};
superSuperView.Border.Thickness = new Thickness (borderThickness);
superSuperView.Border!.Thickness = new Thickness (borderThickness);
var superView = new View ()
{
@@ -64,7 +64,7 @@ public class ViewportTests (ITestOutputHelper output)
Height = Dim.Fill (),
Width = Dim.Fill ()
};
superView.Border.Thickness = new Thickness (borderThickness);
superView.Border!.Thickness = new Thickness (borderThickness);
superSuperView.Add (superView);
@@ -113,7 +113,7 @@ public class ViewportTests (ITestOutputHelper output)
Height = 10,
Width = 10,
};
superSuperView.Border.Thickness = new Thickness (borderThickness);
superSuperView.Border!.Thickness = new Thickness (borderThickness);
var superView = new View ()
{
@@ -122,7 +122,7 @@ public class ViewportTests (ITestOutputHelper output)
Height = Dim.Fill (),
Width = Dim.Fill ()
};
superView.Border.Thickness = new Thickness (borderThickness);
superView.Border!.Thickness = new Thickness (borderThickness);
superSuperView.Add (superView);
@@ -133,7 +133,7 @@ public class ViewportTests (ITestOutputHelper output)
Height = Dim.Fill (),
Width = Dim.Fill ()
};
view.Border.Thickness = new Thickness (borderThickness);
view.Border!.Thickness = new Thickness (borderThickness);
superView.Add (view);
superSuperView.BeginInit ();
@@ -328,7 +328,7 @@ public class ViewportTests (ITestOutputHelper output)
};
view.BeginInit ();
view.EndInit ();
view.Margin.Thickness = new (adornmentThickness);
view.Margin!.Thickness = new (adornmentThickness);
Assert.Equal (expectedOffset, view.GetViewportOffsetFromFrame ().X);
}

View File

@@ -236,14 +236,14 @@ public class SetFocusTests () : TestsAllViews
};
borderSubView.Add (subViewSubView1, subViewSubView2, subViewSubView3);
view.Border.Add (borderSubView);
view.Border!.Add (borderSubView);
view.SetFocus ();
Assert.True (view.HasFocus);
Assert.True (subView.HasFocus);
Assert.False (borderSubView.HasFocus);
view.Border.CanFocus = true;
view.Border!.CanFocus = true;
subViewSubView1.SetFocus ();
Assert.True (view.HasFocus);
Assert.False (subView.HasFocus);
@@ -252,47 +252,47 @@ public class SetFocusTests () : TestsAllViews
Assert.False (subViewSubView2.HasFocus);
Assert.False (subViewSubView3.HasFocus);
view.Border.CanFocus = false;
view.Border!.CanFocus = false;
Assert.True (view.HasFocus);
Assert.True (subView.HasFocus);
Assert.False (view.Border.HasFocus);
Assert.False (view.Border!.HasFocus);
Assert.False (borderSubView.HasFocus);
Assert.False (subViewSubView1.HasFocus);
Assert.False (subViewSubView2.HasFocus);
Assert.False (subViewSubView3.HasFocus);
view.Border.CanFocus = true;
view.Border!.CanFocus = true;
Assert.True (view.HasFocus);
Assert.True (subView.HasFocus);
Assert.False (view.Border.HasFocus);
Assert.False (view.Border!.HasFocus);
Assert.False (borderSubView.HasFocus);
Assert.False (subViewSubView1.HasFocus);
Assert.False (subViewSubView2.HasFocus);
Assert.False (subViewSubView3.HasFocus);
view.Border.SetFocus ();
view.Border!.SetFocus ();
Assert.True (view.HasFocus);
Assert.True (view.Border.HasFocus);
Assert.True (view.Border!.HasFocus);
Assert.False (subView.HasFocus);
Assert.True (borderSubView.HasFocus);
Assert.True (subViewSubView1.HasFocus);
Assert.False (subViewSubView2.HasFocus);
Assert.False (subViewSubView3.HasFocus);
view.Border.CanFocus = false;
view.Border!.CanFocus = false;
Assert.True (view.HasFocus);
Assert.True (subView.HasFocus);
Assert.False (view.Border.HasFocus);
Assert.False (view.Border!.HasFocus);
Assert.False (borderSubView.HasFocus);
Assert.False (subViewSubView1.HasFocus);
Assert.False (subViewSubView2.HasFocus);
Assert.False (subViewSubView3.HasFocus);
view.Border.CanFocus = true;
view.Border!.CanFocus = true;
subViewSubView1.SetFocus ();
Assert.True (view.HasFocus);
Assert.False (subView.HasFocus);
Assert.True (view.Border.HasFocus);
Assert.True (view.Border!.HasFocus);
Assert.True (borderSubView.HasFocus);
Assert.True (subViewSubView1.HasFocus);
Assert.False (subViewSubView2.HasFocus);
@@ -301,7 +301,7 @@ public class SetFocusTests () : TestsAllViews
subView.SetFocus ();
Assert.True (view.HasFocus);
Assert.True (subView.HasFocus);
Assert.False (view.Border.HasFocus);
Assert.False (view.Border!.HasFocus);
Assert.False (borderSubView.HasFocus);
Assert.False (subViewSubView1.HasFocus);
Assert.False (subViewSubView2.HasFocus);

View File

@@ -1,10 +1,11 @@
#nullable enable
using UnitTests.Parallelizable;
using Xunit;
namespace UnitTests_Parallelizable.ViewTests;
[Trait ("Category", "View.Scheme")]
public class SchemeTests
public class SchemeTests : ParallelizableBase
{
[Fact]
@@ -63,7 +64,7 @@ public class SchemeTests
public void GetAttribute_ReturnsCorrectAttribute_Via_Mock ()
{
var view = new View { SchemeName = "Base" };
view.Driver = new MockConsoleDriver ();
view.Driver = CreateFakeDriver ();
view.Driver.SetAttribute (new Attribute (Color.Red, Color.Green));
// Act
@@ -103,7 +104,7 @@ public class SchemeTests
public void SetAttributeForRole_SetsCorrectAttribute ()
{
var view = new View { SchemeName = "Base" };
view.Driver = new MockConsoleDriver ();
view.Driver = CreateFakeDriver ();
view.Driver.SetAttribute (new Attribute (Color.Red, Color.Green));
var previousAttribute = view.SetAttributeForRole (VisualRole.Focus);
@@ -316,16 +317,16 @@ public class SchemeTests
// Border (an Adornment) doesn't have a SuperView but should use its Parent's scheme
var view = new View { SchemeName = "Dialog" };
var border = view.Border!;
Assert.NotNull (border);
Assert.Null (border.SuperView); // Adornments don't have SuperView
Assert.NotNull (border.Parent);
var dialogScheme = SchemeManager.GetHardCodedSchemes ()? ["Dialog"];
// Border should use its Parent's scheme, not Base
Assert.Equal (dialogScheme!.Normal, border.GetAttributeForRole (VisualRole.Normal));
view.Dispose ();
}
@@ -365,11 +366,11 @@ public class SchemeTests
{
// Test: grandchild without explicit scheme defers through parent to grandparent
// Would fail without the SuperView deferral fix (commit 154ac15)
var grandparentView = new View { SchemeName = "Base" };
var parentView = new View (); // No scheme or SchemeName
var childView = new View (); // No scheme or SchemeName
grandparentView.Add (parentView);
parentView.Add (childView);
@@ -386,7 +387,7 @@ public class SchemeTests
// Child should get attribute from grandparent through parent
Assert.Equal (customAttribute, childView.GetAttributeForRole (VisualRole.Normal));
// Parent should also get attribute from grandparent
Assert.Equal (customAttribute, parentView.GetAttributeForRole (VisualRole.Normal));
@@ -400,11 +401,11 @@ public class SchemeTests
{
// Test: parent with SchemeName stops deferral chain
// Would fail without the SchemeName check (commit 866e002)
var grandparentView = new View { SchemeName = "Base" };
var parentView = new View { SchemeName = "Dialog" }; // Sets SchemeName
var childView = new View (); // No scheme or SchemeName
grandparentView.Add (parentView);
parentView.Add (childView);
@@ -423,7 +424,7 @@ public class SchemeTests
var dialogScheme = SchemeManager.GetHardCodedSchemes ()? ["Dialog"];
Assert.NotEqual (customAttribute, parentView.GetAttributeForRole (VisualRole.Normal));
Assert.Equal (dialogScheme!.Normal, parentView.GetAttributeForRole (VisualRole.Normal));
// Child should get parent's Dialog scheme (defers to parent, parent uses Dialog scheme)
Assert.Equal (dialogScheme!.Normal, childView.GetAttributeForRole (VisualRole.Normal));
@@ -437,7 +438,7 @@ public class SchemeTests
{
// Test: view's own OnGettingAttributeForRole takes precedence over parent
// This should work with or without the fix, but validates precedence
var parentView = new View { SchemeName = "Base" };
var childView = new TestViewWithAttributeOverride ();
parentView.Add (childView);
@@ -456,7 +457,7 @@ public class SchemeTests
// Child's own override should take precedence
var childOverrideAttribute = new Attribute (Color.BrightRed, Color.BrightCyan);
childView.OverrideAttribute = childOverrideAttribute;
Assert.Equal (childOverrideAttribute, childView.GetAttributeForRole (VisualRole.Normal));
childView.Dispose ();
@@ -468,7 +469,7 @@ public class SchemeTests
{
// Test: multiple VisualRoles all defer correctly
// Would fail without the SuperView deferral fix for any role
var parentView = new View { SchemeName = "Base" };
var childView = new View ();
parentView.Add (childView);