Merged v2_develop

This commit is contained in:
Tig Kindel
2024-01-16 10:35:03 -07:00
29 changed files with 4087 additions and 3400 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,218 +1,210 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewsTests {
public class CheckboxTests {
readonly ITestOutputHelper output;
namespace Terminal.Gui.ViewsTests;
public CheckboxTests (ITestOutputHelper output)
{
this.output = output;
}
public class CheckboxTests {
readonly ITestOutputHelper _output;
[Fact]
public void Constructors_Defaults ()
{
var ckb = new CheckBox ();
Assert.True (ckb.AutoSize);
Assert.False (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal (string.Empty, ckb.Text);
Assert.Equal ($"{CM.Glyphs.UnChecked} ", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
Assert.Equal (new Rect (0, 0, 2, 1), ckb.Frame);
public CheckboxTests (ITestOutputHelper output) => _output = output;
ckb = new CheckBox ("Test", true);
Assert.True (ckb.AutoSize);
Assert.True (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
Assert.Equal (new Rect (0, 0, 6, 1), ckb.Frame);
[Fact]
public void Constructors_Defaults ()
{
var ckb = new CheckBox ();
Assert.True (ckb.AutoSize);
Assert.False (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal (string.Empty, ckb.Text);
Assert.Equal ($"{CM.Glyphs.UnChecked} ", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
Assert.Equal (new Rect (0, 0, 2, 1), ckb.Frame);
ckb = new CheckBox (1, 2, "Test");
Assert.True (ckb.AutoSize);
Assert.False (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ($"{CM.Glyphs.UnChecked} Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
Assert.Equal (new Rect (1, 2, 6, 1), ckb.Frame);
ckb = new CheckBox ("Test", true);
Assert.True (ckb.AutoSize);
Assert.True (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
Assert.Equal (new Rect (0, 0, 6, 1), ckb.Frame);
ckb = new CheckBox (3, 4, "Test", true);
Assert.True (ckb.AutoSize);
Assert.True (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
Assert.Equal (new Rect (3, 4, 6, 1), ckb.Frame);
}
ckb = new CheckBox (1, 2, "Test");
Assert.True (ckb.AutoSize);
Assert.False (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ($"{CM.Glyphs.UnChecked} Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
Assert.Equal (new Rect (1, 2, 6, 1), ckb.Frame);
[Fact]
[AutoInitShutdown]
public void KeyBindings_Command ()
{
var toggled = false;
CheckBox ckb = new CheckBox ();
ckb.Toggled += (s, e) => toggled = true;
Application.Top.Add (ckb);
Application.Begin (Application.Top);
ckb = new CheckBox (3, 4, "Test", true);
Assert.True (ckb.AutoSize);
Assert.True (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
Assert.True (ckb.CanFocus);
Assert.Equal (new Rect (3, 4, 6, 1), ckb.Frame);
}
Assert.False (ckb.Checked);
Assert.False (toggled);
Assert.Equal (KeyCode.Null, ckb.HotKey);
[Fact]
[AutoInitShutdown]
public void KeyBindings_Command ()
{
var toggled = false;
var ckb = new CheckBox ();
ckb.Toggled += (s, e) => toggled = true;
Application.Top.Add (ckb);
Application.Begin (Application.Top);
ckb.Text = "Test";
Assert.Equal (KeyCode.T, ckb.HotKey);
Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.T)));
Assert.True (ckb.Checked);
Assert.True (toggled);
Assert.False (ckb.Checked);
Assert.False (toggled);
Assert.Equal (KeyCode.Null, ckb.HotKey);
ckb.Text = "T_est";
toggled = false;
Assert.Equal (KeyCode.E, ckb.HotKey);
Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.E | KeyCode.AltMask)));
Assert.True (toggled);
Assert.False (ckb.Checked);
ckb.Text = "_Test";
Assert.Equal (KeyCode.T, ckb.HotKey);
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.T)));
Assert.True (ckb.Checked);
Assert.True (toggled);
toggled = false;
Assert.Equal (KeyCode.E, ckb.HotKey);
Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.E)));
Assert.True (toggled);
Assert.True (ckb.Checked);
ckb.Text = "T_est";
toggled = false;
Assert.Equal (KeyCode.E, ckb.HotKey);
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.E | KeyCode.AltMask)));
Assert.True (toggled);
Assert.False (ckb.Checked);
toggled = false;
Assert.True (Application.Top.NewKeyDownEvent (new ((KeyCode)' ')));
Assert.True (toggled);
Assert.False (ckb.Checked);
toggled = false;
Assert.Equal (KeyCode.E, ckb.HotKey);
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.E)));
Assert.True (toggled);
Assert.True (ckb.Checked);
toggled = false;
Assert.True (Application.Top.NewKeyDownEvent (new (KeyCode.Space)));
Assert.True (toggled);
Assert.True (ckb.Checked);
Assert.True (ckb.AutoSize);
toggled = false;
Assert.True (Application.Top.NewKeyDownEvent (new Key ((KeyCode)' ')));
Assert.True (toggled);
Assert.False (ckb.Checked);
Application.Refresh ();
toggled = false;
Assert.True (Application.Top.NewKeyDownEvent (new Key (KeyCode.Space)));
Assert.True (toggled);
Assert.True (ckb.Checked);
Assert.True (ckb.AutoSize);
var expected = @$"
Application.Refresh ();
var expected = @$"
{CM.Glyphs.Checked} Test
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 6, 1), pos);
}
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 6, 1), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_StaysVisible ()
{
var checkBox = new CheckBox () {
X = 1,
Y = Pos.Center (),
Text = "Check this out 你"
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
[Fact] [AutoInitShutdown]
public void AutoSize_StaysVisible ()
{
var checkBox = new CheckBox {
X = 1,
Y = Pos.Center (),
Text = "Check this out 你"
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
Assert.False (checkBox.IsInitialized);
Assert.False (checkBox.IsInitialized);
var runstate = Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
var runstate = Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
Assert.True (checkBox.IsInitialized);
Assert.Equal (new Rect (1, 1, 19, 1), checkBox.Frame);
Assert.Equal ("Check this out 你", checkBox.Text);
Assert.Equal ($"{CM.Glyphs.UnChecked} Check this out 你", checkBox.TextFormatter.Text);
Assert.True (checkBox.AutoSize);
Assert.True (checkBox.IsInitialized);
Assert.Equal (new Rect (1, 1, 19, 1), checkBox.Frame);
Assert.Equal ("Check this out 你", checkBox.Text);
Assert.Equal ($"{CM.Glyphs.UnChecked} Check this out 你", checkBox.TextFormatter.Text);
Assert.True (checkBox.AutoSize);
checkBox.Checked = true;
Assert.Equal ($"{CM.Glyphs.Checked} Check this out 你", checkBox.TextFormatter.Text);
checkBox.Checked = true;
Assert.Equal ($"{CM.Glyphs.Checked} Check this out 你", checkBox.TextFormatter.Text);
checkBox.AutoSize = false;
checkBox.AutoSize = false;
// It isn't auto-size so the height is guaranteed by the SetMinWidthHeight
checkBox.Text = "Check this out 你 changed";
var firstIteration = false;
Application.RunIteration (ref runstate, ref firstIteration);
// BUGBUG - v2 - Autosize is busted; disabling tests for now
Assert.Equal (new Rect (1, 1, 19, 1), checkBox.Frame);
var expected = @"
checkBox.AutoSize = false;
// It isn't auto-size so the height is guaranteed by the SetMinWidthHeight
checkBox.Text = "Check this out 你 changed";
var firstIteration = false;
Application.RunIteration (ref runstate, ref firstIteration);
// BUGBUG - v2 - Autosize is busted; disabling tests for now
Assert.Equal (new Rect (1, 1, 19, 1), checkBox.Frame);
var expected = @"
┌┤Test Demo 你├──────────────┐
│ │
│ ☑ Check this out 你 │
│ │
└────────────────────────────┘";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
checkBox.Width = 19;
// It isn't auto-size so the height is guaranteed by the SetMinWidthHeight
checkBox.Text = "Check this out 你 changed";
Application.RunIteration (ref runstate, ref firstIteration);
Assert.False (checkBox.AutoSize);
Assert.Equal (new Rect (1, 1, 19, 1), checkBox.Frame);
expected = @"
checkBox.Width = 19;
// It isn't auto-size so the height is guaranteed by the SetMinWidthHeight
checkBox.Text = "Check this out 你 changed";
Application.RunIteration (ref runstate, ref firstIteration);
Assert.False (checkBox.AutoSize);
Assert.Equal (new Rect (1, 1, 19, 1), checkBox.Frame);
expected = @"
┌┤Test Demo 你├──────────────┐
│ │
│ ☑ Check this out 你 │
│ │
└────────────────────────────┘";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
checkBox.AutoSize = true;
Application.RunIteration (ref runstate, ref firstIteration);
Assert.Equal (new Rect (1, 1, 27, 1), checkBox.Frame);
expected = @"
checkBox.AutoSize = true;
Application.RunIteration (ref runstate, ref firstIteration);
Assert.Equal (new Rect (1, 1, 27, 1), checkBox.Frame);
expected = @"
┌┤Test Demo 你├──────────────┐
│ │
│ ☑ Check this out 你 changed│
│ │
└────────────────────────────┘";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
}
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
}
[Fact, AutoInitShutdown]
public void TextAlignment_Left ()
{
var checkBox = new CheckBox () {
X = 1,
Y = Pos.Center (),
Text = "Check this out 你",
AutoSize = false,
Width = 25
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
[Fact] [AutoInitShutdown]
public void TextAlignment_Left ()
{
var checkBox = new CheckBox {
X = 1,
Y = Pos.Center (),
Text = "Check this out 你",
AutoSize = false,
Width = 25
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
Assert.Equal (TextAlignment.Left, checkBox.TextAlignment);
Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
Assert.Equal (TextAlignment.Left, checkBox.TextAlignment);
Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
var expected = @$"
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你 │
@@ -220,12 +212,12 @@ namespace Terminal.Gui.ViewsTests {
└────────────────────────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
checkBox.Checked = true;
Application.Refresh ();
expected = @$"
checkBox.Checked = true;
Application.Refresh ();
expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.Checked} Check this out 你 │
@@ -233,38 +225,38 @@ namespace Terminal.Gui.ViewsTests {
└────────────────────────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
}
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
}
[Fact, AutoInitShutdown]
public void TextAlignment_Centered ()
{
var checkBox = new CheckBox () {
X = 1,
Y = Pos.Center (),
Text = "Check this out 你",
TextAlignment = TextAlignment.Centered,
AutoSize = false,
Width = 25
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
[Fact] [AutoInitShutdown]
public void TextAlignment_Centered ()
{
var checkBox = new CheckBox {
X = 1,
Y = Pos.Center (),
Text = "Check this out 你",
TextAlignment = TextAlignment.Centered,
AutoSize = false,
Width = 25
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
Assert.Equal (TextAlignment.Centered, checkBox.TextAlignment);
Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
Assert.False (checkBox.AutoSize);
Assert.Equal (TextAlignment.Centered, checkBox.TextAlignment);
Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
Assert.False (checkBox.AutoSize);
var expected = @$"
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你 │
@@ -272,12 +264,12 @@ namespace Terminal.Gui.ViewsTests {
└────────────────────────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
checkBox.Checked = true;
Application.Refresh ();
expected = @$"
checkBox.Checked = true;
Application.Refresh ();
expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.Checked} Check this out 你 │
@@ -285,48 +277,48 @@ namespace Terminal.Gui.ViewsTests {
└────────────────────────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
}
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
}
[Fact, AutoInitShutdown]
public void TextAlignment_Justified ()
{
var checkBox1 = new CheckBox () {
X = 1,
Y = Pos.Center (),
Text = "Check first out 你",
TextAlignment = TextAlignment.Justified,
AutoSize = false,
Width = 25
};
var checkBox2 = new CheckBox () {
X = 1,
Y = Pos.Bottom (checkBox1),
Text = "Check second out 你",
TextAlignment = TextAlignment.Justified,
AutoSize = false,
Width = 25
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox1, checkBox2);
Application.Top.Add (win);
[Fact] [AutoInitShutdown]
public void TextAlignment_Justified ()
{
var checkBox1 = new CheckBox {
X = 1,
Y = Pos.Center (),
Text = "Check first out 你",
TextAlignment = TextAlignment.Justified,
AutoSize = false,
Width = 25
};
var checkBox2 = new CheckBox {
X = 1,
Y = Pos.Bottom (checkBox1),
Text = "Check second out 你",
TextAlignment = TextAlignment.Justified,
AutoSize = false,
Width = 25
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox1, checkBox2);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 6);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 6);
Assert.Equal (TextAlignment.Justified, checkBox1.TextAlignment);
Assert.Equal (new Rect (1, 1, 25, 1), checkBox1.Frame);
Assert.Equal (new Size (25, 1), checkBox1.TextFormatter.Size);
Assert.Equal (TextAlignment.Justified, checkBox2.TextAlignment);
Assert.Equal (new Rect (1, 2, 25, 1), checkBox2.Frame);
Assert.Equal (new Size (25, 1), checkBox2.TextFormatter.Size);
Assert.Equal (TextAlignment.Justified, checkBox1.TextAlignment);
Assert.Equal (new Rect (1, 1, 25, 1), checkBox1.Frame);
Assert.Equal (new Size (25, 1), checkBox1.TextFormatter.Size);
Assert.Equal (TextAlignment.Justified, checkBox2.TextAlignment);
Assert.Equal (new Rect (1, 2, 25, 1), checkBox2.Frame);
Assert.Equal (new Size (25, 1), checkBox2.TextFormatter.Size);
var expected = @$"
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check first out 你 │
@@ -335,17 +327,17 @@ namespace Terminal.Gui.ViewsTests {
└────────────────────────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 6), pos);
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 6), pos);
checkBox1.Checked = true;
Assert.Equal (new Rect (1, 1, 25, 1), checkBox1.Frame);
//Assert.Equal (new Size (25, 1), checkBox1.TextFormatter.Size);
checkBox2.Checked = true;
Assert.Equal (new Rect (1, 2, 25, 1), checkBox2.Frame);
//Assert.Equal (new Size (25, 1), checkBox2.TextFormatter.Size);
Application.Refresh ();
expected = @$"
checkBox1.Checked = true;
Assert.Equal (new Rect (1, 1, 25, 1), checkBox1.Frame);
//Assert.Equal (new Size (25, 1), checkBox1.TextFormatter.Size);
checkBox2.Checked = true;
Assert.Equal (new Rect (1, 2, 25, 1), checkBox2.Frame);
//Assert.Equal (new Size (25, 1), checkBox2.TextFormatter.Size);
Application.Refresh ();
expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.Checked} Check first out 你 │
@@ -354,38 +346,38 @@ namespace Terminal.Gui.ViewsTests {
└────────────────────────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 6), pos);
}
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 6), pos);
}
[Fact, AutoInitShutdown]
public void TextAlignment_Right ()
{
var checkBox = new CheckBox () {
X = 1,
Y = Pos.Center (),
Text = "Check this out 你",
TextAlignment = TextAlignment.Right,
AutoSize = false,
Width = 25
};
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
[Fact] [AutoInitShutdown]
public void TextAlignment_Right ()
{
var checkBox = new CheckBox {
X = 1,
Y = Pos.Center (),
Text = "Check this out 你",
TextAlignment = TextAlignment.Right,
AutoSize = false,
Width = 25
};
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
Assert.Equal (TextAlignment.Right, checkBox.TextAlignment);
Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
Assert.False (checkBox.AutoSize);
Assert.Equal (TextAlignment.Right, checkBox.TextAlignment);
Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size);
Assert.False (checkBox.AutoSize);
var expected = @$"
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ Check this out 你 {CM.Glyphs.UnChecked} │
@@ -393,12 +385,12 @@ namespace Terminal.Gui.ViewsTests {
└────────────────────────────┘
";
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
checkBox.Checked = true;
Application.Refresh ();
expected = @$"
checkBox.Checked = true;
Application.Refresh ();
expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ Check this out 你 {CM.Glyphs.Checked} │
@@ -406,131 +398,130 @@ namespace Terminal.Gui.ViewsTests {
└────────────────────────────┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
}
[Fact, AutoInitShutdown]
public void AutoSize_Stays_True_AnchorEnd_Without_HotKeySpecifier ()
{
var checkBox = new CheckBox () {
Y = Pos.Center (),
Text = "Check this out 你"
};
checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
Assert.True (checkBox.AutoSize);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你│
│ │
└────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.True (checkBox.AutoSize);
checkBox.Text = "Check this out 你 changed";
Assert.True (checkBox.AutoSize);
Application.Refresh ();
expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你 changed│
│ │
└────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Fact, AutoInitShutdown]
public void AutoSize_Stays_True_AnchorEnd_With_HotKeySpecifier ()
{
var checkBox = new CheckBox () {
Y = Pos.Center (),
Text = "C_heck this out 你"
};
checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
var win = new Window () {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
Assert.True (checkBox.AutoSize);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你│
│ │
└────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.True (checkBox.AutoSize);
checkBox.Text = "Check this out 你 changed";
Assert.True (checkBox.AutoSize);
Application.Refresh ();
expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你 changed│
│ │
└────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Fact, AutoInitShutdown]
public void AllowNullChecked_Get_Set ()
{
var checkBox = new CheckBox ("Check this out 你");
var top = Application.Top;
top.Add (checkBox);
Application.Begin (top);
Assert.False (checkBox.Checked);
Assert.True (checkBox.NewKeyDownEvent (new (KeyCode.Space)));
Assert.True (checkBox.Checked);
Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.False (checkBox.Checked);
checkBox.AllowNullChecked = true;
Assert.True (checkBox.NewKeyDownEvent (new (KeyCode.Space)));
Assert.Null (checkBox.Checked);
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@$"
{CM.Glyphs.NullChecked} Check this out 你", output);
Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.True (checkBox.Checked);
Assert.True (checkBox.NewKeyDownEvent (new (KeyCode.Space)));
Assert.False (checkBox.Checked);
Assert.True (checkBox.MouseEvent (new MouseEvent () { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.Null (checkBox.Checked);
checkBox.AllowNullChecked = false;
Assert.False (checkBox.Checked);
}
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.Equal (new Rect (0, 0, 30, 5), pos);
}
}
[Fact] [AutoInitShutdown]
public void AutoSize_Stays_True_AnchorEnd_Without_HotKeySpecifier ()
{
var checkBox = new CheckBox {
Y = Pos.Center (),
Text = "Check this out 你"
};
checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
Assert.True (checkBox.AutoSize);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你│
│ │
└────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.True (checkBox.AutoSize);
checkBox.Text = "Check this out 你 changed";
Assert.True (checkBox.AutoSize);
Application.Refresh ();
expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你 changed│
│ │
└────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
}
[Fact] [AutoInitShutdown]
public void AutoSize_Stays_True_AnchorEnd_With_HotKeySpecifier ()
{
var checkBox = new CheckBox {
Y = Pos.Center (),
Text = "C_heck this out 你"
};
checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
var win = new Window {
Width = Dim.Fill (),
Height = Dim.Fill (),
Title = "Test Demo 你"
};
win.Add (checkBox);
Application.Top.Add (win);
Assert.True (checkBox.AutoSize);
Application.Begin (Application.Top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你│
│ │
└────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.True (checkBox.AutoSize);
checkBox.Text = "Check this out 你 changed";
Assert.True (checkBox.AutoSize);
Application.Refresh ();
expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你 changed│
│ │
└────────────────────────────┘
";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
}
[Fact] [AutoInitShutdown]
public void AllowNullChecked_Get_Set ()
{
var checkBox = new CheckBox ("Check this out 你");
var top = Application.Top;
top.Add (checkBox);
Application.Begin (top);
Assert.False (checkBox.Checked);
Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space)));
Assert.True (checkBox.Checked);
Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.False (checkBox.Checked);
checkBox.AllowNullChecked = true;
Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space)));
Assert.Null (checkBox.Checked);
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@$"
{CM.Glyphs.NullChecked} Check this out 你", _output);
Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.True (checkBox.Checked);
Assert.True (checkBox.NewKeyDownEvent (new Key (KeyCode.Space)));
Assert.False (checkBox.Checked);
Assert.True (checkBox.MouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
Assert.Null (checkBox.Checked);
checkBox.AllowNullChecked = false;
Assert.False (checkBox.Checked);
}
}

