From 4e01779e0bc94bfc3f5935c8c08e189826f38783 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 13 May 2024 12:22:43 -0600 Subject: [PATCH] Moved AutoSizeTrue tests to more logical locations; nuked invalid tests --- UnitTests/View/Text/AutoSizeTrueTests.cs | 2059 ---------------------- UnitTests/View/Text/TextTests.cs | 1062 ++++++++++- UnitTests/Views/LabelTests.cs | 937 ++++++++++ 3 files changed, 1998 insertions(+), 2060 deletions(-) delete mode 100644 UnitTests/View/Text/AutoSizeTrueTests.cs diff --git a/UnitTests/View/Text/AutoSizeTrueTests.cs b/UnitTests/View/Text/AutoSizeTrueTests.cs deleted file mode 100644 index 7c1d93670..000000000 --- a/UnitTests/View/Text/AutoSizeTrueTests.cs +++ /dev/null @@ -1,2059 +0,0 @@ -using System.Reflection.Emit; -using System.Text; -using Xunit.Abstractions; - -namespace Terminal.Gui.ViewTests; - -/// Tests of the View.AutoSize property which auto sizes Views based on . -public class AutoSizeTrueTests (ITestOutputHelper output) -{ - private readonly string [] expecteds = new string [21] - { - @" -┌────────────────────┐ -│View with long text │ -│ │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 0 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 1 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 2 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 3 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 4 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 5 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 6 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 7 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 8 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 9 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 10 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 11 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 12 │ -│Label 12 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 12 │ -│Label 13 │ -│Label 13 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 12 │ -│Label 13 │ -│Label 14 │ -│Label 14 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 12 │ -│Label 13 │ -│Label 14 │ -│Label 15 │ -│Label 15 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 12 │ -│Label 13 │ -│Label 14 │ -│Label 15 │ -│Label 16 │ -│Label 16 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 12 │ -│Label 13 │ -│Label 14 │ -│Label 15 │ -│Label 16 │ -│Label 17 │ -│Label 17 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 12 │ -│Label 13 │ -│Label 14 │ -│Label 15 │ -│Label 16 │ -│Label 17 │ -│Label 18 │ -│Label 18 │ -└────────────────────┘", - @" -┌────────────────────┐ -│View with long text │ -│Label 0 │ -│Label 1 │ -│Label 2 │ -│Label 3 │ -│Label 4 │ -│Label 5 │ -│Label 6 │ -│Label 7 │ -│Label 8 │ -│Label 9 │ -│Label 10 │ -│Label 11 │ -│Label 12 │ -│Label 13 │ -│Label 14 │ -│Label 15 │ -│Label 16 │ -│Label 17 │ -│Label 18 │ -│Label 19 │ -│Label 19 │ -└────────────────────┘" - }; - - private static readonly Size _size1x1 = new (1, 1); - - // TODO: This is a Label test. Move to label tests if there's not already a test for this. - [Fact] - [AutoInitShutdown] - public void AutoSize_AnchorEnd_Better_Than_Bottom_Equal_Inside_Window () - { - var win = new Window (); - - var label = new Label - { - Text = "This should be the last line.", - ColorScheme = Colors.ColorSchemes ["Menu"], - - //Width = Dim.Fill (), - X = 0, // keep unit test focused; don't use Center here - Y = Pos.AnchorEnd (1) - }; - - win.Add (label); - - Toplevel top = new (); - top.Add (win); - RunState rs = Application.Begin (top); - ((FakeDriver)Application.Driver).SetBufferSize (40, 10); - - Assert.Equal (29, label.Text.Length); - Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame); - Assert.Equal (new Rectangle (0, 0, 40, 10), win.Frame); - Assert.Equal (new Rectangle (0, 7, 29, 1), label.Frame); - - var expected = @" -┌──────────────────────────────────────┐ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│This should be the last line. │ -└──────────────────────────────────────┘ -"; - - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Application.End (rs); - } - - // TODO: This is a Label test. Move to label tests if there's not already a test for this. - [Fact] - [AutoInitShutdown] - public void AutoSize_AnchorEnd_Better_Than_Bottom_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel () - { - var win = new Window (); - - // Label is AutoSize == true - var label = new Label - { - Text = "This should be the last line.", - ColorScheme = Colors.ColorSchemes ["Menu"], - - X = 0, - Y = Pos.AnchorEnd (1) - }; - - win.Add (label); - - var menu = new MenuBar { Menus = new MenuBarItem [] { new ("Menu", "", null) } }; - var status = new StatusBar (new StatusItem [] { new (KeyCode.F1, "~F1~ Help", null) }); - Toplevel top = new (); - top.Add (win, menu, status); - RunState rs = Application.Begin (top); - - Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame); - Assert.Equal (new Rectangle (0, 0, 80, 1), menu.Frame); - Assert.Equal (new Rectangle (0, 24, 80, 1), status.Frame); - Assert.Equal (new Rectangle (0, 1, 80, 23), win.Frame); - Assert.Equal (new Rectangle (0, 20, 29, 1), label.Frame); - - var expected = @" - Menu -┌──────────────────────────────────────────────────────────────────────────────┐ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│This should be the last line. │ -└──────────────────────────────────────────────────────────────────────────────┘ - F1 Help -"; - - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Application.End (rs); - } - - // TODO: This is a Label test. Move to label tests if there's not already a test for this. - [Fact] - [AutoInitShutdown] - public void AutoSize_Bottom_Equal_Inside_Window () - { - var win = new Window (); - - // Label is AutoSize == true - var label = new Label - { - Text = "This should be the last line.", - ColorScheme = Colors.ColorSchemes ["Menu"], - - //Width = Dim.Fill (), - X = 0, - Y = Pos.Bottom (win) - - 3 // two lines top and bottom borders more one line above the bottom border - }; - - win.Add (label); - - Toplevel top = new (); - top.Add (win); - RunState rs = Application.Begin (top); - ((FakeDriver)Application.Driver).SetBufferSize (40, 10); - - Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame); - Assert.Equal (new Rectangle (0, 0, 40, 10), win.Frame); - Assert.Equal (new Rectangle (0, 7, 29, 1), label.Frame); - - var expected = @" -┌──────────────────────────────────────┐ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│This should be the last line. │ -└──────────────────────────────────────┘ -"; - - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Application.End (rs); - } - - // TODO: This is a Label test. Move to label tests if there's not already a test for this. - - [Fact] - [AutoInitShutdown] - public void AutoSize_Bottom_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel () - { - var win = new Window (); - - // Label is AutoSize == true - var label = new Label - { - Text = "This should be the last line.", - ColorScheme = Colors.ColorSchemes ["Menu"], - - //Width = Dim.Fill (), - X = 0, - Y = Pos.Bottom (win) - 4 // two lines top and bottom borders more two lines above border - }; - - win.Add (label); - - var menu = new MenuBar { Menus = new MenuBarItem [] { new ("Menu", "", null) } }; - var status = new StatusBar (new StatusItem [] { new (KeyCode.F1, "~F1~ Help", null) }); - Toplevel top = new (); - top.Add (win, menu, status); - RunState rs = Application.Begin (top); - - Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame); - Assert.Equal (new Rectangle (0, 0, 80, 1), menu.Frame); - Assert.Equal (new Rectangle (0, 24, 80, 1), status.Frame); - Assert.Equal (new Rectangle (0, 1, 80, 23), win.Frame); - Assert.Equal (new Rectangle (0, 20, 29, 1), label.Frame); - - var expected = @" - Menu -┌──────────────────────────────────────────────────────────────────────────────┐ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│This should be the last line. │ -└──────────────────────────────────────────────────────────────────────────────┘ - F1 Help -"; - - TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Application.End (rs); - } - - // TODO: This is a Label test. Move to label tests if there's not already a test for this. - [Fact] - [AutoInitShutdown] - public void AutoSize_Dim_Add_Operator_With_Text () - { - Toplevel top = new (); - - var view = new View - { - Text = "View with long text", - X = 0, - Y = 0, - Width = 20, - Height = 1 - }; - var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 }; - var count = 0; - - // Label is AutoSize == true - List