From d15f3af388a5bc9b8ea177a14e0a241cbda187af Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 7 Jul 2024 21:41:19 +0100 Subject: [PATCH] Add tests that confirm LineCanvas behavior with Fill --- UnitTests/Drawing/LineCanvasTests.cs | 87 ++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/UnitTests/Drawing/LineCanvasTests.cs b/UnitTests/Drawing/LineCanvasTests.cs index 8426d3952..d160b5420 100644 --- a/UnitTests/Drawing/LineCanvasTests.cs +++ b/UnitTests/Drawing/LineCanvasTests.cs @@ -1,4 +1,5 @@ using System.Text; +using Terminal.Gui.Drawing; using Xunit.Abstractions; namespace Terminal.Gui.DrawingTests; @@ -1303,6 +1304,92 @@ public class LineCanvasTests (ITestOutputHelper output) TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{lc}"); } + [Fact] + public void LineCanvas_UsesFillCorrectly () + { + // Arrange + var foregroundColor = new Color (255, 0, 0); // Red + var backgroundColor = new Color (0, 0, 0); // Black + var foregroundFill = new SolidFill (foregroundColor); + var backgroundFill = new SolidFill (backgroundColor); + var fillPair = new FillPair (foregroundFill, backgroundFill); + + var lineCanvas = new LineCanvas + { + Fill = fillPair + }; + + // Act + lineCanvas.AddLine (new Point (0, 0), 5, Orientation.Horizontal, LineStyle.Single); + var cellMap = lineCanvas.GetCellMap (); + + // Assert + foreach (var cell in cellMap.Values) + { + Assert.NotNull (cell); + Assert.Equal (foregroundColor, cell.Value.Attribute.Value.Foreground); + Assert.Equal (backgroundColor, cell.Value.Attribute.Value.Background); + } + } + + [Fact] + public void LineCanvas_LineColorIgnoredBecauseOfFill () + { + // Arrange + var foregroundColor = new Color (255, 0, 0); // Red + var backgroundColor = new Color (0, 0, 0); // Black + var lineColor = new Attribute (new Color (0, 255, 0), new Color (255, 255, 255)); // Green on White + var foregroundFill = new SolidFill (foregroundColor); + var backgroundFill = new SolidFill (backgroundColor); + var fillPair = new FillPair (foregroundFill, backgroundFill); + + var lineCanvas = new LineCanvas + { + Fill = fillPair + }; + + // Act + lineCanvas.AddLine (new Point (0, 0), 5, Orientation.Horizontal, LineStyle.Single, lineColor); + var cellMap = lineCanvas.GetCellMap (); + + // Assert + foreach (var cell in cellMap.Values) + { + Assert.NotNull (cell); + Assert.Equal (foregroundColor, cell.Value.Attribute.Value.Foreground); + Assert.Equal (backgroundColor, cell.Value.Attribute.Value.Background); + } + } + + [Fact] + public void LineCanvas_IntersectingLinesUseFillCorrectly () + { + // Arrange + var foregroundColor = new Color (255, 0, 0); // Red + var backgroundColor = new Color (0, 0, 0); // Black + var foregroundFill = new SolidFill (foregroundColor); + var backgroundFill = new SolidFill (backgroundColor); + var fillPair = new FillPair (foregroundFill, backgroundFill); + + var lineCanvas = new LineCanvas + { + Fill = fillPair + }; + + // Act + lineCanvas.AddLine (new Point (0, 0), 5, Orientation.Horizontal, LineStyle.Single); + lineCanvas.AddLine (new Point (2, -2), 5, Orientation.Vertical, LineStyle.Single); + var cellMap = lineCanvas.GetCellMap (); + + // Assert + foreach (var cell in cellMap.Values) + { + Assert.NotNull (cell); + Assert.Equal (foregroundColor, cell.Value.Attribute.Value.Foreground); + Assert.Equal (backgroundColor, cell.Value.Attribute.Value.Background); + } + } + // TODO: Remove this and make all LineCanvas tests independent of View /// /// Creates a new into which a is rendered at