mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
* Added ClipRegion; cleaned up driver code * clip region unit tests * api docs * Moved color stuff from ConsoleDriver to Color.cs * Removes unused ConsoleDriver APIs * Code cleanup and Removes unused ConsoleDriver APIs * Code cleanup and Removes unused ConsoleDriver APIs * Work around https://github.com/gui-cs/Terminal.Gui/issues/2610 * adjusted unit tests * initial commit * Made Rows, Cols, Top, Left virtual * Made Clipboard non-virtual * Made EnableConsoleScrolling non-virtual * Made Contents non-virtual * Pulled Row/Col up * Made MoveTo virtual; fixed stupid FakeDriver cursor issue * Made CurrentAttribute non-virtual * Made SetAttribute non-virtual * Moved clipboard code out * Code cleanup * Removes dependecy on NStack from ConsoleDrivers - WIP * Fixed unit tests * Fixed unit tests * Added list of unit tests needed * Did some perf testing; tweaked code and charmap to address * Brough in code from PR #2264 (but commented) * Tons of code cleanup * Fighting with ScrollView * Fixing bugs * Fixed TabView tests * Fixed View.Visible test that was not really working * Fixed unit tests * Cleaned up clipboard APIs in attempt to track down unit test failure * Add Cut_Preserves_Selection test * Removed invalid code * Removed invalid test code; unit tests now pass * EscSeq* - Adjusted naming, added more sequences, made code more consistent, simplified, etc... * Added CSI_SetGraphicsRendition * NetDriver code cleanup * code cleanup * Cleaned up color handling in NetDriver * refixed tabview unit test * WindowsDriver color code cleanup * WindowsDriver color code cleanup * CursesDriver color code cleanup * CursesDriver - Adding _BOLD has no effect. Further up the stack we cast the return of ColorToCursesColor from int to short and the _BOLD values don't fit in a short. * CursesDriver color code - make code more accurate * CursesDriver color code - make code more accurate * Simplified ConsoleDriver.GetColors API * Simplified ConsoleDriver.GetColors API further * Improved encapslation of Attribute; prep for TrueColor & other attributes like blink * Fixes #2249. CharacterMap isn't refreshing well non-BMP code points on scroll. * Use GetRange to take some of the runes before convert to string. * Attempting to fix unit tests not being cleaned up * Fixes #2658 - ConsoleDriver.IsRuneSupported * Fixes #2658 - ConsoleDriver.IsRuneSupported (for WindowsDriver) * Check all the range values and not only the max value. * Reducing code. * Fixes #2674 - Unit test process doesn't exit * Changed Cell to support IsDirty and list of Runes * add support for rendering TrueColor output on Windows merging veeman & tznind code * add colorconverter changes * fixed merged v2_develop * Fixing merge bugs * Fixed merge bugs * Fixed merge bugs - all unit tests pass * Debugging netdriver * More netdriver diag * API docs for escutils * Update unicode scenario to stress more stuff * Contents: Now a 2D array of Cells; WIP * AddRune and ClearContents no longer virtual/abstract * WindowsDriver renders correctly again * Progress on Curses * Progress on Curses * broke windowsdriver * Cleaned up FakeMainLoop * Cleaned up some build warnings * Removed _init from AutoInitShutdown as it's not needed anymore * Removed unused var * Removed unused var * Fixed nullabiltiy warning in LineCanvas * Fixed charmap crash * Fixes #2758 in v2 * Port testonfail fix to v2 * Remove EnableConsoleScrolling * Backport #2764 from develop (clear last line) * Remove uneeded usings * Progress on unicode * Merged in changes from PR #2786, Fixes #2784 * revamp charmap rendering * Charmap option to show glyph widths * Fixed issue with wide glpyhs being overwritten * Fixed charmap startcodepoint change issue * Added abiltiy to see ncurses verison/lib * Fought with CursesDriver; giving up for now. See notes. * Leverage Wcwidth nuget library instaed of our own tables * enhanced charmap Details dialog * Final attempt at fixing curses --------- Co-authored-by: BDisp <bd.bdisp@gmail.com> Co-authored-by: adstep <stephensonadamj@gmail.com>
This commit is contained in:
196
UnitTests/ConsoleDrivers/AddRuneTests.cs
Normal file
196
UnitTests/ConsoleDrivers/AddRuneTests.cs
Normal file
@@ -0,0 +1,196 @@
|
||||
using Microsoft.VisualStudio.TestPlatform.Utilities;
|
||||
using System.Buffers;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using static Terminal.Gui.SpinnerStyle;
|
||||
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
public class AddRuneTests {
|
||||
readonly ITestOutputHelper _output;
|
||||
|
||||
public AddRuneTests (ITestOutputHelper output)
|
||||
{
|
||||
this._output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRune ()
|
||||
{
|
||||
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init (() => { });
|
||||
|
||||
driver.AddRune (new Rune ('a'));
|
||||
Assert.Equal ((Rune)'a', driver.Contents [0, 0].Runes [0]);
|
||||
|
||||
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);
|
||||
driver.AddRune ('a');
|
||||
|
||||
for (var col = 0; col < driver.Cols; col++) {
|
||||
for (var row = 0; row < driver.Rows; row++) {
|
||||
Assert.Equal ((Rune)' ', driver.Contents [row, col].Runes [0]);
|
||||
}
|
||||
}
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRune_MovesToNextColumn ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init (() => { });
|
||||
|
||||
driver.AddRune ('a');
|
||||
Assert.Equal ((Rune)'a', driver.Contents [0, 0].Runes [0]);
|
||||
Assert.Equal (0, driver.Row);
|
||||
Assert.Equal (1, driver.Col);
|
||||
|
||||
driver.AddRune ('b');
|
||||
Assert.Equal ((Rune)'b', driver.Contents [0, 1].Runes [0]);
|
||||
Assert.Equal (0, driver.Row);
|
||||
Assert.Equal (2, driver.Col);
|
||||
|
||||
// Move to the last column of the first row
|
||||
var lastCol = driver.Cols - 1;
|
||||
driver.Move (lastCol, 0);
|
||||
Assert.Equal (0, driver.Row);
|
||||
Assert.Equal (lastCol, driver.Col);
|
||||
|
||||
// Add a rune to the last column of the first row; should increment the row or col even though it's now invalid
|
||||
driver.AddRune ('c');
|
||||
Assert.Equal ((Rune)'c', driver.Contents [0, lastCol].Runes [0]);
|
||||
Assert.Equal (lastCol + 1, driver.Col);
|
||||
|
||||
// Add a rune; should succeed but do nothing as it's outside of Contents
|
||||
driver.AddRune ('d');
|
||||
Assert.Equal (lastCol + 2, driver.Col);
|
||||
for (var col = 0; col < driver.Cols; col++) {
|
||||
for (var row = 0; row < driver.Rows; row++) {
|
||||
Assert.NotEqual ((Rune)'d', driver.Contents [row, col].Runes [0]);
|
||||
}
|
||||
}
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRune_MovesToNextColumn_Wide ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
driver.Init (() => { });
|
||||
|
||||
// 🍕 Slice of Pizza "\U0001F355"
|
||||
var operationStatus = Rune.DecodeFromUtf16 ("\U0001F355", out Rune rune, out int charsConsumed);
|
||||
Assert.Equal (OperationStatus.Done, operationStatus);
|
||||
Assert.Equal (charsConsumed, rune.Utf16SequenceLength);
|
||||
Assert.Equal (2, rune.GetColumns ());
|
||||
|
||||
driver.AddRune (rune);
|
||||
Assert.Equal (rune, driver.Contents [0, 0].Runes [0]);
|
||||
Assert.Equal (0, driver.Row);
|
||||
Assert.Equal (2, driver.Col);
|
||||
|
||||
//driver.AddRune ('b');
|
||||
//Assert.Equal ((Rune)'b', driver.Contents [0, 1].Runes [0]);
|
||||
//Assert.Equal (0, driver.Row);
|
||||
//Assert.Equal (2, driver.Col);
|
||||
|
||||
//// Move to the last column of the first row
|
||||
//var lastCol = driver.Cols - 1;
|
||||
//driver.Move (lastCol, 0);
|
||||
//Assert.Equal (0, driver.Row);
|
||||
//Assert.Equal (lastCol, driver.Col);
|
||||
|
||||
//// Add a rune to the last column of the first row; should increment the row or col even though it's now invalid
|
||||
//driver.AddRune ('c');
|
||||
//Assert.Equal ((Rune)'c', driver.Contents [0, lastCol].Runes [0]);
|
||||
//Assert.Equal (lastCol + 1, driver.Col);
|
||||
|
||||
//// Add a rune; should succeed but do nothing as it's outside of Contents
|
||||
//driver.AddRune ('d');
|
||||
//Assert.Equal (lastCol + 2, driver.Col);
|
||||
//for (var col = 0; col < driver.Cols; col++) {
|
||||
// for (var row = 0; row < driver.Rows; row++) {
|
||||
// Assert.NotEqual ((Rune)'d', driver.Contents [row, col].Runes [0]);
|
||||
// }
|
||||
//}
|
||||
|
||||
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 ('ắ');
|
||||
|
||||
var text = "\u1eaf";
|
||||
driver.AddStr (text);
|
||||
Assert.Equal (expected, driver.Contents [0, 0].Runes [0]);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 1].Runes [0]);
|
||||
|
||||
driver.ClearContents ();
|
||||
driver.Move (0, 0);
|
||||
|
||||
text = "\u0103\u0301";
|
||||
driver.AddStr (text);
|
||||
Assert.Equal (expected, driver.Contents [0, 0].Runes [0]);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 1].Runes [0]);
|
||||
|
||||
driver.ClearContents ();
|
||||
driver.Move (0, 0);
|
||||
|
||||
text = "\u0061\u0306\u0301";
|
||||
driver.AddStr (text);
|
||||
Assert.Equal (expected, driver.Contents [0, 0].Runes [0]);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 1].Runes [0]);
|
||||
|
||||
// var s = "a\u0301\u0300\u0306";
|
||||
|
||||
|
||||
// TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
//ắ", output);
|
||||
|
||||
// tf.Text = "\u1eaf";
|
||||
// Application.Refresh ();
|
||||
// TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
//ắ", output);
|
||||
|
||||
// tf.Text = "\u0103\u0301";
|
||||
// Application.Refresh ();
|
||||
// TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
//ắ", output);
|
||||
|
||||
// tf.Text = "\u0061\u0306\u0301";
|
||||
// Application.Refresh ();
|
||||
// TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
//ắ", output);
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
@@ -23,31 +23,29 @@ namespace Terminal.Gui.DriverTests {
|
||||
Assert.Equal (default (Color), attr.Foreground);
|
||||
Assert.Equal (default (Color), attr.Background);
|
||||
|
||||
// Test value, foreground, background
|
||||
var value = 42;
|
||||
// Test foreground, background
|
||||
var fg = new Color ();
|
||||
fg = Color.Red;
|
||||
|
||||
var bg = new Color ();
|
||||
bg = Color.Blue;
|
||||
|
||||
attr = new Attribute (value, fg, bg);
|
||||
|
||||
Assert.Equal (value, attr.Value);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
// value, foreground, background
|
||||
attr = new Attribute (fg, bg);
|
||||
|
||||
Assert.True (attr.Initialized);
|
||||
Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
attr = new Attribute (fg);
|
||||
Assert.True (attr.Initialized);
|
||||
Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (fg, attr.Background);
|
||||
|
||||
attr = new Attribute (bg);
|
||||
Assert.True (attr.Initialized);
|
||||
Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (bg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
@@ -73,44 +71,15 @@ namespace Terminal.Gui.DriverTests {
|
||||
|
||||
// Test conversion to int
|
||||
attr = new Attribute (value, fg, bg);
|
||||
int value_implicit = (int)attr.Value;
|
||||
int value_implicit = attr.Value;
|
||||
Assert.Equal (value, value_implicit);
|
||||
|
||||
// Test conversion from int
|
||||
attr = value;
|
||||
Assert.Equal (value, attr.Value);
|
||||
|
||||
driver.End ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Implicit_Assign_NoDriver ()
|
||||
{
|
||||
|
||||
var attr = new Attribute ();
|
||||
|
||||
var fg = new Color ();
|
||||
fg = Color.Red;
|
||||
|
||||
var bg = new Color ();
|
||||
bg = Color.Blue;
|
||||
|
||||
// Test conversion to int
|
||||
attr = new Attribute (fg, bg);
|
||||
int value_implicit = (int)attr.Value;
|
||||
Assert.False (attr.Initialized);
|
||||
|
||||
Assert.Equal (-1, value_implicit);
|
||||
Assert.False (attr.Initialized);
|
||||
|
||||
// Test conversion from int
|
||||
attr = -1;
|
||||
Assert.Equal (-1, attr.Value);
|
||||
Assert.False (attr.Initialized);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Make_SetsNotInitialized_NoDriver ()
|
||||
{
|
||||
@@ -227,5 +196,47 @@ namespace Terminal.Gui.DriverTests {
|
||||
attr = new Attribute ((Color)(-1), (Color)(-1));
|
||||
Assert.False (attr.HasValidColors);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_NotInitialized()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Red, Color.Green);
|
||||
|
||||
Assert.True (attr1.Equals (attr2));
|
||||
Assert.True (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotEquals_NotInitialized ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Green, Color.Red);
|
||||
|
||||
Assert.False (attr1.Equals (attr2));
|
||||
Assert.False (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Equals_Initialized ()
|
||||
{
|
||||
Assert.NotNull(Application.Driver);
|
||||
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Red, Color.Green);
|
||||
|
||||
Assert.True (attr1.Equals (attr2));
|
||||
Assert.True (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact,AutoInitShutdown]
|
||||
public void NotEquals_Initialized ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Green);
|
||||
var attr2 = new Attribute (Color.Green, Color.Red);
|
||||
|
||||
Assert.False (attr1.Equals (attr2));
|
||||
Assert.False (attr2.Equals (attr1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
116
UnitTests/ConsoleDrivers/ClipRegionTests.cs
Normal file
116
UnitTests/ConsoleDrivers/ClipRegionTests.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DriverTests {
|
||||
public class ClipRegionTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
public ClipRegionTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void IsValidLocation (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
// positive
|
||||
Assert.True (driver.IsValidLocation (0, 0));
|
||||
Assert.True (driver.IsValidLocation (1, 1));
|
||||
Assert.True (driver.IsValidLocation (driver.Cols - 1, driver.Rows - 1));
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
// Define a clip rectangle
|
||||
driver.Clip = new Rect (5, 5, 5, 5);
|
||||
// positive
|
||||
Assert.True (driver.IsValidLocation (5, 5));
|
||||
Assert.True (driver.IsValidLocation (9, 9));
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (4, 5));
|
||||
Assert.False (driver.IsValidLocation (5, 4));
|
||||
Assert.False (driver.IsValidLocation (10, 9));
|
||||
Assert.False (driver.IsValidLocation (9, 10));
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void Clip_Set_To_Empty_AllInvalid (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
// Define a clip rectangle
|
||||
driver.Clip = Rect.Empty;
|
||||
|
||||
// negative
|
||||
Assert.False (driver.IsValidLocation (4, 5));
|
||||
Assert.False (driver.IsValidLocation (5, 4));
|
||||
Assert.False (driver.IsValidLocation (10, 9));
|
||||
Assert.False (driver.IsValidLocation (9, 10));
|
||||
Assert.False (driver.IsValidLocation (-1, 0));
|
||||
Assert.False (driver.IsValidLocation (0, -1));
|
||||
Assert.False (driver.IsValidLocation (-1, -1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows - 1));
|
||||
Assert.False (driver.IsValidLocation (driver.Cols, driver.Rows));
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void AddRune_Is_Clipped (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddRune ('x');
|
||||
Assert.Equal ((Rune)'x', driver.Contents [0, 0].Runes [0]);
|
||||
|
||||
driver.Move (5, 5);
|
||||
driver.AddRune ('x');
|
||||
Assert.Equal ((Rune)'x', driver.Contents [5, 5].Runes [0]);
|
||||
|
||||
// Clear the contents
|
||||
driver.FillRect (new Rect (0, 0, driver.Rows, driver.Cols), ' ');
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 0].Runes [0]);
|
||||
|
||||
// Setup the region with a single rectangle, fill screen with 'x'
|
||||
driver.Clip = new Rect (5, 5, 5, 5);
|
||||
driver.FillRect (new Rect (0, 0, driver.Rows, driver.Cols), 'x');
|
||||
Assert.Equal ((Rune)' ', driver.Contents [0, 0].Runes [0]);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [4, 9].Runes [0]);
|
||||
Assert.Equal ((Rune)'x', driver.Contents [5, 5].Runes [0]);
|
||||
Assert.Equal ((Rune)'x', driver.Contents [9, 9].Runes [0]);
|
||||
Assert.Equal ((Rune)' ', driver.Contents [10, 10].Runes [0]);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,8 +57,6 @@ namespace Terminal.Gui.DriverTests {
|
||||
Console.BackgroundColor = ConsoleColor.Green;
|
||||
Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
|
||||
driver.Move (2, 3);
|
||||
Assert.Equal (2, Console.CursorLeft);
|
||||
Assert.Equal (3, Console.CursorTop);
|
||||
|
||||
driver.End ();
|
||||
Assert.Equal (0, Console.CursorLeft);
|
||||
@@ -225,17 +223,6 @@ namespace Terminal.Gui.DriverTests {
|
||||
Assert.Equal (40, Application.Driver.Rows);
|
||||
Assert.True (wasTerminalResized);
|
||||
|
||||
// MockDriver will still be 120x40
|
||||
wasTerminalResized = false;
|
||||
Application.EnableConsoleScrolling = true;
|
||||
driver.SetWindowSize (40, 20);
|
||||
Assert.Equal (120, Application.Driver.Cols);
|
||||
Assert.Equal (40, Application.Driver.Rows);
|
||||
Assert.Equal (120, Console.BufferWidth);
|
||||
Assert.Equal (40, Console.BufferHeight);
|
||||
Assert.Equal (40, Console.WindowWidth);
|
||||
Assert.Equal (20, Console.WindowHeight);
|
||||
Assert.True (wasTerminalResized);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
@@ -19,12 +19,11 @@ namespace Terminal.Gui.DriverTests {
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void EnableConsoleScrolling_Is_False_Left_And_Top_Is_Always_Zero (Type driverType)
|
||||
public void Left_And_Top_Is_Always_Zero (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Assert.False (Application.EnableConsoleScrolling);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
@@ -34,123 +33,6 @@ namespace Terminal.Gui.DriverTests {
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void EnableConsoleScrolling_Is_True_Left_Cannot_Be_Greater_Than_WindowWidth (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Application.EnableConsoleScrolling = true;
|
||||
Assert.True (Application.EnableConsoleScrolling);
|
||||
|
||||
driver.SetWindowPosition (81, 25);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void EnableConsoleScrolling_Is_True_Left_Cannot_Be_Greater_Than_BufferWidth_Minus_WindowWidth (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Application.EnableConsoleScrolling = true;
|
||||
Assert.True (Application.EnableConsoleScrolling);
|
||||
|
||||
driver.SetWindowPosition (81, 25);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
// MockDriver will now be sets to 120x25
|
||||
driver.SetBufferSize (120, 25);
|
||||
Assert.Equal (120, Application.Driver.Cols);
|
||||
Assert.Equal (25, Application.Driver.Rows);
|
||||
Assert.Equal (120, Console.BufferWidth);
|
||||
Assert.Equal (25, Console.BufferHeight);
|
||||
Assert.Equal (80, Console.WindowWidth);
|
||||
Assert.Equal (25, Console.WindowHeight);
|
||||
driver.SetWindowPosition (121, 25);
|
||||
Assert.Equal (40, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
driver.SetWindowSize (90, 25);
|
||||
Assert.Equal (120, Application.Driver.Cols);
|
||||
Assert.Equal (25, Application.Driver.Rows);
|
||||
Assert.Equal (120, Console.BufferWidth);
|
||||
Assert.Equal (25, Console.BufferHeight);
|
||||
Assert.Equal (90, Console.WindowWidth);
|
||||
Assert.Equal (25, Console.WindowHeight);
|
||||
driver.SetWindowPosition (121, 25);
|
||||
Assert.Equal (30, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void EnableConsoleScrolling_Is_True_Top_Cannot_Be_Greater_Than_WindowHeight (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Application.EnableConsoleScrolling = true;
|
||||
Assert.True (Application.EnableConsoleScrolling);
|
||||
|
||||
driver.SetWindowPosition (80, 26);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void EnableConsoleScrolling_Is_True_Top_Cannot_Be_Greater_Than_BufferHeight_Minus_WindowHeight (Type driverType)
|
||||
{
|
||||
var driver = (FakeDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Application.EnableConsoleScrolling = true;
|
||||
Assert.True (Application.EnableConsoleScrolling);
|
||||
|
||||
driver.SetWindowPosition (80, 26);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
|
||||
// MockDriver will now be sets to 80x40
|
||||
driver.SetBufferSize (80, 40);
|
||||
Assert.Equal (80, Application.Driver.Cols);
|
||||
Assert.Equal (40, Application.Driver.Rows);
|
||||
Assert.Equal (80, Console.BufferWidth);
|
||||
Assert.Equal (40, Console.BufferHeight);
|
||||
Assert.Equal (80, Console.WindowWidth);
|
||||
Assert.Equal (25, Console.WindowHeight);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (0, Console.WindowTop);
|
||||
driver.SetWindowPosition (80, 40);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (15, Console.WindowTop);
|
||||
|
||||
driver.SetWindowSize (80, 20);
|
||||
Assert.Equal (80, Application.Driver.Cols);
|
||||
Assert.Equal (40, Application.Driver.Rows);
|
||||
Assert.Equal (80, Console.BufferWidth);
|
||||
Assert.Equal (40, Console.BufferHeight);
|
||||
Assert.Equal (80, Console.WindowWidth);
|
||||
Assert.Equal (20, Console.WindowHeight);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (15, Console.WindowTop);
|
||||
driver.SetWindowPosition (80, 41);
|
||||
Assert.Equal (0, Console.WindowLeft);
|
||||
Assert.Equal (20, Console.WindowTop);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
129
UnitTests/ConsoleDrivers/ContentsTests.cs
Normal file
129
UnitTests/ConsoleDrivers/ContentsTests.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
using Console = Terminal.Gui.FakeConsole;
|
||||
|
||||
namespace Terminal.Gui.DriverTests;
|
||||
public class ContentsTests {
|
||||
readonly ITestOutputHelper output;
|
||||
|
||||
public ContentsTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
//[InlineData (typeof (NetDriver))]
|
||||
//[InlineData (typeof (CursesDriver))]
|
||||
//[InlineData (typeof (WindowsDriver))]
|
||||
public void AddStr_With_Combining_Characters (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
// driver.Init (null);
|
||||
|
||||
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
|
||||
|
||||
// 3 char combine
|
||||
// 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 = "ǫ́";
|
||||
|
||||
driver.Move (0, 0);
|
||||
driver.AddStr (combined);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
||||
|
||||
#endif
|
||||
|
||||
// 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))]
|
||||
public void Move_Bad_Coordinates (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Assert.Equal (0, driver.Col);
|
||||
Assert.Equal (0, driver.Row);
|
||||
|
||||
driver.Move (-1, 0);
|
||||
Assert.Equal (-1, driver.Col);
|
||||
Assert.Equal (0, driver.Row);
|
||||
|
||||
driver.Move (0, -1);
|
||||
Assert.Equal (0, driver.Col);
|
||||
Assert.Equal (-1, driver.Row);
|
||||
|
||||
driver.Move (driver.Cols, 0);
|
||||
Assert.Equal (driver.Cols, driver.Col);
|
||||
Assert.Equal (0, driver.Row);
|
||||
|
||||
driver.Move (0, driver.Rows);
|
||||
Assert.Equal (0, driver.Col);
|
||||
Assert.Equal (driver.Rows, driver.Row);
|
||||
|
||||
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 ();
|
||||
}
|
||||
|
||||
// TODO: Add these unit tests
|
||||
|
||||
// AddRune moves correctly
|
||||
|
||||
// AddRune with wide characters are handled correctly
|
||||
|
||||
// AddRune with wide characters and Col < 0 are handled correctly
|
||||
|
||||
// AddRune with wide characters and Col == Cols - 1 are handled correctly
|
||||
|
||||
// AddRune with wide characters and Col == Cols are handled correctly
|
||||
|
||||
// AddStr moves correctly
|
||||
|
||||
// AddStr with wide characters moves correctly
|
||||
|
||||
// AddStr where Col is negative works
|
||||
|
||||
// AddStr where Col is negative and characters include wide / combining characters works
|
||||
|
||||
// AddStr where Col is near Cols and characters include wide / combining characters works
|
||||
|
||||
// Clipping works correctly
|
||||
|
||||
// Clipping works correctly with wide characters
|
||||
|
||||
// Clipping works correctly with combining characters
|
||||
|
||||
// Clipping works correctly with combining characters and wide characters
|
||||
|
||||
// ResizeScreen works correctly
|
||||
|
||||
// Refresh works correctly
|
||||
|
||||
// IsDirty tests
|
||||
}
|
||||
|
||||
@@ -184,41 +184,43 @@ namespace Terminal.Gui.InputTests {
|
||||
[ClassData (typeof (PacketTest))]
|
||||
public void TestVKPacket (uint unicodeCharacter, bool shift, bool alt, bool control, uint initialVirtualKey, uint initialScanCode, Key expectedRemapping, uint expectedVirtualKey, uint expectedScanCode)
|
||||
{
|
||||
var modifiers = new ConsoleModifiers ();
|
||||
if (shift) modifiers |= ConsoleModifiers.Shift;
|
||||
if (alt) modifiers |= ConsoleModifiers.Alt;
|
||||
if (control) modifiers |= ConsoleModifiers.Control;
|
||||
var mappedConsoleKey = ConsoleKeyMapping.GetConsoleKeyFromKey (unicodeCharacter, modifiers, out uint scanCode, out uint outputChar);
|
||||
|
||||
if ((scanCode > 0 || mappedConsoleKey == 0) && mappedConsoleKey == initialVirtualKey) Assert.Equal (mappedConsoleKey, initialVirtualKey);
|
||||
else Assert.Equal (mappedConsoleKey, outputChar < 0xff ? outputChar & 0xff | 0xff << 8 : outputChar);
|
||||
Assert.Equal (scanCode, initialScanCode);
|
||||
|
||||
var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (mappedConsoleKey, modifiers, out uint consoleKey, out scanCode);
|
||||
|
||||
//if (scanCode > 0 && consoleKey == keyChar && consoleKey > 48 && consoleKey > 57 && consoleKey < 65 && consoleKey > 91) {
|
||||
if (scanCode > 0 && keyChar == 0 && consoleKey == mappedConsoleKey) Assert.Equal (0, (double)keyChar);
|
||||
else Assert.Equal (keyChar, unicodeCharacter);
|
||||
Assert.Equal (consoleKey, expectedVirtualKey);
|
||||
Assert.Equal (scanCode, expectedScanCode);
|
||||
|
||||
var top = Application.Top;
|
||||
|
||||
top.KeyPress += (s, e) => {
|
||||
var after = ShortcutHelper.GetModifiersKey (e.KeyEvent);
|
||||
Assert.Equal (expectedRemapping, after);
|
||||
e.Handled = true;
|
||||
Application.RequestStop ();
|
||||
};
|
||||
|
||||
var iterations = -1;
|
||||
|
||||
Application.Iteration += () => {
|
||||
iterations++;
|
||||
if (iterations == 0) Application.Driver.SendKeys ((char)mappedConsoleKey, ConsoleKey.Packet, shift, alt, control);
|
||||
};
|
||||
|
||||
lock (packetLock) {
|
||||
Application._forceFakeConsole = true;
|
||||
Application.Init ();
|
||||
|
||||
var modifiers = new ConsoleModifiers ();
|
||||
if (shift) modifiers |= ConsoleModifiers.Shift;
|
||||
if (alt) modifiers |= ConsoleModifiers.Alt;
|
||||
if (control) modifiers |= ConsoleModifiers.Control;
|
||||
var mappedConsoleKey = ConsoleKeyMapping.GetConsoleKeyFromKey (unicodeCharacter, modifiers, out uint scanCode, out uint outputChar);
|
||||
|
||||
if ((scanCode > 0 || mappedConsoleKey == 0) && mappedConsoleKey == initialVirtualKey) Assert.Equal (mappedConsoleKey, initialVirtualKey);
|
||||
else Assert.Equal (mappedConsoleKey, outputChar < 0xff ? outputChar & 0xff | 0xff << 8 : outputChar);
|
||||
Assert.Equal (scanCode, initialScanCode);
|
||||
|
||||
var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (mappedConsoleKey, modifiers, out uint consoleKey, out scanCode);
|
||||
|
||||
//if (scanCode > 0 && consoleKey == keyChar && consoleKey > 48 && consoleKey > 57 && consoleKey < 65 && consoleKey > 91) {
|
||||
if (scanCode > 0 && keyChar == 0 && consoleKey == mappedConsoleKey) Assert.Equal (0, (double)keyChar);
|
||||
else Assert.Equal (keyChar, unicodeCharacter);
|
||||
Assert.Equal (consoleKey, expectedVirtualKey);
|
||||
Assert.Equal (scanCode, expectedScanCode);
|
||||
|
||||
var top = Application.Top;
|
||||
|
||||
top.KeyPress += (s, e) => {
|
||||
var after = ShortcutHelper.GetModifiersKey (e.KeyEvent);
|
||||
Assert.Equal (expectedRemapping, after);
|
||||
e.Handled = true;
|
||||
Application.RequestStop ();
|
||||
};
|
||||
|
||||
var iterations = -1;
|
||||
|
||||
Application.Iteration += () => {
|
||||
iterations++;
|
||||
if (iterations == 0) Application.Driver.SendKeys ((char)mappedConsoleKey, ConsoleKey.Packet, shift, alt, control);
|
||||
};
|
||||
Application.Run ();
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user