mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Initial plan * Delete AnsiColorNameResolver and MultiStandardColorNameResolver, add legacy 16-color names to StandardColor Co-authored-by: tig <585482+tig@users.noreply.github.com> * Refactor and enhance tests for Color, Region, and Lines Refactored `Color` struct by removing unused methods and simplifying logic. Updated namespaces for better organization. Enhanced test coverage for `Color`, `Region`, and `LineCanvas` with new test cases, parameterized tests, and edge case handling. Added `StraightLineExtensionsTests`, `StraightLineTests`, and `RegionClassTests` to validate behavior under various scenarios. Improved `MergeRectangles` stability and addressed crash patterns. Removed legacy features and unused code. Enhanced documentation and optimized performance in key methods. * Improve Color struct and StandardColors functionality Enhanced the Color struct to fully support the alpha channel for rendering intent while maintaining semantic color identity. Updated TryNameColor to ignore alpha when matching colors, ensuring transparency does not affect color resolution. Expanded XML documentation to clarify alpha channel usage and future alpha blending support. Improved drawing documentation to explain the lifecycle, deferred rendering, and color support, including 24-bit true color and legacy 16-color compatibility. Added a new section on transparency and its role in rendering. Revised StandardColors implementation to use modern C# features and ensure consistent ARGB mapping. Added comprehensive tests for StandardColors and Color, covering alpha handling, color parsing, thread safety, and aliased color resolution. Removed outdated tests relying on legacy behavior. Enhanced code readability, maintainability, and test coverage to ensure correctness and backward compatibility. * Code cleanup * Code cleanup * Fix warnings. Code cleanup * Add comprehensive unit tests for ColorStrings class Introduced a new test class `ColorStringsTests` under the `DrawingTests.ColorTests` namespace to validate the functionality of the `ColorStrings` class. Key changes include: - Added tests for `GetColorName` to verify behavior for standard and non-standard colors, ignoring alpha channels, and handling known colors. - Added tests for `GetStandardColorNames` to ensure the method returns a non-empty, alphabetically sorted collection containing all `StandardColor` enum values. - Implemented tests for `TryParseStandardColorName` to validate case-insensitive parsing, hex color support, handling invalid input, and `ReadOnlySpan<char>` compatibility. - Added tests for `TryParseNamedColor` to verify parsing of named and hex colors, handling of aliases, and `ReadOnlySpan<char>` support. - Added round-trip tests to ensure consistency between `GetColorName`, `TryParseNamedColor`, `GetStandardColorNames`, and `TryParseStandardColorName`. These tests ensure robust validation of color parsing and naming functionality. --------- 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>
UnitTests.Parallelizable
This project contains unit tests that can run in parallel without interference. Tests here must not depend on global state or static Application infrastructure.
Important Notes
- Many tests in
UnitTestsblindly use the the legacy model they don't actually need to - These tests CAN be rewritten to remove unnecessary dependencies and migrated here
- Many tests APPEAR to be integration tests but are just poorly written and cover multiple surface areas - these can be split into focused unit tests
- When in doubt, analyze if the test truly needs global state or can be refactored
Example Migrations
Simple Property Test (no changes needed)
// Before (in UnitTests)
[Fact]
public void Constructor_Sets_Defaults ()
{
var view = new Button ();
Assert.Empty (view.Text);
}
// After (in UnitTests.Parallelizable) - just move it!
[Fact]
public void Constructor_Sets_Defaults ()
{
var view = new Button ();
Assert.Empty (view.Text);
}
Remove Unnecessary [SetupFakeApplication]
// Before (in UnitTests)
[Fact]
[SetupFakeApplication]
public void Event_Fires_When_Property_Changes ()
{
var view = new Button ();
var fired = false;
view.TextChanged += (s, e) => fired = true;
view.Text = "Hello";
Assert.True (fired);
}
// After (in UnitTests.Parallelizable) - remove attribute!
[Fact]
public void Event_Fires_When_Property_Changes ()
{
var view = new Button ();
var fired = false;
view.TextChanged += (s, e) => fired = true;
view.Text = "Hello";
Assert.True (fired);
}
Replace Application.Begin with View Initialization
// Before (in UnitTests)
[Fact]
[AutoInitShutdown]
public void Focus_Test ()
{
var view = new Button ();
var top = new Runnable ();
top.Add (view);
Application.Begin (top);
view.SetFocus ();
Assert.True (view.HasFocus);
top.Dispose ();
}
// After (in UnitTests.Parallelizable) - use BeginInit/EndInit!
[Fact]
public void Focus_Test ()
{
var superView = new View ();
var view = new Button ();
superView.Add (view);
superView.BeginInit ();
superView.EndInit ();
view.SetFocus ();
Assert.True (view.HasFocus);
}
Running Tests
Tests in this project run in parallel automatically. To run them:
dotnet test Tests/UnitTestsParallelizable/UnitTests.Parallelizable.csproj