mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
* POC * View.DrawFrame now uses LineCanvas * Fixes #2531. Toplevel should redraw only if it's needed. * Fix toplevel when mdi is enabled preventing clear the screen twice. * Massive LineCanvis updates * Fixes #2534. Bounds isn't updating when the Frame is changed. * Almost everything works! * Had to disable a few tests but all unit test now pass again * Deleted ConsoleDriver.DrawWindowFrame; hacked ProgressBar * Deleted ConsoleDriver.DrawWindowTitle; moved to Frame.DrawTitle * Renames BorderFrame to Border * Removed old commented code * Tweaked scenario * Added auto convert \r\n to Enviornment.NewLine in TestHelpers.AssertEqual * Fix merge errors. * Fix AssertEqual newlines to platform-specific. * Refactored frames drawing; view adds to its lineview, superview renders them * New titlebar style based on Border.Top size; fixed bugs * wzard bug --------- Co-authored-by: BDisp <bd.bdisp@gmail.com>
This commit is contained in:
@@ -10,6 +10,9 @@ using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using Rune = System.Rune;
|
||||
using Attribute = Terminal.Gui.Attribute;
|
||||
using Microsoft.VisualStudio.TestPlatform.Utilities;
|
||||
using NStack;
|
||||
using Xunit.Sdk;
|
||||
|
||||
|
||||
// This class enables test functions annotated with the [AutoInitShutdown] attribute to
|
||||
@@ -82,6 +85,31 @@ public class AutoInitShutdownAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public class SetupFakeDriverAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
|
||||
/// <summary>
|
||||
/// Enables test functions annotated with the [SetupFakeDriver] attribute to
|
||||
/// set Application.Driver to new FakeDriver().
|
||||
/// </summary>
|
||||
public SetupFakeDriverAttribute ()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Before (MethodInfo methodUnderTest)
|
||||
{
|
||||
Debug.WriteLine ($"Before: {methodUnderTest.Name}");
|
||||
Assert.Null (Application.Driver);
|
||||
Application.Driver = new FakeDriver ();
|
||||
}
|
||||
|
||||
public override void After (MethodInfo methodUnderTest)
|
||||
{
|
||||
Debug.WriteLine ($"After: {methodUnderTest.Name}");
|
||||
Application.Driver = null;
|
||||
}
|
||||
}
|
||||
|
||||
class TestHelpers {
|
||||
#pragma warning disable xUnit1013 // Public method should be marked as test
|
||||
public static void AssertDriverContentsAre (string expectedLook, ITestOutputHelper output, bool ignoreLeadingWhitespace = false)
|
||||
@@ -114,14 +142,13 @@ class TestHelpers {
|
||||
|
||||
// ignore trailing whitespace on each line
|
||||
var trailingWhitespace = new Regex (@"\s+$", RegexOptions.Multiline);
|
||||
var leadingWhitespace = new Regex(@"^\s+",RegexOptions.Multiline);
|
||||
var leadingWhitespace = new Regex (@"^\s+", RegexOptions.Multiline);
|
||||
|
||||
// get rid of trailing whitespace on each line (and leading/trailing whitespace of start/end of full string)
|
||||
expectedLook = trailingWhitespace.Replace (expectedLook, "").Trim ();
|
||||
actualLook = trailingWhitespace.Replace (actualLook, "").Trim ();
|
||||
|
||||
if(ignoreLeadingWhitespace)
|
||||
{
|
||||
if (ignoreLeadingWhitespace) {
|
||||
expectedLook = leadingWhitespace.Replace (expectedLook, "").Trim ();
|
||||
actualLook = leadingWhitespace.Replace (actualLook, "").Trim ();
|
||||
}
|
||||
@@ -286,4 +313,63 @@ class TestHelpers {
|
||||
var a = new Attribute (userExpected);
|
||||
return $"{a.Foreground},{a.Background}";
|
||||
}
|
||||
|
||||
#pragma warning disable xUnit1013 // Public method should be marked as test
|
||||
/// <summary>
|
||||
/// Verifies two strings are equivalent. If the assert fails, output will be generated to standard
|
||||
/// output showing the expected and actual look.
|
||||
/// </summary>
|
||||
/// <param name="output"></param>
|
||||
/// <param name="expectedLook">A string containing the expected look. Newlines should be specified as "\r\n" as
|
||||
/// they will be converted to <see cref="Environment.NewLine"/> to make tests platform independent.</param>
|
||||
/// <param name="actualLook"></param>
|
||||
public static void AssertEqual (ITestOutputHelper output, string expectedLook, string actualLook)
|
||||
{
|
||||
// Convert newlines to platform-specific newlines
|
||||
expectedLook = ReplaceNewLinesToPlatformSpecific (expectedLook);
|
||||
|
||||
// If test is about to fail show user what things looked like
|
||||
if (!string.Equals (expectedLook, actualLook)) {
|
||||
output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
|
||||
output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);
|
||||
}
|
||||
|
||||
Assert.Equal (expectedLook, actualLook);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies two strings are equivalent. If the assert fails, output will be generated to standard
|
||||
/// output showing the expected and actual look.
|
||||
/// </summary>
|
||||
/// <param name="output">Uses <see cref="ustring.ToString()"/> on <paramref name="actualLook"/>.</param>
|
||||
/// <param name="expectedLook">A string containing the expected look. Newlines should be specified as "\r\n" as
|
||||
/// they will be converted to <see cref="Environment.NewLine"/> to make tests platform independent.</param>
|
||||
/// <param name="actualLook"></param>
|
||||
public static void AssertEqual (ITestOutputHelper output, string expectedLook, ustring actualLook)
|
||||
{
|
||||
// Convert newlines to platform-specific newlines
|
||||
expectedLook = ReplaceNewLinesToPlatformSpecific (expectedLook);
|
||||
|
||||
// If test is about to fail show user what things looked like
|
||||
if (!string.Equals (expectedLook, actualLook.ToString ())) {
|
||||
output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
|
||||
output?.WriteLine ("But Was:" + Environment.NewLine + actualLook.ToString ());
|
||||
}
|
||||
|
||||
Assert.Equal (expectedLook, actualLook);
|
||||
}
|
||||
#pragma warning restore xUnit1013 // Public method should be marked as test
|
||||
|
||||
private static string ReplaceNewLinesToPlatformSpecific (string toReplace)
|
||||
{
|
||||
var replaced = toReplace;
|
||||
|
||||
if (Environment.NewLine.Length == 2 && !replaced.Contains ("\r\n")) {
|
||||
replaced = replaced.Replace ("\n", Environment.NewLine);
|
||||
} else if (Environment.NewLine.Length == 1) {
|
||||
replaced = replaced.Replace ("\r\n", Environment.NewLine);
|
||||
}
|
||||
|
||||
return replaced;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user