mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Merge branch 'v2_develop' into v2_3847_tabview-focus-fix
This commit is contained in:
68
UnitTests/Application/ApplicationScreenTests.cs
Normal file
68
UnitTests/Application/ApplicationScreenTests.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.ApplicationTests;
|
||||
|
||||
public class ApplicationScreenTests (ITestOutputHelper output)
|
||||
{
|
||||
[Fact]
|
||||
public void ClearScreenNextIteration_Resets_To_False_After_LayoutAndDraw ()
|
||||
{
|
||||
// Arrange
|
||||
Application.Init ();
|
||||
|
||||
// Act
|
||||
Application.ClearScreenNextIteration = true;
|
||||
Application.LayoutAndDraw ();
|
||||
|
||||
// Assert
|
||||
Assert.False (Application.ClearScreenNextIteration);
|
||||
|
||||
// Cleanup
|
||||
Application.ResetState (true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearContents_Called_When_Top_Frame_Changes ()
|
||||
{
|
||||
// Arrange
|
||||
Application.Init (new FakeDriver ());
|
||||
Application.Top = new Toplevel ();
|
||||
Application.TopLevels.Push (Application.Top);
|
||||
|
||||
int clearedContentsRaised = 0;
|
||||
|
||||
Application.Driver!.ClearedContents += (e, a) => clearedContentsRaised++;
|
||||
|
||||
// Act
|
||||
Application.LayoutAndDraw ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (1, clearedContentsRaised);
|
||||
|
||||
// Act
|
||||
Application.Top.SetNeedsLayout ();
|
||||
Application.LayoutAndDraw ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (1, clearedContentsRaised);
|
||||
|
||||
// Act
|
||||
Application.Top.X = 1;
|
||||
Application.LayoutAndDraw ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (2, clearedContentsRaised);
|
||||
|
||||
// Act
|
||||
Application.Top.Width = 10;
|
||||
Application.LayoutAndDraw ();
|
||||
|
||||
// Assert
|
||||
Assert.Equal (3, clearedContentsRaised);
|
||||
|
||||
// Cleanup
|
||||
Application.Top.Dispose ();
|
||||
Application.Top = null;
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ public class ApplicationTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Init_DriverName_Should_Pick_Correct_Driver (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driverName: driverType.Name);
|
||||
Assert.NotNull (Application.Driver);
|
||||
Assert.NotEqual (driver, Application.Driver);
|
||||
@@ -620,6 +620,27 @@ public class ApplicationTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Screen_Size_Changes ()
|
||||
{
|
||||
var driver = new FakeDriver ();
|
||||
Application.Init (driver);
|
||||
Assert.Equal (new (0, 0, 80, 25), driver.Screen);
|
||||
Assert.Equal (new (0, 0, 80, 25), Application.Screen);
|
||||
|
||||
driver.Cols = 100;
|
||||
driver.Rows = 30;
|
||||
// IConsoleDriver.Screen isn't assignable
|
||||
//driver.Screen = new (0, 0, driver.Cols, Rows);
|
||||
Assert.Equal (new (0, 0, 100, 30), driver.Screen);
|
||||
Assert.NotEqual (new (0, 0, 100, 30), Application.Screen);
|
||||
Assert.Equal (new (0, 0, 80, 25), Application.Screen);
|
||||
Application.Screen = new (0, 0, driver.Cols, driver.Rows);
|
||||
Assert.Equal (new (0, 0, 100, 30), driver.Screen);
|
||||
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
private void Init ()
|
||||
{
|
||||
Application.Init (new FakeDriver ());
|
||||
|
||||
@@ -4,9 +4,10 @@ namespace Terminal.Gui.ApplicationTests;
|
||||
|
||||
public class SyncrhonizationContextTests
|
||||
{
|
||||
[Fact(Skip = "Causes ubuntu to crash in github action.")]
|
||||
[Fact]
|
||||
public void SynchronizationContext_CreateCopy ()
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
Application.Init ();
|
||||
SynchronizationContext context = SynchronizationContext.Current;
|
||||
Assert.NotNull (context);
|
||||
@@ -20,11 +21,12 @@ public class SyncrhonizationContextTests
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
//[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
//[InlineData (typeof (CursesDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void SynchronizationContext_Post (Type driverType)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
Application.Init (driverName: driverType.Name);
|
||||
SynchronizationContext context = SynchronizationContext.Current;
|
||||
|
||||
@@ -60,6 +62,7 @@ public class SyncrhonizationContextTests
|
||||
[AutoInitShutdown]
|
||||
public void SynchronizationContext_Send ()
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
Application.Init ();
|
||||
SynchronizationContext context = SynchronizationContext.Current;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ using System.Text.Json.Serialization;
|
||||
using Terminal.Gui;
|
||||
using Xunit;
|
||||
|
||||
namespace Terminal.Gui.ConfigurationTests;
|
||||
|
||||
public class ConfigPropertyTests
|
||||
{
|
||||
[Fact]
|
||||
|
||||
@@ -25,7 +25,7 @@ public class AddRuneTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void AddRune (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
driver.Rows = 25;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ClipRegionTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void AddRune_Is_Clipped (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
Application.Driver!.Rows = 25;
|
||||
Application.Driver!.Cols = 80;
|
||||
@@ -62,7 +62,7 @@ public class ClipRegionTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Clip_Set_To_Empty_AllInvalid (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
// Define a clip rectangle
|
||||
@@ -92,7 +92,7 @@ public class ClipRegionTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void IsValidLocation (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
Application.Driver!.Rows = 10;
|
||||
Application.Driver!.Cols = 10;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ConsoleDriverTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void End_Cleans_Up (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
driver.End ();
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class ConsoleDriverTests
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void FakeDriver_MockKeyPresses (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
var text = "MockKeyPresses";
|
||||
@@ -85,7 +85,7 @@ public class ConsoleDriverTests
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
public void FakeDriver_Only_Sends_Keystrokes_Through_MockKeyPresses (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
Application.Init (driver);
|
||||
|
||||
Toplevel top = new ();
|
||||
@@ -124,7 +124,7 @@ public class ConsoleDriverTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Init_Inits (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
MainLoop ml = driver.Init ();
|
||||
Assert.NotNull (ml);
|
||||
Assert.NotNull (driver.Clipboard);
|
||||
@@ -140,7 +140,7 @@ public class ConsoleDriverTests
|
||||
//[InlineData (typeof (FakeDriver))]
|
||||
//public void FakeDriver_MockKeyPresses_Press_AfterTimeOut (Type driverType)
|
||||
//{
|
||||
// var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
// var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
// Application.Init (driver);
|
||||
|
||||
// // Simulating pressing of QuitKey after a short period of time
|
||||
@@ -201,7 +201,7 @@ public class ConsoleDriverTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void TerminalResized_Simulation (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver?.Init ();
|
||||
driver.Cols = 80;
|
||||
driver.Rows = 25;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ContentsTests
|
||||
//[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
|
||||
public void AddStr_Combining_Character_1st_Column (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
var expected = "\u0301!";
|
||||
driver.AddStr ("\u0301!"); // acute accent + exclamation mark
|
||||
@@ -42,7 +42,7 @@ public class ContentsTests
|
||||
//[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
|
||||
public void AddStr_With_Combining_Characters (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
var acuteaccent = new Rune (0x0301); // Combining acute accent (é)
|
||||
@@ -98,7 +98,7 @@ public class ContentsTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Move_Bad_Coordinates (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
Assert.Equal (0, driver.Col);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class DriverColorTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void Force16Colors_Sets (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
driver.Force16Colors = true;
|
||||
@@ -35,7 +35,7 @@ public class DriverColorTests
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void SetColors_Changes_Colors (Type driverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
|
||||
@@ -63,7 +63,7 @@ public class DriverColorTests
|
||||
[InlineData (typeof (CursesDriver), true)]
|
||||
public void SupportsTrueColor_Defaults (Type driverType, bool expectedSetting)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
driver.Init ();
|
||||
|
||||
Assert.Equal (expectedSetting, driver.SupportsTrueColor);
|
||||
|
||||
@@ -17,7 +17,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_AddIdle_ValidIdleHandler_ReturnsToken (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
var idleHandlerInvoked = false;
|
||||
@@ -47,7 +47,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_AddTimeout_ValidParameters_ReturnsToken (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
var callbackInvoked = false;
|
||||
@@ -83,7 +83,7 @@ public class MainLoopDriverTests
|
||||
Type mainLoopDriverType
|
||||
)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
@@ -107,7 +107,7 @@ public class MainLoopDriverTests
|
||||
Type mainLoopDriverType
|
||||
)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
@@ -130,7 +130,7 @@ public class MainLoopDriverTests
|
||||
Type mainLoopDriverType
|
||||
)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
@@ -151,7 +151,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_Constructs_Disposes (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
@@ -182,7 +182,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RemoveIdle_InvalidToken_ReturnsFalse (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
@@ -201,7 +201,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RemoveIdle_ValidToken_ReturnsTrue (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
@@ -223,7 +223,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RemoveTimeout_InvalidToken_ReturnsFalse (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
@@ -241,7 +241,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RemoveTimeout_ValidToken_ReturnsTrue (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
|
||||
@@ -261,7 +261,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (ANSIDriver), typeof (AnsiMainLoopDriver))]
|
||||
public void MainLoop_RunIteration_ValidIdleHandler_CallsIdleHandler (Type driverType, Type mainLoopDriverType)
|
||||
{
|
||||
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, driver);
|
||||
var mainLoop = new MainLoop (mainLoopDriver);
|
||||
var idleHandlerInvoked = false;
|
||||
@@ -287,7 +287,7 @@ public class MainLoopDriverTests
|
||||
//[InlineData (typeof (WindowsDriver), typeof (WindowsMainLoop))]
|
||||
//public void MainLoop_Invoke_ValidAction_RunsAction (Type driverType, Type mainLoopDriverType)
|
||||
//{
|
||||
// var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
|
||||
// var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
|
||||
// var mainLoopDriver = (IMainLoopDriver)Activator.CreateInstance (mainLoopDriverType, new object [] { driver });
|
||||
// var mainLoop = new MainLoop (mainLoopDriver);
|
||||
// var actionInvoked = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Color = Terminal.Gui.Color;
|
||||
|
||||
namespace UnitTests.Drawing;
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public class SixelEncoderTests
|
||||
{
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
namespace Terminal.Gui.InputTests;
|
||||
|
||||
public class EscSeqReqTests
|
||||
{
|
||||
[Fact]
|
||||
public void Add_Tests ()
|
||||
{
|
||||
var escSeqReq = new EscSeqRequests ();
|
||||
escSeqReq.Add ("t");
|
||||
Assert.Single (escSeqReq.Statuses);
|
||||
Assert.Equal ("t", escSeqReq.Statuses [^1].Terminator);
|
||||
Assert.Equal (1, escSeqReq.Statuses [^1].NumRequests);
|
||||
Assert.Equal (1, escSeqReq.Statuses [^1].NumOutstanding);
|
||||
|
||||
escSeqReq.Add ("t", 2);
|
||||
Assert.Single (escSeqReq.Statuses);
|
||||
Assert.Equal ("t", escSeqReq.Statuses [^1].Terminator);
|
||||
Assert.Equal (1, escSeqReq.Statuses [^1].NumRequests);
|
||||
Assert.Equal (1, escSeqReq.Statuses [^1].NumOutstanding);
|
||||
|
||||
escSeqReq = new EscSeqRequests ();
|
||||
escSeqReq.Add ("t", 2);
|
||||
Assert.Single (escSeqReq.Statuses);
|
||||
Assert.Equal ("t", escSeqReq.Statuses [^1].Terminator);
|
||||
Assert.Equal (2, escSeqReq.Statuses [^1].NumRequests);
|
||||
Assert.Equal (2, escSeqReq.Statuses [^1].NumOutstanding);
|
||||
|
||||
escSeqReq.Add ("t", 3);
|
||||
Assert.Single (escSeqReq.Statuses);
|
||||
Assert.Equal ("t", escSeqReq.Statuses [^1].Terminator);
|
||||
Assert.Equal (2, escSeqReq.Statuses [^1].NumRequests);
|
||||
Assert.Equal (2, escSeqReq.Statuses [^1].NumOutstanding);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_Defaults ()
|
||||
{
|
||||
var escSeqReq = new EscSeqRequests ();
|
||||
Assert.NotNull (escSeqReq.Statuses);
|
||||
Assert.Empty (escSeqReq.Statuses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Remove_Tests ()
|
||||
{
|
||||
var escSeqReq = new EscSeqRequests ();
|
||||
escSeqReq.Add ("t");
|
||||
escSeqReq.Remove ("t");
|
||||
Assert.Empty (escSeqReq.Statuses);
|
||||
|
||||
escSeqReq.Add ("t", 2);
|
||||
escSeqReq.Remove ("t");
|
||||
Assert.Single (escSeqReq.Statuses);
|
||||
Assert.Equal ("t", escSeqReq.Statuses [^1].Terminator);
|
||||
Assert.Equal (2, escSeqReq.Statuses [^1].NumRequests);
|
||||
Assert.Equal (1, escSeqReq.Statuses [^1].NumOutstanding);
|
||||
|
||||
escSeqReq.Remove ("t");
|
||||
Assert.Empty (escSeqReq.Statuses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Requested_Tests ()
|
||||
{
|
||||
var escSeqReq = new EscSeqRequests ();
|
||||
Assert.False (escSeqReq.HasResponse ("t"));
|
||||
|
||||
escSeqReq.Add ("t");
|
||||
Assert.False (escSeqReq.HasResponse ("r"));
|
||||
Assert.True (escSeqReq.HasResponse ("t"));
|
||||
}
|
||||
}
|
||||
188
UnitTests/Input/EscSeqRequestsTests.cs
Normal file
188
UnitTests/Input/EscSeqRequestsTests.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
namespace Terminal.Gui.InputTests;
|
||||
|
||||
public class EscSeqRequestsTests
|
||||
{
|
||||
[Fact]
|
||||
public void Add_Tests ()
|
||||
{
|
||||
EscSeqRequests.Add ("t");
|
||||
Assert.Single (EscSeqRequests.Statuses);
|
||||
Assert.Equal ("t", EscSeqRequests.Statuses [^1].Terminator);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumRequests);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumOutstanding);
|
||||
|
||||
EscSeqRequests.Add ("t", 2);
|
||||
Assert.Single (EscSeqRequests.Statuses);
|
||||
Assert.Equal ("t", EscSeqRequests.Statuses [^1].Terminator);
|
||||
Assert.Equal (3, EscSeqRequests.Statuses [^1].NumRequests);
|
||||
Assert.Equal (3, EscSeqRequests.Statuses [^1].NumOutstanding);
|
||||
|
||||
EscSeqRequests.Clear ();
|
||||
EscSeqRequests.Add ("t", 2);
|
||||
Assert.Single (EscSeqRequests.Statuses);
|
||||
Assert.Equal ("t", EscSeqRequests.Statuses [^1].Terminator);
|
||||
Assert.Equal (2, EscSeqRequests.Statuses [^1].NumRequests);
|
||||
Assert.Equal (2, EscSeqRequests.Statuses [^1].NumOutstanding);
|
||||
|
||||
EscSeqRequests.Add ("t", 3);
|
||||
Assert.Single (EscSeqRequests.Statuses);
|
||||
Assert.Equal ("t", EscSeqRequests.Statuses [^1].Terminator);
|
||||
Assert.Equal (5, EscSeqRequests.Statuses [^1].NumRequests);
|
||||
Assert.Equal (5, EscSeqRequests.Statuses [^1].NumOutstanding);
|
||||
|
||||
EscSeqRequests.Clear ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_Defaults ()
|
||||
{
|
||||
Assert.NotNull (EscSeqRequests.Statuses);
|
||||
Assert.Empty (EscSeqRequests.Statuses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Remove_Tests ()
|
||||
{
|
||||
EscSeqRequests.Add ("t");
|
||||
EscSeqRequests.Remove ("t");
|
||||
Assert.Empty (EscSeqRequests.Statuses);
|
||||
|
||||
EscSeqRequests.Add ("t", 2);
|
||||
EscSeqRequests.Remove ("t");
|
||||
Assert.Single (EscSeqRequests.Statuses);
|
||||
Assert.Equal ("t", EscSeqRequests.Statuses [^1].Terminator);
|
||||
Assert.Equal (2, EscSeqRequests.Statuses [^1].NumRequests);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumOutstanding);
|
||||
|
||||
EscSeqRequests.Remove ("t");
|
||||
Assert.Empty (EscSeqRequests.Statuses);
|
||||
|
||||
EscSeqRequests.Clear ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasResponse_Tests ()
|
||||
{
|
||||
Assert.False (EscSeqRequests.HasResponse ("t"));
|
||||
|
||||
EscSeqRequests.Add ("t");
|
||||
Assert.False (EscSeqRequests.HasResponse ("r"));
|
||||
Assert.True (EscSeqRequests.HasResponse ("t"));
|
||||
Assert.Single (EscSeqRequests.Statuses);
|
||||
Assert.Equal ("t", EscSeqRequests.Statuses [^1].Terminator);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumRequests);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumOutstanding);
|
||||
|
||||
EscSeqRequests.Remove ("t");
|
||||
Assert.Empty (EscSeqRequests.Statuses);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (null)]
|
||||
[InlineData ("")]
|
||||
public void Add_Null_Or_Empty_Terminator_Throws (string terminator)
|
||||
{
|
||||
if (terminator is null)
|
||||
{
|
||||
Assert.Throws<ArgumentNullException> (() => EscSeqRequests.Add (terminator));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Throws<ArgumentException> (() => EscSeqRequests.Add (terminator));
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (null)]
|
||||
[InlineData ("")]
|
||||
public void HasResponse_Null_Or_Empty_Terminator_Does_Not_Throws (string terminator)
|
||||
{
|
||||
EscSeqRequests.Add ("t");
|
||||
|
||||
Assert.False (EscSeqRequests.HasResponse (terminator));
|
||||
|
||||
EscSeqRequests.Clear ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (null)]
|
||||
[InlineData ("")]
|
||||
public void Remove_Null_Or_Empty_Terminator_Throws (string terminator)
|
||||
{
|
||||
EscSeqRequests.Add ("t");
|
||||
|
||||
if (terminator is null)
|
||||
{
|
||||
Assert.Throws<ArgumentNullException> (() => EscSeqRequests.Remove (terminator));
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Throws<ArgumentException> (() => EscSeqRequests.Remove (terminator));
|
||||
}
|
||||
|
||||
EscSeqRequests.Clear ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Requests_Responses_Tests ()
|
||||
{
|
||||
// This is simulated response from a CSI_ReportTerminalSizeInChars
|
||||
ConsoleKeyInfo [] cki =
|
||||
[
|
||||
new ('\u001b', 0, false, false, false),
|
||||
new ('[', 0, false, false, false),
|
||||
new ('8', 0, false, false, false),
|
||||
new (';', 0, false, false, false),
|
||||
new ('1', 0, false, false, false),
|
||||
new ('0', 0, false, false, false),
|
||||
new (';', 0, false, false, false),
|
||||
new ('2', 0, false, false, false),
|
||||
new ('0', 0, false, false, false),
|
||||
new ('t', 0, false, false, false)
|
||||
];
|
||||
ConsoleKeyInfo newConsoleKeyInfo = default;
|
||||
ConsoleKey key = default;
|
||||
ConsoleModifiers mod = default;
|
||||
|
||||
Assert.Empty (EscSeqRequests.Statuses);
|
||||
|
||||
EscSeqRequests.Add ("t");
|
||||
Assert.Single (EscSeqRequests.Statuses);
|
||||
Assert.Equal ("t", EscSeqRequests.Statuses [^1].Terminator);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumRequests);
|
||||
Assert.Equal (1, EscSeqRequests.Statuses [^1].NumOutstanding);
|
||||
|
||||
EscSeqUtils.DecodeEscSeq (
|
||||
ref newConsoleKeyInfo,
|
||||
ref key,
|
||||
cki,
|
||||
ref mod,
|
||||
out string c1Control,
|
||||
out string code,
|
||||
out string [] values,
|
||||
out string terminating,
|
||||
out bool isKeyMouse,
|
||||
out List<MouseFlags> mouseFlags,
|
||||
out Point pos,
|
||||
out bool isResponse,
|
||||
null
|
||||
);
|
||||
|
||||
Assert.Empty (EscSeqRequests.Statuses);
|
||||
Assert.Equal (default, newConsoleKeyInfo);
|
||||
Assert.Equal (default, key);
|
||||
Assert.Equal (10, cki.Length);
|
||||
Assert.Equal (default, mod);
|
||||
Assert.Equal ("CSI", c1Control);
|
||||
Assert.Null (code);
|
||||
// ReSharper disable once HeuristicUnreachableCode
|
||||
Assert.Equal (3, values.Length);
|
||||
Assert.Equal ("8", values [0]);
|
||||
Assert.Equal ("t", terminating);
|
||||
Assert.False (isKeyMouse);
|
||||
Assert.Single (mouseFlags);
|
||||
Assert.Equal (default, mouseFlags [^1]);
|
||||
Assert.Equal (Point.Empty, pos);
|
||||
Assert.True (isResponse);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -342,10 +342,8 @@ public class KeyTests
|
||||
[InlineData ((KeyCode)'{', "{")]
|
||||
[InlineData ((KeyCode)'\'', "\'")]
|
||||
[InlineData ((KeyCode)'ó', "ó")]
|
||||
[InlineData (
|
||||
(KeyCode)'Ó' | KeyCode.ShiftMask,
|
||||
"Shift+Ó"
|
||||
)] // TODO: This is not correct, it should be Shift+ó or just Ó
|
||||
[InlineData ((KeyCode)'Ó' | KeyCode.ShiftMask, "Shift+Ó")]
|
||||
[InlineData ((KeyCode)'ó' | KeyCode.ShiftMask, "Shift+ó")]
|
||||
[InlineData ((KeyCode)'Ó', "Ó")]
|
||||
[InlineData ((KeyCode)'ç' | KeyCode.ShiftMask | KeyCode.AltMask | KeyCode.CtrlMask, "Ctrl+Alt+Shift+ç")]
|
||||
[InlineData ((KeyCode)'a', "a")] // 97 or Key.Space | Key.A
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace Terminal.Gui;
|
||||
|
||||
namespace Terminal.Gui.BuildAndDeployTests;
|
||||
|
||||
public class LocalPackagesTests
|
||||
{
|
||||
|
||||
@@ -25,21 +25,21 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute
|
||||
/// </summary>
|
||||
/// <param name="autoInit">If true, Application.Init will be called Before the test runs.</param>
|
||||
/// <param name="consoleDriverType">
|
||||
/// Determines which ConsoleDriver (FakeDriver, WindowsDriver, CursesDriver, NetDriver)
|
||||
/// Determines which IConsoleDriver (FakeDriver, WindowsDriver, CursesDriver, NetDriver)
|
||||
/// will be used when Application.Init is called. If null FakeDriver will be used. Only valid if
|
||||
/// <paramref name="autoInit"/> is true.
|
||||
/// </param>
|
||||
/// <param name="useFakeClipboard">
|
||||
/// If true, will force the use of <see cref="FakeDriver.FakeClipboard"/>. Only valid if
|
||||
/// <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
|
||||
/// <see cref="IConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
|
||||
/// </param>
|
||||
/// <param name="fakeClipboardAlwaysThrowsNotSupportedException">
|
||||
/// Only valid if <paramref name="autoInit"/> is true. Only
|
||||
/// valid if <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
|
||||
/// valid if <see cref="IConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
|
||||
/// </param>
|
||||
/// <param name="fakeClipboardIsSupportedAlwaysTrue">
|
||||
/// Only valid if <paramref name="autoInit"/> is true. Only valid if
|
||||
/// <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
|
||||
/// <see cref="IConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
|
||||
/// </param>
|
||||
/// <param name="configLocation">Determines what config file locations <see cref="ConfigurationManager"/> will load from.</param>
|
||||
/// <param name="verifyShutdown">If true and <see cref="Application.Initialized"/> is true, the test will fail.</param>
|
||||
@@ -135,7 +135,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute
|
||||
View.Instances.Clear ();
|
||||
}
|
||||
#endif
|
||||
Application.Init ((ConsoleDriver)Activator.CreateInstance (_driverType));
|
||||
Application.Init ((IConsoleDriver)Activator.CreateInstance (_driverType));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +199,8 @@ public class SetupFakeDriverAttribute : BeforeAfterTestAttribute
|
||||
|
||||
if (Application.Driver is { })
|
||||
{
|
||||
((FakeDriver)Application.Driver).Rows = 25;
|
||||
((FakeDriver)Application.Driver).Cols = 25;
|
||||
((FakeDriver)Application.Driver).End ();
|
||||
}
|
||||
|
||||
@@ -249,12 +251,12 @@ internal partial class TestHelpers
|
||||
/// <paramref name="expectedAttributes"/>.
|
||||
/// </param>
|
||||
/// <param name="output"></param>
|
||||
/// <param name="driver">The ConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
|
||||
/// <param name="driver">The IConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
|
||||
/// <param name="expectedAttributes"></param>
|
||||
public static void AssertDriverAttributesAre (
|
||||
string expectedLook,
|
||||
ITestOutputHelper output,
|
||||
ConsoleDriver driver = null,
|
||||
IConsoleDriver driver = null,
|
||||
params Attribute [] expectedAttributes
|
||||
)
|
||||
{
|
||||
@@ -319,12 +321,12 @@ internal partial class TestHelpers
|
||||
/// <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="driver">The IConsoleDriver 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,
|
||||
IConsoleDriver driver = null,
|
||||
bool ignoreLeadingWhitespace = false
|
||||
)
|
||||
{
|
||||
@@ -365,12 +367,12 @@ internal partial class TestHelpers
|
||||
/// </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="driver">The IConsoleDriver to use. If null <see cref="Application.Driver"/> will be used.</param>
|
||||
/// <returns></returns>
|
||||
public static Rectangle AssertDriverContentsWithFrameAre (
|
||||
string expectedLook,
|
||||
ITestOutputHelper output,
|
||||
ConsoleDriver driver = null
|
||||
IConsoleDriver driver = null
|
||||
)
|
||||
{
|
||||
List<List<Rune>> lines = new ();
|
||||
@@ -623,7 +625,7 @@ internal partial class TestHelpers
|
||||
/// </summary>
|
||||
/// <param name="driver">if null uses <see cref="Application.Driver"/></param>
|
||||
/// <param name="expectedColors"></param>
|
||||
internal static void AssertDriverUsedColors (ConsoleDriver driver = null, params Attribute [] expectedColors)
|
||||
internal static void AssertDriverUsedColors (IConsoleDriver driver = null, params Attribute [] expectedColors)
|
||||
{
|
||||
driver ??= Application.Driver;
|
||||
Cell [,] contents = driver.Contents;
|
||||
|
||||
Reference in New Issue
Block a user