mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* 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:
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
using Terminal.Gui.App;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@@ -89,7 +90,7 @@ public class MouseInterfaceTests (ITestOutputHelper output)
|
||||
// Arrange
|
||||
MouseImpl mouse = new ();
|
||||
var eventFired = false;
|
||||
MouseEventArgs capturedArgs = null;
|
||||
MouseEventArgs? capturedArgs = null;
|
||||
|
||||
mouse.MouseEvent += (sender, args) =>
|
||||
{
|
||||
@@ -120,7 +121,7 @@ public class MouseInterfaceTests (ITestOutputHelper output)
|
||||
MouseImpl mouse = new ();
|
||||
var eventCount = 0;
|
||||
|
||||
void Handler (object sender, MouseEventArgs args) => eventCount++;
|
||||
void Handler (object? sender, MouseEventArgs args) => eventCount++;
|
||||
|
||||
mouse.MouseEvent += Handler;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace UnitTests_Parallelizable.DriverTests;
|
||||
using UnitTests.Parallelizable;
|
||||
|
||||
public class EscSeqRequestsTests : UnitTests.Parallelizable.ParallelizableBase
|
||||
namespace UnitTests_Parallelizable.DriverTests;
|
||||
|
||||
public class EscSeqRequestsTests : ParallelizableBase
|
||||
{
|
||||
[Fact]
|
||||
public void Add_Tests ()
|
||||
@@ -122,67 +124,4 @@ public class EscSeqRequestsTests : UnitTests.Parallelizable.ParallelizableBase
|
||||
|
||||
EscSeqRequests.Clear ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Requests_Responses_Tests ()
|
||||
{
|
||||
// This is simulated response from a CSI_ReportTerminalSizeInChars
|
||||
ConsoleKeyInfo [] cki =
|
||||
[
|
||||
new ('\u001b', 0, false, false, false),
|
||||
new ('[', 0, false, false, false),
|
||||
new ('8', 0, false, false, false),
|
||||
new (';', 0, false, false, false),
|
||||
new ('1', 0, false, false, false),
|
||||
new ('0', 0, false, false, false),
|
||||
new (';', 0, false, false, false),
|
||||
new ('2', 0, false, false, false),
|
||||
new ('0', 0, false, false, false),
|
||||
new ('t', 0, false, false, false)
|
||||
];
|
||||
ConsoleKeyInfo newConsoleKeyInfo = default;
|
||||
ConsoleKey key = default;
|
||||
ConsoleModifiers mod = default;
|
||||
|
||||
Assert.Empty (EscSeqRequests.Statuses);
|
||||
|
||||
EscSeqRequests.Add ("t");
|
||||
Assert.Single (EscSeqRequests.Statuses);
|
||||
Assert.Equal ("t", EscSeqRequests.Statuses [^1].Terminator);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumRequests);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumOutstanding);
|
||||
|
||||
EscSeqUtils.DecodeEscSeq (
|
||||
ref newConsoleKeyInfo,
|
||||
ref key,
|
||||
cki,
|
||||
ref mod,
|
||||
out string c1Control,
|
||||
out string code,
|
||||
out string [] values,
|
||||
out string terminating,
|
||||
out bool isKeyMouse,
|
||||
out List<MouseFlags> mouseFlags,
|
||||
out Point pos,
|
||||
out bool isResponse,
|
||||
null
|
||||
);
|
||||
|
||||
Assert.Empty (EscSeqRequests.Statuses);
|
||||
Assert.Equal (default, newConsoleKeyInfo);
|
||||
Assert.Equal (default, key);
|
||||
Assert.Equal (10, cki.Length);
|
||||
Assert.Equal (default, mod);
|
||||
Assert.Equal ("CSI", c1Control);
|
||||
Assert.Null (code);
|
||||
// ReSharper disable once HeuristicUnreachableCode
|
||||
Assert.Equal (3, values.Length);
|
||||
Assert.Equal ("8", values [0]);
|
||||
Assert.Equal ("t", terminating);
|
||||
Assert.False (isKeyMouse);
|
||||
Assert.Single (mouseFlags);
|
||||
Assert.Equal (default, mouseFlags [^1]);
|
||||
Assert.Equal (Point.Empty, pos);
|
||||
Assert.True (isResponse);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Text;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
namespace UnitTests_Parallelizable.ConoleDriverTests;
|
||||
|
||||
public class Osc8UrlLinkerTests (ITestOutputHelper output)
|
||||
{
|
||||
|
||||
@@ -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
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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 ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,4 +573,22 @@ public class KeyTests
|
||||
Key b = Key.A;
|
||||
Assert.False (a.Equals (b));
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void KeyPressed_Handled_True_Cancels_KeyPress ()
|
||||
{
|
||||
var r = new View ();
|
||||
var args = new Key { KeyCode = KeyCode.Null };
|
||||
|
||||
Assert.False (r.NewKeyDownEvent (args));
|
||||
Assert.False (args.Handled);
|
||||
|
||||
r.KeyDown += (s, a) => a.Handled = true;
|
||||
Assert.True (r.NewKeyDownEvent (args));
|
||||
Assert.True (args.Handled);
|
||||
|
||||
r.Dispose ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
|
||||
namespace UnitTests_Parallelizable.InputTests;
|
||||
|
||||
public class ResponderTests
|
||||
{
|
||||
[Fact]
|
||||
public void KeyPressed_Handled_True_Cancels_KeyPress ()
|
||||
{
|
||||
var r = new View ();
|
||||
var args = new Key { KeyCode = KeyCode.Null };
|
||||
|
||||
Assert.False (r.NewKeyDownEvent (args));
|
||||
Assert.False (args.Handled);
|
||||
|
||||
r.KeyDown += (s, a) => a.Handled = true;
|
||||
Assert.True (r.NewKeyDownEvent (args));
|
||||
Assert.True (args.Handled);
|
||||
|
||||
r.Dispose ();
|
||||
}
|
||||
|
||||
public class DerivedView : View
|
||||
{
|
||||
protected override bool OnKeyDown (Key keyEvent) { return true; }
|
||||
}
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
#nullable enable
|
||||
using System.Text;
|
||||
|
||||
|
||||
internal class MockConsoleDriver : IConsoleDriver
|
||||
{
|
||||
public event EventHandler<Attribute>? AttributeSet;
|
||||
|
||||
private IClipboard? _clipboard;
|
||||
private Rectangle _screen;
|
||||
private Region? _clip;
|
||||
private int _col;
|
||||
private int _cols;
|
||||
private Cell [,]? _contents;
|
||||
private int _left;
|
||||
private int _row;
|
||||
private int _rows;
|
||||
private int _top;
|
||||
private bool _supportsTrueColor;
|
||||
private bool _force16Colors;
|
||||
private Attribute _currentAttribute;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IClipboard? Clipboard => _clipboard;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Rectangle Screen => _screen;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Region? Clip
|
||||
{
|
||||
get => _clip;
|
||||
set => _clip = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Col => _col;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Cols
|
||||
{
|
||||
get => _cols;
|
||||
set => _cols = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Cell [,]? Contents
|
||||
{
|
||||
get => _contents;
|
||||
set => _contents = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Left
|
||||
{
|
||||
get => _left;
|
||||
set => _left = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Row => _row;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Rows
|
||||
{
|
||||
get => _rows;
|
||||
set => _rows = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Top
|
||||
{
|
||||
get => _top;
|
||||
set => _top = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsTrueColor => _supportsTrueColor;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Force16Colors
|
||||
{
|
||||
get => _force16Colors;
|
||||
set => _force16Colors = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Attribute CurrentAttribute
|
||||
{
|
||||
get => _currentAttribute;
|
||||
set => _currentAttribute = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string GetVersionInfo () { return string.Empty; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void WriteRaw (string ansi) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsRuneSupported (Rune rune) { return true; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsValidLocation (Rune rune, int col, int row) { return true; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Move (int col, int row)
|
||||
{
|
||||
_col = col;
|
||||
_row = row;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddRune (Rune rune) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddRune (char c) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddStr (string str) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ClearContents () { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<EventArgs>? ClearedContents;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void FillRect (Rectangle rect, Rune rune = default) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void FillRect (Rectangle rect, char c) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool GetCursorVisibility (out CursorVisibility visibility)
|
||||
{
|
||||
visibility = CursorVisibility.Invisible;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Refresh () { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SetCursorVisibility (CursorVisibility visibility) { throw new NotImplementedException (); }
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<SizeChangedEventArgs>? SizeChanged;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Suspend () { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void UpdateCursor () {}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Init () { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void End () { }
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
/// <inheritdoc />
|
||||
public Attribute SetAttribute (Attribute c)
|
||||
{
|
||||
Attribute oldAttribute = _currentAttribute;
|
||||
_currentAttribute = c;
|
||||
|
||||
AttributeSet?.Invoke (this, c);
|
||||
|
||||
return oldAttribute;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Attribute GetAttribute ()
|
||||
{
|
||||
return _currentAttribute;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public Attribute MakeColor (in Color foreground, in Color background) { throw new NotImplementedException (); }
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<MouseEventArgs>? MouseEvent;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<Key>? KeyDown;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler<Key>? KeyUp;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool ctrl) { throw new NotImplementedException (); }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void QueueAnsiRequest (AnsiEscapeSequenceRequest request) { throw new NotImplementedException (); }
|
||||
|
||||
/// <inheritdoc />
|
||||
public AnsiRequestScheduler GetRequestScheduler () { throw new NotImplementedException (); }
|
||||
}
|
||||
@@ -20,11 +20,10 @@ public abstract class ParallelizableBase
|
||||
/// <param name="width">Width of the driver buffer</param>
|
||||
/// <param name="height">Height of the driver buffer</param>
|
||||
/// <returns>A configured IFakeConsoleDriver instance</returns>
|
||||
protected static IFakeConsoleDriver CreateFakeDriver (int width = 25, int height = 25)
|
||||
protected static IConsoleDriver CreateFakeDriver (int width = 25, int height = 25)
|
||||
{
|
||||
var factory = new FakeDriverFactory ();
|
||||
IFakeConsoleDriver driver = factory.Create ();
|
||||
driver.SetBufferSize (width, height);
|
||||
IConsoleDriver driver = new FakeDriver ();
|
||||
driver.SetScreenSize (width, height);
|
||||
return driver;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="..\UnitTests\TestsAllViews.cs" Link="TestsAllViews.cs" />
|
||||
<Compile Include="..\UnitTests\DriverAssert.cs" Link="DriverAssert.cs" />
|
||||
<Compile Include="..\UnitTests\OutputAssert.cs" Link="OutputAssert.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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) });
|
||||
}
|
||||
|
||||
|
||||
@@ -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..");
|
||||
}
|
||||
|
||||
|
||||
@@ -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)))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class ToScreenTests ()
|
||||
Height = 1
|
||||
};
|
||||
|
||||
view.Border.Add (subviewOfBorder);
|
||||
view.Border!.Add (subviewOfBorder);
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -146,37 +146,37 @@ public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
|
||||
view?.Dispose ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData (nameof (AllViewTypes))]
|
||||
public void AllViews_Disabled_Draws_Disabled_Or_Faint (Type viewType)
|
||||
{
|
||||
var view = CreateInstanceIfNotGeneric (viewType);
|
||||
//[Theory]
|
||||
//[MemberData (nameof (AllViewTypes))]
|
||||
//public void AllViews_Disabled_Draws_Disabled_Or_Faint (Type viewType)
|
||||
//{
|
||||
// var view = CreateInstanceIfNotGeneric (viewType);
|
||||
|
||||
if (view == null)
|
||||
{
|
||||
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
|
||||
// if (view == null)
|
||||
// {
|
||||
// output.WriteLine ($"Ignoring {viewType} - It's a Generic");
|
||||
|
||||
return;
|
||||
}
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (view is IDesignable designable)
|
||||
{
|
||||
designable.EnableForDesign ();
|
||||
}
|
||||
// if (view is IDesignable designable)
|
||||
// {
|
||||
// designable.EnableForDesign ();
|
||||
// }
|
||||
|
||||
var mockDriver = new MockConsoleDriver ();
|
||||
mockDriver.AttributeSet += (_, args) =>
|
||||
{
|
||||
if (args != view.GetAttributeForRole (VisualRole.Disabled) && args.Style != TextStyle.Faint)
|
||||
{
|
||||
Assert.Fail($"{viewType} with `Enabled == false` tried to SetAttribute to {args}");
|
||||
}
|
||||
};
|
||||
view.Driver = mockDriver;
|
||||
view.Enabled = false;
|
||||
view.SetNeedsDraw ();
|
||||
view.Draw ();
|
||||
// var driver = CreateFakeDriver ();
|
||||
// driver.AttributeSet += (_, args) =>
|
||||
// {
|
||||
// if (args != view.GetAttributeForRole (VisualRole.Disabled) && args.Style != TextStyle.Faint)
|
||||
// {
|
||||
// Assert.Fail($"{viewType} with `Enabled == false` tried to SetAttribute to {args}");
|
||||
// }
|
||||
// };
|
||||
// view.Driver = driver;
|
||||
// view.Enabled = false;
|
||||
// view.SetNeedsDraw ();
|
||||
// view.Draw ();
|
||||
|
||||
view?.Dispose ();
|
||||
}
|
||||
// view?.Dispose ();
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Xunit.Abstractions;
|
||||
|
||||
namespace UnitTests_Parallelizable.ViewsTests;
|
||||
|
||||
public class CheckBoxTests (ITestOutputHelper output)
|
||||
public class CheckBoxTests ()
|
||||
{
|
||||
[Theory]
|
||||
[InlineData ("01234", 0, 0, 0, 0)]
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System.Text;
|
||||
using UnitTests;
|
||||
using UnitTests.Parallelizable;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace UnitTests_Parallelizable.ViewsTests;
|
||||
|
||||
public class TextFieldTests
|
||||
public class TextFieldTests (ITestOutputHelper output) : ParallelizableBase
|
||||
{
|
||||
[Fact]
|
||||
public void Cancel_TextChanging_ThenBackspace ()
|
||||
@@ -554,4 +557,80 @@ public class TextFieldTests
|
||||
Assert.Equal (new (3, 0), tf.PositionCursor ());
|
||||
Assert.Equal ("📄a", tf.Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Accented_Letter_With_Three_Combining_Unicode_Chars ()
|
||||
{
|
||||
IConsoleDriver driver = CreateFakeDriver ();
|
||||
|
||||
var tf = new TextField { Width = 3, Text = "ắ" };
|
||||
tf.Driver = driver;
|
||||
tf.Layout ();
|
||||
tf.Draw ();
|
||||
|
||||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
ắ",
|
||||
output,
|
||||
driver
|
||||
);
|
||||
|
||||
tf.Text = "\u1eaf";
|
||||
tf.Layout ();
|
||||
tf.Draw ();
|
||||
|
||||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
ắ",
|
||||
output,
|
||||
driver
|
||||
);
|
||||
|
||||
tf.Text = "\u0103\u0301";
|
||||
tf.Layout ();
|
||||
tf.Draw ();
|
||||
|
||||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
ắ",
|
||||
output,
|
||||
driver
|
||||
);
|
||||
|
||||
tf.Text = "\u0061\u0306\u0301";
|
||||
tf.Layout ();
|
||||
tf.Draw ();
|
||||
|
||||
DriverAssert.AssertDriverContentsWithFrameAre (
|
||||
@"
|
||||
ắ",
|
||||
output,
|
||||
driver
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Adjust_First ()
|
||||
{
|
||||
IConsoleDriver driver = CreateFakeDriver ();
|
||||
|
||||
var tf = new TextField { Width = Dim.Fill (), Text = "This is a test." };
|
||||
tf.Driver = driver;
|
||||
tf.SetRelativeLayout (new (20, 20));
|
||||
tf.Draw ();
|
||||
|
||||
Assert.Equal ("This is a test. ", GetContents ());
|
||||
|
||||
string GetContents ()
|
||||
{
|
||||
var item = "";
|
||||
|
||||
for (var i = 0; i < 16; i++)
|
||||
{
|
||||
item += driver.Contents [0, i]!.Rune;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user