|
@@ -22,25 +22,25 @@ namespace Terminal.Gui.Views {
|
|
Assert.False (ckb.Checked);
|
|
Assert.False (ckb.Checked);
|
|
Assert.Equal (string.Empty, ckb.Text);
|
|
Assert.Equal (string.Empty, ckb.Text);
|
|
Assert.True (ckb.CanFocus);
|
|
Assert.True (ckb.CanFocus);
|
|
- Assert.Equal (new Rect (0, 0, 4, 1), ckb.Frame);
|
|
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 2, 1), ckb.Frame);
|
|
|
|
|
|
ckb = new CheckBox ("Test", true);
|
|
ckb = new CheckBox ("Test", true);
|
|
Assert.True (ckb.Checked);
|
|
Assert.True (ckb.Checked);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.True (ckb.CanFocus);
|
|
Assert.True (ckb.CanFocus);
|
|
- Assert.Equal (new Rect (0, 0, 8, 1), ckb.Frame);
|
|
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 6, 1), ckb.Frame);
|
|
|
|
|
|
ckb = new CheckBox (1, 2, "Test");
|
|
ckb = new CheckBox (1, 2, "Test");
|
|
Assert.False (ckb.Checked);
|
|
Assert.False (ckb.Checked);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.True (ckb.CanFocus);
|
|
Assert.True (ckb.CanFocus);
|
|
- Assert.Equal (new Rect (1, 2, 8, 1), ckb.Frame);
|
|
|
|
|
|
+ Assert.Equal (new Rect (1, 2, 6, 1), ckb.Frame);
|
|
|
|
|
|
ckb = new CheckBox (3, 4, "Test", true);
|
|
ckb = new CheckBox (3, 4, "Test", true);
|
|
Assert.True (ckb.Checked);
|
|
Assert.True (ckb.Checked);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.Equal ("Test", ckb.Text);
|
|
Assert.True (ckb.CanFocus);
|
|
Assert.True (ckb.CanFocus);
|
|
- Assert.Equal (new Rect (3, 4, 8, 1), ckb.Frame);
|
|
|
|
|
|
+ Assert.Equal (new Rect (3, 4, 6, 1), ckb.Frame);
|
|
}
|
|
}
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
@@ -48,17 +48,19 @@ namespace Terminal.Gui.Views {
|
|
public void KeyBindings_Command ()
|
|
public void KeyBindings_Command ()
|
|
{
|
|
{
|
|
var isChecked = false;
|
|
var isChecked = false;
|
|
- CheckBox ckb = new CheckBox ("Test");
|
|
|
|
|
|
+ CheckBox ckb = new CheckBox ();
|
|
ckb.Toggled += (e) => isChecked = true;
|
|
ckb.Toggled += (e) => isChecked = true;
|
|
Application.Top.Add (ckb);
|
|
Application.Top.Add (ckb);
|
|
Application.Begin (Application.Top);
|
|
Application.Begin (Application.Top);
|
|
|
|
|
|
Assert.Equal (Key.Null, ckb.HotKey);
|
|
Assert.Equal (Key.Null, ckb.HotKey);
|
|
|
|
+ ckb.Text = "Test";
|
|
|
|
+ Assert.Equal (Key.T, ckb.HotKey);
|
|
Assert.False (ckb.ProcessHotKey (new KeyEvent (Key.T, new KeyModifiers ())));
|
|
Assert.False (ckb.ProcessHotKey (new KeyEvent (Key.T, new KeyModifiers ())));
|
|
Assert.False (isChecked);
|
|
Assert.False (isChecked);
|
|
- ckb.Text = "_Test";
|
|
|
|
- Assert.Equal (Key.T, ckb.HotKey);
|
|
|
|
- Assert.True (ckb.ProcessHotKey (new KeyEvent (Key.T | Key.AltMask, new KeyModifiers () { Alt = true })));
|
|
|
|
|
|
+ ckb.Text = "T_est";
|
|
|
|
+ Assert.Equal (Key.E, ckb.HotKey);
|
|
|
|
+ Assert.True (ckb.ProcessHotKey (new KeyEvent (Key.E | Key.AltMask, new KeyModifiers () { Alt = true })));
|
|
Assert.True (isChecked);
|
|
Assert.True (isChecked);
|
|
isChecked = false;
|
|
isChecked = false;
|
|
Assert.True (ckb.ProcessKey (new KeyEvent ((Key)' ', new KeyModifiers ())));
|
|
Assert.True (ckb.ProcessKey (new KeyEvent ((Key)' ', new KeyModifiers ())));
|
|
@@ -66,8 +68,17 @@ namespace Terminal.Gui.Views {
|
|
isChecked = false;
|
|
isChecked = false;
|
|
Assert.True (ckb.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ())));
|
|
Assert.True (ckb.ProcessKey (new KeyEvent (Key.Space, new KeyModifiers ())));
|
|
Assert.True (isChecked);
|
|
Assert.True (isChecked);
|
|
- }
|
|
|
|
|
|
+ Assert.True (ckb.AutoSize);
|
|
|
|
+
|
|
|
|
+ Application.Refresh ();
|
|
|
|
+
|
|
|
|
+ var expected = @"
|
|
|
|
+√ Test
|
|
|
|
+";
|
|
|
|
|
|
|
|
+ var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 6, 1), pos);
|
|
|
|
+ }
|
|
|
|
|
|
[Fact, AutoInitShutdown]
|
|
[Fact, AutoInitShutdown]
|
|
public void AutoSize_StaysVisible ()
|
|
public void AutoSize_StaysVisible ()
|
|
@@ -91,7 +102,10 @@ namespace Terminal.Gui.Views {
|
|
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
|
|
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
|
|
|
|
|
|
Assert.True (checkBox.IsInitialized);
|
|
Assert.True (checkBox.IsInitialized);
|
|
|
|
+ Assert.Equal (new Rect (1, 1, 19, 1), checkBox.Frame);
|
|
Assert.Equal ("Check this out 你", checkBox.Text);
|
|
Assert.Equal ("Check this out 你", checkBox.Text);
|
|
|
|
+ Assert.Equal ("╴ Check this out 你", checkBox.TextFormatter.Text);
|
|
|
|
+ Assert.True (checkBox.AutoSize);
|
|
|
|
|
|
var expected = @"
|
|
var expected = @"
|
|
┌ Test Demo 你 ──────────────┐
|
|
┌ Test Demo 你 ──────────────┐
|
|
@@ -105,13 +119,260 @@ namespace Terminal.Gui.Views {
|
|
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
|
|
- // Negative test
|
|
|
|
|
|
+ // Also Positive test
|
|
checkBox.AutoSize = true;
|
|
checkBox.AutoSize = true;
|
|
bool first = false;
|
|
bool first = false;
|
|
Application.RunMainLoopIteration (ref runstate, true, ref first);
|
|
Application.RunMainLoopIteration (ref runstate, true, ref first);
|
|
|
|
|
|
GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+
|
|
|
|
+ checkBox.Checked = true;
|
|
|
|
+ Application.RunMainLoopIteration (ref runstate, true, ref first);
|
|
|
|
+ expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ √ Check this out 你 │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+
|
|
|
|
+ checkBox.AutoSize = false;
|
|
|
|
+ checkBox.Text = "Check this out 你 changed";
|
|
|
|
+ Application.RunMainLoopIteration (ref runstate, true, ref first);
|
|
|
|
+ expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ √ Check this out 你 │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+
|
|
|
|
+ checkBox.AutoSize = true;
|
|
|
|
+ Application.RunMainLoopIteration (ref runstate, true, ref first);
|
|
|
|
+ expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ √ Check this out 你 changed│
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ pos = GraphViewTests.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 你",
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ Assert.Equal (TextAlignment.Left, checkBox.TextAlignment);
|
|
|
|
+ Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
|
|
|
|
+ Assert.Equal ("Check this out 你", checkBox.Text);
|
|
|
|
+ Assert.Equal ("╴ Check this out 你", checkBox.TextFormatter.Text);
|
|
|
|
+ Assert.False (checkBox.AutoSize);
|
|
|
|
+
|
|
|
|
+ var expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ ╴ Check this out 你 │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+
|
|
|
|
+ checkBox.Checked = true;
|
|
|
|
+ Application.Refresh ();
|
|
|
|
+ expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ √ Check this out 你 │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ pos = GraphViewTests.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 你",
|
|
|
|
+ Width = 25,
|
|
|
|
+ TextAlignment = TextAlignment.Centered
|
|
|
|
+ };
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ Assert.Equal (TextAlignment.Centered, checkBox.TextAlignment);
|
|
|
|
+ Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
|
|
|
|
+ Assert.Equal ("Check this out 你", checkBox.Text);
|
|
|
|
+ Assert.Equal ("╴ Check this out 你", checkBox.TextFormatter.Text);
|
|
|
|
+ Assert.False (checkBox.AutoSize);
|
|
|
|
+
|
|
|
|
+ var expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ ╴ Check this out 你 │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+
|
|
|
|
+ checkBox.Checked = true;
|
|
|
|
+ Application.Refresh ();
|
|
|
|
+ expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ √ Check this out 你 │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact, AutoInitShutdown]
|
|
|
|
+ public void TextAlignment_Justified ()
|
|
|
|
+ {
|
|
|
|
+ var checkBox = new CheckBox () {
|
|
|
|
+ X = 1,
|
|
|
|
+ Y = Pos.Center (),
|
|
|
|
+ Text = "Check this out 你",
|
|
|
|
+ Width = 25,
|
|
|
|
+ TextAlignment = TextAlignment.Justified
|
|
|
|
+ };
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ Assert.Equal (TextAlignment.Justified, checkBox.TextAlignment);
|
|
|
|
+ Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
|
|
|
|
+ Assert.Equal ("Check this out 你", checkBox.Text);
|
|
|
|
+ Assert.Equal ("╴ Check this out 你", checkBox.TextFormatter.Text);
|
|
|
|
+ Assert.False (checkBox.AutoSize);
|
|
|
|
+
|
|
|
|
+ var expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ ╴ Check this out 你 │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+
|
|
|
|
+ checkBox.Checked = true;
|
|
|
|
+ Application.Refresh ();
|
|
|
|
+ expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ √ Check this out 你 │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact, AutoInitShutdown]
|
|
|
|
+ public void TextAlignment_Right ()
|
|
|
|
+ {
|
|
|
|
+ var checkBox = new CheckBox () {
|
|
|
|
+ X = 1,
|
|
|
|
+ Y = Pos.Center (),
|
|
|
|
+ Text = "Check this out 你",
|
|
|
|
+ Width = 25,
|
|
|
|
+ TextAlignment = TextAlignment.Right
|
|
|
|
+ };
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ Assert.Equal (TextAlignment.Right, checkBox.TextAlignment);
|
|
|
|
+ Assert.Equal (new Rect (1, 1, 25, 1), checkBox.Frame);
|
|
|
|
+ Assert.Equal ("Check this out 你", checkBox.Text);
|
|
|
|
+ Assert.Equal ("Check this out 你 ╴", checkBox.TextFormatter.Text);
|
|
|
|
+ Assert.False (checkBox.AutoSize);
|
|
|
|
+
|
|
|
|
+ var expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ Check this out 你 ╴ │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
|
|
+
|
|
|
|
+ checkBox.Checked = true;
|
|
|
|
+ Application.Refresh ();
|
|
|
|
+ expected = @"
|
|
|
|
+┌ Test Demo 你 ──────────────┐
|
|
|
|
+│ │
|
|
|
|
+│ Check this out 你 √ │
|
|
|
|
+│ │
|
|
|
|
+└────────────────────────────┘
|
|
|
|
+";
|
|
|
|
+
|
|
|
|
+ pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
|
|
|
+ Assert.Equal (new Rect (0, 0, 30, 5), pos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|