|
@@ -3,7 +3,7 @@ using Xunit.Abstractions;
|
|
|
|
|
|
namespace Terminal.Gui.DrawingTests;
|
|
|
|
|
|
-public class LineCanvasTests (ITestOutputHelper output)
|
|
|
+public class LineCanvasTests (ITestOutputHelper _output)
|
|
|
{
|
|
|
[Theory]
|
|
|
|
|
@@ -294,7 +294,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
lc.AddLine (new (x1, y1), len1, o1, s1);
|
|
|
lc.AddLine (new (x2, y2), len2, o2, s2);
|
|
|
|
|
|
- TestHelpers.AssertEqual (output, expected, lc.ToString ());
|
|
|
+ TestHelpers.AssertEqual (_output, expected, lc.ToString ());
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -503,7 +503,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
Assert.Equal (new (x, y, 4, 2), lc.Viewport);
|
|
|
|
|
|
TestHelpers.AssertEqual (
|
|
|
- output,
|
|
|
+ _output,
|
|
|
@"
|
|
|
╔╡╞╗
|
|
|
║ ║",
|
|
@@ -553,7 +553,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
Assert.Equal (new (x, y, 4, 2), lc.Viewport);
|
|
|
|
|
|
TestHelpers.AssertEqual (
|
|
|
- output,
|
|
|
+ _output,
|
|
|
@"
|
|
|
╔╡╞╗
|
|
|
║ ║",
|
|
@@ -596,7 +596,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
|
|
|
// Add a line at 5, 5 that's has length of 1
|
|
|
canvas.AddLine (new (x, y), 1, orientation, LineStyle.Single);
|
|
|
- TestHelpers.AssertEqual (output, $"{expected}", $"{canvas}");
|
|
|
+ TestHelpers.AssertEqual (_output, $"{expected}", $"{canvas}");
|
|
|
}
|
|
|
|
|
|
// X is offset by 2
|
|
@@ -653,7 +653,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
canvas.AddLine (new (x, y), length, orientation, LineStyle.Single);
|
|
|
|
|
|
var result = canvas.ToString ();
|
|
|
- TestHelpers.AssertEqual (output, expected, result);
|
|
|
+ TestHelpers.AssertEqual (_output, expected, result);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
@@ -680,7 +680,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
|
|
|
// Add a line at 0, 0 that's has length of 0
|
|
|
lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single);
|
|
|
- TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
|
+ TestHelpers.AssertEqual (_output, expected, $"{lc}");
|
|
|
}
|
|
|
|
|
|
[InlineData (Orientation.Horizontal, "┼")]
|
|
@@ -701,7 +701,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
|
|
|
// Add a line at 0, 0 that's has length of 0
|
|
|
lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single);
|
|
|
- TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
|
+ TestHelpers.AssertEqual (_output, expected, $"{lc}");
|
|
|
}
|
|
|
|
|
|
[InlineData (Orientation.Horizontal, "╥")]
|
|
@@ -724,7 +724,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
|
|
|
// Add a line at 0, 0 that's has length of 0
|
|
|
lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single);
|
|
|
- TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
|
+ TestHelpers.AssertEqual (_output, expected, $"{lc}");
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
@@ -740,7 +740,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
@"
|
|
|
┌─
|
|
|
│ ";
|
|
|
- TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
|
+ TestHelpers.AssertEqual (_output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
@@ -767,7 +767,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
┣━━━━╋━━━┫
|
|
|
┃ ┃ ┃
|
|
|
┗━━━━┻━━━┛";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -798,7 +798,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
│ │ │
|
|
|
┕━━━━┷━━━┙
|
|
|
";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -830,7 +830,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
┖────┸───┚
|
|
|
|
|
|
";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -848,7 +848,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
@"
|
|
|
┌─
|
|
|
│ ";
|
|
|
- TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
|
+ TestHelpers.AssertEqual (_output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
@@ -878,7 +878,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
Assert.Equal (2, map.Count);
|
|
|
|
|
|
TestHelpers.AssertEqual (
|
|
|
- output,
|
|
|
+ _output,
|
|
|
@"
|
|
|
─
|
|
|
─",
|
|
@@ -891,7 +891,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
public void ToString_Empty ()
|
|
|
{
|
|
|
var lc = new LineCanvas ();
|
|
|
- TestHelpers.AssertEqual (output, string.Empty, lc.ToString ());
|
|
|
+ TestHelpers.AssertEqual (_output, string.Empty, lc.ToString ());
|
|
|
}
|
|
|
|
|
|
// 012
|
|
@@ -910,7 +910,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
{
|
|
|
var lc = new LineCanvas ();
|
|
|
lc.AddLine (new (x, y), 3, Orientation.Horizontal, LineStyle.Double);
|
|
|
- TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
|
+ TestHelpers.AssertEqual (_output, expected, $"{lc}");
|
|
|
}
|
|
|
|
|
|
[InlineData (0, 0, 0, 0, "═══")]
|
|
@@ -935,7 +935,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
lc.AddLine (new (x1, y1), 3, Orientation.Horizontal, LineStyle.Double);
|
|
|
lc.AddLine (new (x2, y2), 3, Orientation.Horizontal, LineStyle.Double);
|
|
|
|
|
|
- TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
|
+ TestHelpers.AssertEqual (_output, expected, $"{lc}");
|
|
|
}
|
|
|
|
|
|
// [Fact, SetupFakeDriver]
|
|
@@ -995,7 +995,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
|
|
|
v.Draw ();
|
|
|
|
|
|
- TestHelpers.AssertDriverContentsAre (expected, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (expected, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1014,7 +1014,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
@"
|
|
|
┌─
|
|
|
│";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1037,7 +1037,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
──
|
|
|
│
|
|
|
│";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1055,7 +1055,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
var looksLike =
|
|
|
@"
|
|
|
──";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1071,7 +1071,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
var looksLike =
|
|
|
@"
|
|
|
══";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1090,7 +1090,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
@"
|
|
|
│
|
|
|
│";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1107,7 +1107,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
@"
|
|
|
║
|
|
|
║";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1135,7 +1135,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
╠════╬═══╣
|
|
|
║ ║ ║
|
|
|
╚════╩═══╝";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1166,7 +1166,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
│ │ │
|
|
|
╘════╧═══╛
|
|
|
";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1203,7 +1203,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
├────┼───┤
|
|
|
│ │ │
|
|
|
╰────┴───╯";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1235,7 +1235,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
╙────╨───╜
|
|
|
|
|
|
";
|
|
|
- TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
|
+ TestHelpers.AssertDriverContentsAre (looksLike, _output);
|
|
|
v.Dispose ();
|
|
|
}
|
|
|
|
|
@@ -1262,7 +1262,7 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
├────┼───┤
|
|
|
│ │ │
|
|
|
└────┴───┘";
|
|
|
- TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
|
+ TestHelpers.AssertEqual (_output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
@@ -1300,7 +1300,93 @@ public class LineCanvasTests (ITestOutputHelper output)
|
|
|
var looksLike = @"
|
|
|
╔╡╞══╗
|
|
|
║ ║";
|
|
|
- TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{lc}");
|
|
|
+ TestHelpers.AssertEqual (_output, looksLike, $"{Environment.NewLine}{lc}");
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void LineCanvas_UsesFillCorrectly ()
|
|
|
+ {
|
|
|
+ // Arrange
|
|
|
+ var foregroundColor = new Color (255, 0); // Red
|
|
|
+ var backgroundColor = new Color (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 (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
|
|
|
+ Dictionary<Point, Cell?> cellMap = lineCanvas.GetCellMap ();
|
|
|
+
|
|
|
+ // Assert
|
|
|
+ foreach (Cell? 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); // Red
|
|
|
+ var backgroundColor = new Color (0, 0); // Black
|
|
|
+ var lineColor = new Attribute (new Color (0, 255), 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 (0, 0), 5, Orientation.Horizontal, LineStyle.Single, lineColor);
|
|
|
+ Dictionary<Point, Cell?> cellMap = lineCanvas.GetCellMap ();
|
|
|
+
|
|
|
+ // Assert
|
|
|
+ foreach (Cell? 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); // Red
|
|
|
+ var backgroundColor = new Color (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 (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
|
|
|
+ lineCanvas.AddLine (new (2, -2), 5, Orientation.Vertical, LineStyle.Single);
|
|
|
+ Dictionary<Point, Cell?> cellMap = lineCanvas.GetCellMap ();
|
|
|
+
|
|
|
+ // Assert
|
|
|
+ foreach (Cell? 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
|