View File

@@ -15,9 +15,9 @@ public class MenuTests {
}
// TODO: Create more low-level unit tests for Menu and MenuItem
[Fact]
public void Menu_Constuctors_Defaults ()
public void Menu_Constructors_Defaults ()
{
Assert.Throws<ArgumentNullException> (() => new Menu (null, 0, 0, null));
@@ -28,7 +28,7 @@ public class MenuTests {
}
[Fact]
public void MenuItem_Constuctors_Defaults ()
public void MenuItem_Constructors_Defaults ()
{
var menuItem = new MenuItem ();
Assert.Equal ("", menuItem.Title);
@@ -48,4 +48,4 @@ public class MenuTests {
void Run () { }
}
}
}

View File

@@ -170,7 +170,7 @@ public class RadioGroupTests {
[Fact]
public void KeyBindings_Are_Added_Correctly ()
{
var rg = new RadioGroup (new string [] { "Left", "Right" });
var rg = new RadioGroup (new string [] { "_Left", "_Right" });
Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L));
Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.R));
@@ -185,7 +185,7 @@ public class RadioGroupTests {
[Fact]
public void KeyBindings_HotKeys ()
{
var rg = new RadioGroup (new string [] { "Left", "Right", "Cen_tered", "Justified" });
var rg = new RadioGroup (new string [] { "_Left", "_Right", "Cen_tered", "_Justified" });
Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L));
Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.ShiftMask));
Assert.NotEmpty (rg.KeyBindings.GetCommands (KeyCode.L | KeyCode.AltMask));

View File

@@ -0,0 +1,15 @@
using Xunit;
namespace Terminal.Gui.ViewsTests;
public class TabTests {
[Fact]
public void Constructor_Defaults ()
{
Tab tab = new Tab ();
Assert.Equal ("Unamed", tab.DisplayText);
Assert.Null (tab.View);
Assert.Equal (LineStyle.Rounded, tab.BorderStyle);
Assert.True (tab.CanFocus);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff