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

@@ -217,24 +217,6 @@ public class AttributeTests
Assert.Equal (attr1.GetHashCode (), attr2.GetHashCode ());
}
[Fact]
public void Implicit_Assign ()
{
var driver = new FakeDriver ();
driver.Init ();
var attr = new Attribute ();
var value = 42;
var fg = new Color ();
fg = new (Color.Red);
var bg = new Color ();
bg = new (Color.Blue);
driver.End ();
}
[Fact]
public void InequalityOperator_ShouldReturnFalseForEqualAttributes ()
{

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,8 @@
using Microsoft.VisualStudio.TestPlatform.Utilities;
using UnitTests;
using UnitTests.Parallelizable;
using Xunit.Abstractions;
namespace UnitTests_Parallelizable.DrawingTests;
/// <summary>
@@ -6,7 +11,7 @@ namespace UnitTests_Parallelizable.DrawingTests;
///
/// Note: Tests that verify rendered output (Draw methods) require Application.Driver and remain in UnitTests as integration tests.
/// </summary>
public class RulerTests : UnitTests.Parallelizable.ParallelizableBase
public class RulerTests (ITestOutputHelper output): ParallelizableBase
{
[Fact]
public void Constructor_Defaults ()
@@ -43,4 +48,143 @@ public class RulerTests : UnitTests.Parallelizable.ParallelizableBase
r.Orientation = Orientation.Vertical;
Assert.Equal (Orientation.Vertical, r.Orientation);
}
[Fact]
public void Draw_Default ()
{
IConsoleDriver driver = CreateFakeDriver ();
var r = new Ruler ();
r.Draw (Point.Empty, driver: driver);
DriverAssert.AssertDriverContentsWithFrameAre (@"", output, driver);
}
[Fact]
public void Draw_Horizontal ()
{
IConsoleDriver driver = CreateFakeDriver ();
var len = 15;
var r = new Ruler ();
Assert.Equal (Orientation.Horizontal, r.Orientation);
r.Length = len;
r.Draw (Point.Empty, driver: driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
|123456789|1234",
output,
driver
);
// Postive offset
r.Draw (new (1, 1), driver: driver);
DriverAssert.AssertDriverContentsAre (
@"
|123456789|1234
|123456789|1234
",
output,
driver
);
// Negative offset
r.Draw (new (-1, 3), driver: driver);
DriverAssert.AssertDriverContentsAre (
@"
|123456789|1234
|123456789|1234
123456789|1234
",
output,
driver
);
}
[Fact]
public void Draw_Vertical ()
{
IConsoleDriver driver = CreateFakeDriver ();
var len = 15;
var r = new Ruler ();
r.Orientation = Orientation.Vertical;
r.Length = len;
r.Draw (Point.Empty, driver: driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
-
1
2
3
4
5
6
7
8
9
-
1
2
3
4",
output,
driver
);
r.Draw (new (1, 1), driver: driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
-
1-
21
32
43
54
65
76
87
98
-9
1-
21
32
43
4",
output,
driver
);
// Negative offset
r.Draw (new (2, -1), driver: driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
- 1
1-2
213
324
435
546
657
768
879
98-
-91
1-2
213
324
43
4 ",
output,
driver
);
}
}

View File

