mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Migrate 210 tests to UnitTests.Parallelizable, add CreateFakeDriver helper, prove View.Draw() works in parallel tests, and provide comprehensive performance analysis (#4297)
* Initial plan * Migrate Category A test files to UnitTests.Parallelizable (135 tests) Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add 11 ButtonTests to Parallelizable, remove from UnitTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive test migration report Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive performance analysis of UnitTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate 2 Autocomplete tests and add Text tests analysis Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add proof-of-concept: TextFormatter.Draw works in parallel tests with local driver Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add CreateFakeDriver helper to ParallelizableBase and migrate 4 TextFormatterTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Remove proof-of-concept test from AutocompleteTests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Move Scheme-accessing tests back to UnitTests to fix intermittent failures Co-authored-by: tig <585482+tig@users.noreply.github.com> * Update parallel tests README to document ConfigurationManager/SchemeManager restrictions Co-authored-by: tig <585482+tig@users.noreply.github.com> * Document static member restriction in parallel tests README Co-authored-by: tig <585482+tig@users.noreply.github.com> * Restore accidentally deleted ButtonTests.Accept_Cancel_Event_OnAccept_Returns_True test Co-authored-by: tig <585482+tig@users.noreply.github.com> * Migrate Accept_Cancel_Event_OnAccept_Returns_True test to Parallelizable 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>
This commit is contained in:
44
Tests/UnitTestsParallelizable/Text/AutocompleteTests.cs
Normal file
44
Tests/UnitTestsParallelizable/Text/AutocompleteTests.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using TerminalGuiFluentTesting;
|
||||
using UnitTests;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.TextTests;
|
||||
|
||||
/// <summary>
|
||||
/// Pure unit tests for Autocomplete functionality that don't require Application or Driver.
|
||||
/// Integration tests for Autocomplete (popup behavior, rendering) remain in UnitTests.
|
||||
/// </summary>
|
||||
public class AutocompleteTests : UnitTests.Parallelizable.ParallelizableBase
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public AutocompleteTests (ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
}
|
||||
[Fact]
|
||||
public void Test_GenerateSuggestions_Simple ()
|
||||
{
|
||||
var ac = new TextViewAutocomplete ();
|
||||
|
||||
((SingleWordSuggestionGenerator)ac.SuggestionGenerator).AllSuggestions =
|
||||
new () { "fish", "const", "Cobble" };
|
||||
|
||||
var tv = new TextView ();
|
||||
tv.InsertText ("co");
|
||||
|
||||
ac.HostControl = tv;
|
||||
|
||||
ac.GenerateSuggestions (
|
||||
new (
|
||||
Cell.ToCellList (tv.Text),
|
||||
2
|
||||
)
|
||||
);
|
||||
|
||||
Assert.Equal (2, ac.Suggestions.Count);
|
||||
Assert.Equal ("const", ac.Suggestions [0].Title);
|
||||
Assert.Equal ("Cobble", ac.Suggestions [1].Title);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
using System.Text;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
using UnitTests;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
|
||||
namespace Terminal.Gui.TextTests;
|
||||
|
||||
public class TextFormatterTests
|
||||
public class TextFormatterTests : UnitTests.Parallelizable.ParallelizableBase
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public TextFormatterTests (ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
}
|
||||
[Theory]
|
||||
[InlineData ("")]
|
||||
[InlineData (null)]
|
||||
@@ -2959,4 +2964,120 @@ public class TextFormatterTests
|
||||
string actual = TextFormatter.ReplaceCRLFWithSpace(input);
|
||||
Assert.Equal (expected, actual);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// MIGRATED TESTS FROM UnitTests/Text/TextFormatterTests.cs
|
||||
// These tests now use CreateFakeDriver() from ParallelizableBase
|
||||
// instead of relying on Application.Driver via [SetupFakeDriver]
|
||||
// ============================================================
|
||||
|
||||
[Theory]
|
||||
[InlineData ("A", 0, "")]
|
||||
[InlineData ("A", 1, "A")]
|
||||
[InlineData ("A", 2, "A")]
|
||||
[InlineData ("A", 3, " A")]
|
||||
[InlineData ("AB", 1, "A")]
|
||||
[InlineData ("AB", 2, "AB")]
|
||||
[InlineData ("ABC", 3, "ABC")]
|
||||
[InlineData ("ABC", 4, "ABC")]
|
||||
[InlineData ("ABC", 5, " ABC")]
|
||||
[InlineData ("ABC", 6, " ABC")]
|
||||
[InlineData ("ABC", 9, " ABC")]
|
||||
public void Draw_Horizontal_Centered (string text, int width, string expectedText)
|
||||
{
|
||||
var driver = CreateFakeDriver (width > 0 ? width : 1, 1);
|
||||
|
||||
TextFormatter tf = new ()
|
||||
{
|
||||
Text = text,
|
||||
Alignment = Alignment.Center,
|
||||
ConstrainToWidth = width,
|
||||
ConstrainToHeight = 1
|
||||
};
|
||||
|
||||
tf.Draw (new Rectangle (0, 0, width, 1), Attribute.Default, Attribute.Default, default, driver);
|
||||
|
||||
DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output, driver);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData ("A", 0, "")]
|
||||
[InlineData ("A", 1, "A")]
|
||||
[InlineData ("A", 2, "A")]
|
||||
[InlineData ("A B", 3, "A B")]
|
||||
[InlineData ("A B", 1, "A")]
|
||||
[InlineData ("A B", 2, "A")]
|
||||
[InlineData ("A B", 4, "A B")]
|
||||
[InlineData ("A B", 5, "A B")]
|
||||
[InlineData ("A B", 6, "A B")]
|
||||
[InlineData ("A B", 10, "A B")]
|
||||
[InlineData ("ABC ABC", 10, "ABC ABC")]
|
||||
public void Draw_Horizontal_Justified (string text, int width, string expectedText)
|
||||
{
|
||||
var driver = CreateFakeDriver (width > 0 ? width : 1, 1);
|
||||
|
||||
TextFormatter tf = new ()
|
||||
{
|
||||
Text = text,
|
||||
Alignment = Alignment.Fill,
|
||||
ConstrainToWidth = width,
|
||||
ConstrainToHeight = 1
|
||||
};
|
||||
|
||||
tf.Draw (new Rectangle (0, 0, width, 1), Attribute.Default, Attribute.Default, default, driver);
|
||||
|
||||
DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output, driver);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData ("A", 0, "")]
|
||||
[InlineData ("A", 1, "A")]
|
||||
[InlineData ("A", 2, "A")]
|
||||
[InlineData ("AB", 1, "A")]
|
||||
[InlineData ("AB", 2, "AB")]
|
||||
[InlineData ("ABC", 3, "ABC")]
|
||||
[InlineData ("ABC", 4, "ABC")]
|
||||
[InlineData ("ABC", 6, "ABC")]
|
||||
public void Draw_Horizontal_Left (string text, int width, string expectedText)
|
||||
{
|
||||
var driver = CreateFakeDriver (width > 0 ? width : 1, 1);
|
||||
|
||||
TextFormatter tf = new ()
|
||||
{
|
||||
Text = text,
|
||||
Alignment = Alignment.Start,
|
||||
ConstrainToWidth = width,
|
||||
ConstrainToHeight = 1
|
||||
};
|
||||
|
||||
tf.Draw (new Rectangle (0, 0, width, 1), Attribute.Default, Attribute.Default, default, driver);
|
||||
|
||||
DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output, driver);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData ("A", 0, "")]
|
||||
[InlineData ("A", 1, "A")]
|
||||
[InlineData ("A", 2, " A")]
|
||||
[InlineData ("AB", 1, "B")]
|
||||
[InlineData ("AB", 2, "AB")]
|
||||
[InlineData ("ABC", 3, "ABC")]
|
||||
[InlineData ("ABC", 4, " ABC")]
|
||||
[InlineData ("ABC", 6, " ABC")]
|
||||
public void Draw_Horizontal_Right (string text, int width, string expectedText)
|
||||
{
|
||||
var driver = CreateFakeDriver (width > 0 ? width : 1, 1);
|
||||
|
||||
TextFormatter tf = new ()
|
||||
{
|
||||
Text = text,
|
||||
Alignment = Alignment.End,
|
||||
ConstrainToWidth = width,
|
||||
ConstrainToHeight = 1
|
||||
};
|
||||
|
||||
tf.Draw (new Rectangle (0, 0, width, 1), Attribute.Default, Attribute.Default, default, driver);
|
||||
|
||||
DriverAssert.AssertDriverContentsWithFrameAre (expectedText, _output, driver);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user