From 6e951882e02b22c08baaad822bb9e3cba7fc34ed Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 30 Apr 2024 11:35:41 -0600 Subject: [PATCH] Updated Draw_Text_Alignment --- UnitTests/Text/TextFormatterTests.cs | 120 +++++++++++++++++++++++++++ UnitTests/View/DrawTests.cs | 119 -------------------------- 2 files changed, 120 insertions(+), 119 deletions(-) diff --git a/UnitTests/Text/TextFormatterTests.cs b/UnitTests/Text/TextFormatterTests.cs index a879c9d5d..25d19b2f9 100644 --- a/UnitTests/Text/TextFormatterTests.cs +++ b/UnitTests/Text/TextFormatterTests.cs @@ -3664,4 +3664,124 @@ ek")] }; Assert.Equal (new (1, expected), tf.Size); } + + // Draw tests - Note that these depend on View + + [Fact] + [TestRespondersDisposed] + public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds () + { + Application.Init (new FakeDriver ()); + + Toplevel top = new (); + + var view = new View { Y = -2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight, Text = "view" }; + top.Add (view); + + Application.Iteration += (s, a) => + { + Assert.Equal (-2, view.Y); + + Application.RequestStop (); + }; + + try + { + Application.Run (top); + } + catch (IndexOutOfRangeException ex) + { + // After the fix this exception will not be caught. + Assert.IsType (ex); + } + + top.Dispose (); + // Shutdown must be called to safely clean up Application if Init has been called + Application.Shutdown (); + } + + //TODO: Expand this test to cover Vertical Alignment as well + [SetupFakeDriver] + [Theory] + [InlineData ("0 2 4", TextAlignment.Left, TextDirection.LeftRight_BottomTop, @" +0 2 4** +******* +******* +******* +******* +******* +*******")] + [InlineData ("0 2 4", TextAlignment.Right, TextDirection.LeftRight_BottomTop, @" +**0 2 4 +******* +******* +******* +******* +******* +*******")] + [InlineData ("0 2 4", TextAlignment.Centered, TextDirection.LeftRight_BottomTop, @" +*0 2 4* +******* +******* +******* +******* +******* +*******")] + + [InlineData ("0 2 4", TextAlignment.Justified, TextDirection.LeftRight_BottomTop, @" +0 2 4 +******* +******* +******* +******* +******* +*******")] + + [InlineData ("0 2 4", TextAlignment.Left, TextDirection.LeftRight_BottomTop, @" +0 2 4** +******* +******* +******* +******* +******* +*******")] + [InlineData ("0 你 4", TextAlignment.Right, TextDirection.LeftRight_BottomTop, @" +*0 你 4 +******* +******* +******* +******* +******* +*******")] + [InlineData ("0 你 4", TextAlignment.Centered, TextDirection.LeftRight_BottomTop, @" +0 你 4* +******* +******* +******* +******* +******* +*******")] + + [InlineData ("0 你 4", TextAlignment.Justified, TextDirection.LeftRight_BottomTop, @" +0 你 4 +******* +******* +******* +******* +******* +*******")] + public void Draw_Text_Alignment (string text, TextAlignment horizontalTextAlignment, TextDirection textDirection, string expectedText) + { + TextFormatter tf = new () + { + Alignment = horizontalTextAlignment, + Direction = textDirection, + Size = new (7, 7), + Text = text + }; + + Application.Driver.FillRect (new Rectangle (0, 0, 7, 7), (Rune)'*'); + tf.Draw (new Rectangle (0, 0, 7, 7), Attribute.Default, Attribute.Default); + TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output); + } } diff --git a/UnitTests/View/DrawTests.cs b/UnitTests/View/DrawTests.cs index 0586e934a..6d9c4b0af 100644 --- a/UnitTests/View/DrawTests.cs +++ b/UnitTests/View/DrawTests.cs @@ -1007,123 +1007,4 @@ public class DrawTests (ITestOutputHelper _output) Application.Shutdown (); } - [Fact] - [TestRespondersDisposed] - public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds () - { - Application.Init (new FakeDriver ()); - - Toplevel top = new (); - - var view = new View { Y = -2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight, Text = "view" }; - top.Add (view); - - Application.Iteration += (s, a) => - { - Assert.Equal (-2, view.Y); - - Application.RequestStop (); - }; - - try - { - Application.Run (top); - } - catch (IndexOutOfRangeException ex) - { - // After the fix this exception will not be caught. - Assert.IsType (ex); - } - - top.Dispose (); - // Shutdown must be called to safely clean up Application if Init has been called - Application.Shutdown (); - } - - //TODO: Expand this test to cover Vertical Alignment as well - [SetupFakeDriver] - [Theory] - [InlineData ("0 2 4", TextAlignment.Left, @" -0 2 4** -******* -******* -******* -******* -******* -*******")] - [InlineData ("0 2 4", TextAlignment.Right, @" -**0 2 4 -******* -******* -******* -******* -******* -*******")] - [InlineData ("0 2 4", TextAlignment.Centered, @" -*0 2 4* -******* -******* -******* -******* -******* -*******")] - - [InlineData ("0 2 4", TextAlignment.Justified, @" -0 2 4 -******* -******* -******* -******* -******* -*******")] - - [InlineData ("0 2 4", TextAlignment.Left, @" -0 2 4** -******* -******* -******* -******* -******* -*******")] - [InlineData ("0 你 4", TextAlignment.Right, @" -*0 你 4 -******* -******* -******* -******* -******* -*******")] - [InlineData ("0 你 4", TextAlignment.Centered, @" -0 你 4* -******* -******* -******* -******* -******* -*******")] - - [InlineData ("0 你 4", TextAlignment.Justified, @" -0 你 4 -******* -******* -******* -******* -******* -*******")] - public void Draw_Text_Alignment (string text, TextAlignment textAlignment, string expectedText) - { - View view = new () - { - TextAlignment = textAlignment, - Text = text, - Width = 7, - Height = 7 - }; - - Assert.Equal (new Size (7, 7), view.TextFormatter.Size); - Assert.True (view.NeedsDisplay); - Application.Driver.FillRect (view.Frame, (Rune)'*'); - view.Draw (); - TestHelpers.AssertDriverContentsWithFrameAre (expectedText, _output); - } }