mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 00:46:39 +01:00
Fixes #4282 - Migrate tests from UnitTests to UnitTests.Parallelizable (67 tests migrated + comprehensive documentation) (#4293)
* Initial plan * Add 31 parallelizable LineCanvas unit tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add 4 parallelizable Ruler unit tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Complete Category A migration - 35 tests migrated Co-authored-by: tig <585482+tig@users.noreply.github.com> * Remove duplicate tests from UnitTests after migration to Parallelizable Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 6 pure unit tests from ColorPicker and DatePicker to Parallelizable Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix duplicate test names between UnitTests and Parallelizable Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 11 Label tests to Parallelizable (52 tests total) Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix documentation: SetupFakeDriver tests CAN be parallelized Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive parallelization rules to documentation Co-authored-by: tig <585482+tig@users.noreply.github.com> * Update README and start migrating Button/CheckBox/RadioGroup tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Remove duplicate Button tests from UnitTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 5 CheckBox unit tests to Parallelizable (27 with Theory expansion) Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 4 more CheckBox tests to Parallelizable (67 tests total, 9,478 passing) Co-authored-by: tig <585482+tig@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com> Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
260
Tests/UnitTestsParallelizable/Drawing/LineCanvasTests.cs
Normal file
260
Tests/UnitTestsParallelizable/Drawing/LineCanvasTests.cs
Normal file
@@ -0,0 +1,260 @@
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
/// <summary>
|
||||
/// Pure unit tests for <see cref="LineCanvas"/> that don't require Application.Driver or View context.
|
||||
/// These tests focus on properties and behavior that don't depend on glyph rendering.
|
||||
///
|
||||
/// Note: Tests that verify rendered output (ToString()) cannot be parallelized because LineCanvas
|
||||
/// depends on Application.Driver for glyph resolution and configuration. Those tests remain in UnitTests.
|
||||
/// </summary>
|
||||
public class LineCanvasTests : UnitTests.Parallelizable.ParallelizableBase
|
||||
{
|
||||
#region Basic API Tests
|
||||
|
||||
[Fact]
|
||||
public void Empty_Canvas_ToString_Returns_EmptyString ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
Assert.Equal (string.Empty, canvas.ToString ());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Clear_Removes_All_Lines ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
|
||||
canvas.AddLine (new (0, 0), 3, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
canvas.Clear ();
|
||||
|
||||
Assert.Empty (canvas.Lines);
|
||||
Assert.Equal (Rectangle.Empty, canvas.Bounds);
|
||||
Assert.Equal (string.Empty, canvas.ToString ());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Lines_Property_Returns_ReadOnly_Collection ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
Assert.Single (canvas.Lines);
|
||||
Assert.IsAssignableFrom<IReadOnlyCollection<StraightLine>> (canvas.Lines);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddLine_Adds_Line_To_Collection ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
Assert.Empty (canvas.Lines);
|
||||
|
||||
canvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
|
||||
Assert.Single (canvas.Lines);
|
||||
|
||||
canvas.AddLine (new (0, 0), 3, Orientation.Vertical, LineStyle.Single);
|
||||
Assert.Equal (2, canvas.Lines.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_With_Lines_Creates_Canvas_With_Lines ()
|
||||
{
|
||||
var lines = new[]
|
||||
{
|
||||
new StraightLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single),
|
||||
new StraightLine (new (0, 0), 3, Orientation.Vertical, LineStyle.Single)
|
||||
};
|
||||
|
||||
var canvas = new LineCanvas (lines);
|
||||
|
||||
Assert.Equal (2, canvas.Lines.Count);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bounds Tests - Tests for Bounds property
|
||||
|
||||
[Theory]
|
||||
[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)]
|
||||
public void Viewport_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 (x, y), length, Orientation.Horizontal, LineStyle.Single);
|
||||
canvas.AddLine (new (x, y), length, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
Assert.Equal (new (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Bounds);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[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)]
|
||||
public void Viewport_H_Line (
|
||||
int x,
|
||||
int y,
|
||||
int length,
|
||||
int expectedX,
|
||||
int expectedY,
|
||||
int expectedWidth,
|
||||
int expectedHeight
|
||||
)
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (x, y), length, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
Assert.Equal (new (expectedX, expectedY, expectedWidth, expectedHeight), canvas.Bounds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bounds_Specific_Coordinates ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (5, 5), 3, Orientation.Horizontal, LineStyle.Single);
|
||||
Assert.Equal (new (5, 5, 3, 1), canvas.Bounds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bounds_Empty_Canvas_Returns_Empty_Rectangle ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
Assert.Equal (Rectangle.Empty, canvas.Bounds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bounds_Single_Point_Zero_Length ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (5, 5), 0, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
Assert.Equal (new (5, 5, 1, 1), canvas.Bounds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bounds_Horizontal_Line ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (2, 3), 5, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
Assert.Equal (new (2, 3, 5, 1), canvas.Bounds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bounds_Vertical_Line ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (2, 3), 5, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
Assert.Equal (new (2, 3, 1, 5), canvas.Bounds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bounds_Multiple_Lines_Returns_Union ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
|
||||
canvas.AddLine (new (0, 0), 3, Orientation.Vertical, LineStyle.Single);
|
||||
|
||||
Assert.Equal (new (0, 0, 5, 3), canvas.Bounds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bounds_Negative_Length_Line ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (5, 5), -3, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
// Line from (5,5) going left 3 positions: includes points 3, 4, 5 (width 3, X starts at 3)
|
||||
Assert.Equal (new (3, 5, 3, 1), canvas.Bounds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bounds_Complex_Box ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
// top
|
||||
canvas.AddLine (new (0, 0), 3, Orientation.Horizontal, LineStyle.Single);
|
||||
// left
|
||||
canvas.AddLine (new (0, 0), 2, Orientation.Vertical, LineStyle.Single);
|
||||
// right
|
||||
canvas.AddLine (new (2, 0), 2, Orientation.Vertical, LineStyle.Single);
|
||||
// bottom
|
||||
canvas.AddLine (new (0, 2), 3, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
Assert.Equal (new (0, 0, 3, 3), canvas.Bounds);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Exclusion Tests
|
||||
|
||||
[Fact]
|
||||
public void ClearExclusions_Clears_Exclusion_Region ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
var region = new Region (new Rectangle (0, 0, 2, 1));
|
||||
canvas.Exclude (region);
|
||||
canvas.ClearExclusions ();
|
||||
|
||||
// After clearing exclusions, GetMap should return all points
|
||||
var map = canvas.GetMap ();
|
||||
Assert.Equal (5, map.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Exclude_Removes_Points_From_Map ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
canvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
|
||||
|
||||
var region = new Region (new Rectangle (0, 0, 2, 1));
|
||||
canvas.Exclude (region);
|
||||
|
||||
var map = canvas.GetMap ();
|
||||
// Should have 5 - 2 = 3 points (excluding the first 2)
|
||||
Assert.Equal (3, map.Count);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fill Property Tests
|
||||
|
||||
[Fact]
|
||||
public void Fill_Property_Can_Be_Set ()
|
||||
{
|
||||
var foregroundFill = new SolidFill (new Color (255, 0));
|
||||
var backgroundFill = new SolidFill (new Color (0, 0));
|
||||
var fillPair = new FillPair (foregroundFill, backgroundFill);
|
||||
|
||||
var canvas = new LineCanvas { Fill = fillPair };
|
||||
|
||||
Assert.Equal (fillPair, canvas.Fill);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Fill_Property_Defaults_To_Null ()
|
||||
{
|
||||
var canvas = new LineCanvas ();
|
||||
Assert.Null (canvas.Fill);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
46
Tests/UnitTestsParallelizable/Drawing/RulerTests.cs
Normal file
46
Tests/UnitTestsParallelizable/Drawing/RulerTests.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
/// <summary>
|
||||
/// Pure unit tests for <see cref="Ruler"/> that don't require Application.Driver or View context.
|
||||
/// These tests focus on properties and behavior that don't depend on rendering.
|
||||
///
|
||||
/// Note: Tests that verify rendered output (Draw methods) require Application.Driver and remain in UnitTests as integration tests.
|
||||
/// </summary>
|
||||
public class RulerTests : UnitTests.Parallelizable.ParallelizableBase
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_Defaults ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (0, r.Length);
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attribute_Set ()
|
||||
{
|
||||
var newAttribute = new Attribute (Color.Red, Color.Green);
|
||||
|
||||
var r = new Ruler ();
|
||||
r.Attribute = newAttribute;
|
||||
Assert.Equal (newAttribute, r.Attribute);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Length_Set ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (0, r.Length);
|
||||
r.Length = 42;
|
||||
Assert.Equal (42, r.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Orientation_Set ()
|
||||
{
|
||||
var r = new Ruler ();
|
||||
Assert.Equal (Orientation.Horizontal, r.Orientation);
|
||||
r.Orientation = Orientation.Vertical;
|
||||
Assert.Equal (Orientation.Vertical, r.Orientation);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user