mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 08:17:53 +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>
166 lines
4.4 KiB
C#
166 lines
4.4 KiB
C#
using Xunit.Sdk;
|
|
|
|
namespace DrawingTests.RegionTests;
|
|
|
|
public class DifferenceTests
|
|
{
|
|
|
|
[Fact]
|
|
public void Difference_Rectangle_ExcludesFromRegion ()
|
|
{
|
|
var region = new Region (new (10, 10, 50, 50));
|
|
region.Combine (new Rectangle (20, 20, 20, 20), RegionOp.Difference);
|
|
Assert.False (region.Contains (25, 25));
|
|
Assert.True (region.Contains (15, 15));
|
|
}
|
|
|
|
[Fact]
|
|
public void Difference_Region_ExcludesRegions ()
|
|
{
|
|
var region1 = new Region (new (10, 10, 50, 50));
|
|
var region2 = new Region (new (20, 20, 20, 20));
|
|
region1.Combine (region2, RegionOp.Difference);
|
|
Assert.False (region1.Contains (25, 25));
|
|
Assert.True (region1.Contains (15, 15));
|
|
}
|
|
|
|
[Fact]
|
|
public void Difference_WithRectangle_ExcludesRectangle ()
|
|
{
|
|
var region = new Region (new (10, 10, 50, 50));
|
|
var rect = new Rectangle (30, 30, 50, 50);
|
|
|
|
region.Combine (rect, RegionOp.Difference);
|
|
|
|
Assert.True (region.Contains (20, 20));
|
|
Assert.False (region.Contains (35, 35));
|
|
}
|
|
|
|
[Fact]
|
|
public void Difference_WithRegion_ExcludesRegion ()
|
|
{
|
|
var region1 = new Region (new (10, 10, 50, 50));
|
|
var region2 = new Region (new (30, 30, 50, 50));
|
|
|
|
region1.Combine (region2, RegionOp.Difference);
|
|
|
|
Assert.True (region1.Contains (20, 20));
|
|
Assert.False (region1.Contains (35, 35));
|
|
}
|
|
|
|
[Fact]
|
|
public void Difference_ContainedRectangle_ExcludesRectangle ()
|
|
{
|
|
|
|
/*
|
|
INPUT: (top-left origin, x→, y↓):
|
|
|
|
x=0 1 2 3 4 5
|
|
y=0 A A A A A A
|
|
y=1 A A A A A A
|
|
y=2 A A B B A A
|
|
y=3 A A B B A A
|
|
y=4 A A A A A A
|
|
y=5 A A A A A A
|
|
|
|
*/
|
|
|
|
|
|
var regionA = new Region (new (0, 0, 6, 6));
|
|
var rectangleB = new Rectangle (2, 2, 2, 2);
|
|
|
|
regionA.Combine (rectangleB, RegionOp.Difference);
|
|
|
|
Assert.True (regionA.Contains (0, 0));
|
|
Assert.True (regionA.Contains (1, 1));
|
|
Assert.True (regionA.Contains (4, 4));
|
|
Assert.True (regionA.Contains (5, 5));
|
|
|
|
Assert.False (regionA.Contains (2, 2));
|
|
Assert.False (regionA.Contains (3, 3));
|
|
}
|
|
|
|
[Fact]
|
|
public void Difference_ContainedRegion_ExcludesRegion ()
|
|
{
|
|
|
|
/*
|
|
INPUT: (top-left origin, x→, y↓):
|
|
|
|
x=0 1 2 3 4 5
|
|
y=0 A A A A A A
|
|
y=1 A A A A A A
|
|
y=2 A A B B A A
|
|
y=3 A A B B A A
|
|
y=4 A A A A A A
|
|
y=5 A A A A A A
|
|
|
|
*/
|
|
|
|
|
|
var regionA = new Region (new (0, 0, 6, 6));
|
|
var regionB = new Region (new (2, 2, 2, 2));
|
|
|
|
regionA.Combine (regionB, RegionOp.Difference);
|
|
|
|
Assert.True (regionA.Contains (0, 0));
|
|
Assert.True (regionA.Contains (1, 1));
|
|
Assert.True (regionA.Contains (4, 4));
|
|
Assert.True (regionA.Contains (5, 5));
|
|
|
|
Assert.False (regionA.Contains (2, 2));
|
|
Assert.False (regionA.Contains (3, 3));
|
|
}
|
|
|
|
[Fact]
|
|
public void Difference_NonRectangularRegion_ExcludesRegion ()
|
|
{
|
|
|
|
/*
|
|
INPUT: (top-left origin, x→, y↓):
|
|
|
|
x=0 1 2 3 4 5
|
|
y=0 A A A A A A
|
|
y=1 A A A A A A
|
|
y=2 A A B B A A
|
|
y=3 A A B A A A
|
|
y=4 A A A A A A
|
|
y=5 A A A A A A
|
|
|
|
*/
|
|
|
|
var regionA = new Region (new (0, 0, 6, 6));
|
|
|
|
var regionB = new Region ();
|
|
regionB.Combine (new Rectangle (2, 2, 2, 1), RegionOp.MinimalUnion);
|
|
regionB.Combine (new Rectangle (2, 3, 1, 1), RegionOp.MinimalUnion);
|
|
|
|
// regionB is a non-rectangular region that looks like this:
|
|
// x= 0 1 2 3 4 5
|
|
// y=0 . . . . . .
|
|
// y=1 . . . . . .
|
|
// y=2 . . B B . .
|
|
// y=3 . . B . . .
|
|
// y=4 . . . . . .
|
|
// y=5 . . . . . .
|
|
|
|
Assert.True (regionB.Contains (2, 2));
|
|
Assert.True (regionB.Contains (3, 2));
|
|
Assert.True (regionB.Contains (2, 3));
|
|
Assert.False (regionB.Contains (3, 3));
|
|
|
|
regionA.Combine (regionB, RegionOp.Difference);
|
|
|
|
Assert.True (regionA.Contains (0, 0));
|
|
Assert.True (regionA.Contains (1, 1));
|
|
Assert.True (regionA.Contains (3, 3));
|
|
Assert.True (regionA.Contains (4, 4));
|
|
Assert.True (regionA.Contains (5, 5));
|
|
|
|
Assert.False (regionA.Contains (2, 2));
|
|
Assert.False (regionA.Contains (3, 2));
|
|
Assert.False (regionA.Contains (2, 3));
|
|
|
|
}
|
|
|
|
} |