From 20a2f727f724032880c7932ee5e6d7af3e162c81 Mon Sep 17 00:00:00 2001 From: BlazeFace Date: Tue, 9 Apr 2024 06:03:45 -0700 Subject: [PATCH 1/7] Updating test and Ratio calculation --- src/Spectre.Console/Internal/Ratio.cs | 15 +++++++-- src/Spectre.Console/Rendering/Segment.cs | 6 ++++ .../Unit/Widgets/LayoutTests.cs | 33 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Spectre.Console/Internal/Ratio.cs b/src/Spectre.Console/Internal/Ratio.cs index fb38bdd..80059fc 100644 --- a/src/Spectre.Console/Internal/Ratio.cs +++ b/src/Spectre.Console/Internal/Ratio.cs @@ -9,7 +9,17 @@ internal static class Ratio { static (int Div, float Mod) DivMod(float x, float y) { - return ((int)(x / y), x % y); + var (div, mod) = ((int)(x / y), x % y); + + // If remainder is withing .0001 of 1 then we round up + if (!(mod > 0.9999)) + { + return (div, mod); + } + + div++; + mod = 0; + return (div, mod); } static int? GetEdgeWidth(IRatioResolvable edge) @@ -46,7 +56,8 @@ internal static class Ratio .ToList(); } - var portion = (float)remaining / flexibleEdges.Sum(x => Math.Max(1, x.Edge.Ratio)); + var r = flexibleEdges.Sum(x => Math.Max(1, x.Edge.Ratio)); + var portion = (float)remaining / r; var invalidate = false; foreach (var (index, size, edge) in flexibleEdges) diff --git a/src/Spectre.Console/Rendering/Segment.cs b/src/Spectre.Console/Rendering/Segment.cs index 9f36a77..6b11ca6 100644 --- a/src/Spectre.Console/Rendering/Segment.cs +++ b/src/Spectre.Console/Rendering/Segment.cs @@ -463,8 +463,14 @@ public class Segment var result = new List(); var segmentBuilder = (SegmentBuilder?)null; + var c = 0; foreach (var segment in segments) { + if (c == 163) + { + System.Console.Write("test"); + } + c++; if (segmentBuilder == null) { segmentBuilder = new SegmentBuilder(segment); diff --git a/test/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs b/test/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs index 550922a..b73cb67 100644 --- a/test/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs +++ b/test/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs @@ -264,4 +264,37 @@ public sealed class LayoutTests // Then return Verifier.Verify(console.Output); } + + [Fact] + [Expectation("Render_Layout_With_Three_And_One_Columns")] + public Task Should_Render_Layout_With_Three_And_One_Columns() + { + // Given + var console = new TestConsole().Size(new Size(40, 17)); + var layout = new Layout(); + var col1 = new Layout(); + var col1Row1 = new Layout(); + var col1Row2 = new Layout(); + var col1Row3 = new Layout(); + + col1.SplitRows(col1Row1, col1Row2, col1Row3); + + var col2 = new Layout(); + + layout.SplitColumns(col1, col2); + + var panel = new Panel("Hello, World!") { Expand = true }; + + List layouts = [col1Row1, col1Row2, col1Row3, col2]; + foreach (var l in layouts) + { + l.Update(panel); + } + + // When + console.Write(layout); + + // Then + return Verifier.Verify(console.Output); + } } From 4f22f5b7c37681904a9e1e3c20fbb8a87e95d381 Mon Sep 17 00:00:00 2001 From: BlazeFace Date: Sat, 13 Apr 2024 17:19:19 -0700 Subject: [PATCH 2/7] Add Reference File --- ...th_Three_And_One_Columns.Output.verified.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Three_And_One_Columns.Output.verified.txt diff --git a/test/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Three_And_One_Columns.Output.verified.txt b/test/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Three_And_One_Columns.Output.verified.txt new file mode 100644 index 0000000..1a64de7 --- /dev/null +++ b/test/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Three_And_One_Columns.Output.verified.txt @@ -0,0 +1,17 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file From a62e79992b3ef44b99cb5217abd19d44f96c360e Mon Sep 17 00:00:00 2001 From: BlazeFace Date: Sat, 13 Apr 2024 17:20:12 -0700 Subject: [PATCH 3/7] Undo debug changes --- src/Spectre.Console/Rendering/Segment.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Spectre.Console/Rendering/Segment.cs b/src/Spectre.Console/Rendering/Segment.cs index 6b11ca6..9f36a77 100644 --- a/src/Spectre.Console/Rendering/Segment.cs +++ b/src/Spectre.Console/Rendering/Segment.cs @@ -463,14 +463,8 @@ public class Segment var result = new List(); var segmentBuilder = (SegmentBuilder?)null; - var c = 0; foreach (var segment in segments) { - if (c == 163) - { - System.Console.Write("test"); - } - c++; if (segmentBuilder == null) { segmentBuilder = new SegmentBuilder(segment); From d52d14e848a88e1eac6b1472f502b46dc9fac1fd Mon Sep 17 00:00:00 2001 From: BlazeFace Date: Sat, 13 Apr 2024 17:23:26 -0700 Subject: [PATCH 4/7] Undo debug change and add method group --- src/Spectre.Console/Internal/Ratio.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Spectre.Console/Internal/Ratio.cs b/src/Spectre.Console/Internal/Ratio.cs index 80059fc..69f752c 100644 --- a/src/Spectre.Console/Internal/Ratio.cs +++ b/src/Spectre.Console/Internal/Ratio.cs @@ -32,7 +32,7 @@ internal static class Ratio return edge.Size; } - var sizes = edges.Select(x => GetEdgeWidth(x)).ToArray(); + var sizes = edges.Select(GetEdgeWidth).ToArray(); while (sizes.Any(s => s == null)) { @@ -56,8 +56,7 @@ internal static class Ratio .ToList(); } - var r = flexibleEdges.Sum(x => Math.Max(1, x.Edge.Ratio)); - var portion = (float)remaining / r; + var portion = (float)remaining / flexibleEdges.Sum(x => Math.Max(1, x.Edge.Ratio)); var invalidate = false; foreach (var (index, size, edge) in flexibleEdges) From 00b9aecb4f4bc381f8720786ef38a4b149fcddc0 Mon Sep 17 00:00:00 2001 From: BlazeFace Date: Sat, 26 Oct 2024 07:18:52 -0700 Subject: [PATCH 5/7] Add new test files --- ...Rows_In_One_Column.Output_17.verified.txt} | 0 ..._Rows_In_One_Column.Output_20.verified.txt | 20 ++++++++++++ ..._Rows_In_One_Column.Output_23.verified.txt | 23 ++++++++++++++ ..._Rows_In_One_Column.Output_28.verified.txt | 28 +++++++++++++++++ ..._Rows_In_One_Column.Output_30.verified.txt | 31 +++++++++++++++++++ 5 files changed, 102 insertions(+) rename src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/{Render_Layout_With_Three_And_One_Columns.Output.verified.txt => Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_17.verified.txt} (100%) create mode 100644 src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_20.verified.txt create mode 100644 src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_23.verified.txt create mode 100644 src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_28.verified.txt create mode 100644 src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_30.verified.txt diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Three_And_One_Columns.Output.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_17.verified.txt similarity index 100% rename from src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Three_And_One_Columns.Output.verified.txt rename to src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_17.verified.txt diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_20.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_20.verified.txt new file mode 100644 index 0000000..4c6a7c9 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_20.verified.txt @@ -0,0 +1,20 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_23.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_23.verified.txt new file mode 100644 index 0000000..d6e7471 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_23.verified.txt @@ -0,0 +1,23 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_28.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_28.verified.txt new file mode 100644 index 0000000..f34e9d7 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_28.verified.txt @@ -0,0 +1,28 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_30.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_30.verified.txt new file mode 100644 index 0000000..be6f4b5 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_30.verified.txt @@ -0,0 +1,31 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file From bc88da80560b49967d6c1673559deda064072f32 Mon Sep 17 00:00:00 2001 From: BlazeFace Date: Sat, 26 Oct 2024 07:25:38 -0700 Subject: [PATCH 6/7] Added last file and used fluent style, relocated test --- ..._Rows_In_One_Column.Output_31.verified.txt | 31 ++++++++++ .../Unit/Widgets/LayoutTests.cs | 62 +++++++++---------- 2 files changed, 60 insertions(+), 33 deletions(-) create mode 100644 src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_31.verified.txt diff --git a/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_31.verified.txt b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_31.verified.txt new file mode 100644 index 0000000..be6f4b5 --- /dev/null +++ b/src/Tests/Spectre.Console.Tests/Expectations/Widgets/Layout/Render_Layout_With_Nested_Three_Rows_In_One_Column.Output_31.verified.txt @@ -0,0 +1,31 @@ +┌──────────────────┐┌──────────────────┐ +│ Hello, World! ││ Hello, World! │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘│ │ +┌──────────────────┐│ │ +│ Hello, World! ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +│ ││ │ +└──────────────────┘└──────────────────┘ \ No newline at end of file diff --git a/src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs b/src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs index b73cb67..54182e1 100644 --- a/src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs +++ b/src/Tests/Spectre.Console.Tests/Unit/Widgets/LayoutTests.cs @@ -153,6 +153,35 @@ public sealed class LayoutTests return Verifier.Verify(console.Output); } + [Theory] + [InlineData(17, "17")] + [InlineData(20, "20")] + [InlineData(23, "23")] + [InlineData(28, "28")] + [InlineData(31, "31")] + [Expectation("Render_Layout_With_Nested_Three_Rows_In_One_Column")] + public Task Should_Render_Layout_With_Three_And_One_Columns(int height, string expectationPrefix) + { + // Given + var console = new TestConsole().Size(new Size(40, height)); + + // Layout with 2 columns, left column has 3 rows and right column has 1 row + var layout = new Layout(new Panel("Hello, World!") { Expand = true }) + .SplitColumns( + new Layout(new Panel("Hello, World!") { Expand = true }) + .SplitRows( + new Layout(new Panel("Hello, World!") { Expand = true }), + new Layout(new Panel("Hello, World!") { Expand = true }), + new Layout(new Panel("Hello, World!") { Expand = true })), + new Layout(new Panel("Hello, World!") { Expand = true })); + + // When + console.Write(layout); + + // Then + return Verifier.Verify(console.Output).UseTextForParameters(expectationPrefix); + } + [Fact] [Expectation("Render_Layout_Without_Invisible_Children")] public Task Should_Render_Layout_Without_Invisible_Children() @@ -264,37 +293,4 @@ public sealed class LayoutTests // Then return Verifier.Verify(console.Output); } - - [Fact] - [Expectation("Render_Layout_With_Three_And_One_Columns")] - public Task Should_Render_Layout_With_Three_And_One_Columns() - { - // Given - var console = new TestConsole().Size(new Size(40, 17)); - var layout = new Layout(); - var col1 = new Layout(); - var col1Row1 = new Layout(); - var col1Row2 = new Layout(); - var col1Row3 = new Layout(); - - col1.SplitRows(col1Row1, col1Row2, col1Row3); - - var col2 = new Layout(); - - layout.SplitColumns(col1, col2); - - var panel = new Panel("Hello, World!") { Expand = true }; - - List layouts = [col1Row1, col1Row2, col1Row3, col2]; - foreach (var l in layouts) - { - l.Update(panel); - } - - // When - console.Write(layout); - - // Then - return Verifier.Verify(console.Output); - } } From 3eb620a44e7baf399d124a4b21412c8eb61cb8ba Mon Sep 17 00:00:00 2001 From: BlazeFace Date: Sat, 26 Oct 2024 07:27:31 -0700 Subject: [PATCH 7/7] Fix typo --- src/Spectre.Console/Internal/Ratio.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spectre.Console/Internal/Ratio.cs b/src/Spectre.Console/Internal/Ratio.cs index 69f752c..4ef5504 100644 --- a/src/Spectre.Console/Internal/Ratio.cs +++ b/src/Spectre.Console/Internal/Ratio.cs @@ -11,7 +11,7 @@ internal static class Ratio { var (div, mod) = ((int)(x / y), x % y); - // If remainder is withing .0001 of 1 then we round up + // If remainder is within .0001 of 1 then we round up if (!(mod > 0.9999)) { return (div, mod);