Fixes #4289 - Simplify Drawing/Color: unify named color handling under StandardColor and remove layered resolvers (#4432)

* 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>
This commit is contained in:
Copilot
2025-12-03 11:09:02 -07:00
committed by GitHub
parent c9868e9901
commit 6d53276be2
43 changed files with 951 additions and 835 deletions

View File

@@ -52,7 +52,7 @@ public class ColorJsonConverterTests
[InlineData (ColorName16.Red, "Red")]
[InlineData (ColorName16.Magenta, "Fuchsia")] // W3C+ Standard overrides
[InlineData (ColorName16.Yellow, "Yellow")]
[InlineData (ColorName16.DarkGray, "DarkGray")]
[InlineData (ColorName16.DarkGray, "BrightBlack")] // Legacy ColorName16.DarkGray now serializes as BrightBlack (first alphabetical match)
[InlineData (ColorName16.BrightBlue, "BrightBlue")]
[InlineData (ColorName16.BrightGreen, "BrightGreen")]
[InlineData (ColorName16.BrightCyan, "BrightCyan")]
@@ -98,7 +98,7 @@ public class ColorJsonConverterTests
[InlineData ("BrightYellow", Color.BrightYellow)]
[InlineData ("Yellow", Color.Yellow)]
[InlineData ("Cyan", Color.Cyan)]
[InlineData ("DarkGray", Color.DarkGray)]
[InlineData ("BrightBlack", Color.DarkGray)] // Legacy ColorName16.DarkGray is now accessible as BrightBlack
[InlineData ("Gray", Color.Gray)]
[InlineData ("Green", Color.Green)]
[InlineData ("Magenta", Color.Magenta)]
@@ -113,7 +113,7 @@ public class ColorJsonConverterTests
var actualColor = JsonSerializer.Deserialize<Color> (json, JsonOptions);
// Assert
Assert.Equal (new Color (expectedColor), actualColor);
Assert.Equal (new (expectedColor), actualColor);
}
[Fact]

View File

@@ -12,7 +12,7 @@ public class SourcesManagerTests
// Arrange
var sourcesManager = new SourcesManager ();
var stream = new MemoryStream ();
var source = "test.json";
var source = "Load_WithNullSettingsScope_ReturnsFalse";
var location = ConfigLocations.AppCurrent;
// Act
@@ -37,7 +37,7 @@ public class SourcesManagerTests
}
""";
var location = ConfigLocations.HardCoded;
var source = "stream";
var source = "Load_WithValidStream_UpdatesSettingsScope";
var stream = new MemoryStream ();
var writer = new StreamWriter (stream);
@@ -69,7 +69,7 @@ public class SourcesManagerTests
writer.Flush ();
stream.Position = 0;
var source = "test.json";
var source = "Load_WithInvalidJson_AddsJsonError";
var location = ConfigLocations.AppCurrent;
// Act
@@ -180,7 +180,7 @@ public class SourcesManagerTests
var sourcesManager = new SourcesManager ();
var settingsScope = new SettingsScope ();
var source = "test.json";
var source = "Load_WithNullOrEmptyJson_ReturnsFalse";
var location = ConfigLocations.AppCurrent;
// Act
@@ -206,7 +206,7 @@ public class SourcesManagerTests
"Application.QuitKey": "Ctrl+Z"
}
""";
var source = "test.json";
var source = "Load_WithValidJson_UpdatesSettingsScope";
var location = ConfigLocations.HardCoded;
// Act
@@ -233,7 +233,7 @@ public class SourcesManagerTests
// "Button.DefaultShadowStyle": "None"
// }
// """;
// var source = "test.json";
// var source = "Update_WithValidJson_UpdatesThemeScope";
// var location = ConfigLocations.HardCoded;
// // Act