mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 01:38:01 +01:00
* Replace all 342 `== null` with `is null`
* Replace 354 `!= null` with `is { }`
* Wrap these in conditionals since they break tests against Release configuration
The members they depend on do not exist in Release configuration
* Split these up and dispose properly
This test needs to be revisited for several reasons at some point.
* Fix release configuration tests
* Declare interface these already support
* Annotate constructor properly and use throw helper
* Move class to its own file
* Rename these files so they nest in the solution explorer
* Make this a record type and remove now-redundant/illegal members
* Reference passing to avoid some struct copies
* Simplify this
* Carry reference passing through as appropriate
* Turn this into a record struct
* Remove unused internal constructor and its test
It was only used by that test.
* Simplify this constructor
* This should be a property
* Simplify constructor
* Simplify GetHashCode
* Mark this ignored just in case
* Missed a couple of opportunities for reference passing
* record struct already does this by value
* Remove unused class
* Simplify the type initializer and Reset method
* Implement INotifyCollectionChanged and IDictionary by delegating to ColorSchemes
* Fix for reflection-based configuration
* Make CI build happy by disambiguiating this attribute
* Add PERF, NOTE, QUESTION, and CONCURRENCY tags for the todo explorer
* Make this string comparison faster.
* Add a tag for unclear intent
* This is a constant
* Turn this into a constant via use of a unicode literal
* Remove this method and its test
It is unused
There's no guarantee at all that the parent process is the terminal.
There are good reasons, including that one, why there's no simple way to do it in .net.
It's also of course a windows-only thing, if using WMI.
* With the WMI method gone, we no longer need this
* Make this more efficient
* Add detail to this property's XmlDoc
* Move the general properties up top because order matters
* Make sure any constants defined at higher levels are not clobbered and define a couple more
* Put InternalsVisibleTo in its own group
* Sort dependencies alphabetically and update
* Global usings
* Split to one type per file
* Collection expression
* Fix naming
* Inline to avoid copies
* This is already a value copy (struct)
* Combine to one non-destructive mutation
* Avoid some potential boxing
* Turn on null analysis here
* Remove unnecessary cast and use real type name
* Seal this
* Fix name
* Move nested class to a nested file (no type layout change made)
* Undo naming change that isn't changed globally until next batch
* Rename Rect to Rectangle in preparation for removal
* Add baseline test for ToString checking for current behavior.
* Change to behavior matching System.Drawing.Rectangle
* Fix this test
This is not a test of Rectangle, so trust that Rectangle gets it right.
* Fix these tests the same way as the previous commit
* These should be testing against the Rectangles, not the strings
* Slightly de-couple these as well
* Test against Rectangles, not strings
* Collection expressions and constants
* Remove this
* Perform proper platform-agnostic normalization
* Make this easier to follow (naming only)
* Add a category to this
* Use raw strings for better clarity
* Some more categorization
* Re-apply backed-out naming change from parent branch
* Change GetHashCode to be equivalent to System.Drawing.Rectangle
* Update this since 6.0.0 is no longer available and prevents build
* This check is redundant with the rectangle check below
* Re-apply Rect->Rectangle name changes in these files
1332 lines
42 KiB
C#
1332 lines
42 KiB
C#
using System.Text;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.DrawingTests;
|
|
|
|
public class LineCanvasTests
|
|
{
|
|
private readonly ITestOutputHelper output;
|
|
public LineCanvasTests (ITestOutputHelper output) { this.output = output; }
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
|
|
// Horizontal lines with a vertical zero-length
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
"╞"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
"╡"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
"╟"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
"╢"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
"├"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
"┤"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
"╠"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
"╣"
|
|
)]
|
|
|
|
// Vertical lines with a horizontal zero-length
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
"╥"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
"╨"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
"╤"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
"╧"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
"┬"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
"┴"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
"╦"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
"╩"
|
|
)]
|
|
|
|
// Crosses (two zero-length)
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
"╫"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
"╪"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Single,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Single,
|
|
"┼"
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Vertical,
|
|
LineStyle.Double,
|
|
0,
|
|
0,
|
|
0,
|
|
Orientation.Horizontal,
|
|
LineStyle.Double,
|
|
"╬"
|
|
)]
|
|
public void Add_2_Lines (
|
|
int x1,
|
|
int y1,
|
|
int len1,
|
|
Orientation o1,
|
|
LineStyle s1,
|
|
int x2,
|
|
int y2,
|
|
int len2,
|
|
Orientation o2,
|
|
LineStyle s2,
|
|
string expected
|
|
)
|
|
{
|
|
View v = GetCanvas (out LineCanvas lc);
|
|
v.Width = 10;
|
|
v.Height = 10;
|
|
v.Bounds = new Rectangle (0, 0, 10, 10);
|
|
|
|
lc.AddLine (new Point (x1, y1), len1, o1, s1);
|
|
lc.AddLine (new Point (x2, y2), len2, o2, s2);
|
|
|
|
TestHelpers.AssertEqual (output, expected, lc.ToString ());
|
|
}
|
|
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
1,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
2,
|
|
0,
|
|
0,
|
|
2,
|
|
2
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
3,
|
|
0,
|
|
0,
|
|
3,
|
|
3
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
0,
|
|
0,
|
|
1,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-2,
|
|
-1,
|
|
-1,
|
|
2,
|
|
2
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-3,
|
|
-2,
|
|
-2,
|
|
3,
|
|
3
|
|
)]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void Bounds_H_And_V_Lines_Both_Positive (
|
|
int x,
|
|
int y,
|
|
int length,
|
|
int expectedX,
|
|
int expectedY,
|
|
int expectedWidth,
|
|
int expectedHeight
|
|
)
|
|
{
|
|
var canvas = new LineCanvas ();
|
|
canvas.AddLine (new Point (x, y), length, Orientation.Horizontal, LineStyle.Single);
|
|
canvas.AddLine (new Point (x, y), length, Orientation.Vertical, LineStyle.Single);
|
|
|
|
Assert.Equal (new Rectangle (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Bounds);
|
|
}
|
|
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
1,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
2,
|
|
0,
|
|
0,
|
|
2,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
3,
|
|
0,
|
|
0,
|
|
3,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-1,
|
|
0,
|
|
0,
|
|
1,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-2,
|
|
-1,
|
|
0,
|
|
2,
|
|
1
|
|
)]
|
|
[InlineData (
|
|
0,
|
|
0,
|
|
-3,
|
|
-2,
|
|
0,
|
|
3,
|
|
1
|
|
)]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void Bounds_H_Line (
|
|
int x,
|
|
int y,
|
|
int length,
|
|
int expectedX,
|
|
int expectedY,
|
|
int expectedWidth,
|
|
int expectedHeight
|
|
)
|
|
{
|
|
var canvas = new LineCanvas ();
|
|
canvas.AddLine (new Point (x, y), length, Orientation.Horizontal, LineStyle.Single);
|
|
|
|
Assert.Equal (new Rectangle (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Bounds);
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Bounds_Specific ()
|
|
{
|
|
// Draw at 1,1 within client area of View (i.e. leave a top and left margin of 1)
|
|
// This proves we aren't drawing excess above
|
|
var x = 1;
|
|
var y = 2;
|
|
var width = 3;
|
|
var height = 2;
|
|
|
|
var lc = new LineCanvas ();
|
|
|
|
// 01230
|
|
// ╔╡╞╗1
|
|
// ║ ║2
|
|
|
|
// Add a short horiz line for ╔╡
|
|
lc.AddLine (new Point (x, y), 2, Orientation.Horizontal, LineStyle.Double);
|
|
Assert.Equal (new Rectangle (x, y, 2, 1), lc.Bounds);
|
|
|
|
//LHS line down
|
|
lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double);
|
|
Assert.Equal (new Rectangle (x, y, 2, 2), lc.Bounds);
|
|
|
|
//Vertical line before Title, results in a ╡
|
|
lc.AddLine (new Point (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
|
|
Assert.Equal (new Rectangle (x, y, 2, 2), lc.Bounds);
|
|
|
|
//Vertical line after Title, results in a ╞
|
|
lc.AddLine (new Point (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
|
|
Assert.Equal (new Rectangle (x, y, 3, 2), lc.Bounds);
|
|
|
|
// remainder of top line
|
|
lc.AddLine (new Point (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
|
|
Assert.Equal (new Rectangle (x, y, 4, 2), lc.Bounds);
|
|
|
|
//RHS line down
|
|
lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double);
|
|
Assert.Equal (new Rectangle (x, y, 4, 2), lc.Bounds);
|
|
|
|
TestHelpers.AssertEqual (
|
|
output,
|
|
@"
|
|
╔╡╞╗
|
|
║ ║",
|
|
$"{Environment.NewLine}{lc}"
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Bounds_Specific_With_Ustring ()
|
|
{
|
|
// Draw at 1,1 within client area of View (i.e. leave a top and left margin of 1)
|
|
// This proves we aren't drawing excess above
|
|
var x = 1;
|
|
var y = 2;
|
|
var width = 3;
|
|
var height = 2;
|
|
|
|
var lc = new LineCanvas ();
|
|
|
|
// 01230
|
|
// ╔╡╞╗1
|
|
// ║ ║2
|
|
|
|
// Add a short horiz line for ╔╡
|
|
lc.AddLine (new Point (x, y), 2, Orientation.Horizontal, LineStyle.Double);
|
|
Assert.Equal (new Rectangle (x, y, 2, 1), lc.Bounds);
|
|
|
|
//LHS line down
|
|
lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double);
|
|
Assert.Equal (new Rectangle (x, y, 2, 2), lc.Bounds);
|
|
|
|
//Vertical line before Title, results in a ╡
|
|
lc.AddLine (new Point (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
|
|
Assert.Equal (new Rectangle (x, y, 2, 2), lc.Bounds);
|
|
|
|
//Vertical line after Title, results in a ╞
|
|
lc.AddLine (new Point (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
|
|
Assert.Equal (new Rectangle (x, y, 3, 2), lc.Bounds);
|
|
|
|
// remainder of top line
|
|
lc.AddLine (new Point (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
|
|
Assert.Equal (new Rectangle (x, y, 4, 2), lc.Bounds);
|
|
|
|
//RHS line down
|
|
lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double);
|
|
Assert.Equal (new Rectangle (x, y, 4, 2), lc.Bounds);
|
|
|
|
TestHelpers.AssertEqual (
|
|
output,
|
|
@"
|
|
╔╡╞╗
|
|
║ ║",
|
|
$"{Environment.NewLine}{lc}"
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Canvas_Updates_On_Changes ()
|
|
{
|
|
var lc = new LineCanvas ();
|
|
|
|
Assert.Equal (Rectangle.Empty, lc.Bounds);
|
|
|
|
lc.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Double);
|
|
Assert.NotEqual (Rectangle.Empty, lc.Bounds);
|
|
|
|
lc.Clear ();
|
|
Assert.Equal (Rectangle.Empty, lc.Bounds);
|
|
}
|
|
|
|
[InlineData (0, 0, Orientation.Horizontal, "─")]
|
|
[InlineData (1, 0, Orientation.Horizontal, "─")]
|
|
[InlineData (0, 1, Orientation.Horizontal, "─")]
|
|
[InlineData (-1, 0, Orientation.Horizontal, "─")]
|
|
[InlineData (0, -1, Orientation.Horizontal, "─")]
|
|
[InlineData (-1, -1, Orientation.Horizontal, "─")]
|
|
[InlineData (0, 0, Orientation.Vertical, "│")]
|
|
[InlineData (1, 0, Orientation.Vertical, "│")]
|
|
[InlineData (0, 1, Orientation.Vertical, "│")]
|
|
[InlineData (0, -1, Orientation.Vertical, "│")]
|
|
[InlineData (-1, 0, Orientation.Vertical, "│")]
|
|
[InlineData (-1, -1, Orientation.Vertical, "│")]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void Length_0_Is_1_Long (int x, int y, Orientation orientation, string expected)
|
|
{
|
|
var canvas = new LineCanvas ();
|
|
|
|
// Add a line at 5, 5 that's has length of 1
|
|
canvas.AddLine (new Point (x, y), 1, orientation, LineStyle.Single);
|
|
TestHelpers.AssertEqual (output, $"{expected}", $"{canvas}");
|
|
}
|
|
|
|
// X is offset by 2
|
|
[InlineData (0, 0, 1, Orientation.Horizontal, "─")]
|
|
[InlineData (1, 0, 1, Orientation.Horizontal, "─")]
|
|
[InlineData (0, 1, 1, Orientation.Horizontal, "─")]
|
|
[InlineData (0, 0, 1, Orientation.Vertical, "│")]
|
|
[InlineData (1, 0, 1, Orientation.Vertical, "│")]
|
|
[InlineData (0, 1, 1, Orientation.Vertical, "│")]
|
|
[InlineData (-1, 0, 1, Orientation.Horizontal, "─")]
|
|
[InlineData (0, -1, 1, Orientation.Horizontal, "─")]
|
|
[InlineData (-1, 0, 1, Orientation.Vertical, "│")]
|
|
[InlineData (0, -1, 1, Orientation.Vertical, "│")]
|
|
[InlineData (0, 0, -1, Orientation.Horizontal, "─")]
|
|
[InlineData (1, 0, -1, Orientation.Horizontal, "─")]
|
|
[InlineData (0, 1, -1, Orientation.Horizontal, "─")]
|
|
[InlineData (0, 0, -1, Orientation.Vertical, "│")]
|
|
[InlineData (1, 0, -1, Orientation.Vertical, "│")]
|
|
[InlineData (0, 1, -1, Orientation.Vertical, "│")]
|
|
[InlineData (-1, 0, -1, Orientation.Horizontal, "─")]
|
|
[InlineData (0, -1, -1, Orientation.Horizontal, "─")]
|
|
[InlineData (-1, 0, -1, Orientation.Vertical, "│")]
|
|
[InlineData (0, -1, -1, Orientation.Vertical, "│")]
|
|
[InlineData (0, 0, 2, Orientation.Horizontal, "──")]
|
|
[InlineData (1, 0, 2, Orientation.Horizontal, "──")]
|
|
[InlineData (0, 1, 2, Orientation.Horizontal, "──")]
|
|
[InlineData (1, 1, 2, Orientation.Horizontal, "──")]
|
|
[InlineData (0, 0, 2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (1, 0, 2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (0, 1, 2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (1, 1, 2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (-1, 0, 2, Orientation.Horizontal, "──")]
|
|
[InlineData (0, -1, 2, Orientation.Horizontal, "──")]
|
|
[InlineData (-1, 0, 2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (0, -1, 2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (-1, -1, 2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (0, 0, -2, Orientation.Horizontal, "──")]
|
|
[InlineData (1, 0, -2, Orientation.Horizontal, "──")]
|
|
[InlineData (0, 1, -2, Orientation.Horizontal, "──")]
|
|
[InlineData (0, 0, -2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (1, 0, -2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (0, 1, -2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (1, 1, -2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (-1, 0, -2, Orientation.Horizontal, "──")]
|
|
[InlineData (0, -1, -2, Orientation.Horizontal, "──")]
|
|
[InlineData (-1, 0, -2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (0, -1, -2, Orientation.Vertical, "│\r\n│")]
|
|
[InlineData (-1, -1, -2, Orientation.Vertical, "│\r\n│")]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void Length_n_Is_n_Long (int x, int y, int length, Orientation orientation, string expected)
|
|
{
|
|
var canvas = new LineCanvas ();
|
|
canvas.AddLine (new Point (x, y), length, orientation, LineStyle.Single);
|
|
|
|
var result = canvas.ToString ();
|
|
TestHelpers.AssertEqual (output, expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Length_Negative ()
|
|
{
|
|
var offset = new Point (5, 5);
|
|
|
|
var canvas = new LineCanvas ();
|
|
canvas.AddLine (offset, -3, Orientation.Horizontal, LineStyle.Single);
|
|
|
|
var looksLike = "───";
|
|
|
|
Assert.Equal (looksLike, $"{canvas}");
|
|
}
|
|
|
|
[InlineData (Orientation.Horizontal, "─")]
|
|
[InlineData (Orientation.Vertical, "│")]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void Length_Zero_Alone_Is_Line (Orientation orientation, string expected)
|
|
{
|
|
var lc = new LineCanvas ();
|
|
|
|
// Add a line at 0, 0 that's has length of 0
|
|
lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single);
|
|
TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
}
|
|
|
|
[InlineData (Orientation.Horizontal, "┼")]
|
|
[InlineData (Orientation.Vertical, "┼")]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void Length_Zero_Cross_Is_Cross (Orientation orientation, string expected)
|
|
{
|
|
var lc = new LineCanvas ();
|
|
|
|
// Add point at opposite orientation
|
|
lc.AddLine (
|
|
new Point (0, 0),
|
|
0,
|
|
orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal,
|
|
LineStyle.Single
|
|
);
|
|
|
|
// Add a line at 0, 0 that's has length of 0
|
|
lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single);
|
|
TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
}
|
|
|
|
[InlineData (Orientation.Horizontal, "╥")]
|
|
[InlineData (Orientation.Vertical, "╞")]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void Length_Zero_NextTo_Opposite_Is_T (Orientation orientation, string expected)
|
|
{
|
|
var lc = new LineCanvas ();
|
|
|
|
// Add line with length of 1 in opposite orientation starting at same location
|
|
if (orientation == Orientation.Horizontal)
|
|
{
|
|
lc.AddLine (new Point (0, 0), 1, Orientation.Vertical, LineStyle.Double);
|
|
}
|
|
else
|
|
{
|
|
lc.AddLine (new Point (0, 0), 1, Orientation.Horizontal, LineStyle.Double);
|
|
}
|
|
|
|
// Add a line at 0, 0 that's has length of 0
|
|
lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single);
|
|
TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void TestLineCanvas_LeaveMargin_Top1_Left1 ()
|
|
{
|
|
var canvas = new LineCanvas ();
|
|
|
|
// Upper box
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Single);
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, LineStyle.Single);
|
|
|
|
var looksLike =
|
|
@"
|
|
┌─
|
|
│ ";
|
|
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void TestLineCanvas_Window_Heavy ()
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
|
|
// outer box
|
|
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Heavy);
|
|
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Heavy);
|
|
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy);
|
|
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Heavy);
|
|
|
|
canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Heavy);
|
|
canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Heavy);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
┏━━━━┳━━━┓
|
|
┃ ┃ ┃
|
|
┣━━━━╋━━━┫
|
|
┃ ┃ ┃
|
|
┗━━━━┻━━━┛";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
[InlineData (LineStyle.Single)]
|
|
[InlineData (LineStyle.Rounded)]
|
|
public void TestLineCanvas_Window_HeavyTop_ThinSides (LineStyle thinStyle)
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
|
|
// outer box
|
|
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Heavy);
|
|
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, thinStyle);
|
|
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy);
|
|
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, thinStyle);
|
|
|
|
canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, thinStyle);
|
|
canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Heavy);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
┍━━━━┯━━━┑
|
|
│ │ │
|
|
┝━━━━┿━━━┥
|
|
│ │ │
|
|
┕━━━━┷━━━┙
|
|
";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
[InlineData (LineStyle.Single)]
|
|
[InlineData (LineStyle.Rounded)]
|
|
public void TestLineCanvas_Window_ThinTop_HeavySides (LineStyle thinStyle)
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
|
|
// outer box
|
|
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, thinStyle);
|
|
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Heavy);
|
|
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, thinStyle);
|
|
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Heavy);
|
|
|
|
canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Heavy);
|
|
canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, thinStyle);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
┎────┰───┒
|
|
┃ ┃ ┃
|
|
┠────╂───┨
|
|
┃ ┃ ┃
|
|
┖────┸───┚
|
|
|
|
";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Top_Left_From_TopRight_LeftUp ()
|
|
{
|
|
var canvas = new LineCanvas ();
|
|
|
|
// Upper box
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Single);
|
|
canvas.AddLine (new Point (0, 1), -2, Orientation.Vertical, LineStyle.Single);
|
|
|
|
var looksLike =
|
|
@"
|
|
┌─
|
|
│ ";
|
|
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Top_With_1Down ()
|
|
{
|
|
var canvas = new LineCanvas ();
|
|
|
|
// Top ─
|
|
canvas.AddLine (new Point (0, 0), 1, Orientation.Horizontal, LineStyle.Single);
|
|
|
|
// Bottom ─
|
|
canvas.AddLine (new Point (1, 1), -1, Orientation.Horizontal, LineStyle.Single);
|
|
|
|
//// Right down
|
|
//canvas.AddLine (new Point (9, 0), 3, Orientation.Vertical, LineStyle.Single);
|
|
|
|
//// Bottom
|
|
//canvas.AddLine (new Point (9, 3), -10, Orientation.Horizontal, LineStyle.Single);
|
|
|
|
//// Left Up
|
|
//canvas.AddLine (new Point (0, 3), -3, Orientation.Vertical, LineStyle.Single);
|
|
|
|
Assert.Equal (new Rectangle (0, 0, 2, 2), canvas.Bounds);
|
|
|
|
Dictionary<Point, Rune> map = canvas.GetMap ();
|
|
Assert.Equal (2, map.Count);
|
|
|
|
TestHelpers.AssertEqual (
|
|
output,
|
|
@"
|
|
─
|
|
─",
|
|
$"{Environment.NewLine}{canvas}"
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void ToString_Empty ()
|
|
{
|
|
var lc = new LineCanvas ();
|
|
TestHelpers.AssertEqual (output, string.Empty, lc.ToString ());
|
|
}
|
|
|
|
// 012
|
|
[InlineData (0, 0, "═══")]
|
|
[InlineData (1, 0, "═══")]
|
|
[InlineData (0, 1, "═══")]
|
|
[InlineData (1, 1, "═══")]
|
|
[InlineData (2, 2, "═══")]
|
|
[InlineData (-1, 0, "═══")]
|
|
[InlineData (0, -1, "═══")]
|
|
[InlineData (-1, -1, "═══")]
|
|
[InlineData (-2, -2, "═══")]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void ToString_Positive_Horizontal_1Line_Offset (int x, int y, string expected)
|
|
{
|
|
var lc = new LineCanvas ();
|
|
lc.AddLine (new Point (x, y), 3, Orientation.Horizontal, LineStyle.Double);
|
|
TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
}
|
|
|
|
[InlineData (0, 0, 0, 0, "═══")]
|
|
[InlineData (1, 0, 1, 0, "═══")]
|
|
[InlineData (-1, 0, -1, 0, "═══")]
|
|
[InlineData (0, 0, 1, 0, "════")]
|
|
[InlineData (1, 0, 3, 0, "═════")]
|
|
[InlineData (1, 0, 4, 0, "══════")]
|
|
[InlineData (1, 0, 5, 0, "═══ ═══")]
|
|
[InlineData (0, 0, 0, 1, "\u2550\u2550\u2550\r\n\u2550\u2550\u2550")]
|
|
[InlineData (0, 0, 1, 1, "═══ \r\n ═══")]
|
|
[InlineData (0, 0, 2, 1, "═══ \r\n ═══")]
|
|
[InlineData (1, 0, 0, 1, " ═══\r\n═══ ")]
|
|
[InlineData (0, 1, 0, 1, "═══")]
|
|
[InlineData (1, 1, 0, 1, "════")]
|
|
[InlineData (2, 2, 0, 1, "═══ \r\n ═══")]
|
|
[Theory]
|
|
[SetupFakeDriver]
|
|
public void ToString_Positive_Horizontal_2Line_Offset (int x1, int y1, int x2, int y2, string expected)
|
|
{
|
|
var lc = new LineCanvas ();
|
|
lc.AddLine (new Point (x1, y1), 3, Orientation.Horizontal, LineStyle.Double);
|
|
lc.AddLine (new Point (x2, y2), 3, Orientation.Horizontal, LineStyle.Double);
|
|
|
|
TestHelpers.AssertEqual (output, expected, $"{lc}");
|
|
}
|
|
|
|
// [Fact, SetupFakeDriver]
|
|
// public void LeaveMargin_Top1_Left1 ()
|
|
// {
|
|
// var canvas = new LineCanvas ();
|
|
|
|
// // Upper box
|
|
// canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, LineStyle.Single);
|
|
// canvas.AddLine (new Point (8, 0), 3, Orientation.Vertical, LineStyle.Single);
|
|
// canvas.AddLine (new Point (8, 3), -9, Orientation.Horizontal, LineStyle.Single);
|
|
// canvas.AddLine (new Point (0, 2), -3, Orientation.Vertical, LineStyle.Single);
|
|
|
|
// // Lower Box
|
|
// canvas.AddLine (new Point (5, 0), 2, Orientation.Vertical, LineStyle.Single);
|
|
// canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, LineStyle.Single);
|
|
|
|
// string looksLike =
|
|
//@"
|
|
//┌────┬──┐
|
|
//│ │ │
|
|
//├────┼──┤
|
|
//└────┴──┘
|
|
//";
|
|
// Assert.Equal (looksLike, $"{Environment.NewLine}{canvas}");
|
|
// }
|
|
|
|
[InlineData (0, 0, 0, Orientation.Horizontal, LineStyle.Double, "═")]
|
|
[InlineData (0, 0, 0, Orientation.Vertical, LineStyle.Double, "║")]
|
|
[InlineData (0, 0, 0, Orientation.Horizontal, LineStyle.Single, "─")]
|
|
[InlineData (0, 0, 0, Orientation.Vertical, LineStyle.Single, "│")]
|
|
[InlineData (0, 0, 1, Orientation.Horizontal, LineStyle.Double, "═")]
|
|
[InlineData (0, 0, 1, Orientation.Vertical, LineStyle.Double, "║")]
|
|
[InlineData (0, 0, 1, Orientation.Horizontal, LineStyle.Single, "─")]
|
|
[InlineData (0, 0, 1, Orientation.Vertical, LineStyle.Single, "│")]
|
|
[InlineData (0, 0, 2, Orientation.Horizontal, LineStyle.Double, "══")]
|
|
[InlineData (0, 0, 2, Orientation.Vertical, LineStyle.Double, "║\n║")]
|
|
[InlineData (0, 0, 2, Orientation.Horizontal, LineStyle.Single, "──")]
|
|
[InlineData (0, 0, 2, Orientation.Vertical, LineStyle.Single, "│\n│")]
|
|
[AutoInitShutdown]
|
|
[Theory]
|
|
public void View_Draws_1LineTests (
|
|
int x1,
|
|
int y1,
|
|
int length,
|
|
Orientation o1,
|
|
LineStyle s1,
|
|
string expected
|
|
)
|
|
{
|
|
View v = GetCanvas (out LineCanvas lc);
|
|
v.Width = 10;
|
|
v.Height = 10;
|
|
v.Bounds = new Rectangle (0, 0, 10, 10);
|
|
|
|
lc.AddLine (new Point (x1, y1), length, o1, s1);
|
|
|
|
v.Draw ();
|
|
|
|
TestHelpers.AssertDriverContentsAre (expected, output);
|
|
}
|
|
|
|
/// <summary>This test demonstrates how to correctly trigger a corner. By overlapping the lines in the same cell</summary>
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void View_Draws_Corner_Correct ()
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Single);
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, LineStyle.Single);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
┌─
|
|
│";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
/// <summary>
|
|
/// This test demonstrates that corners are only drawn when lines overlap. Not when they terminate adjacent to one
|
|
/// another.
|
|
/// </summary>
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void View_Draws_Corner_NoOverlap ()
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Single);
|
|
canvas.AddLine (new Point (0, 1), 2, Orientation.Vertical, LineStyle.Single);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
──
|
|
│
|
|
│";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[InlineData (LineStyle.Single)]
|
|
[InlineData (LineStyle.Rounded)]
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
public void View_Draws_Horizontal (LineStyle style)
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, style);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
──";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void View_Draws_Horizontal_Double ()
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Double);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
══";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[InlineData (LineStyle.Single)]
|
|
[InlineData (LineStyle.Rounded)]
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
public void View_Draws_Vertical (LineStyle style)
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, style);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
│
|
|
│";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void View_Draws_Vertical_Double ()
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, LineStyle.Double);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
║
|
|
║";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void View_Draws_Window_Double ()
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
|
|
// outer box
|
|
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Double);
|
|
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Double);
|
|
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Double);
|
|
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Double);
|
|
|
|
canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Double);
|
|
canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Double);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
╔════╦═══╗
|
|
║ ║ ║
|
|
╠════╬═══╣
|
|
║ ║ ║
|
|
╚════╩═══╝";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
[InlineData (LineStyle.Single)]
|
|
[InlineData (LineStyle.Rounded)]
|
|
public void View_Draws_Window_DoubleTop_SingleSides (LineStyle thinStyle)
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
|
|
// outer box
|
|
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Double);
|
|
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, thinStyle);
|
|
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Double);
|
|
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, thinStyle);
|
|
|
|
canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, thinStyle);
|
|
canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Double);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
╒════╤═══╕
|
|
│ │ │
|
|
╞════╪═══╡
|
|
│ │ │
|
|
╘════╧═══╛
|
|
";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Demonstrates when <see cref="LineStyle.Rounded"/> corners are used. Notice how not all lines declare rounded.
|
|
/// If there are 1+ lines intersecting and a corner is to be used then if any of them are rounded a rounded corner is
|
|
/// used.
|
|
/// </summary>
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void View_Draws_Window_Rounded ()
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
|
|
// outer box
|
|
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Rounded);
|
|
|
|
// LineStyle.Single is ignored because corner overlaps with the above line which is Rounded
|
|
// this results in a rounded corner being used.
|
|
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single);
|
|
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Rounded);
|
|
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single);
|
|
|
|
// These lines say rounded but they will result in the T sections which are never rounded.
|
|
canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Rounded);
|
|
canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Rounded);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
╭────┬───╮
|
|
│ │ │
|
|
├────┼───┤
|
|
│ │ │
|
|
╰────┴───╯";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
[InlineData (LineStyle.Single)]
|
|
[InlineData (LineStyle.Rounded)]
|
|
public void View_Draws_Window_SingleTop_DoubleSides (LineStyle thinStyle)
|
|
{
|
|
View v = GetCanvas (out LineCanvas canvas);
|
|
|
|
// outer box
|
|
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, thinStyle);
|
|
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Double);
|
|
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, thinStyle);
|
|
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Double);
|
|
|
|
canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Double);
|
|
canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, thinStyle);
|
|
|
|
v.Draw ();
|
|
|
|
var looksLike =
|
|
@"
|
|
╓────╥───╖
|
|
║ ║ ║
|
|
╟────╫───╢
|
|
║ ║ ║
|
|
╙────╨───╜
|
|
|
|
";
|
|
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Window ()
|
|
{
|
|
var canvas = new LineCanvas ();
|
|
|
|
// Frame
|
|
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single);
|
|
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single);
|
|
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
|
|
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single);
|
|
|
|
// Cross
|
|
canvas.AddLine (new Point (5, 0), 5, Orientation.Vertical, LineStyle.Single);
|
|
canvas.AddLine (new Point (0, 2), 10, Orientation.Horizontal, LineStyle.Single);
|
|
|
|
var looksLike =
|
|
@"
|
|
┌────┬───┐
|
|
│ │ │
|
|
├────┼───┤
|
|
│ │ │
|
|
└────┴───┘";
|
|
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
|
|
}
|
|
|
|
[Fact]
|
|
[SetupFakeDriver]
|
|
public void Zero_Length_Intersections ()
|
|
{
|
|
// Draw at 1,2 within client area of View (i.e. leave a top and left margin of 1)
|
|
// This proves we aren't drawing excess above
|
|
var x = 1;
|
|
var y = 2;
|
|
var width = 5;
|
|
var height = 2;
|
|
|
|
var lc = new LineCanvas ();
|
|
|
|
// ╔╡╞═════╗
|
|
// Add a short horiz line for ╔╡
|
|
lc.AddLine (new Point (x, y), 2, Orientation.Horizontal, LineStyle.Double);
|
|
|
|
//LHS line down
|
|
lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double);
|
|
|
|
//Vertical line before Title, results in a ╡
|
|
lc.AddLine (new Point (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
|
|
|
|
//Vertical line after Title, results in a ╞
|
|
lc.AddLine (new Point (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
|
|
|
|
// remainder of top line
|
|
lc.AddLine (new Point (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
|
|
|
|
//RHS line down
|
|
lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double);
|
|
|
|
var looksLike = @"
|
|
╔╡╞══╗
|
|
║ ║";
|
|
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{lc}");
|
|
}
|
|
|
|
// TODO: Remove this and make all LineCanvas tests independent of View
|
|
/// <summary>
|
|
/// Creates a new <see cref="View"/> into which a <see cref="LineCanvas"/> is rendered at
|
|
/// <see cref="View.DrawContentComplete"/> time.
|
|
/// </summary>
|
|
/// <param name="canvas">The <see cref="LineCanvas"/> you can draw into.</param>
|
|
/// <param name="offsetX">How far to offset drawing in X</param>
|
|
/// <param name="offsetY">How far to offset drawing in Y</param>
|
|
/// <returns></returns>
|
|
private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0)
|
|
{
|
|
var v = new View { Width = 10, Height = 5, Bounds = new Rectangle (0, 0, 10, 5) };
|
|
Application.Top.Add (v);
|
|
Application.Begin (Application.Top);
|
|
|
|
LineCanvas canvasCopy = canvas = new LineCanvas ();
|
|
|
|
v.DrawContentComplete += (s, e) =>
|
|
{
|
|
v.Clear ();
|
|
|
|
foreach (KeyValuePair<Point, Rune> p in canvasCopy.GetMap ())
|
|
{
|
|
v.AddRune (
|
|
offsetX + p.Key.X,
|
|
offsetY + p.Key.Y,
|
|
p.Value
|
|
);
|
|
}
|
|
|
|
canvasCopy.Clear ();
|
|
};
|
|
|
|
return v;
|
|
}
|
|
}
|