mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 08:17:53 +01:00
* Remove NStack and replace ustring to string.
* Add unit test and improving some code.
* Adjust code and fix all unit tests errors.
* Add XML Document and move the Rune folder into the Text folder.
* Improve unit tests with byte array on DecodeRune and DecodeLastRune.
* Fix unit test.
* 😂Code review
* Reduce unit tests code.
* Change StringExtensions.Make to StringExtensions.ToString and added some more unit tests.
* Fix merge errors.
* Remove GetTextWidth and calls replaced with StringExtensions.GetColumns.
* Hack to use UseSystemConsole passed in the command line arguments.
* Revert "Hack to use UseSystemConsole passed in the command line arguments."
This reverts commit b74d11c786.
* Remove Application.UseSystemConsole from the config file.
* Fix errors related by removing UseSystemConsole from the config file.
* Fixes #2633. DecodeEscSeq throw an exception if cki is null.
* Fix an exception if SelectedItem is -1.
* Set SelectedItem to 0 and remove unnecessary ToString.
* Using a unique ToString method for Rune and other for byte.
* Fix a bug where a wider rune is added with only a width of 1.
* Force the SelectedGlyph is the one that was typed after jumpList is executed.
* Added more InlineData to RuneTests.
* Reducing significantly the code by using Theory attribute in the TextFormatterTests.
* Override PositionCursor to handle the CharMap cursor position.
* Fix merge errors.
* Minor tweaks to API docs
---------
Co-authored-by: Tig Kindel <tig@users.noreply.github.com>
191 lines
6.2 KiB
C#
191 lines
6.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.ViewsTests {
|
|
public class RadioGroupTests {
|
|
readonly ITestOutputHelper output;
|
|
|
|
public RadioGroupTests (ITestOutputHelper output)
|
|
{
|
|
this.output = output;
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructors_Defaults ()
|
|
{
|
|
var rg = new RadioGroup ();
|
|
Assert.True (rg.CanFocus);
|
|
Assert.Empty (rg.RadioLabels);
|
|
Assert.Null (rg.X);
|
|
Assert.Null (rg.Y);
|
|
Assert.Null (rg.Width);
|
|
Assert.Null (rg.Height);
|
|
Assert.Equal (Rect.Empty, rg.Frame);
|
|
Assert.Equal (0, rg.SelectedItem);
|
|
|
|
rg = new RadioGroup (new string [] { "Test" });
|
|
Assert.True (rg.CanFocus);
|
|
Assert.Single (rg.RadioLabels);
|
|
Assert.Null (rg.X);
|
|
Assert.Null (rg.Y);
|
|
Assert.Null (rg.Width);
|
|
Assert.Null (rg.Height);
|
|
Assert.Equal (new Rect (0, 0, 0, 0), rg.Frame);
|
|
Assert.Equal (0, rg.SelectedItem);
|
|
|
|
rg = new RadioGroup (new Rect (1, 2, 20, 5), new string [] { "Test" });
|
|
Assert.True (rg.CanFocus);
|
|
Assert.Single (rg.RadioLabels);
|
|
Assert.Equal (LayoutStyle.Absolute, rg.LayoutStyle);
|
|
Assert.Null (rg.X);
|
|
Assert.Null (rg.Y);
|
|
Assert.Null (rg.Width);
|
|
Assert.Null (rg.Height);
|
|
Assert.Equal (new Rect (1, 2, 20, 5), rg.Frame);
|
|
Assert.Equal (0, rg.SelectedItem);
|
|
|
|
rg = new RadioGroup (1, 2, new string [] { "Test" });
|
|
Assert.True (rg.CanFocus);
|
|
Assert.Single (rg.RadioLabels);
|
|
Assert.Equal (LayoutStyle.Absolute, rg.LayoutStyle);
|
|
Assert.Null (rg.X);
|
|
Assert.Null (rg.Y);
|
|
Assert.Null (rg.Width);
|
|
Assert.Null (rg.Height);
|
|
Assert.Equal (new Rect (1, 2, 6, 1), rg.Frame);
|
|
Assert.Equal (0, rg.SelectedItem);
|
|
}
|
|
|
|
[Fact]
|
|
public void Initialize_SelectedItem_With_Minus_One ()
|
|
{
|
|
var rg = new RadioGroup (new string [] { "Test" }, -1);
|
|
Assert.Equal (-1, rg.SelectedItem);
|
|
Assert.True (rg.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ())));
|
|
Assert.Equal (0, rg.SelectedItem);
|
|
}
|
|
|
|
[Fact, AutoInitShutdown]
|
|
public void DisplayMode_Width_Height_Vertical_Horizontal_Space ()
|
|
{
|
|
var rg = new RadioGroup (new string [] { "Test", "New Test 你" });
|
|
var win = new Window () {
|
|
Width = Dim.Fill (),
|
|
Height = Dim.Fill ()
|
|
};
|
|
win.Add (rg);
|
|
Application.Top.Add (win);
|
|
|
|
Application.Begin (Application.Top);
|
|
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
|
|
|
|
Assert.Equal (DisplayModeLayout.Vertical, rg.DisplayMode);
|
|
Assert.Equal (2, rg.RadioLabels.Length);
|
|
Assert.Equal (0, rg.X);
|
|
Assert.Equal (0, rg.Y);
|
|
Assert.Equal (13, rg.Frame.Width);
|
|
Assert.Equal (2, rg.Frame.Height);
|
|
var expected = @$"
|
|
┌────────────────────────────┐
|
|
│{CM.Glyphs.Selected} Test │
|
|
│{CM.Glyphs.UnSelected} New Test 你 │
|
|
│ │
|
|
└────────────────────────────┘
|
|
";
|
|
|
|
var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
rg.DisplayMode = DisplayModeLayout.Horizontal;
|
|
Application.Refresh ();
|
|
|
|
Assert.Equal (DisplayModeLayout.Horizontal, rg.DisplayMode);
|
|
Assert.Equal (2, rg.HorizontalSpace);
|
|
Assert.Equal (0, rg.X);
|
|
Assert.Equal (0, rg.Y);
|
|
Assert.Equal (21, rg.Width);
|
|
Assert.Equal (1, rg.Height);
|
|
|
|
expected = @$"
|
|
┌────────────────────────────┐
|
|
│{CM.Glyphs.Selected} Test {CM.Glyphs.UnSelected} New Test 你 │
|
|
│ │
|
|
│ │
|
|
└────────────────────────────┘
|
|
";
|
|
|
|
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
rg.HorizontalSpace = 4;
|
|
Application.Refresh ();
|
|
|
|
Assert.Equal (DisplayModeLayout.Horizontal, rg.DisplayMode);
|
|
Assert.Equal (4, rg.HorizontalSpace);
|
|
Assert.Equal (0, rg.X);
|
|
Assert.Equal (0, rg.Y);
|
|
Assert.Equal (23, rg.Width);
|
|
Assert.Equal (1, rg.Height);
|
|
expected = @$"
|
|
┌────────────────────────────┐
|
|
│{CM.Glyphs.Selected} Test {CM.Glyphs.UnSelected} New Test 你 │
|
|
│ │
|
|
│ │
|
|
└────────────────────────────┘
|
|
";
|
|
|
|
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
}
|
|
|
|
[Fact]
|
|
public void SelectedItemChanged_Event ()
|
|
{
|
|
var previousSelectedItem = -1;
|
|
var selectedItem = -1;
|
|
var rg = new RadioGroup (new string [] { "Test", "New Test" });
|
|
rg.SelectedItemChanged += (s,e) => {
|
|
previousSelectedItem = e.PreviousSelectedItem;
|
|
selectedItem = e.SelectedItem;
|
|
};
|
|
|
|
rg.SelectedItem = 1;
|
|
Assert.Equal (0, previousSelectedItem);
|
|
Assert.Equal (selectedItem, rg.SelectedItem);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyBindings_Command ()
|
|
{
|
|
var rg = new RadioGroup (new string [] { "Test", "New Test" });
|
|
|
|
Assert.True (rg.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ())));
|
|
Assert.True (rg.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
|
|
Assert.True (rg.ProcessKey (new KeyEvent (Key.Home, new KeyModifiers ())));
|
|
Assert.True (rg.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ())));
|
|
Assert.True (rg.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ())));
|
|
Assert.Equal (1, rg.SelectedItem);
|
|
}
|
|
|
|
[Fact]
|
|
public void ProcessColdKey_HotKey ()
|
|
{
|
|
var rg = new RadioGroup (new string [] { "Left", "Right", "Cen_tered", "Justified" });
|
|
|
|
Assert.True (rg.ProcessColdKey (new KeyEvent (Key.t, new KeyModifiers ())));
|
|
Assert.Equal (2, rg.SelectedItem);
|
|
Assert.True (rg.ProcessColdKey (new KeyEvent (Key.L, new KeyModifiers ())));
|
|
Assert.Equal (0, rg.SelectedItem);
|
|
Assert.True (rg.ProcessColdKey (new KeyEvent (Key.J, new KeyModifiers ())));
|
|
Assert.Equal (3, rg.SelectedItem);
|
|
Assert.True (rg.ProcessColdKey (new KeyEvent (Key.R, new KeyModifiers ())));
|
|
Assert.Equal (1, rg.SelectedItem);
|
|
}
|
|
}
|
|
}
|