ShadowStyleTests.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.ViewTests;
  4. public class ShadowStyleTests (ITestOutputHelper output)
  5. {
  6. [Theory]
  7. [InlineData (
  8. ShadowStyle.None,
  9. """
  10. 011
  11. 111
  12. 111
  13. """)]
  14. [InlineData (
  15. ShadowStyle.Transparent,
  16. """
  17. 031
  18. 131
  19. 111
  20. """)]
  21. [InlineData (
  22. ShadowStyle.Opaque,
  23. """
  24. 021
  25. 221
  26. 111
  27. """)]
  28. [SetupFakeDriver]
  29. public void ShadowView_Colors (ShadowStyle style, string expectedAttrs)
  30. {
  31. ((FakeDriver)Application.Driver!).SetBufferSize (5, 5);
  32. Color fg = Color.Red;
  33. Color bg = Color.Green;
  34. // 0 - View
  35. // 1 - SuperView
  36. // 2 - Opaque - fg is Black, bg is SuperView.Bg
  37. // 3 - Transparent - fg is darker fg, bg is darker bg
  38. Attribute [] attributes =
  39. {
  40. Attribute.Default,
  41. new (fg, bg),
  42. new (Color.Black, bg),
  43. new (fg.GetDarkerColor (), bg.GetDarkerColor ())
  44. };
  45. var superView = new Toplevel
  46. {
  47. Height = 3,
  48. Width = 3,
  49. Text = "012ABC!@#",
  50. ColorScheme = new (new Attribute (fg, bg))
  51. };
  52. superView.TextFormatter.WordWrap = true;
  53. View view = new ()
  54. {
  55. Width = Dim.Auto (),
  56. Height = Dim.Auto (),
  57. Text = "*",
  58. ShadowStyle = style,
  59. ColorScheme = new (Attribute.Default)
  60. };
  61. superView.Add (view);
  62. Application.TopLevels.Push (superView);
  63. Application.LayoutAndDraw (true);
  64. DriverAssert.AssertDriverAttributesAre (expectedAttrs, output, Application.Driver, attributes);
  65. Application.ResetState (true);
  66. }
  67. // Visual tests
  68. [Theory]
  69. [InlineData (
  70. ShadowStyle.None,
  71. """
  72. 01#$
  73. AB#$
  74. !@#$
  75. !@#$
  76. """)]
  77. [InlineData (
  78. ShadowStyle.Opaque,
  79. """
  80. 01▖$
  81. AB▌$
  82. ▝▀▘$
  83. !@#$
  84. """)]
  85. [InlineData (
  86. ShadowStyle.Transparent,
  87. """
  88. 01#$
  89. AB#$
  90. !@#$
  91. !@#$
  92. """)]
  93. [SetupFakeDriver]
  94. public void Visual_Test (ShadowStyle style, string expected)
  95. {
  96. ((FakeDriver)Application.Driver!).SetBufferSize (5, 5);
  97. var superView = new Toplevel
  98. {
  99. Width = 4,
  100. Height = 4,
  101. Text = "!@#$".Repeat (4)!
  102. };
  103. superView.TextFormatter.WordWrap = true;
  104. var view = new View
  105. {
  106. Text = "01\nAB",
  107. Width = Dim.Auto (),
  108. Height = Dim.Auto ()
  109. };
  110. view.ShadowStyle = style;
  111. superView.Add (view);
  112. Application.TopLevels.Push (superView);
  113. Application.LayoutAndDraw (true);
  114. DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  115. view.Dispose ();
  116. Application.ResetState (true);
  117. }
  118. }