|
@@ -3,12 +3,9 @@ using Xunit.Abstractions;
|
|
|
|
|
|
namespace Terminal.Gui.ViewsTests;
|
|
namespace Terminal.Gui.ViewsTests;
|
|
|
|
|
|
-public class CheckBoxTests
|
|
|
|
|
|
+public class CheckBoxTests (ITestOutputHelper output)
|
|
{
|
|
{
|
|
- private readonly ITestOutputHelper _output;
|
|
|
|
private static readonly Size _size25x1 = new (25, 1);
|
|
private static readonly Size _size25x1 = new (25, 1);
|
|
- public CheckBoxTests (ITestOutputHelper output) { _output = output; }
|
|
|
|
-
|
|
|
|
|
|
|
|
[Theory]
|
|
[Theory]
|
|
[InlineData ("01234", 0, 0, 0, 0)]
|
|
[InlineData ("01234", 0, 0, 0, 0)]
|
|
@@ -39,9 +36,9 @@ public class CheckBoxTests
|
|
Text = text
|
|
Text = text
|
|
};
|
|
};
|
|
|
|
|
|
- Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.Frame.Size);
|
|
|
|
- Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.Viewport.Size);
|
|
|
|
- Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.TextFormatter.Size);
|
|
|
|
|
|
+ Assert.Equal (new (expectedWidth, expectedHeight), checkBox.Frame.Size);
|
|
|
|
+ Assert.Equal (new (expectedWidth, expectedHeight), checkBox.Viewport.Size);
|
|
|
|
+ Assert.Equal (new (expectedWidth, expectedHeight), checkBox.TextFormatter.Size);
|
|
|
|
|
|
checkBox.Dispose ();
|
|
checkBox.Dispose ();
|
|
}
|
|
}
|
|
@@ -60,12 +57,12 @@ public class CheckBoxTests
|
|
X = 0,
|
|
X = 0,
|
|
Y = 0,
|
|
Y = 0,
|
|
Width = width,
|
|
Width = width,
|
|
- Height = height,
|
|
|
|
|
|
+ Height = height
|
|
};
|
|
};
|
|
|
|
|
|
- Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.Frame.Size);
|
|
|
|
- Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.Viewport.Size);
|
|
|
|
- Assert.Equal (new Size (expectedWidth, expectedHeight), checkBox.TextFormatter.Size);
|
|
|
|
|
|
+ Assert.Equal (new (expectedWidth, expectedHeight), checkBox.Frame.Size);
|
|
|
|
+ Assert.Equal (new (expectedWidth, expectedHeight), checkBox.Viewport.Size);
|
|
|
|
+ Assert.Equal (new (expectedWidth, expectedHeight), checkBox.TextFormatter.Size);
|
|
|
|
|
|
checkBox.Dispose ();
|
|
checkBox.Dispose ();
|
|
}
|
|
}
|
|
@@ -77,7 +74,7 @@ public class CheckBoxTests
|
|
var view = new CheckBox ();
|
|
var view = new CheckBox ();
|
|
view.Title = "Hello";
|
|
view.Title = "Hello";
|
|
Assert.Equal ("Hello", view.Title);
|
|
Assert.Equal ("Hello", view.Title);
|
|
- Assert.Equal ($"Hello", view.TitleTextFormatter.Text);
|
|
|
|
|
|
+ Assert.Equal ("Hello", view.TitleTextFormatter.Text);
|
|
|
|
|
|
Assert.Equal ("Hello", view.Text);
|
|
Assert.Equal ("Hello", view.Text);
|
|
Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
|
|
Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
|
|
@@ -92,7 +89,7 @@ public class CheckBoxTests
|
|
Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
|
|
Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
|
|
|
|
|
|
Assert.Equal ("Hello", view.Title);
|
|
Assert.Equal ("Hello", view.Title);
|
|
- Assert.Equal ($"Hello", view.TitleTextFormatter.Text);
|
|
|
|
|
|
+ Assert.Equal ("Hello", view.TitleTextFormatter.Text);
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -107,7 +104,7 @@ public class CheckBoxTests
|
|
Assert.False (checkBox.Checked);
|
|
Assert.False (checkBox.Checked);
|
|
Assert.True (checkBox.NewKeyDownEvent (Key.Space));
|
|
Assert.True (checkBox.NewKeyDownEvent (Key.Space));
|
|
Assert.True (checkBox.Checked);
|
|
Assert.True (checkBox.Checked);
|
|
- Assert.True (checkBox.NewMouseEvent (new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
|
|
|
|
|
|
+ Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
|
|
Assert.False (checkBox.Checked);
|
|
Assert.False (checkBox.Checked);
|
|
|
|
|
|
checkBox.AllowNullChecked = true;
|
|
checkBox.AllowNullChecked = true;
|
|
@@ -118,17 +115,18 @@ public class CheckBoxTests
|
|
TestHelpers.AssertDriverContentsWithFrameAre (
|
|
TestHelpers.AssertDriverContentsWithFrameAre (
|
|
@$"
|
|
@$"
|
|
{CM.Glyphs.NullChecked} Check this out 你",
|
|
{CM.Glyphs.NullChecked} Check this out 你",
|
|
- _output
|
|
|
|
|
|
+ output
|
|
);
|
|
);
|
|
- Assert.True (checkBox.NewMouseEvent (new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
|
|
|
|
|
|
+ Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
|
|
Assert.True (checkBox.Checked);
|
|
Assert.True (checkBox.Checked);
|
|
Assert.True (checkBox.NewKeyDownEvent (Key.Space));
|
|
Assert.True (checkBox.NewKeyDownEvent (Key.Space));
|
|
Assert.False (checkBox.Checked);
|
|
Assert.False (checkBox.Checked);
|
|
- Assert.True (checkBox.NewMouseEvent (new MouseEvent { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
|
|
|
|
|
|
+ Assert.True (checkBox.NewMouseEvent (new() { Position = new (0, 0), Flags = MouseFlags.Button1Clicked }));
|
|
Assert.Null (checkBox.Checked);
|
|
Assert.Null (checkBox.Checked);
|
|
|
|
|
|
checkBox.AllowNullChecked = false;
|
|
checkBox.AllowNullChecked = false;
|
|
Assert.False (checkBox.Checked);
|
|
Assert.False (checkBox.Checked);
|
|
|
|
+ top.Dispose ();
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -142,9 +140,9 @@ public class CheckBoxTests
|
|
Assert.Equal (string.Empty, ckb.Text);
|
|
Assert.Equal (string.Empty, ckb.Text);
|
|
Assert.Equal ($"{CM.Glyphs.UnChecked} ", ckb.TextFormatter.Text);
|
|
Assert.Equal ($"{CM.Glyphs.UnChecked} ", ckb.TextFormatter.Text);
|
|
Assert.True (ckb.CanFocus);
|
|
Assert.True (ckb.CanFocus);
|
|
- Assert.Equal (new Rectangle (0, 0, 2, 1), ckb.Frame);
|
|
|
|
|
|
+ Assert.Equal (new (0, 0, 2, 1), ckb.Frame);
|
|
|
|
|
|
- ckb = new CheckBox { Text = "Test", Checked = true };
|
|
|
|
|
|
+ ckb = new() { Text = "Test", Checked = true };
|
|
Assert.True (ckb.Width is DimAuto);
|
|
Assert.True (ckb.Width is DimAuto);
|
|
Assert.True (ckb.Height is DimAuto);
|
|
Assert.True (ckb.Height is DimAuto);
|
|
Assert.True (ckb.Checked);
|
|
Assert.True (ckb.Checked);
|
|
@@ -152,9 +150,9 @@ public class CheckBoxTests
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
|
|
Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
|
|
Assert.True (ckb.CanFocus);
|
|
Assert.True (ckb.CanFocus);
|
|
- Assert.Equal (new Rectangle (0, 0, 6, 1), ckb.Frame);
|
|
|
|
|
|
+ Assert.Equal (new (0, 0, 6, 1), ckb.Frame);
|
|
|
|
|
|
- ckb = new CheckBox { Text = "Test", X = 1, Y = 2 };
|
|
|
|
|
|
+ ckb = new() { Text = "Test", X = 1, Y = 2 };
|
|
Assert.True (ckb.Width is DimAuto);
|
|
Assert.True (ckb.Width is DimAuto);
|
|
Assert.True (ckb.Height is DimAuto);
|
|
Assert.True (ckb.Height is DimAuto);
|
|
Assert.False (ckb.Checked);
|
|
Assert.False (ckb.Checked);
|
|
@@ -162,9 +160,9 @@ public class CheckBoxTests
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ($"{CM.Glyphs.UnChecked} Test", ckb.TextFormatter.Text);
|
|
Assert.Equal ($"{CM.Glyphs.UnChecked} Test", ckb.TextFormatter.Text);
|
|
Assert.True (ckb.CanFocus);
|
|
Assert.True (ckb.CanFocus);
|
|
- Assert.Equal (new Rectangle (1, 2, 6, 1), ckb.Frame);
|
|
|
|
|
|
+ Assert.Equal (new (1, 2, 6, 1), ckb.Frame);
|
|
|
|
|
|
- ckb = new CheckBox { Text = "Test", X = 3, Y = 4, Checked = true };
|
|
|
|
|
|
+ ckb = new() { Text = "Test", X = 3, Y = 4, Checked = true };
|
|
Assert.True (ckb.Width is DimAuto);
|
|
Assert.True (ckb.Width is DimAuto);
|
|
Assert.True (ckb.Height is DimAuto);
|
|
Assert.True (ckb.Height is DimAuto);
|
|
Assert.True (ckb.Checked);
|
|
Assert.True (ckb.Checked);
|
|
@@ -172,7 +170,7 @@ public class CheckBoxTests
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
|
|
Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
|
|
Assert.True (ckb.CanFocus);
|
|
Assert.True (ckb.CanFocus);
|
|
- Assert.Equal (new Rectangle (3, 4, 6, 1), ckb.Frame);
|
|
|
|
|
|
+ Assert.Equal (new (3, 4, 6, 1), ckb.Frame);
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -229,11 +227,12 @@ public class CheckBoxTests
|
|
|
|
|
|
ckb.Accept += ViewOnAccept;
|
|
ckb.Accept += ViewOnAccept;
|
|
|
|
|
|
- var ret = ckb.InvokeCommand (Command.Accept);
|
|
|
|
|
|
+ bool? ret = ckb.InvokeCommand (Command.Accept);
|
|
Assert.True (ret);
|
|
Assert.True (ret);
|
|
Assert.True (acceptInvoked);
|
|
Assert.True (acceptInvoked);
|
|
|
|
|
|
return;
|
|
return;
|
|
|
|
+
|
|
void ViewOnAccept (object sender, CancelEventArgs e)
|
|
void ViewOnAccept (object sender, CancelEventArgs e)
|
|
{
|
|
{
|
|
acceptInvoked = true;
|
|
acceptInvoked = true;
|
|
@@ -273,7 +272,7 @@ public class CheckBoxTests
|
|
└────────────────────────────┘
|
|
└────────────────────────────┘
|
|
";
|
|
";
|
|
|
|
|
|
- Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
|
|
+ Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
|
|
|
|
checkBox.Checked = true;
|
|
checkBox.Checked = true;
|
|
@@ -287,8 +286,9 @@ public class CheckBoxTests
|
|
└────────────────────────────┘
|
|
└────────────────────────────┘
|
|
";
|
|
";
|
|
|
|
|
|
- pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
|
|
+ pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
|
|
+ top.Dispose ();
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -324,7 +324,7 @@ public class CheckBoxTests
|
|
Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame);
|
|
Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame);
|
|
Assert.Equal (Alignment.Fill, checkBox2.TextAlignment);
|
|
Assert.Equal (Alignment.Fill, checkBox2.TextAlignment);
|
|
Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame);
|
|
Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame);
|
|
-
|
|
|
|
|
|
+
|
|
var expected = @$"
|
|
var expected = @$"
|
|
┌┤Test Demo 你├──────────────┐
|
|
┌┤Test Demo 你├──────────────┐
|
|
│ │
|
|
│ │
|
|
@@ -334,7 +334,7 @@ public class CheckBoxTests
|
|
└────────────────────────────┘
|
|
└────────────────────────────┘
|
|
";
|
|
";
|
|
|
|
|
|
- Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
|
|
+ Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 30, 6), pos);
|
|
Assert.Equal (new (0, 0, 30, 6), pos);
|
|
|
|
|
|
checkBox1.Checked = true;
|
|
checkBox1.Checked = true;
|
|
@@ -354,8 +354,9 @@ public class CheckBoxTests
|
|
└────────────────────────────┘
|
|
└────────────────────────────┘
|
|
";
|
|
";
|
|
|
|
|
|
- pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
|
|
+ pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 30, 6), pos);
|
|
Assert.Equal (new (0, 0, 30, 6), pos);
|
|
|
|
+ top.Dispose ();
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -389,7 +390,7 @@ public class CheckBoxTests
|
|
└────────────────────────────┘
|
|
└────────────────────────────┘
|
|
";
|
|
";
|
|
|
|
|
|
- Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
|
|
+ Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
|
|
|
|
checkBox.Checked = true;
|
|
checkBox.Checked = true;
|
|
@@ -403,8 +404,9 @@ public class CheckBoxTests
|
|
└────────────────────────────┘
|
|
└────────────────────────────┘
|
|
";
|
|
";
|
|
|
|
|
|
- pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
|
|
+ pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
|
|
+ top.Dispose ();
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -439,7 +441,7 @@ public class CheckBoxTests
|
|
└────────────────────────────┘
|
|
└────────────────────────────┘
|
|
";
|
|
";
|
|
|
|
|
|
- Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
|
|
+ Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
|
|
|
|
checkBox.Checked = true;
|
|
checkBox.Checked = true;
|
|
@@ -453,8 +455,9 @@ public class CheckBoxTests
|
|
└────────────────────────────┘
|
|
└────────────────────────────┘
|
|
";
|
|
";
|
|
|
|
|
|
- pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
|
|
+ pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
Assert.Equal (new (0, 0, 30, 5), pos);
|
|
|
|
+ top.Dispose ();
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -469,6 +472,7 @@ public class CheckBoxTests
|
|
Assert.True (accepted);
|
|
Assert.True (accepted);
|
|
|
|
|
|
return;
|
|
return;
|
|
|
|
+
|
|
void CheckBoxOnAccept (object sender, CancelEventArgs e) { accepted = true; }
|
|
void CheckBoxOnAccept (object sender, CancelEventArgs e) { accepted = true; }
|
|
}
|
|
}
|
|
|
|
|
|
@@ -478,19 +482,20 @@ public class CheckBoxTests
|
|
[InlineData (null)]
|
|
[InlineData (null)]
|
|
public void Toggled_Cancel_Event_Prevents_Toggle (bool? initialState)
|
|
public void Toggled_Cancel_Event_Prevents_Toggle (bool? initialState)
|
|
{
|
|
{
|
|
- var ckb = new CheckBox () { AllowNullChecked = true };
|
|
|
|
|
|
+ var ckb = new CheckBox { AllowNullChecked = true };
|
|
var checkedInvoked = false;
|
|
var checkedInvoked = false;
|
|
|
|
|
|
ckb.Toggled += CheckBoxToggled;
|
|
ckb.Toggled += CheckBoxToggled;
|
|
|
|
|
|
ckb.Checked = initialState;
|
|
ckb.Checked = initialState;
|
|
- Assert.Equal(initialState, ckb.Checked);
|
|
|
|
- var ret = ckb.OnToggled ();
|
|
|
|
|
|
+ Assert.Equal (initialState, ckb.Checked);
|
|
|
|
+ bool? ret = ckb.OnToggled ();
|
|
Assert.True (ret);
|
|
Assert.True (ret);
|
|
Assert.True (checkedInvoked);
|
|
Assert.True (checkedInvoked);
|
|
Assert.Equal (initialState, ckb.Checked);
|
|
Assert.Equal (initialState, ckb.Checked);
|
|
|
|
|
|
return;
|
|
return;
|
|
|
|
+
|
|
void CheckBoxToggled (object sender, CancelEventArgs e)
|
|
void CheckBoxToggled (object sender, CancelEventArgs e)
|
|
{
|
|
{
|
|
checkedInvoked = true;
|
|
checkedInvoked = true;
|