Tons of changes - mostly experiments, but some goodness.

There's a huge issue that TextFormatter is confused about AutoSize.
a) It behaves 'automatically' even when AutoSize == false (e.g. in Text_set).
b) It doesn't support auto sizing only one dimension.
This commit is contained in:
Tig
2024-04-25 13:29:18 -06:00
parent 6209aceb5f
commit 09565a0ef1
19 changed files with 1067 additions and 788 deletions

View File

@@ -10,6 +10,67 @@ public class CheckBoxTests
public CheckBoxTests (ITestOutputHelper output) { _output = output; }
[Theory]
[InlineData ("01234", 0, 0, 0, 0)]
[InlineData ("01234", 1, 0, 1, 0)]
[InlineData ("01234", 0, 1, 0, 1)]
[InlineData ("01234", 1, 1, 1, 1)]
[InlineData ("01234", 10, 1, 10, 1)]
[InlineData ("01234", 10, 3, 10, 3)]
[InlineData ("0_1234", 0, 0, 0, 0)]
[InlineData ("0_1234", 1, 0, 1, 0)]
[InlineData ("0_1234", 0, 1, 0, 1)]
[InlineData ("0_1234", 1, 1, 1, 1)]
[InlineData ("0_1234", 10, 1, 10, 1)]
[InlineData ("0_12你", 10, 3, 10, 3)]
[InlineData ("0_12你", 0, 0, 0, 0)]
[InlineData ("0_12你", 1, 0, 1, 0)]
[InlineData ("0_12你", 0, 1, 0, 1)]
[InlineData ("0_12你", 1, 1, 1, 1)]
[InlineData ("0_12你", 10, 1, 10, 1)]
[InlineData ("0_12你", 10, 3, 10, 3)]
public void CheckBox_AbsoluteSize_Text (string text, int width, int height, int expectedWidth, int expectedHeight)
{
var checkBox = new CheckBox
{
X = 0,
Y = 0,
Width = width,
Height = height,
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);
checkBox.Dispose ();
}
[Theory]
[InlineData (0, 0, 0, 0)]
[InlineData (1, 0, 1, 0)]
[InlineData (0, 1, 0, 1)]
[InlineData (1, 1, 1, 1)]
[InlineData (10, 1, 10, 1)]
[InlineData (10, 3, 10, 3)]
public void CheckBox_AbsoluteSize_DefaultText (int width, int height, int expectedWidth, int expectedHeight)
{
var checkBox = new CheckBox
{
X = 0,
Y = 0,
Width = width,
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);
checkBox.Dispose ();
}
// Test that Title and Text are the same
[Fact]
public void Text_Mirrors_Title ()
@@ -71,93 +132,93 @@ public class CheckBoxTests
Assert.False (checkBox.Checked);
}
[Fact]
[AutoInitShutdown]
public void AutoSize_Stays_True_AnchorEnd_With_HotKeySpecifier ()
{
var checkBox = new CheckBox { Y = Pos.Center (), Text = "C_heck this out 你" };
// [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 (0) - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
// checkBox.X = Pos.AnchorEnd (0) - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
win.Add (checkBox);
var top = new Toplevel ();
top.Add (win);
// var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
// win.Add (checkBox);
// var top = new Toplevel ();
// top.Add (win);
Assert.True (checkBox.AutoSize);
// //Assert.True (checkBox.AutoSize);
Application.Begin (top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
// Application.Begin (top);
// ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你│
│ │
└────────────────────────────┘
";
// var expected = @$"
//┌┤Test Demo 你├──────────────┐
//│ │
//│ {CM.Glyphs.UnChecked} Check this out 你│
//│ │
//└────────────────────────────┘
//";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
// TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.True (checkBox.AutoSize);
checkBox.Text = "Check this out 你 changed";
Assert.True (checkBox.AutoSize);
Application.Refresh ();
// //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│
│ │
└────────────────────────────┘
";
// expected = @$"
//┌┤Test Demo 你├──────────────┐
//│ │
//│ {CM.Glyphs.UnChecked} Check this out 你 changed│
//│ │
//└────────────────────────────┘
//";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
}
// TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
// }
[Fact]
[AutoInitShutdown]
public void AutoSize_Stays_True_AnchorEnd_Without_HotKeySpecifier ()
{
var checkBox = new CheckBox { Y = Pos.Center (), Text = "Check this out 你" };
// [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 (0) - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
// checkBox.X = Pos.AnchorEnd (0) - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
win.Add (checkBox);
var top = new Toplevel ();
top.Add (win);
// var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
// win.Add (checkBox);
// var top = new Toplevel ();
// top.Add (win);
Assert.True (checkBox.AutoSize);
//// Assert.True (checkBox.AutoSize);
Application.Begin (top);
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
// Application.Begin (top);
// ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
var expected = @$"
┌┤Test Demo 你├──────────────┐
│ │
│ {CM.Glyphs.UnChecked} Check this out 你│
│ │
└────────────────────────────┘
";
// var expected = @$"
//┌┤Test Demo 你├──────────────┐
//│ │
//│ {CM.Glyphs.UnChecked} Check this out 你│
//│ │
//└────────────────────────────┘
//";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
// TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
Assert.True (checkBox.AutoSize);
checkBox.Text = "Check this out 你 changed";
Assert.True (checkBox.AutoSize);
Application.Refresh ();
// // 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│
│ │
└────────────────────────────┘
";
// expected = @$"
//┌┤Test Demo 你├──────────────┐
//│ │
//│ {CM.Glyphs.UnChecked} Check this out 你 changed│
//│ │
//└────────────────────────────┘
//";
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
}
// TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
// }
// [Fact]
// [AutoInitShutdown]
@@ -241,7 +302,8 @@ public class CheckBoxTests
public void Constructors_Defaults ()
{
var ckb = new CheckBox ();
Assert.True (ckb.AutoSize);
Assert.True (ckb.Width is Dim.DimAuto);
Assert.Equal (Dim.Sized (1), ckb.Height);
Assert.False (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal (string.Empty, ckb.Text);
@@ -250,7 +312,8 @@ public class CheckBoxTests
Assert.Equal (new Rectangle (0, 0, 2, 1), ckb.Frame);
ckb = new CheckBox { Text = "Test", Checked = true };
Assert.True (ckb.AutoSize);
Assert.True (ckb.Width is Dim.DimAuto);
Assert.Equal (Dim.Sized (1), ckb.Height);
Assert.True (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
@@ -259,7 +322,8 @@ public class CheckBoxTests
Assert.Equal (new Rectangle (0, 0, 6, 1), ckb.Frame);
ckb = new CheckBox { Text = "Test", X = 1, Y = 2 };
Assert.True (ckb.AutoSize);
Assert.True (ckb.Width is Dim.DimAuto);
Assert.Equal (Dim.Sized (1), ckb.Height);
Assert.False (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
@@ -268,7 +332,8 @@ public class CheckBoxTests
Assert.Equal (new Rectangle (1, 2, 6, 1), ckb.Frame);
ckb = new CheckBox { Text = "Test", X = 3, Y = 4, Checked = true };
Assert.True (ckb.AutoSize);
Assert.True (ckb.Width is Dim.DimAuto);
Assert.Equal (Dim.Sized (1), ckb.Height);
Assert.True (ckb.Checked);
Assert.False (ckb.AllowNullChecked);
Assert.Equal ("Test", ckb.Text);
@@ -405,7 +470,6 @@ public class CheckBoxTests
Y = Pos.Center (),
Text = "Check first out 你",
TextAlignment = TextAlignment.Justified,
AutoSize = false,
Width = 25
};
@@ -415,7 +479,6 @@ public class CheckBoxTests
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 你" };