mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 01:38:01 +01:00
* Reduces indentation by remove the namespace braces. * Reduces indentation and removes unused using. * Ensures clear selection if it isn't selecting. * Turn on nullability context for TryParse and update usages as needed. * Use IsNullOrWhiteSpace, which includes IsNullOrEmpty All-whitespace values are also illegal, so may as well handle that here too * Respect the nullable here * It's a struct * Use byte.MaxValue and add remark * Just use the bytes directly * Must respect endianness * Add uint constructor so consumers don't have to do unchecked math * Completely re-work parsing and implement ISpanParsable<Color> All parsing is now almost-0 allocation, and is significantly faster than before * Extension methods required by new code * Use standard Math.Clamp method here * Add some new unit tests for TryParse * De-duplicate code and handle more cases * Enable nullability context for the file * Go ahead and enable the language features and analysis * Implicit usings remove a lot of boilerplate usings. * Add these to the dictionary to shut spell check up * Make this thing a record struct and a union, and update constructors This commit won't build. I'm just breaking out changes a little bit. * Some additional XmlDoc standardizing * Make FindClosestColor and CalculateColorDistance use the vector for SIMD * Add a TryFormat method for support of I*Formattable * Add an interface for support of custom formatting of Colors * Pass by in reference * Parse string delegates to Parse span * Parse now does all the work * Remove the old new code from TryParse * Some new cast operators * Add IFormattable.ToString implementation * Add the rest of the code for Color in its current (unfinished) state * Move that interface to its own file * Add ColorParseException class * Move Attribute to its own file, too. * Re-implement these operators as explicit methods * Get rid of fuzzy equality operators and update tests to use the named methods that replace them * Add an explicit test case for ToString with null format string and explicitly specified Invariant culture * Fix byte orders for hex format to be standard ARGB * Prove that ToString and Parse can round-trip values * Unroll this test into parameterized cases * Fix a couple of comments to match byte order * Update R# dictionary to match correct byte orders * Remove stray comment * Separate all types in this to their own files * Convert this one to use the handy extension * Add test for Argb property * Add a file nesting rule to make some incoming file changes display nicely * Move constructor tests to their own file and add some new tests * Add implicit cast from uint * More constructor tests * Since this is now a record, the equality operators are compiler generated Still spot-checking a few arbitrary values for completeness * Override ToString to delegate to Attribute * Simplify and clean up ToString. Delegate to ColorScheme * Update the test to match new output * These should be fields, really. It's a value type. * Add some type checks for change control * Allow unsafe and turn on implicit usings * Make this one better * Rename tests and remove redundant checks (the type checks already guarantee field consistency) * Reorganize a bit * Make these test 16 random values * Existing operator tests converted * That one is now redundant with both of the other tests that check all the named colors * Move this to type checks and simplify a little bit * These lambdas can be static * Move operators to another file. * Add global using for System.Text because it's EVERYWHERE * Reorganization of Color and some related types. Updated usages to reflect changes * Update tests to reflect changes in Terminal.Gui * Add missing keyword * Add entry to dictionary * Add dotsettings for Terminal.Gui Only specifies language level * Commit unsaved changes for usings here * Implement last remaining TryFormat method * A little cleanup/formality * Sorting rules Sort methods by name and interface they implement * Sort code * Match namespace for tests None! * Unroll ordinal check and reorganize. * Sort before writing new tests * These got reversed... * Add test to prove explicit cast to Vector3 works properly * Sort these too * Add test for uint->Color implicit operator * Add test for Color->uint implicit operator * Correct this test name and re-order * Add test for implicit conversion from Vector3 to Color * Add test for implicit conversion from Vector4 to Color * These also got reversed, like with Vector3 * Add test for implicit conversion from Color to Vector4 * Add test for GetHashCode * Make sure these are all under the same namespace * Remove a now-redundant test * Reorganize formatting and parsing tests to another type part * Tests moved back to Terminal.Gui.DrawingTests namespace as before. * Add tests for the constructor taking 3 or 4 integers and sort * Cleanup - Renamed some tests - Make a test even clearer - Removed redundant code - Got rid of unused parameter in Constructor_WithColorName_AllChannelsCorrect * That needs to be from the reverse map Not broken - just was sub-optimal due to my error. * Enable nullability context in this file Not sure how it got removed but whatev * Respect nullability context in this file now that it's on 🤦♂️ * Add tests for expected exceptions with whitespace or null values * Add test for parameterless constructor * A couple more places for reference passing and some SkipLocalsInit attributes. * Some XmlDoc corrections to reflect the final implementation * Remove namespace qualifier * Can't use these because of lambdas :( * Removed a collection that never ended up being needed. * Add bracing, newline, and modifier style rules * Add spacing rules inside parens/brackets * This was still under the Terminal.Gui.Drawing namespace. Revert that. * Applied updated formatting settings and addressed XmlDoc reviews in #3204 * More places where spaces got added in dependent code. Also a couple of null checks fixed to not use the equality operator * More dependent code format fixes * Finished re-formatting modified code that got spaces added everywhere * Visual studio didn't actually write this file to disk til I closed out of VS... Grr * Delete the ReSharper settings files from this branch. --------- Co-authored-by: BDisp <bd.bdisp@gmail.com>
740 lines
17 KiB
C#
740 lines
17 KiB
C#
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.ViewTests;
|
|
public class BorderTests {
|
|
readonly ITestOutputHelper _output;
|
|
|
|
public BorderTests (ITestOutputHelper output)
|
|
{
|
|
_output = output;
|
|
}
|
|
|
|
[Fact]
|
|
public void View_BorderStyle_Defaults ()
|
|
{
|
|
var view = new View ();
|
|
Assert.Equal (LineStyle.None, view.BorderStyle);
|
|
Assert.Equal (Thickness.Empty, view.Border.Thickness);
|
|
view.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void View_SetBorderStyle ()
|
|
{
|
|
var view = new View ();
|
|
view.BorderStyle = LineStyle.Single;
|
|
Assert.Equal (LineStyle.Single, view.BorderStyle);
|
|
Assert.Equal (new Thickness (1), view.Border.Thickness);
|
|
|
|
view.BorderStyle = LineStyle.Double;
|
|
Assert.Equal (LineStyle.Double, view.BorderStyle);
|
|
Assert.Equal (new Thickness (1), view.Border.Thickness);
|
|
|
|
view.BorderStyle = LineStyle.None;
|
|
Assert.Equal (LineStyle.None, view.BorderStyle);
|
|
Assert.Equal (Thickness.Empty, view.Border.Thickness);
|
|
view.Dispose ();
|
|
}
|
|
|
|
[Theory, AutoInitShutdown]
|
|
[InlineData (0)]
|
|
[InlineData (1)]
|
|
[InlineData (2)]
|
|
[InlineData (3)]
|
|
public void Border_With_Title_Size_Height (int height)
|
|
{
|
|
var win = new Window () {
|
|
Title = "1234",
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill ()
|
|
};
|
|
|
|
var rs = Application.Begin (win);
|
|
bool firstIteration = false;
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (20, height);
|
|
Application.RunIteration (ref rs, ref firstIteration);
|
|
var expected = string.Empty;
|
|
|
|
switch (height) {
|
|
case 0:
|
|
//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
|
|
expected = @"
|
|
";
|
|
break;
|
|
case 1:
|
|
//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
|
|
expected = @"
|
|
────────────────────";
|
|
break;
|
|
case 2:
|
|
//Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
|
|
expected = @"
|
|
┌┤1234├────────────┐
|
|
└──────────────────┘
|
|
";
|
|
break;
|
|
case 3:
|
|
//Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
|
|
expected = @"
|
|
┌┤1234├────────────┐
|
|
│ │
|
|
└──────────────────┘
|
|
";
|
|
break;
|
|
}
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
Application.End (rs);
|
|
}
|
|
|
|
[Theory, AutoInitShutdown]
|
|
[InlineData (0)]
|
|
[InlineData (1)]
|
|
[InlineData (2)]
|
|
[InlineData (3)]
|
|
[InlineData (4)]
|
|
[InlineData (5)]
|
|
[InlineData (6)]
|
|
[InlineData (7)]
|
|
[InlineData (8)]
|
|
[InlineData (9)]
|
|
[InlineData (10)]
|
|
public void Border_With_Title_Size_Width (int width)
|
|
{
|
|
var win = new Window () {
|
|
Title = "1234",
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill ()
|
|
};
|
|
|
|
var rs = Application.Begin (win);
|
|
bool firstIteration = false;
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (width, 3);
|
|
Application.RunIteration (ref rs, ref firstIteration);
|
|
var expected = string.Empty;
|
|
|
|
switch (width) {
|
|
case 1:
|
|
//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
|
|
expected = @"
|
|
│
|
|
│
|
|
│";
|
|
break;
|
|
case 2:
|
|
//Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
|
|
expected = @"
|
|
┌┐
|
|
││
|
|
└┘";
|
|
break;
|
|
case 3:
|
|
//Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
|
|
expected = @"
|
|
┌─┐
|
|
│ │
|
|
└─┘
|
|
";
|
|
break;
|
|
case 4:
|
|
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
|
|
expected = @"
|
|
┌┤├┐
|
|
│ │
|
|
└──┘";
|
|
break;
|
|
case 5:
|
|
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
|
|
expected = @"
|
|
┌┤1├┐
|
|
│ │
|
|
└───┘";
|
|
break;
|
|
case 6:
|
|
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
|
|
expected = @"
|
|
┌┤12├┐
|
|
│ │
|
|
└────┘";
|
|
break;
|
|
case 7:
|
|
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
|
|
expected = @"
|
|
┌┤123├┐
|
|
│ │
|
|
└─────┘";
|
|
break;
|
|
case 8:
|
|
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
|
|
expected = @"
|
|
┌┤1234├┐
|
|
│ │
|
|
└──────┘";
|
|
break;
|
|
case 9:
|
|
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
|
|
expected = @"
|
|
┌┤1234├─┐
|
|
│ │
|
|
└───────┘";
|
|
break;
|
|
case 10:
|
|
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
|
|
expected = @"
|
|
┌┤1234├──┐
|
|
│ │
|
|
└────────┘";
|
|
break;
|
|
}
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
}
|
|
|
|
[Fact, AutoInitShutdown]
|
|
public void NoSuperView ()
|
|
{
|
|
var win = new Window () {
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill ()
|
|
};
|
|
|
|
var rs = Application.Begin (win);
|
|
bool firstIteration = false;
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (3, 3);
|
|
Application.RunIteration (ref rs, ref firstIteration);
|
|
var expected = @"
|
|
┌─┐
|
|
│ │
|
|
└─┘";
|
|
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
}
|
|
|
|
[Fact, AutoInitShutdown]
|
|
public void HasSuperView ()
|
|
{
|
|
Application.Top.BorderStyle = LineStyle.Double;
|
|
|
|
var frame = new FrameView () {
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill ()
|
|
};
|
|
|
|
Application.Top.Add (frame);
|
|
var rs = Application.Begin (Application.Top);
|
|
bool firstIteration = false;
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (5, 5);
|
|
Application.RunIteration (ref rs, ref firstIteration);
|
|
var expected = @"
|
|
╔═══╗
|
|
║┌─┐║
|
|
║│ │║
|
|
║└─┘║
|
|
╚═══╝";
|
|
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
Application.End (rs);
|
|
}
|
|
|
|
[Fact, AutoInitShutdown]
|
|
public void HasSuperView_Title ()
|
|
{
|
|
Application.Top.BorderStyle = LineStyle.Double;
|
|
|
|
var frame = new FrameView () {
|
|
Title = "1234",
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill ()
|
|
};
|
|
|
|
Application.Top.Add (frame);
|
|
var rs = Application.Begin (Application.Top);
|
|
bool firstIteration = false;
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (10, 4);
|
|
Application.RunIteration (ref rs, ref firstIteration);
|
|
var expected = @"
|
|
╔════════╗
|
|
║┌┤1234├┐║
|
|
║└──────┘║
|
|
╚════════╝";
|
|
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
Application.End (rs);
|
|
}
|
|
|
|
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 1, 1)]
|
|
[InlineData (1, 0, 0, 2, 2)]
|
|
[InlineData (2, 0, 0, 3, 3)]
|
|
[InlineData (1, 1, 0, 3, 2)]
|
|
[InlineData (1, 0, 1, 2, 3)]
|
|
[InlineData (1, 1, 1, 3, 3)]
|
|
[InlineData (1, 10, 10, 12, 12)]
|
|
public void FrameToScreen_SuperView_WithBorder (int superOffset, int frameX, int frameY, int expectedScreenX, int expectedScreenY)
|
|
{
|
|
var super = new View () {
|
|
X = superOffset,
|
|
Y = superOffset,
|
|
Width = 20,
|
|
Height = 20,
|
|
BorderStyle = LineStyle.Single
|
|
};
|
|
|
|
var view = new View () {
|
|
X = frameX,
|
|
Y = frameY,
|
|
Width = 10,
|
|
Height = 10
|
|
};
|
|
super.Add (view);
|
|
var expected = new Rect (expectedScreenX, expectedScreenY, 10, 10);
|
|
var actual = view.FrameToScreen ();
|
|
Assert.Equal (expected, actual);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData (0, 0, 0, 2, 2)]
|
|
[InlineData (1, 0, 0, 4, 4)]
|
|
[InlineData (2, 0, 0, 6, 6)]
|
|
[InlineData (1, 1, 0, 5, 4)]
|
|
[InlineData (1, 0, 1, 4, 5)]
|
|
[InlineData (1, 1, 1, 5, 5)]
|
|
[InlineData (1, 10, 10, 14, 14)]
|
|
public void FrameToScreen_NestedSuperView_WithBorder (int superOffset, int frameX, int frameY, int expectedScreenX, int expectedScreenY)
|
|
{
|
|
var superSuper = new View () {
|
|
X = superOffset,
|
|
Y = superOffset,
|
|
Width = 30,
|
|
Height = 30,
|
|
BorderStyle = LineStyle.Single
|
|
};
|
|
|
|
var super = new View () {
|
|
X = superOffset,
|
|
Y = superOffset,
|
|
Width = 20,
|
|
Height = 20,
|
|
BorderStyle = LineStyle.Single
|
|
};
|
|
superSuper.Add (super);
|
|
|
|
var view = new View () {
|
|
X = frameX,
|
|
Y = frameY,
|
|
Width = 10,
|
|
Height = 10
|
|
};
|
|
super.Add (view);
|
|
var expected = new Rect (expectedScreenX, expectedScreenY, 10, 10);
|
|
var actual = view.FrameToScreen ();
|
|
Assert.Equal (expected, actual);
|
|
}
|
|
|
|
|
|
[Theory, AutoInitShutdown]
|
|
[InlineData (0)]
|
|
[InlineData (1)]
|
|
[InlineData (2)]
|
|
[InlineData (3)]
|
|
[InlineData (4)]
|
|
[InlineData (5)]
|
|
[InlineData (6)]
|
|
[InlineData (7)]
|
|
[InlineData (8)]
|
|
[InlineData (9)]
|
|
[InlineData (10)]
|
|
public void Border_With_Title_Border_Double_Thickness_Top_Two_Size_Width (int width)
|
|
{
|
|
var win = new Window () {
|
|
Title = "1234",
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill (),
|
|
BorderStyle = LineStyle.Double,
|
|
};
|
|
win.Border.Thickness.Top = 2;
|
|
|
|
var rs = Application.Begin (win);
|
|
bool firstIteration = false;
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (width, 4);
|
|
Application.RunIteration (ref rs, ref firstIteration);
|
|
var expected = string.Empty;
|
|
|
|
switch (width) {
|
|
case 1:
|
|
Assert.Equal (new Rect (0, 0, 1, 4), win.Frame);
|
|
expected = @"
|
|
║
|
|
║
|
|
║";
|
|
break;
|
|
case 2:
|
|
Assert.Equal (new Rect (0, 0, 2, 4), win.Frame);
|
|
expected = @"
|
|
╔╗
|
|
║║
|
|
╚╝";
|
|
break;
|
|
case 3:
|
|
Assert.Equal (new Rect (0, 0, 3, 4), win.Frame);
|
|
expected = @"
|
|
╔═╗
|
|
║ ║
|
|
╚═╝";
|
|
break;
|
|
case 4:
|
|
Assert.Equal (new Rect (0, 0, 4, 4), win.Frame);
|
|
expected = @"
|
|
╒╕
|
|
╔╛╘╗
|
|
║ ║
|
|
╚══╝";
|
|
break;
|
|
case 5:
|
|
Assert.Equal (new Rect (0, 0, 5, 4), win.Frame);
|
|
expected = @"
|
|
╒═╕
|
|
╔╛1╘╗
|
|
║ ║
|
|
╚═══╝";
|
|
break;
|
|
case 6:
|
|
Assert.Equal (new Rect (0, 0, 6, 4), win.Frame);
|
|
expected = @"
|
|
╒══╕
|
|
╔╛12╘╗
|
|
║ ║
|
|
╚════╝";
|
|
break;
|
|
case 7:
|
|
Assert.Equal (new Rect (0, 0, 7, 4), win.Frame);
|
|
expected = @"
|
|
╒═══╕
|
|
╔╛123╘╗
|
|
║ ║
|
|
╚═════╝";
|
|
break;
|
|
case 8:
|
|
Assert.Equal (new Rect (0, 0, 8, 4), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╛1234╘╗
|
|
║ ║
|
|
╚══════╝";
|
|
break;
|
|
case 9:
|
|
Assert.Equal (new Rect (0, 0, 9, 4), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╛1234╘═╗
|
|
║ ║
|
|
╚═══════╝";
|
|
break;
|
|
case 10:
|
|
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╛1234╘══╗
|
|
║ ║
|
|
╚════════╝";
|
|
break;
|
|
}
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
Application.End (rs);
|
|
}
|
|
|
|
[Theory, AutoInitShutdown]
|
|
[InlineData (0)]
|
|
[InlineData (1)]
|
|
[InlineData (2)]
|
|
[InlineData (3)]
|
|
[InlineData (4)]
|
|
[InlineData (5)]
|
|
[InlineData (6)]
|
|
[InlineData (7)]
|
|
[InlineData (8)]
|
|
[InlineData (9)]
|
|
[InlineData (10)]
|
|
public void Border_With_Title_Border_Double_Thickness_Top_Three_Size_Width (int width)
|
|
{
|
|
var win = new Window () {
|
|
Title = "1234",
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill (),
|
|
BorderStyle = LineStyle.Double,
|
|
};
|
|
win.Border.Thickness.Top = 3;
|
|
|
|
var rs = Application.Begin (win);
|
|
bool firstIteration = false;
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (width, 4);
|
|
Application.RunIteration (ref rs, ref firstIteration);
|
|
var expected = string.Empty;
|
|
|
|
switch (width) {
|
|
case 1:
|
|
Assert.Equal (new Rect (0, 0, 1, 4), win.Frame);
|
|
expected = @"
|
|
║
|
|
║
|
|
║";
|
|
break;
|
|
case 2:
|
|
Assert.Equal (new Rect (0, 0, 2, 4), win.Frame);
|
|
expected = @"
|
|
╔╗
|
|
║║
|
|
╚╝";
|
|
break;
|
|
case 3:
|
|
Assert.Equal (new Rect (0, 0, 3, 4), win.Frame);
|
|
expected = @"
|
|
╔═╗
|
|
║ ║
|
|
╚═╝";
|
|
break;
|
|
case 4:
|
|
Assert.Equal (new Rect (0, 0, 4, 4), win.Frame);
|
|
expected = @"
|
|
╒╕
|
|
╔╡╞╗
|
|
║╘╛║
|
|
╚══╝";
|
|
break;
|
|
case 5:
|
|
Assert.Equal (new Rect (0, 0, 5, 4), win.Frame);
|
|
expected = @"
|
|
╒═╕
|
|
╔╡1╞╗
|
|
║╘═╛║
|
|
╚═══╝";
|
|
break;
|
|
case 6:
|
|
Assert.Equal (new Rect (0, 0, 6, 4), win.Frame);
|
|
expected = @"
|
|
╒══╕
|
|
╔╡12╞╗
|
|
║╘══╛║
|
|
╚════╝";
|
|
break;
|
|
case 7:
|
|
Assert.Equal (new Rect (0, 0, 7, 4), win.Frame);
|
|
expected = @"
|
|
╒═══╕
|
|
╔╡123╞╗
|
|
║╘═══╛║
|
|
╚═════╝";
|
|
break;
|
|
case 8:
|
|
Assert.Equal (new Rect (0, 0, 8, 4), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╡1234╞╗
|
|
║╘════╛║
|
|
╚══════╝";
|
|
break;
|
|
case 9:
|
|
Assert.Equal (new Rect (0, 0, 9, 4), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╡1234╞═╗
|
|
║╘════╛ ║
|
|
╚═══════╝";
|
|
break;
|
|
case 10:
|
|
Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╡1234╞══╗
|
|
║╘════╛ ║
|
|
╚════════╝";
|
|
break;
|
|
}
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
Application.End (rs);
|
|
}
|
|
|
|
[Theory, AutoInitShutdown]
|
|
[InlineData (0)]
|
|
[InlineData (1)]
|
|
[InlineData (2)]
|
|
[InlineData (3)]
|
|
[InlineData (4)]
|
|
[InlineData (5)]
|
|
[InlineData (6)]
|
|
[InlineData (7)]
|
|
[InlineData (8)]
|
|
[InlineData (9)]
|
|
[InlineData (10)]
|
|
public void Border_With_Title_Border_Double_Thickness_Top_Four_Size_Width (int width)
|
|
{
|
|
var win = new Window () {
|
|
Title = "1234",
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill (),
|
|
BorderStyle = LineStyle.Double,
|
|
};
|
|
win.Border.Thickness.Top = 4;
|
|
|
|
var rs = Application.Begin (win);
|
|
bool firstIteration = false;
|
|
|
|
((FakeDriver)Application.Driver).SetBufferSize (width, 5);
|
|
Application.RunIteration (ref rs, ref firstIteration);
|
|
var expected = string.Empty;
|
|
|
|
switch (width) {
|
|
case 1:
|
|
Assert.Equal (new Rect (0, 0, 1, 5), win.Frame);
|
|
expected = @"
|
|
║
|
|
║
|
|
║";
|
|
break;
|
|
case 2:
|
|
Assert.Equal (new Rect (0, 0, 2, 5), win.Frame);
|
|
expected = @"
|
|
╔╗
|
|
║║
|
|
╚╝";
|
|
break;
|
|
case 3:
|
|
Assert.Equal (new Rect (0, 0, 3, 5), win.Frame);
|
|
expected = @"
|
|
╔═╗
|
|
║ ║
|
|
╚═╝";
|
|
break;
|
|
case 4:
|
|
Assert.Equal (new Rect (0, 0, 4, 5), win.Frame);
|
|
expected = @"
|
|
╒╕
|
|
╔╡╞╗
|
|
║╘╛║
|
|
╚══╝";
|
|
break;
|
|
case 5:
|
|
Assert.Equal (new Rect (0, 0, 5, 5), win.Frame);
|
|
expected = @"
|
|
╒═╕
|
|
╔╡1╞╗
|
|
║╘═╛║
|
|
╚═══╝";
|
|
break;
|
|
case 6:
|
|
Assert.Equal (new Rect (0, 0, 6, 5), win.Frame);
|
|
expected = @"
|
|
╒══╕
|
|
╔╡12╞╗
|
|
║╘══╛║
|
|
╚════╝";
|
|
break;
|
|
case 7:
|
|
Assert.Equal (new Rect (0, 0, 7, 5), win.Frame);
|
|
expected = @"
|
|
╒═══╕
|
|
╔╡123╞╗
|
|
║╘═══╛║
|
|
╚═════╝";
|
|
break;
|
|
case 8:
|
|
Assert.Equal (new Rect (0, 0, 8, 5), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╡1234╞╗
|
|
║╘════╛║
|
|
╚══════╝";
|
|
break;
|
|
case 9:
|
|
Assert.Equal (new Rect (0, 0, 9, 5), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╡1234╞═╗
|
|
║╘════╛ ║
|
|
╚═══════╝";
|
|
break;
|
|
case 10:
|
|
Assert.Equal (new Rect (0, 0, 10, 5), win.Frame);
|
|
expected = @"
|
|
╒════╕
|
|
╔╡1234╞══╗
|
|
║╘════╛ ║
|
|
╚════════╝";
|
|
break;
|
|
}
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
Application.End (rs);
|
|
}
|
|
|
|
[Fact, SetupFakeDriver]
|
|
public void Border_Uses_Parent_ColorScheme ()
|
|
{
|
|
var view = new View () {
|
|
Title = "A",
|
|
Height = 2,
|
|
Width = 5
|
|
};
|
|
view.Border.Thickness = new Thickness (0, 1, 0, 0);
|
|
view.Border.LineStyle = LineStyle.Single;
|
|
view.ColorScheme = new ColorScheme () {
|
|
Normal = new Attribute (Color.Red, Color.Green),
|
|
Focus = new Attribute (Color.Green, Color.Red),
|
|
};
|
|
Assert.Equal (ColorName.Red, view.Border.GetNormalColor ().Foreground.GetClosestNamedColor ());
|
|
Assert.Equal (ColorName.Green, view.Border.GetFocusColor ().Foreground.GetClosestNamedColor ());
|
|
Assert.Equal (view.GetNormalColor(), view.Border.GetNormalColor ());
|
|
Assert.Equal (view.GetFocusColor (), view.Border.GetFocusColor ());
|
|
|
|
view.BeginInit ();
|
|
view.EndInit ();
|
|
view.Draw ();
|
|
|
|
var expected = @"─┤A├─";
|
|
TestHelpers.AssertDriverContentsAre (expected, _output);
|
|
TestHelpers.AssertDriverAttributesAre ("00000", null, view.ColorScheme.Normal);
|
|
}
|
|
|
|
[Fact, SetupFakeDriver]
|
|
public void Border_Parent_HasFocus_Title_Uses_FocusAttribute ()
|
|
{
|
|
var view = new View () {
|
|
Title = "A",
|
|
Height = 2,
|
|
Width = 5
|
|
};
|
|
view.Border.Thickness = new Thickness (0, 1, 0, 0);
|
|
view.Border.LineStyle = LineStyle.Single;
|
|
view.ColorScheme = new ColorScheme () {
|
|
Normal = new Attribute (Color.Red, Color.Green),
|
|
Focus = new Attribute (Color.Green, Color.Red),
|
|
};
|
|
Assert.NotEqual (view.ColorScheme.Normal.Foreground, view.ColorScheme.Focus.Foreground);
|
|
Assert.Equal (ColorName.Red, view.Border.GetNormalColor ().Foreground.GetClosestNamedColor ());
|
|
Assert.Equal (ColorName.Green, view.Border.GetFocusColor ().Foreground.GetClosestNamedColor ());
|
|
Assert.Equal (view.GetFocusColor (), view.Border.GetFocusColor ());
|
|
|
|
view.BeginInit ();
|
|
view.EndInit ();
|
|
view.Draw ();
|
|
|
|
var expected = @"─┤A├─";
|
|
TestHelpers.AssertDriverContentsAre (expected, _output);
|
|
TestHelpers.AssertDriverAttributesAre ("00000", null, view.ColorScheme.Normal);
|
|
|
|
view.CanFocus = true;
|
|
view.SetFocus ();
|
|
view.Draw ();
|
|
Assert.Equal (view.GetFocusColor (), view.Border.GetFocusColor ());
|
|
Assert.Equal (view.ColorScheme.Focus.Foreground, view.Border.GetFocusColor ().Foreground);
|
|
Assert.Equal (view.ColorScheme.Normal.Foreground, view.Border.GetNormalColor ().Foreground);
|
|
TestHelpers.AssertDriverAttributesAre ("00100", null, view.ColorScheme.Normal, view.GetFocusColor ());
|
|
}
|
|
}
|