Add DrawIncompleteFrame method and unit tests.

This commit is contained in:
BDisp
2023-11-18 23:22:46 +00:00
parent 98f9e1e856
commit 680ba264e1
2 changed files with 580 additions and 13 deletions

View File

@@ -2,6 +2,7 @@
using System;
using Xunit;
using Xunit.Abstractions;
using static Terminal.Gui.View;
namespace Terminal.Gui.ViewsTests {
public class DrawTests {
@@ -336,11 +337,11 @@ t ", output);
}
[Fact, AutoInitShutdown]
public void DrawFrame_Test ()
public void DrawFrame_Merge ()
{
var label = new View () { X = Pos.Center (), Y = Pos.Center (), Text = "test", AutoSize = true };
var view = new View () { Width = 10, Height = 5 };
view.DrawContentComplete += (s, e) => view.DrawFrame (view.Bounds, LineStyle.Single);
view.DrawContent += (s, e) => view.DrawFrame (view.Bounds, LineStyle.Single);
view.Add (label);
Application.Top.Add (view);
Application.Begin (Application.Top);
@@ -352,5 +353,316 @@ t ", output);
│ │
└────────┘", output);
}
[Fact, AutoInitShutdown]
public void DrawFrame_Without_Merge ()
{
var label = new View () { X = Pos.Center (), Y = Pos.Center (), Text = "test", AutoSize = true };
var view = new View () { Width = 10, Height = 5 };
view.DrawContentComplete += (s, e) => {
view.DrawFrame (view.Bounds, LineStyle.Single, null, false);
view.OnRenderLineCanvas ();
};
view.Add (label);
Application.Top.Add (view);
Application.Begin (Application.Top);
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌────────┐
│ │
│ test │
│ │
└────────┘", output);
}
[Theory, AutoInitShutdown]
[InlineData (1, Side.Left, 5, Side.Left, @"
┌────────┐
│ │
test │
─────────┘")]
[InlineData (1, Side.Left, 4, Side.Left, @"
┌────────┐
│ │
test │
└────────┘")]
[InlineData (0, Side.Left, 3, Side.Left, @"
┌────────┐
test │
│ │
└────────┘")]
[InlineData (5, Side.Top, -1, Side.Top, @"
│ ────┐
│ │
│ test │
│ │
└────────┘")]
[InlineData (5, Side.Top, 0, Side.Top, @"
┌ ────┐
│ │
│ test │
│ │
└────────┘")]
[InlineData (6, Side.Top, 1, Side.Top, @"
┌─ ───┐
│ │
│ test │
│ │
└────────┘")]
[InlineData (7, Side.Top, 2, Side.Top, @"
┌── ──┐
│ │
│ test │
│ │
└────────┘")]
[InlineData (8, Side.Top, 3, Side.Top, @"
┌─── ─┐
│ │
│ test │
│ │
└────────┘")]
[InlineData (9, Side.Top, 4, Side.Top, @"
┌──── ┐
│ │
│ test │
│ │
└────────┘")]
[InlineData (10, Side.Top, 5, Side.Top, @"
┌───── │
│ │
│ test │
│ │
└────────┘")]
[InlineData (3, Side.Right, -1, Side.Right, @"
┌─────────
│ test
│ │
└────────┘")]
[InlineData (3, Side.Right, 0, Side.Right, @"
┌────────┐
│ test
│ │
└────────┘")]
[InlineData (4, Side.Right, 1, Side.Right, @"
┌────────┐
│ │
│ test
└────────┘")]
[InlineData (4, Side.Bottom, 10, Side.Bottom, @"
┌────────┐
│ │
│ test │
│ │
└──── │")]
[InlineData (4, Side.Bottom, 9, Side.Bottom, @"
┌────────┐
│ │
│ test │
│ │
└──── ┘")]
[InlineData (3, Side.Bottom, 8, Side.Bottom, @"
┌────────┐
│ │
│ test │
│ │
└─── ─┘")]
[InlineData (2, Side.Bottom, 7, Side.Bottom, @"
┌────────┐
│ │
│ test │
│ │
└── ──┘")]
[InlineData (1, Side.Bottom, 6, Side.Bottom, @"
┌────────┐
│ │
│ test │
│ │
└─ ───┘")]
[InlineData (0, Side.Bottom, 5, Side.Bottom, @"
┌────────┐
│ │
│ test │
│ │
└ ────┘")]
[InlineData (-1, Side.Bottom, 5, Side.Bottom, @"
┌────────┐
│ │
│ test │
│ │
│ ────┘")]
public void DrawIncompleteFrame_All_Sides (int start, Side startSide, int end, Side endSide, string expected)
{
View view = GetViewsForDrawFrameTests (start, startSide, end, endSide);
Application.Top.Add (view);
Application.Begin (Application.Top);
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
private static View GetViewsForDrawFrameTests (int start, Side startSide, int end, Side endSide)
{
var label = new View () { X = Pos.Center (), Y = Pos.Center (), Text = "test", AutoSize = true };
var view = new View () { Width = 10, Height = 5 };
view.DrawContent += (s, e) =>
view.DrawIncompleteFrame (new (start, startSide), new (end, endSide), view.Bounds, LineStyle.Single);
view.Add (label);
return view;
}
[Theory, AutoInitShutdown]
[InlineData (4, Side.Left, 4, Side.Right, @"
┌────────┐
│ │
│ test │
│ │
│ │")]
[InlineData (0, Side.Top, 0, Side.Bottom, @"
─────────┐
test │
─────────┘")]
[InlineData (0, Side.Right, 0, Side.Left, @"
│ │
│ │
│ test │
│ │
└────────┘")]
[InlineData (9, Side.Bottom, 9, Side.Top, @"
┌─────────
│ test
└─────────")]
public void DrawIncompleteFrame_Three_Full_Sides (int start, Side startSide, int end, Side endSide, string expected)
{
View view = GetViewsForDrawFrameTests (start, startSide, end, endSide);
Application.Top.Add (view);
Application.Begin (Application.Top);
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Theory, AutoInitShutdown]
[InlineData (4, Side.Left, 10, Side.Top, @"
┌─────────
│ test
│ ")]
[InlineData (0, Side.Top, 5, Side.Right, @"
─────────┐
test │
│")]
[InlineData (0, Side.Right, 0, Side.Bottom, @"
test │
─────────┘")]
[InlineData (9, Side.Bottom, 0, Side.Left, @"
│ test
└─────────")]
public void DrawIncompleteFrame_Two_Full_Sides (int start, Side startSide, int end, Side endSide, string expected)
{
View view = GetViewsForDrawFrameTests (start, startSide, end, endSide);
Application.Top.Add (view);
Application.Begin (Application.Top);
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Theory, AutoInitShutdown]
[InlineData (4, Side.Left, 0, Side.Left, @"
│ test
│ ")]
[InlineData (0, Side.Top, 9, Side.Top, @"
──────────
test ")]
[InlineData (0, Side.Right, 4, Side.Right, @"
test │
│")]
[InlineData (9, Side.Bottom, 0, Side.Bottom, @"
test
──────────")]
public void DrawIncompleteFrame_One_Full_Sides (int start, Side startSide, int end, Side endSide, string expected)
{
View view = GetViewsForDrawFrameTests (start, startSide, end, endSide);
Application.Top.Add (view);
Application.Begin (Application.Top);
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Theory, AutoInitShutdown]
[InlineData (0, Side.Bottom, 0, Side.Top, @"
│ test
└ ")]
[InlineData (0, Side.Left, 0, Side.Right, @"
┌────────┐
test ")]
[InlineData (9, Side.Top, 9, Side.Bottom, @"
test │
┘")]
[InlineData (4, Side.Right, 4, Side.Left, @"
test
└────────┘")]
public void DrawIncompleteFrame_One_Full_Sides_With_Corner (int start, Side startSide, int end, Side endSide, string expected)
{
View view = GetViewsForDrawFrameTests (start, startSide, end, endSide);
Application.Top.Add (view);
Application.Begin (Application.Top);
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Theory, AutoInitShutdown]
[InlineData (2, Side.Left, 2, Side.Left, @"
│ test")]
[InlineData (3, Side.Top, 6, Side.Top, @"
────
test")]
[InlineData (2, Side.Right, 2, Side.Right, @"
test │")]
[InlineData (6, Side.Bottom, 3, Side.Bottom, @"
test
────")]
public void DrawIncompleteFrame_One_Part_Sides (int start, Side startSide, int end, Side endSide, string expected)
{
View view = GetViewsForDrawFrameTests (start, startSide, end, endSide);
Application.Top.Add (view);
Application.Begin (Application.Top);
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
}
}