mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
* Fixes #2616. Support combining sequences that don't normalize * Decouples Application from ConsoleDriver in TestHelpers * Updates driver tests to match new arch * Start on making all driver tests test all drivers * Improves handling if combining marks. * Fix unit tests fails. * Fix unit tests fails. * Handling combining mask. * Tying to fix this unit test that sometimes fail. * Add support for combining mask on NetDriver. * Enable CombiningMarks as List<Rune>. * Prevents combining marks on invalid runes default and space. * Formatting for CI tests. * Fix non-normalized combining mark to add 1 to Col. * Reformatting for retest the CI. * Forces non-normalized CMs to be ignored. --------- Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
@@ -422,20 +422,25 @@ public class ApplicationTests {
|
||||
|
||||
#region ShutdownTests
|
||||
[Fact]
|
||||
public void Shutdown_Allows_Async ()
|
||||
public async void Shutdown_Allows_Async ()
|
||||
{
|
||||
static async Task TaskWithAsyncContinuation ()
|
||||
bool isCompletedSuccessfully = false;
|
||||
|
||||
async Task TaskWithAsyncContinuation ()
|
||||
{
|
||||
await Task.Yield ();
|
||||
await Task.Yield ();
|
||||
|
||||
isCompletedSuccessfully = true;
|
||||
}
|
||||
|
||||
Init ();
|
||||
Application.Shutdown ();
|
||||
|
||||
var task = TaskWithAsyncContinuation ();
|
||||
Assert.False (isCompletedSuccessfully);
|
||||
await TaskWithAsyncContinuation ();
|
||||
Thread.Sleep (100);
|
||||
Assert.True (task.IsCompletedSuccessfully);
|
||||
Assert.True (isCompletedSuccessfully);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Buffers;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
@@ -11,29 +12,33 @@ public class AddRuneTests {
|
||||
|
||||
public AddRuneTests (ITestOutputHelper output)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
this._output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRune ()
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void AddRune (Type driverType)
|
||||
{
|
||||
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
driver.Rows = 25;
|
||||
driver.Cols = 80;
|
||||
driver.Init ();
|
||||
driver.AddRune (new Rune ('a'));
|
||||
Assert.Equal ((Rune)'a', driver.Contents [0, 0].Rune);
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRune_InvalidLocation_DoesNothing ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
driver.Move (driver.Cols, driver.Rows);
|
||||
@@ -46,14 +51,12 @@ public class AddRuneTests {
|
||||
}
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRune_MovesToNextColumn ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
driver.AddRune ('a');
|
||||
@@ -87,14 +90,12 @@ public class AddRuneTests {
|
||||
}
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRune_MovesToNextColumn_Wide ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
// 🍕 Slice of Pizza "\U0001F355"
|
||||
@@ -134,15 +135,12 @@ public class AddRuneTests {
|
||||
//}
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void AddRune_Accented_Letter_With_Three_Combining_Unicode_Chars ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
var expected = new Rune ('ắ');
|
||||
@@ -189,6 +187,5 @@ public class AddRuneTests {
|
||||
// TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
//ắ", output);
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,53 +20,33 @@ namespace Terminal.Gui.DriverTests {
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
//[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (CursesDriver))]
|
||||
//[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void Init_Inits (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
var ml = driver.Init ();
|
||||
Assert.NotNull (ml);
|
||||
Assert.NotNull (driver.Clipboard);
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
|
||||
Console.BackgroundColor = ConsoleColor.Green;
|
||||
Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
|
||||
|
||||
Assert.Equal (80, Console.BufferWidth);
|
||||
Assert.Equal (25, Console.BufferHeight);
|
||||
|
||||
// MockDriver is always 80x25
|
||||
Assert.Equal (Console.BufferWidth, driver.Cols);
|
||||
Assert.Equal (Console.BufferHeight, driver.Rows);
|
||||
driver.End ();
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
//[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (CursesDriver))]
|
||||
//[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void End_Cleans_Up (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
|
||||
|
||||
Console.BackgroundColor = ConsoleColor.Green;
|
||||
Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
|
||||
driver.Move (2, 3);
|
||||
|
||||
driver.End ();
|
||||
Assert.Equal (0, Console.CursorLeft);
|
||||
Assert.Equal (0, Console.CursorTop);
|
||||
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
|
||||
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -199,88 +179,89 @@ namespace Terminal.Gui.DriverTests {
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void TerminalResized_Simulation (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver?.Init ();
|
||||
driver.Cols = 80;
|
||||
driver.Rows = 25;
|
||||
|
||||
var wasTerminalResized = false;
|
||||
Application.SizeChanging += (s, e) => {
|
||||
driver.SizeChanged += (s, e) => {
|
||||
wasTerminalResized = true;
|
||||
Assert.Equal (120, e.Size.Width);
|
||||
Assert.Equal (40, e.Size.Height);
|
||||
};
|
||||
|
||||
Assert.Equal (80, Console.BufferWidth);
|
||||
Assert.Equal (25, Console.BufferHeight);
|
||||
|
||||
// MockDriver is by default 80x25
|
||||
Assert.Equal (Console.BufferWidth, driver.Cols);
|
||||
Assert.Equal (Console.BufferHeight, driver.Rows);
|
||||
Assert.Equal (80, driver.Cols);
|
||||
Assert.Equal (25, driver.Rows);
|
||||
Assert.False (wasTerminalResized);
|
||||
|
||||
// MockDriver will now be sets to 120x40
|
||||
driver.SetBufferSize (120, 40);
|
||||
Assert.Equal (120, Application.Driver.Cols);
|
||||
Assert.Equal (40, Application.Driver.Rows);
|
||||
driver.Cols = 120;
|
||||
driver.Rows = 40;
|
||||
driver.OnSizeChanged (new SizeChangedEventArgs(new Size(driver.Cols, driver.Rows)));
|
||||
Assert.Equal (120, driver.Cols);
|
||||
Assert.Equal (40, driver.Rows);
|
||||
Assert.True (wasTerminalResized);
|
||||
|
||||
|
||||
Application.Shutdown ();
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
// Disabled due to test error - Change Task.Delay to an await
|
||||
// [Fact, AutoInitShutdown]
|
||||
// public void Write_Do_Not_Change_On_ProcessKey ()
|
||||
// {
|
||||
// var win = new Window ();
|
||||
// Application.Begin (win);
|
||||
// ((FakeDriver)Application.Driver).SetBufferSize (20, 8);
|
||||
// [Fact, AutoInitShutdown]
|
||||
// public void Write_Do_Not_Change_On_ProcessKey ()
|
||||
// {
|
||||
// var win = new Window ();
|
||||
// Application.Begin (win);
|
||||
// ((FakeDriver)Application.Driver).SetBufferSize (20, 8);
|
||||
|
||||
// System.Threading.Tasks.Task.Run (() => {
|
||||
// System.Threading.Tasks.Task.Delay (500).Wait ();
|
||||
// Application.Invoke (() => {
|
||||
// var lbl = new Label ("Hello World") { X = Pos.Center () };
|
||||
// var dlg = new Dialog ();
|
||||
// dlg.Add (lbl);
|
||||
// Application.Begin (dlg);
|
||||
// System.Threading.Tasks.Task.Run (() => {
|
||||
// System.Threading.Tasks.Task.Delay (500).Wait ();
|
||||
// Application.Invoke (() => {
|
||||
// var lbl = new Label ("Hello World") { X = Pos.Center () };
|
||||
// var dlg = new Dialog ();
|
||||
// dlg.Add (lbl);
|
||||
// Application.Begin (dlg);
|
||||
|
||||
// var expected = @"
|
||||
//┌──────────────────┐
|
||||
//│┌───────────────┐ │
|
||||
//││ Hello World │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//│└───────────────┘ │
|
||||
//└──────────────────┘
|
||||
//";
|
||||
// var expected = @"
|
||||
//┌──────────────────┐
|
||||
//│┌───────────────┐ │
|
||||
//││ Hello World │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//│└───────────────┘ │
|
||||
//└──────────────────┘
|
||||
//";
|
||||
|
||||
// var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
// Assert.Equal (new Rect (0, 0, 20, 8), pos);
|
||||
// var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
// Assert.Equal (new Rect (0, 0, 20, 8), pos);
|
||||
|
||||
// Assert.True (dlg.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
|
||||
// dlg.Draw ();
|
||||
// Assert.True (dlg.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ())));
|
||||
// dlg.Draw ();
|
||||
|
||||
// expected = @"
|
||||
//┌──────────────────┐
|
||||
//│┌───────────────┐ │
|
||||
//││ Hello World │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//│└───────────────┘ │
|
||||
//└──────────────────┘
|
||||
//";
|
||||
// expected = @"
|
||||
//┌──────────────────┐
|
||||
//│┌───────────────┐ │
|
||||
//││ Hello World │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//││ │ │
|
||||
//│└───────────────┘ │
|
||||
//└──────────────────┘
|
||||
//";
|
||||
|
||||
// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
// Assert.Equal (new Rect (0, 0, 20, 8), pos);
|
||||
// pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
// Assert.Equal (new Rect (0, 0, 20, 8), pos);
|
||||
|
||||
// win.RequestStop ();
|
||||
// });
|
||||
// });
|
||||
// win.RequestStop ();
|
||||
// });
|
||||
// });
|
||||
|
||||
// Application.Run (win);
|
||||
// Application.Shutdown ();
|
||||
// }
|
||||
// Application.Run (win);
|
||||
// Application.Shutdown ();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@@ -14,54 +15,90 @@ public class ContentsTests {
|
||||
|
||||
public ContentsTests (ITestOutputHelper output)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (CursesDriver))] // TODO: Uncomment when #2796 and #2615 are fixed
|
||||
//[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
|
||||
public void AddStr_Combining_Character_1st_Column (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
var expected = "\u0301!";
|
||||
driver.AddStr ("\u0301!"); // acute accent + exclamation mark
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, driver);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
//[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (CursesDriver))]
|
||||
//[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (CursesDriver))] // TODO: Uncomment when #2796 and #2615 are fixed
|
||||
//[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
|
||||
public void AddStr_With_Combining_Characters (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
// driver.Init (null);
|
||||
driver.Init ();
|
||||
|
||||
var acuteaccent = new System.Text.Rune (0x0301); // Combining acute accent (é)
|
||||
var combined = "e" + acuteaccent;
|
||||
var expected = "é";
|
||||
|
||||
driver.AddStr (combined);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
|
||||
#if false // Disabled Until #2616 is fixed
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, driver);
|
||||
|
||||
// 3 char combine
|
||||
// a + ogonek + acute = <U+0061, U+0328, U+0301> ( ǫ́ )
|
||||
// a + ogonek + acute = <U+0061, U+0328, U+0301> ( ą́ )
|
||||
var ogonek = new System.Text.Rune (0x0328); // Combining ogonek (a small hook or comma shape)
|
||||
combined = "a" + ogonek + acuteaccent;
|
||||
expected = "ǫ́";
|
||||
expected = ("a" + ogonek).Normalize(NormalizationForm.FormC); // See Issue #2616
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddStr (combined);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, driver);
|
||||
|
||||
#endif
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
// e + ogonek + acute = <U+0061, U+0328, U+0301> ( ę́́ )
|
||||
combined = "e" + ogonek + acuteaccent;
|
||||
expected = ("e" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddStr (combined);
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, driver);
|
||||
|
||||
// i + ogonek + acute = <U+0061, U+0328, U+0301> ( į́́́ )
|
||||
combined = "i" + ogonek + acuteaccent;
|
||||
expected = ("i" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddStr (combined);
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, driver);
|
||||
|
||||
// u + ogonek + acute = <U+0061, U+0328, U+0301> ( ų́́́́ )
|
||||
combined = "u" + ogonek + acuteaccent;
|
||||
expected = ("u" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddStr (combined);
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, driver);
|
||||
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
//[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (CursesDriver))]
|
||||
//[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
public void Move_Bad_Coordinates (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
Assert.Equal (0, driver.Col);
|
||||
Assert.Equal (0, driver.Row);
|
||||
@@ -85,13 +122,11 @@ public class ContentsTests {
|
||||
driver.Move (500, 500);
|
||||
Assert.Equal (500, driver.Col);
|
||||
Assert.Equal (500, driver.Row);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
// TODO: Add these unit tests
|
||||
|
||||
|
||||
// AddRune moves correctly
|
||||
|
||||
// AddRune with wide characters are handled correctly
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Terminal.Gui.DriverTests {
|
||||
public void SetColors_Changes_Colors (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
|
||||
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
|
||||
@@ -34,8 +34,7 @@ namespace Terminal.Gui.DriverTests {
|
||||
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
|
||||
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
driver.End ();
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +51,6 @@ namespace Terminal.Gui.DriverTests {
|
||||
Assert.Equal (expectedSetting, driver.SupportsTrueColor);
|
||||
|
||||
driver.End ();
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -71,9 +67,6 @@ namespace Terminal.Gui.DriverTests {
|
||||
Assert.True (driver.Force16Colors);
|
||||
|
||||
driver.End ();
|
||||
|
||||
// Shutdown must be called to safely clean up Application if Init has been called
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,6 @@ public class AttributeTests {
|
||||
public void Constuctors_Constuct ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
// Test parameterless constructor
|
||||
@@ -127,7 +126,6 @@ public class AttributeTests {
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -196,7 +194,6 @@ public class AttributeTests {
|
||||
public void Implicit_Assign ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
var attr = new Attribute ();
|
||||
@@ -216,7 +213,6 @@ public class AttributeTests {
|
||||
Assert.Equal (value, attr.PlatformColor);
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -237,7 +233,6 @@ public class AttributeTests {
|
||||
public void Make_Creates ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init ();
|
||||
|
||||
var fg = new Color ();
|
||||
@@ -252,7 +247,6 @@ public class AttributeTests {
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -401,7 +401,7 @@ namespace Terminal.Gui.FileServicesTests {
|
||||
│{CM.Glyphs.LeftBracket} ►► {CM.Glyphs.RightBracket} Enter Search {CM.Glyphs.LeftBracket} OK {CM.Glyphs.RightBracket} {CM.Glyphs.LeftBracket} Cancel {CM.Glyphs.RightBracket} │
|
||||
└─────────────────────────────────────────────────────────────────────────┘
|
||||
";
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, true);
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, ignoreLeadingWhitespace: true);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -437,7 +437,7 @@ namespace Terminal.Gui.FileServicesTests {
|
||||
│{CM.Glyphs.LeftBracket} ►► {CM.Glyphs.RightBracket} Enter Search {CM.Glyphs.LeftBracket} OK {CM.Glyphs.RightBracket} {CM.Glyphs.LeftBracket} Cancel {CM.Glyphs.RightBracket} │
|
||||
└─────────────────────────────────────────────────────────────────────────┘
|
||||
";
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, true);
|
||||
TestHelpers.AssertDriverContentsAre (expected, output, ignoreLeadingWhitespace: true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -147,18 +147,24 @@ partial class TestHelpers {
|
||||
private static partial Regex LeadingWhitespaceRegEx ();
|
||||
|
||||
#pragma warning disable xUnit1013 // Public method should be marked as test
|
||||
public static void AssertDriverContentsAre (string expectedLook, ITestOutputHelper output, bool ignoreLeadingWhitespace = false)
|
||||
/// <summary>
|
||||
/// Asserts that the driver contents match the expected contents, optionally ignoring any trailing whitespace.
|
||||
/// </summary>
|
||||
/// <param name="expectedLook"></param>
|
||||
/// <param name="output"></param>
|
||||
/// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
|
||||
/// <param name="ignoreLeadingWhitespace"></param>
|
||||
public static void AssertDriverContentsAre (string expectedLook, ITestOutputHelper output, ConsoleDriver driver = null, bool ignoreLeadingWhitespace = false)
|
||||
{
|
||||
#pragma warning restore xUnit1013 // Public method should be marked as test
|
||||
|
||||
var sb = new StringBuilder ();
|
||||
var driver = (FakeDriver)Application.Driver;
|
||||
driver ??= Application.Driver;
|
||||
|
||||
var contents = driver.Contents;
|
||||
|
||||
for (int r = 0; r < driver.Rows; r++) {
|
||||
for (int c = 0; c < driver.Cols; c++) {
|
||||
// TODO: Remove hard-coded [0] once combining pairs is supported
|
||||
Rune rune = contents [r, c].Rune;
|
||||
if (rune.DecodeSurrogatePair (out char [] spair)) {
|
||||
sb.Append (spair);
|
||||
@@ -168,6 +174,10 @@ partial class TestHelpers {
|
||||
if (rune.GetColumns () > 1) {
|
||||
c++;
|
||||
}
|
||||
// See Issue #2616
|
||||
//foreach (var combMark in contents [r, c].CombiningMarks) {
|
||||
// sb.Append ((char)combMark.Value);
|
||||
//}
|
||||
}
|
||||
sb.AppendLine ();
|
||||
}
|
||||
@@ -198,11 +208,18 @@ partial class TestHelpers {
|
||||
Assert.Equal (expectedLook, actualLook);
|
||||
}
|
||||
|
||||
public static Rect AssertDriverContentsWithFrameAre (string expectedLook, ITestOutputHelper output)
|
||||
/// <summary>
|
||||
/// Asserts that the driver contents are equal to the expected look, and that the cursor is at the expected position.
|
||||
/// </summary>
|
||||
/// <param name="expectedLook"></param>
|
||||
/// <param name="output"></param>
|
||||
/// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
|
||||
/// <returns></returns>
|
||||
public static Rect AssertDriverContentsWithFrameAre (string expectedLook, ITestOutputHelper output, ConsoleDriver driver = null)
|
||||
{
|
||||
var lines = new List<List<Rune>> ();
|
||||
var sb = new StringBuilder ();
|
||||
var driver = Application.Driver;
|
||||
driver ??= Application.Driver;
|
||||
var x = -1;
|
||||
var y = -1;
|
||||
var w = -1;
|
||||
@@ -213,7 +230,6 @@ partial class TestHelpers {
|
||||
for (var r = 0; r < driver.Rows; r++) {
|
||||
var runes = new List<Rune> ();
|
||||
for (var c = 0; c < driver.Cols; c++) {
|
||||
// TODO: Remove hard-coded [0] once combining pairs is supported
|
||||
Rune rune = contents [r, c].Rune;
|
||||
if (rune != (Rune)' ') {
|
||||
if (x == -1) {
|
||||
@@ -232,6 +248,10 @@ partial class TestHelpers {
|
||||
h = r - y + 1;
|
||||
}
|
||||
if (x > -1) runes.Add (rune);
|
||||
// See Issue #2616
|
||||
//foreach (var combMark in contents [r, c].CombiningMarks) {
|
||||
// runes.Add (combMark);
|
||||
//}
|
||||
}
|
||||
if (runes.Count > 0) lines.Add (runes);
|
||||
}
|
||||
@@ -290,15 +310,16 @@ partial class TestHelpers {
|
||||
/// test method will verify those colors were used in the row/col of the console during rendering
|
||||
/// </summary>
|
||||
/// <param name="expectedLook">Numbers between 0 and 9 for each row/col of the console. Must be valid indexes of <paramref name="expectedColors"/></param>
|
||||
/// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
|
||||
/// <param name="expectedColors"></param>
|
||||
public static void AssertDriverColorsAre (string expectedLook, params Attribute [] expectedColors)
|
||||
public static void AssertDriverColorsAre (string expectedLook, ConsoleDriver driver = null, params Attribute [] expectedColors)
|
||||
{
|
||||
#pragma warning restore xUnit1013 // Public method should be marked as test
|
||||
|
||||
if (expectedColors.Length > 10) throw new ArgumentException ("This method only works for UIs that use at most 10 colors");
|
||||
|
||||
expectedLook = expectedLook.Trim ();
|
||||
var driver = (FakeDriver)Application.Driver;
|
||||
driver ??= Application.Driver;
|
||||
|
||||
var contents = driver.Contents;
|
||||
|
||||
@@ -331,11 +352,11 @@ partial class TestHelpers {
|
||||
/// If one or more of the expected colors are not used then the failure will output both
|
||||
/// the colors that were found to be used and which of your expectations was not met.
|
||||
/// </summary>
|
||||
/// <param name="driver">if null uses <see cref="Application.Driver"/></param>
|
||||
/// <param name="expectedColors"></param>
|
||||
internal static void AssertDriverUsedColors (params Attribute [] expectedColors)
|
||||
internal static void AssertDriverUsedColors (ConsoleDriver driver = null, params Attribute [] expectedColors)
|
||||
{
|
||||
var driver = (FakeDriver)Application.Driver;
|
||||
|
||||
driver ??= Application.Driver;
|
||||
var contents = driver.Contents;
|
||||
|
||||
var toFind = expectedColors.ToList ();
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
0020000000
|
||||
0000000000
|
||||
0111000000
|
||||
0000000000", expectedColors);
|
||||
0000000000", driver: Application.Driver, expectedColors);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -106,7 +106,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
0022000000
|
||||
0000000000
|
||||
0111000000
|
||||
0000000000", expectedColors);
|
||||
0000000000", driver: Application.Driver, expectedColors);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -147,7 +147,7 @@ t ", output);
|
||||
0
|
||||
0
|
||||
0
|
||||
0", new Attribute [] { Colors.Base.Normal });
|
||||
0", driver: Application.Driver, new Attribute [] { Colors.Base.Normal });
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
|
||||
@@ -942,11 +942,11 @@ cccccccccccccccccccc", output);
|
||||
if (label) {
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
111111111111111111110
|
||||
111111111111111111110", attributes);
|
||||
111111111111111111110", driver: Application.Driver, attributes);
|
||||
} else {
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
222222222222222222220
|
||||
111111111111111111110", attributes);
|
||||
111111111111111111110", driver: Application.Driver, attributes);
|
||||
}
|
||||
|
||||
if (label) {
|
||||
@@ -958,7 +958,7 @@ cccccccccccccccccccc", output);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
222222222222222222220
|
||||
111111111111111111110", attributes);
|
||||
111111111111111111110", driver: Application.Driver, attributes);
|
||||
}
|
||||
Application.End (runState);
|
||||
}
|
||||
|
||||
@@ -836,7 +836,7 @@ Three ", output);
|
||||
000000
|
||||
222222
|
||||
222222
|
||||
222222", attributes);
|
||||
222222", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
|
||||
Assert.Equal ("", selected);
|
||||
@@ -848,7 +848,7 @@ Three ", output);
|
||||
000000
|
||||
222222
|
||||
000002
|
||||
222222", attributes);
|
||||
222222", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
|
||||
Assert.Equal ("", selected);
|
||||
@@ -860,7 +860,7 @@ Three ", output);
|
||||
000000
|
||||
222222
|
||||
222222
|
||||
000002", attributes);
|
||||
000002", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
|
||||
Assert.Equal ("Three", selected);
|
||||
@@ -878,7 +878,7 @@ Three ", output);
|
||||
000000
|
||||
222222
|
||||
222222
|
||||
000002", attributes);
|
||||
000002", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
|
||||
Assert.Equal ("Three", selected);
|
||||
@@ -890,7 +890,7 @@ Three ", output);
|
||||
000000
|
||||
222222
|
||||
000002
|
||||
111112", attributes);
|
||||
111112", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (cb.Subviews [1].ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
|
||||
Assert.Equal ("Three", selected);
|
||||
@@ -902,7 +902,7 @@ Three ", output);
|
||||
000000
|
||||
000002
|
||||
222222
|
||||
111112", attributes);
|
||||
111112", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (cb.ProcessKey (new KeyEvent (Key.F4, new KeyModifiers ())));
|
||||
Assert.Equal ("Three", selected);
|
||||
|
||||
@@ -1589,7 +1589,7 @@ Edit
|
||||
};
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
00000000000000", attributes);
|
||||
00000000000000", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (menu.MouseEvent (new MouseEvent {
|
||||
X = 0,
|
||||
@@ -1605,7 +1605,7 @@ Edit
|
||||
02222222222220
|
||||
00000000000000
|
||||
00000000000000
|
||||
00000000000000", attributes);
|
||||
00000000000000", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (top.Subviews [1].MouseEvent (new MouseEvent {
|
||||
X = 0,
|
||||
@@ -1621,7 +1621,7 @@ Edit
|
||||
02222222222220
|
||||
00000000000000
|
||||
00000000000000
|
||||
00000000000000", attributes);
|
||||
00000000000000", driver: Application.Driver, attributes);
|
||||
|
||||
Assert.True (top.Subviews [1].MouseEvent (new MouseEvent {
|
||||
X = 0,
|
||||
@@ -1637,7 +1637,7 @@ Edit
|
||||
02222222222220
|
||||
00000000000000
|
||||
00000000000000
|
||||
00000000000000", attributes);
|
||||
00000000000000", driver: Application.Driver, attributes);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
|
||||
@@ -116,12 +116,12 @@ Error ";
|
||||
2222220000
|
||||
3333000000
|
||||
4444400000";
|
||||
TestHelpers.AssertDriverColorsAre (expectedColor, attributes);
|
||||
TestHelpers.AssertDriverColorsAre (expectedColor, driver: Application.Driver, attributes);
|
||||
|
||||
tv.WordWrap = true;
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output);
|
||||
TestHelpers.AssertDriverColorsAre (expectedColor, attributes);
|
||||
TestHelpers.AssertDriverColorsAre (expectedColor, driver: Application.Driver, attributes);
|
||||
|
||||
tv.CursorPosition = new Point (6, 2);
|
||||
tv.SelectionStartColumn = 0;
|
||||
@@ -149,7 +149,7 @@ Dialogror ";
|
||||
4444444444
|
||||
4444000000
|
||||
4444444440";
|
||||
TestHelpers.AssertDriverColorsAre (expectedColor, attributes);
|
||||
TestHelpers.AssertDriverColorsAre (expectedColor, driver: Application.Driver, attributes);
|
||||
|
||||
tv.Undo ();
|
||||
tv.CursorPosition = new Point (0, 3);
|
||||
@@ -180,7 +180,7 @@ ror ";
|
||||
4444000000
|
||||
4444440000
|
||||
4440000000";
|
||||
TestHelpers.AssertDriverColorsAre (expectedColor, attributes);
|
||||
TestHelpers.AssertDriverColorsAre (expectedColor, driver: Application.Driver, attributes);
|
||||
|
||||
Application.End (rs);
|
||||
}
|
||||
|
||||
@@ -836,7 +836,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
01000
|
||||
";
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, driver: Application.Driver, new Attribute [] {
|
||||
// 0
|
||||
tv.ColorScheme.Normal,
|
||||
// 1
|
||||
@@ -883,7 +883,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
var invertFocus = new Attribute (tv.ColorScheme.Focus.Background, tv.ColorScheme.Focus.Foreground);
|
||||
var invertHotNormal = new Attribute (tv.ColorScheme.HotNormal.Background, tv.ColorScheme.HotNormal.Foreground);
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, driver: Application.Driver, new Attribute [] {
|
||||
// 0
|
||||
tv.ColorScheme.Normal,
|
||||
// 1
|
||||
@@ -938,7 +938,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
21222
|
||||
";
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, driver: Application.Driver, new Attribute [] {
|
||||
// 0
|
||||
tv.ColorScheme.Normal,
|
||||
// 1
|
||||
@@ -971,7 +971,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
// now we only see 2 colors used (the selected cell color and Normal
|
||||
// rowHighlight should no longer be used because the delegate returned null
|
||||
// (now that the cell value is 5 - which does not match the conditional)
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, driver: Application.Driver, new Attribute [] {
|
||||
// 0
|
||||
tv.ColorScheme.Normal,
|
||||
// 1
|
||||
@@ -1030,7 +1030,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
01020
|
||||
";
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, driver: Application.Driver, new Attribute [] {
|
||||
// 0
|
||||
tv.ColorScheme.Normal,
|
||||
// 1
|
||||
@@ -1063,7 +1063,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
// now we only see 2 colors used (the selected cell color and Normal
|
||||
// cellHighlight should no longer be used because the delegate returned null
|
||||
// (now that the cell value is 5 - which does not match the conditional)
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, new Attribute [] {
|
||||
TestHelpers.AssertDriverColorsAre (expectedColors, driver: Application.Driver, new Attribute [] {
|
||||
// 0
|
||||
tv.ColorScheme.Normal,
|
||||
// 1
|
||||
@@ -2113,7 +2113,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
00000000000000000000
|
||||
01111101101111111110
|
||||
";
|
||||
TestHelpers.AssertDriverColorsAre (expected, new Attribute [] { tv.ColorScheme.Normal, color });
|
||||
TestHelpers.AssertDriverColorsAre (expected, driver: Application.Driver, new Attribute [] { tv.ColorScheme.Normal, color });
|
||||
|
||||
}
|
||||
|
||||
@@ -2233,7 +2233,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
0111110
|
||||
0000000";
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (expected, normal, focus);
|
||||
TestHelpers.AssertDriverColorsAre (expected, driver: Application.Driver, normal, focus);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -2290,7 +2290,7 @@ namespace Terminal.Gui.ViewsTests {
|
||||
0101010
|
||||
0000000";
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (expected, normal, focus);
|
||||
TestHelpers.AssertDriverColorsAre (expected, driver: Application.Driver, normal, focus);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
@@ -2785,7 +2785,7 @@ A B C
|
||||
000000
|
||||
111111";
|
||||
|
||||
TestHelpers.AssertDriverColorsAre (expected, normal, focus);
|
||||
TestHelpers.AssertDriverColorsAre (expected, driver: Application.Driver, normal, focus);
|
||||
}
|
||||
|
||||
public static DataTableSource BuildTable (int cols, int rows)
|
||||
|
||||
@@ -858,19 +858,19 @@ namespace Terminal.Gui.ViewsTests {
|
||||
|
||||
|
||||
// Normal drawing of the tree view
|
||||
TestHelpers.AssertDriverContentsAre (
|
||||
@"├-normal
|
||||
TestHelpers.AssertDriverContentsAre (@"
|
||||
├-normal
|
||||
│ ├─pink
|
||||
│ └─normal
|
||||
└─pink
|
||||
", output);
|
||||
// Should all be the same color
|
||||
TestHelpers.AssertDriverColorsAre (
|
||||
@"00000000
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
00000000
|
||||
00000000
|
||||
0000000000
|
||||
000000
|
||||
",
|
||||
", driver: Application.Driver,
|
||||
new [] { tv.ColorScheme.Normal, pink });
|
||||
|
||||
var pinkScheme = new ColorScheme {
|
||||
@@ -887,20 +887,20 @@ namespace Terminal.Gui.ViewsTests {
|
||||
tv.Draw ();
|
||||
|
||||
// Same text
|
||||
TestHelpers.AssertDriverContentsAre (
|
||||
@"├-normal
|
||||
TestHelpers.AssertDriverContentsAre (@"
|
||||
├-normal
|
||||
│ ├─pink
|
||||
│ └─normal
|
||||
└─pink
|
||||
", output);
|
||||
// but now the item (only not lines) appear
|
||||
// in pink when they are the word "pink"
|
||||
TestHelpers.AssertDriverColorsAre (
|
||||
@"00000000
|
||||
TestHelpers.AssertDriverColorsAre (@"
|
||||
00000000
|
||||
00001111
|
||||
0000000000
|
||||
001111
|
||||
",
|
||||
", driver: Application.Driver,
|
||||
new [] { tv.ColorScheme.Normal, pink });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user