mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 00:07:58 +01:00
* Removed resharper settings from editorconfig * Remove constructors with frame parameters from Button class. * Remove constructors with frame parameters from CheckBox class. * Cleanup code. * Remove constructors with frame parameters from ComboBox class. * @BDisp Remove constructors with frame parameters from FrameView class. * Remove constructors with frame parameters from Label class. * Remove constructors with frame parameters from ListView class. * Remove constructors with frame parameters from ScrollBarView class. * Remove constructors with frame parameters from ScrollView class. * Remove namespace braces. * Cleanup code. * Cleanup code. * Cleanup code. * Remove constructors with frame parameters from TextField class. * Remove constructors with frame parameters from TimeField class. * Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty. * Remove constructors with frame parameters from Toplevel class. * Remove constructors with frame parameters from Window class. * Fix merge errors. * Revert "Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty." This reverts commitcf9c24b846. * Revert unit test. * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame (#2980) * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame * Trying fix this unit test that sometimes fail. * Fixes #2983. View need a alternative DrawFrame for the v2. * Use new DrawFrame method. * Change _lines field to Lines property. * Add TabWindow unit test. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Revert "Change _lines field to Lines property." This reverts commitab6c5f3094. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Force render immediately instead of join. * I will never rely on zero-location-based unit test again. * Fix TestTreeViewColor unit test fail. * Using location of 3 to avoid be divisible by 2 and so avoiding bugs. * Revert "Using location of 3 to avoid be divisible by 2 and so avoiding bugs." This reverts commitdd3df135d8. * Revert "I will never rely on zero-location-based unit test again." This reverts commit62adf6f285. * Revert "Fix newline conflict errors." This reverts commit4acf72612d. * Revert "Add more unit tests to LineCanvas." This reverts commit66bc6f514e. * Revert "Add DrawIncompleteFrame method and unit tests." This reverts commit680ba264e1. * Resolving merge conflicts. * Revert "Use new DrawFrame method." This reverts commit69a7f17f19. * Revert "Fixes #2983. View need a alternative DrawFrame for the v2." This reverts commitdade9fd767. * Reverting this changes to start a new one. * Add horizontal and vertical support for combining glyphs. * Fix text and auto size behavior. * Add TabWidth property. * Add unit test for WordWrap. * Fixes #3017. View TextDirection returns incorrect size on a vertical direction instance with AutoSize as false. * Using Frame to force read from the get method. * Fix some issues with AutoSize and ForceValidatePosDim. * Fixing broken unit tests. * Restoring code I've broken. * Removing forgotten code. * Only LayoutStyle.Computed can change the Frame. * DateField and TimeField depends on LayoutStyle.Computed. * Fix unit tests related with LayoutStyle. * Implements tabs, left and right arrows as View. * Draws a minimum full border. * Adds missing XML parameter. * Adds assert tests for Frame. * Removes duplicates InlineData. * Adds more unit tests for minimum full border without Left and Right thickness. * Trying to fix the TestTreeViewColor unit test fail. * Prevents a user to set TextDirection to -1. * Prevents any invalid TextDirection value. * Removes (TextDirection)(-1). * Removes unnecessary TextDirection initialization. * Removes LayoutStyle. * Fixing unit tests with border. * Trying to fix TestTreeViewColor again. * Revert "Trying to fix TestTreeViewColor again." This reverts commitc2efa8e42e. * Trying to fix TestTreeViewColor again. * Fix merge errors. * Fix merge errors. * Restoring unit test. * Restores the right XML comment. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Only call OnResizeNeeded if it's LayoutStyle.Computed. * Fix merge errors. * Fix merge errors. * Fix unit tests fail. * Reformat. * Again. * Rename to OnDrawAdornments. * Fix failing unit tests. * Reduces indentation and cleanup code. * Cleanup code. * Fix bug done when cleanup. * Replace FrameHandledMouseEvent to AdornmentHandledMouseEvent. * Removes Tab constructor parameters. --------- Co-authored-by: Tig <tig@users.noreply.github.com> * Fix merge errors. * Remove constructors with parameters from Button. * Remove parenthesis on objects initializers from Button. * Remove constructors with parameters from CheckBox. * Remove parenthesis on objects initializers from CheckBox. * Remove constructors with parameters from ComboBox. * Remove constructors with parameters from FrameView. * Remove parenthesis on objects initializers from FrameView. * Initial commit * Renamed Direction enum for clarity in refactoring unit tests * Moved nav tests to NavigationTests * Moved view tests around * Cleaning up TextFormatter and View.AutoSize code * Fixed latent TextFormatter bug with \n * removed Application dependency on some autosize unit tests * Fixed Label tests to deal with auotsize overriding height/width * Fixed more label tests. WIP * Fixed all places where AutoSize = happend after setting Dims * Started adding new primitive View.Text tests * Code comments * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Remove frame set from the View constructor and prevent SetRelativeLayout running if not yet initialized. * Changes needed for unit tests pass on remove parameters constructors from the Label class. * Remove constructors with parameters from Label. * Remove parenthesis on objects initializers from Label. * Prefix private fields with underscore. * Renamed to MaxLength. * Remove constructors with parameters from ListView. * MakeWrapper not needed anymore. * Remove parenthesis on objects initializers from ListView. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Fixed messagebox * Remove constructors with parameters from ScrollBarView and ScrollView. * Remove parenthesis on objects initializers from ScrollBarView and ScrollView. * Cleanup code. * Fix merge errors. * Add empty dotsettings for solution and projects. * Set ReSharper language analysis level for projects to C#12 * Make ReSharper consider itself the boss for style * Add rule to enforce property backing fields above the property * Disable auto-detection of naming rules so ReSharper doesn't change them by itself * Don't let someone's VS settings override the indent settings * Explicitly set tab width to 4 spaces and force spaces. * Rules to keep various multi-line constructs aligned within themselves * Curly brace rules (Using K&R style, per current project spec) * Blank line rules Mostly to add breaks in various situations, and also to enforce max of 1 blank line. * Increase auto-wrap to 160 from default of 120 * Line break at end of all files, to make Unixy systems happy * Keep attributes on their own lines except for methods and records that are themselves single-line * Increase attribute auto-wrap to 60 from default of 38 * Wrap/chop rules for long method signatures and record declarations Chop if either already multi-line or if over 8 parameters. Chop AFTER the left paren and BEFORE the first parameter. * Chop rules for generics For generics with multi-line type parameters or multiple type parameter constraints, chop in a way that has consistent alignment. * Always enforce enum members on their own lines * One-line functions completely on one line They're usually expression-bodied anyway, here, so this is almost irrelevant * Keep control flow statements on their own lines * Follow same chop rules for method invocation as method declaration * Chop long or multi-line method chains or patterns * Wrap rules for binary operators Operator at beginning of new lines Auto-chop if long or already multi-line * Spaces between keywords and their opening parentheses * Add file layout rules for organization of reorderable items like fields, properties, etc. Ugly XML, so load it up in the UI to look at it It's MOSTLY the ReSharper defaults, but with more aggressive sorting, generally by access modifier and name, within each grouping. * Deconstructors use per-member types * Use keywords for built-in types and increase severity of inspection for violations Also apply to IntPtr and similar, which should now be nint and similar * Apply syntax style on completion. * Use var when evident for built-in and simple types, but not elsewhere * Increase severity for some minor redundancy and clarity inspections * Enforce braces always required for blocks, and treat as error * Warn if a local function is not statement-bodied * Increase various inspection severities IF Condition => Severity: Attributes not wrapped property => Suggestion Constructors expression-bodied => Error default doesn't have type when it isn't clear => suggestion Namespaces not file-scoped => error Methods not statement-bodied => hint Null check pattern not the object property pattern => Error * Adjust preference order of null check patterns to make object pattern highest * XmlDoc rules to keep tags and contents aligned and wrapped * Add a few custom profiles for code cleanup and make the full profile default * Remove parts for languages not used in this solution * copied in v2_develop changes * Merged v2_develop * Added Begin/Init unit tests. Removed Application dependencey from AutoSizeFalse tests * TextFormatter.Lines -> GetLines () * Let ReSharper know we intend to localize things * TextFormatter code cleanup * copied in v2_develop changes * Merged v2_develop * Spaces aren't wanted here either. * Fix merge errors. * Fixes ContentBottomRightCorner related with https://github.com/gui-cs/Terminal.Gui/issues/3211#issue-2098878820 * Remove constructors with parameters from ContextMenu. * Remove commented code. * Remove constructors with parameters from OpenDialog. * Remove constructors with parameters from SaveDialog. * Remove constructors with parameters from TextField. * Remove constructors with parameters from TimeField. * Fix unit test. * Remove unnecessary SetInitialProperties method. * Remove unnecessary SetInitialProperties method. * Remove parenthesis on objects initializers from Toplevel and Window. * Remove constructors with parameters from RadioGroup. * Remove constructors with parameters from TextView. * Remove constructors with parameters from MenuBar. * TEMPORARY: Turn everything that was set to error down to warning or lower * Fixes #3219. MenuBar is opened by call OpenMenu even it's disabled. * Remove constructors with parameters from Menu. * Remove constructors with parameters from View. * Change constructor to internal because is mainly useful for testing. * ReSharper Cleanup Code. * Added format only r# config * Fixes #3224. TextFormatter.Lines should return a single string.Empty list even with Width or Height equal to zero. * Remove constructors with parameters from Dialog. * Remove constructors with parameters from TextValidateField. * Fixes https://github.com/gui-cs/Terminal.Gui/issues/3224#issuecomment-1924096038 * Fixes #3225. Press CursorDown on TabView doesn't move to the next view. * Fixes #3229. TextFormatter should have a FillRemaining property. * Testing formatting merge in bdisp * Testing formatting merge * Testing formatting merge bdisp * Testing formatting merge 2 * xmldoc format * R# Full Code Cleanup * R# Full Code Cleanup2 * R# Full Code Cleanup2 * Merged! But broke tests * Refixing... * Refixed DrawTests * Refixed ViewTests * Refixed Text Tests * Refixed more unit tests * Refixed scenarios * Refixed rest of scenarios * Refixed ViewsTests * Refixed rest of tests. All unit tests pass again! * Fixed warnings * Updated R# version. Added new code cleanup settings * Applied latest code cleanup to solution * Another code cleanup pass * Tweaked r# settings. .editorconfig now matches. * r# else on separate line * r# - update * r# - full solution * test commit * test commit * test commit * Removed extra profiles * Full cleanup following cleaning up profiles * Null checking pattern rules/inspections * Tabs and extra whitespace are evil * Attributes on their own lines * Code layout rules to put fields first and to put backing fields with their properties * Merged v2_develop * Full cleanup following dodexahedron's PR --------- Co-authored-by: BDisp <bd.bdisp@gmail.com> Co-authored-by: Brandon Thetford <github@snapsinazfs.com>
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 Rect (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 Rect (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 Rect (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 Rect (x, y, 2, 1), lc.Bounds);
|
|
|
|
//LHS line down
|
|
lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double);
|
|
Assert.Equal (new Rect (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 Rect (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 Rect (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 Rect (x, y, 4, 2), lc.Bounds);
|
|
|
|
//RHS line down
|
|
lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double);
|
|
Assert.Equal (new Rect (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 Rect (x, y, 2, 1), lc.Bounds);
|
|
|
|
//LHS line down
|
|
lc.AddLine (new Point (x, y), height, Orientation.Vertical, LineStyle.Double);
|
|
Assert.Equal (new Rect (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 Rect (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 Rect (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 Rect (x, y, 4, 2), lc.Bounds);
|
|
|
|
//RHS line down
|
|
lc.AddLine (new Point (x + width, y), height, Orientation.Vertical, LineStyle.Double);
|
|
Assert.Equal (new Rect (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 (Rect.Empty, lc.Bounds);
|
|
|
|
lc.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Double);
|
|
Assert.NotEqual (Rect.Empty, lc.Bounds);
|
|
|
|
lc.Clear ();
|
|
Assert.Equal (Rect.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 Rect (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 Rect (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 Rect (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;
|
|
}
|
|
}
|