@@ -0,0 +1,478 @@
using Xunit.Abstractions;
namespace UnitTests.DrawingTests;
public class StraightLineExtensionsTests (ITestOutputHelper output)
{
[Fact]
public void LineCanvasIntegrationTest ()
{
var lc = new LineCanvas ();
lc.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Single);
lc.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Single);
lc.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
lc.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Single);
OutputAssert.AssertEqual (
output,
@"
┌────────┐
│ │
│ │
│ │
└────────┘",
$"{Environment.NewLine}{lc}"
);
IReadOnlyCollection<StraightLine> origLines = lc.Lines;
lc = new (origLines.Exclude (Point.Empty, 10, Orientation.Horizontal));
OutputAssert.AssertEqual (
output,
@"
│ │
│ │
│ │
└────────┘",
$"{Environment.NewLine}{lc}"
);
lc = new (origLines.Exclude (new (0, 1), 10, Orientation.Horizontal));
OutputAssert.AssertEqual (
output,
@"
┌────────┐
│ │
│ │
└────────┘",
$"{Environment.NewLine}{lc}"
);
lc = new (origLines.Exclude (new (0, 2), 10, Orientation.Horizontal));
OutputAssert.AssertEqual (
output,
@"
┌────────┐
│ │
│ │
└────────┘",
$"{Environment.NewLine}{lc}"
);
lc = new (origLines.Exclude (new (0, 3), 10, Orientation.Horizontal));
OutputAssert.AssertEqual (
output,
@"
┌────────┐
│ │
│ │
└────────┘",
$"{Environment.NewLine}{lc}"
);
lc = new (origLines.Exclude (new (0, 4), 10, Orientation.Horizontal));
OutputAssert.AssertEqual (
output,
@"
┌────────┐
│ │
│ │
│ │",
$"{Environment.NewLine}{lc}"
);
lc = new (origLines.Exclude (Point.Empty, 10, Orientation.Vertical));
OutputAssert.AssertEqual (
output,
@"
────────┐
────────┘",
$"{Environment.NewLine}{lc}"
);
lc = new (origLines.Exclude (new (1, 0), 10, Orientation.Vertical));
OutputAssert.AssertEqual (
output,
@"
┌ ───────┐
│ │
│ │
│ │
└ ───────┘",
$"{Environment.NewLine}{lc}"
);
lc = new (origLines.Exclude (new (8, 0), 10, Orientation.Vertical));
OutputAssert.AssertEqual (
output,
@"
┌─────── ┐
│ │
│ │
│ │
└─────── ┘",
$"{Environment.NewLine}{lc}"
);
lc = new (origLines.Exclude (new (9, 0), 10, Orientation.Vertical));
OutputAssert.AssertEqual (
output,
@"
┌────────
└────────",
$"{Environment.NewLine}{lc}"
);
}
#region Parallel Tests
[Fact]
public void TestExcludeParallel_HorizontalLines_LeftOnly ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=3 to x=103
.Exclude (new (3, 2), 100, Orientation.Horizontal)
.ToArray ();
// x=1 to x=2
StraightLine afterLine = Assert.Single (after);
Assert.Equal (l1.Start, afterLine.Start);
Assert.Equal (2, afterLine.Length);
}
[Fact]
public void TestExcludeParallel_HorizontalLines_RightOnly ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=0 to x=2
.Exclude (new (0, 2), 3, Orientation.Horizontal)
.ToArray ();
// x=3 to x=10
StraightLine afterLine = Assert.Single (after);
Assert.Equal (3, afterLine.Start.X);
Assert.Equal (2, afterLine.Start.Y);
Assert.Equal (8, afterLine.Length);
}
[Fact]
public void TestExcludeParallel_HorizontalLines_HorizontalSplit ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=4 to x=5
.Exclude (new (4, 2), 2, Orientation.Horizontal)
.ToArray ();
// x=1 to x=3,
// x=6 to x=10
Assert.Equal (2, after.Length);
StraightLine afterLeft = after [0];
StraightLine afterRight = after [1];
Assert.Equal (1, afterLeft.Start.X);
Assert.Equal (2, afterLeft.Start.Y);
Assert.Equal (3, afterLeft.Length);
Assert.Equal (6, afterRight.Start.X);
Assert.Equal (2, afterRight.Start.Y);
Assert.Equal (5, afterRight.Length);
}
[Fact]
public void TestExcludeParallel_HorizontalLines_CoverCompletely ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=4 to x=5
.Exclude (new (1, 2), 10, Orientation.Horizontal)
.ToArray ();
Assert.Empty (after);
}
[Fact]
public void TestExcludeParallel_VerticalLines_TopOnly ()
{
// y=1 to y=10
var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude y=3 to y=103
.Exclude (new (2, 3), 100, Orientation.Vertical)
.ToArray ();
// y=1 to y=2
StraightLine afterLine = Assert.Single (after);
Assert.Equal (l1.Start, afterLine.Start);
Assert.Equal (2, afterLine.Length);
}
[Fact]
public void TestExcludeParallel_HorizontalLines_BottomOnly ()
{
// y=1 to y=10
var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude y=0 to y=2
.Exclude (new (2, 0), 3, Orientation.Vertical)
.ToArray ();
// y=3 to y=10
StraightLine afterLine = Assert.Single (after);
Assert.Equal (3, afterLine.Start.Y);
Assert.Equal (2, afterLine.Start.X);
Assert.Equal (8, afterLine.Length);
}
[Fact]
public void TestExcludeParallel_VerticalLines_VerticalSplit ()
{
// y=1 to y=10
var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude y=4 to y=5
.Exclude (new (2, 4), 2, Orientation.Vertical)
.ToArray ();
// y=1 to y=3,
// y=6 to y=10
Assert.Equal (2, after.Length);
StraightLine afterLeft = after [0];
StraightLine afterRight = after [1];
Assert.Equal (1, afterLeft.Start.Y);
Assert.Equal (2, afterLeft.Start.X);
Assert.Equal (3, afterLeft.Length);
Assert.Equal (6, afterRight.Start.Y);
Assert.Equal (2, afterRight.Start.X);
Assert.Equal (5, afterRight.Length);
}
[Fact]
public void TestExcludeParallel_VerticalLines_CoverCompletely ()
{
// y=1 to y=10
var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude y=4 to y=5
.Exclude (new (2, 1), 10, Orientation.Vertical)
.ToArray ();
Assert.Empty (after);
}
#endregion
#region Perpendicular Intersection Tests
[Fact]
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_Splits ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=3 y=0-10
.Exclude (new (3, 0), 10, Orientation.Vertical)
.ToArray ();
// x=1 to x=2,
// x=4 to x=10
Assert.Equal (2, after.Length);
StraightLine afterLeft = after [0];
StraightLine afterRight = after [1];
Assert.Equal (1, afterLeft.Start.X);
Assert.Equal (2, afterLeft.Start.Y);
Assert.Equal (2, afterLeft.Length);
Assert.Equal (4, afterRight.Start.X);
Assert.Equal (2, afterRight.Start.Y);
Assert.Equal (7, afterRight.Length);
}
[Fact]
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipLeft ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=1 y=0-10
.Exclude (new (1, 0), 10, Orientation.Vertical)
.ToArray ();
// x=2 to x=10,
StraightLine lineAfter = Assert.Single (after);
Assert.Equal (2, lineAfter.Start.X);
Assert.Equal (2, lineAfter.Start.Y);
Assert.Equal (9, lineAfter.Length);
}
[Fact]
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_ClipRight ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=10 y=0-10
.Exclude (new (10, 0), 10, Orientation.Vertical)
.ToArray ();
// x=1 to x=9,
StraightLine lineAfter = Assert.Single (after);
Assert.Equal (1, lineAfter.Start.X);
Assert.Equal (2, lineAfter.Start.Y);
Assert.Equal (9, lineAfter.Length);
}
[Fact]
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissLeft ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=0 y=0-10
.Exclude (Point.Empty, 10, Orientation.Vertical)
.ToArray ();
// Exclusion line is too far to the left so hits nothing
Assert.Same (Assert.Single (after), l1);
}
[Fact]
public void TestExcludePerpendicular_HorizontalLine_VerticalExclusion_MissRight ()
{
// x=1 to x=10
var l1 = new StraightLine (new (1, 2), 10, Orientation.Horizontal, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude x=11 y=0-10
.Exclude (new (11, 0), 10, Orientation.Vertical)
.ToArray ();
// Exclusion line is too far to the right so hits nothing
Assert.Same (Assert.Single (after), l1);
}
[Fact]
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipTop ()
{
// y=1 to y=10
var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude y=1 x=0-10
.Exclude (new (0, 1), 10, Orientation.Horizontal)
.ToArray ();
// y=2 to y=10,
StraightLine lineAfter = Assert.Single (after);
Assert.Equal (2, lineAfter.Start.Y);
Assert.Equal (2, lineAfter.Start.X);
Assert.Equal (9, lineAfter.Length);
}
[Fact]
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_ClipBottom ()
{
// y=1 to y=10
var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude y=10 x=0-10
.Exclude (new (0, 10), 10, Orientation.Horizontal)
.ToArray ();
// y=1 to y=9,
StraightLine lineAfter = Assert.Single (after);
Assert.Equal (1, lineAfter.Start.Y);
Assert.Equal (2, lineAfter.Start.X);
Assert.Equal (9, lineAfter.Length);
}
[Fact]
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissTop ()
{
// y=1 to y=10
var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude y=0 x=0-10
.Exclude (Point.Empty, 10, Orientation.Horizontal)
.ToArray ();
// Exclusion line is too far above so hits nothing
Assert.Same (Assert.Single (after), l1);
}
[Fact]
public void TestExcludePerpendicular_VerticalLine_HorizontalExclusion_MissBottom ()
{
// y=1 to y=10
var l1 = new StraightLine (new (2, 1), 10, Orientation.Vertical, LineStyle.Single);
StraightLine [] after = new [] { l1 }
// exclude y=11 x=0-10
.Exclude (new (0, 11), 10, Orientation.Horizontal)
.ToArray ();
// Exclusion line is too far to the right so hits nothing
Assert.Same (Assert.Single (after), l1);
}
#endregion Perpendicular Intersection Tests
}

