mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 16:58:01 +01:00
* Fixes #3054. VkeyPacketSimulator scenario is broken. * Fix some key handle and unit tests. * Remove unnecessary conditional. * Improves key handling. * Also allow map capslock to shift with accented characters. * Change to MemberData. * Remove unnecessary using. * Fix merge errors. * Fixes #3095. WindowsDriver should return the mask keys to IsShift, IsAlt and IsCtrl return the right value. * Modifiers keys are valid to be handled on key down and key up. * Map KeyCode.Enter to ConsoleKey.Enter and vice versa. * Updated ScanCodeMapping table with readable constants * Documented bugs * Implemented mapping using MapVirtualKeyEx * Implemented mapping using MapVirtualKeyEx * Changed KeyCode special keys to match ConsoleKey values + max unicode codepoint * Fixed bogus CollectionNavigator impl and tests * Nuked DeleteChar. renamed InsertChar to Insert * KeyCode.Enter = ConsoleKey.Enter, not \n * Code cleanup * Added diag for keyboard layout name * Fixed AltGr support (hopefully) * Simplified code * Simplified KeyCode by removing ShiftKeys * Fixed TextView * Code cleanup * Fixes cursesdriver (somewhat) * Code cleanup * netdriver wip * Fixed netdriver under WSL * Turned off debug spew * Removed old code --------- Co-authored-by: Tig Kindel <tig@users.noreply.github.com> Co-authored-by: Tig Kindel <tig@kindel.com>
104 lines
3.4 KiB
C#
104 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace Terminal.Gui.ViewsTests {
|
|
public class DateFieldTests {
|
|
[Fact]
|
|
public void Constructors_Defaults ()
|
|
{
|
|
var df = new DateField ();
|
|
Assert.False (df.IsShortFormat);
|
|
Assert.Equal (DateTime.MinValue, df.Date);
|
|
Assert.Equal (1, df.CursorPosition);
|
|
Assert.Equal (new Rect (0, 0, 12, 1), df.Frame);
|
|
|
|
var date = DateTime.Now;
|
|
df = new DateField (date);
|
|
Assert.False (df.IsShortFormat);
|
|
Assert.Equal (date, df.Date);
|
|
Assert.Equal (1, df.CursorPosition);
|
|
Assert.Equal (new Rect (0, 0, 12, 1), df.Frame);
|
|
|
|
df = new DateField (1, 2, date);
|
|
Assert.False (df.IsShortFormat);
|
|
Assert.Equal (date, df.Date);
|
|
Assert.Equal (1, df.CursorPosition);
|
|
Assert.Equal (new Rect (1, 2, 12, 1), df.Frame);
|
|
|
|
df = new DateField (3, 4, date, true);
|
|
Assert.True (df.IsShortFormat);
|
|
Assert.Equal (date, df.Date);
|
|
Assert.Equal (1, df.CursorPosition);
|
|
Assert.Equal (new Rect (3, 4, 10, 1), df.Frame);
|
|
|
|
df.IsShortFormat = false;
|
|
Assert.Equal (new Rect (3, 4, 12, 1), df.Frame);
|
|
Assert.Equal (12, df.Width);
|
|
}
|
|
|
|
[Fact]
|
|
public void CursorPosition_Min_Is_Always_One_Max_Is_Always_Max_Format ()
|
|
{
|
|
var df = new DateField ();
|
|
Assert.Equal (1, df.CursorPosition);
|
|
df.CursorPosition = 0;
|
|
Assert.Equal (1, df.CursorPosition);
|
|
df.CursorPosition = 11;
|
|
Assert.Equal (10, df.CursorPosition);
|
|
df.IsShortFormat = true;
|
|
df.CursorPosition = 0;
|
|
Assert.Equal (1, df.CursorPosition);
|
|
df.CursorPosition = 9;
|
|
Assert.Equal (8, df.CursorPosition);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyBindings_Command ()
|
|
{
|
|
CultureInfo cultureBackup = CultureInfo.CurrentCulture;
|
|
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
|
|
DateField df = new DateField (DateTime.Parse ("12/12/1971"));
|
|
df.ReadOnly = true;
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.Delete)));
|
|
Assert.Equal (" 12/12/1971", df.Text);
|
|
df.ReadOnly = false;
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.D | KeyCode.CtrlMask)));
|
|
Assert.Equal (" 02/12/1971", df.Text);
|
|
df.CursorPosition = 4;
|
|
df.ReadOnly = true;
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.Delete)));
|
|
Assert.Equal (" 02/12/1971", df.Text);
|
|
df.ReadOnly = false;
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.Backspace)));
|
|
Assert.Equal (" 02/02/1971", df.Text);
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.Home)));
|
|
Assert.Equal (1, df.CursorPosition);
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.End)));
|
|
Assert.Equal (10, df.CursorPosition);
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.A | KeyCode.CtrlMask)));
|
|
Assert.Equal (1, df.CursorPosition);
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.E | KeyCode.CtrlMask)));
|
|
Assert.Equal (10, df.CursorPosition);
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.CursorLeft)));
|
|
Assert.Equal (9, df.CursorPosition);
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.CursorRight)));
|
|
Assert.Equal (10, df.CursorPosition);
|
|
// Non-numerics are ignored
|
|
Assert.False (df.NewKeyDownEvent (new (KeyCode.A)));
|
|
df.ReadOnly = true;
|
|
df.CursorPosition = 1;
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.D1)));
|
|
Assert.Equal (" 02/02/1971", df.Text);
|
|
df.ReadOnly = false;
|
|
Assert.True (df.NewKeyDownEvent (new (KeyCode.D1)));
|
|
Assert.Equal (" 12/02/1971", df.Text);
|
|
CultureInfo.CurrentCulture = cultureBackup;
|
|
}
|
|
}
|
|
}
|