浏览代码

Adds transparent shadow test (#4487)

* Add tests for overlapped view transparent shadow config

* Add test for transparent shadow showing background text

Added a unit test to verify that overlapped views with transparent shadows allow background text to show through the shadow area. The test checks both right and bottom shadow regions and asserts that the underlying content is visible, ensuring correct rendering behavior.

* Add test for transparent shadow in overlapped views

Adds Overlapped_View_With_TransparentShadow_Driver_Output_Shows_Background_Text to verify that background text is visible through transparent shadows in overlapped views. The test checks for correct rendering, ANSI color codes, and ensures the shadow area displays the expected background character.

* Refactor transparent shadow test for stricter output check

Update Overlapped_View_With_TransparentShadow_Driver_Output_Shows_Background_Text to use a smaller screen, dynamic sizing, and new overlapped view text. Replace loose output assertion with strict ANSI output comparison. Make shadow cell coordinate calculation dynamic based on view frame.

* Consolidate transparent shadow tests into ShadowStyleTests

Moved the transparent shadow driver output test from OverlappedViewTransparentShadowTests to ShadowStyleTests for better organization. Removed the now-redundant OverlappedViewTransparentShadowTests class and updated ShadowStyleTests to support output logging. All transparent shadow rendering tests are now grouped under ShadowStyleTests.
Tig 1 天之前
父节点
当前提交
84f977937b
共有 1 个文件被更改,包括 83 次插入2 次删除
  1. 83 2
      Tests/UnitTestsParallelizable/ViewBase/Adornment/ShadowStyletests.cs

+ 83 - 2
Tests/UnitTestsParallelizable/ViewBase/Adornment/ShadowStyletests.cs

@@ -1,9 +1,14 @@
-namespace ViewBaseTests.Adornments;
+using UnitTests;
+using Xunit.Abstractions;
+
+namespace ViewBaseTests.Adornments;
 
 [Collection ("Global Test Setup")]
 
-public class ShadowStyleTests
+public class ShadowStyleTests (ITestOutputHelper output)
 {
+    private readonly ITestOutputHelper _output = output;
+
     [Fact]
     public void Default_None ()
     {
@@ -73,4 +78,80 @@ public class ShadowStyleTests
         view.Dispose ();
     }
 
+
+    [Fact]
+    public void TransparentShadow_Draws_Transparent_At_Driver_Output ()
+    {
+        // Arrange
+        IApplication app = Application.Create ();
+        app.Init ("fake");
+        app.Driver!.SetScreenSize (5, 3);
+
+        // Force 16-bit colors off to get predictable RGB output
+        app.Driver.Force16Colors = false;
+
+        var superView = new Runnable
+        {
+            Width = Dim.Fill (),
+            Height = Dim.Fill (),
+            Text = "ABC".Repeat (40)!
+        };
+        superView.SetScheme (new (new Attribute (Color.White, Color.Blue)));
+        superView.TextFormatter.WordWrap = true;
+
+        // Create an overlapped view with transparent shadow
+        var overlappedView = new View
+        {
+            Width = 4,
+            Height = 2,
+            Text = "123",
+            Arrangement = ViewArrangement.Overlapped,
+            ShadowStyle = ShadowStyle.Transparent
+        };
+        overlappedView.SetScheme (new (new Attribute (Color.Black, Color.Green)));
+
+        superView.Add (overlappedView);
+
+        // Act
+        SessionToken? token = app.Begin (superView);
+        app.LayoutAndDraw ();
+        app.Driver.Refresh ();
+
+        // Assert
+        _output.WriteLine ("Actual driver contents:");
+        _output.WriteLine (app.Driver.ToString ());
+        _output.WriteLine ("\nActual driver output:");
+        string? output = app.Driver.GetOutput ().GetLastOutput ();
+        _output.WriteLine (output);
+
+        DriverAssert.AssertDriverOutputIs ("""
+                                           \x1b[38;2;0;0;0m\x1b[48;2;0;128;0m123\x1b[38;2;0;0;0m\x1b[48;2;189;189;189mA\x1b[38;2;0;0;255m\x1b[48;2;255;255;255mBC\x1b[38;2;0;0;0m\x1b[48;2;189;189;189mABC\x1b[38;2;0;0;255m\x1b[48;2;255;255;255mABCABC
+                                           """, _output, app.Driver);
+
+        // The output should contain ANSI color codes for the transparent shadow
+        // which will have dimmed colors compared to the original
+        Assert.Contains ("\x1b[38;2;", output); // Should have RGB foreground color codes
+        Assert.Contains ("\x1b[48;2;", output); // Should have RGB background color codes
+
+        // Verify driver contents show the background text in shadow areas
+        int shadowX = overlappedView.Frame.X + overlappedView.Frame.Width;
+        int shadowY = overlappedView.Frame.Y + overlappedView.Frame.Height;
+
+        Cell shadowCell = app.Driver.Contents! [shadowY, shadowX];
+        _output.WriteLine ($"\nShadow cell at [{shadowY},{shadowX}]: Grapheme='{shadowCell.Grapheme}', Attr={shadowCell.Attribute}");
+
+        // The grapheme should be from background text
+        Assert.NotEqual (string.Empty, shadowCell.Grapheme);
+        Assert.Contains (shadowCell.Grapheme, "ABC"); // Should be one of the background characters
+
+        // Cleanup
+        if (token is { })
+        {
+            app.End (token);
+        }
+
+        superView.Dispose ();
+        app.Dispose ();
+    }
+
 }