View File

@@ -1,6 +1,11 @@
namespace UnitTests_Parallelizable.DrawingTests;
using System.Text;
using UnitTests;
using UnitTests.Parallelizable;
using Xunit.Abstractions;
public class ThicknessTests
namespace UnitTests_Parallelizable.DrawingTests;
public class ThicknessTests (ITestOutputHelper output) : ParallelizableBase
{
[Fact]
public void Constructor_Defaults ()
@@ -616,4 +621,263 @@ public class ThicknessTests
Assert.Equal (expectedRight, result.Right);
Assert.Equal (expectedBottom, result.Bottom);
}
[Fact]
public void DrawTests ()
{
IConsoleDriver driver = new FakeDriver ();
driver.SetScreenSize (60, 40);
var t = new Thickness (0, 0, 0, 0);
var r = new Rectangle (5, 5, 40, 15);
driver.FillRect (
new (0, 0, driver!.Cols, driver!.Rows),
(Rune)' '
);
t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
Test (Left=0,Top=0,Right=0,Bottom=0)",
output,
driver
);
t = new (1, 1, 1, 1);
r = new (5, 5, 40, 15);
driver.FillRect (
new (0, 0, driver!.Cols, driver!.Rows),
(Rune)' '
);
t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
T T
T T
T T
T T
T T
T T
T T
T T
T T
T T
T T
T T
T T
TTTest (Left=1,Top=1,Right=1,Bottom=1)TT",
output,
driver
);
t = new (1, 2, 3, 4);
r = new (5, 5, 40, 15);
driver?.FillRect (
new (0, 0, driver!.Cols, driver!.Rows),
(Rune)' '
);
t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
T TTT
T TTT
T TTT
T TTT
T TTT
T TTT
T TTT
T TTT
T TTT
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
TTTest (Left=1,Top=2,Right=3,Bottom=4)TT",
output,
driver
);
t = new (-1, 1, 1, 1);
r = new (5, 5, 40, 15);
driver?.FillRect (
new (0, 0, driver!.Cols, driver!.Rows),
(Rune)' '
);
t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
T
T
T
T
T
T
T
T
T
T
T
T
T
TTest (Left=-1,Top=1,Right=1,Bottom=1)TT",
output,
driver
);
}
[Fact]
public void DrawTests_Ruler ()
{
IConsoleDriver driver = new FakeDriver ();
// Add a frame so we can see the ruler
var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (), BorderStyle = LineStyle.Single };
f.Driver = driver;
driver.SetScreenSize (45, 20);
var top = new Toplevel () { Width = driver.Cols, Height = driver.Rows };
top.Driver = driver;
top.Add (f);
top.Layout ();
var t = new Thickness (0, 0, 0, 0);
var r = new Rectangle (2, 2, 40, 15);
top.Draw ();
t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
DriverAssert.AssertDriverContentsAre (
@"
┌───────────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└───────────────────────────────────────────┘",
output,
driver
);
t = new (1, 1, 1, 1);
r = new (1, 1, 40, 15);
top.SetNeedsDraw ();
top.Draw ();
t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
DriverAssert.AssertDriverContentsAre (
@"
┌───────────────────────────────────────────┐
│|123456789|123456789|123456789|123456789 │
│1 1 │
│2 2 │
│3 3 │
│4 4 │
│5 5 │
│6 6 │
│7 7 │
│8 8 │
│9 9 │
│- - │
│1 1 │
│2 2 │
│3 3 │
│|123456789|123456789|123456789|123456789 │
│ │
│ │
│ │
└───────────────────────────────────────────┘",
output,
driver
);
t = new (1, 2, 3, 4);
r = new (2, 2, 40, 15);
top.SetNeedsDraw ();
top.Draw ();
t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
┌───────────────────────────────────────────┐
│ │
│ |123456789|123456789|123456789|123456789 │
│ 1 1 │
│ 2 2 │
│ 3 3 │
│ 4 4 │
│ 5 5 │
│ 6 6 │
│ 7 7 │
│ 8 8 │
│ 9 9 │
│ - - │
│ 1 1 │
│ 2 2 │
│ 3 3 │
│ |123456789|123456789|123456789|123456789 │
│ │
│ │
└───────────────────────────────────────────┘",
output,
driver
);
t = new (-1, 1, 1, 1);
r = new (5, 5, 40, 15);
top.SetNeedsDraw ();
top.Draw ();
t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
DriverAssert.AssertDriverContentsWithFrameAre (
@"
┌───────────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ |123456789|123456789|123456789|123456789
│ 1
│ 2
│ 3
│ 4
│ 5
│ 6
│ 7
│ 8
│ 9
│ -
│ 1
│ 2
│ 3
└────|123456789|123456789|123456789|123456789",
output,
driver
);
top.Dispose ();
}
}