BorderArrangementTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. ๏ปฟ#nullable enable
  2. using System.Text;
  3. using UnitTests;
  4. using Xunit.Abstractions;
  5. namespace ViewBaseTests.Adornments;
  6. [Collection ("Global Test Setup")]
  7. public class BorderArrangementTests (ITestOutputHelper output)
  8. {
  9. [Fact]
  10. public void Arrangement_Handles_Wide_Glyphs_Correctly ()
  11. {
  12. IApplication app = Application.Create ();
  13. app.Init ("fake");
  14. app.Driver?.SetScreenSize (6, 5);
  15. // Using a replacement char to make sure wide glyphs are handled correctly
  16. // in the shadow area, to not confusing with a space char.
  17. app.Driver?.GetOutputBuffer ().SetWideGlyphReplacement (Rune.ReplacementChar);
  18. Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
  19. superview.Text = """
  20. ๐ŸŽ๐ŸŽ๐ŸŽ
  21. ๐ŸŽ๐ŸŽ๐ŸŽ
  22. ๐ŸŽ๐ŸŽ๐ŸŽ
  23. ๐ŸŽ๐ŸŽ๐ŸŽ
  24. ๐ŸŽ๐ŸŽ๐ŸŽ
  25. """;
  26. View view = new ()
  27. {
  28. X = 2, Width = 4, Height = 4, BorderStyle = LineStyle.Single,
  29. Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, CanFocus = true
  30. };
  31. superview.Add (view);
  32. app.Begin (superview);
  33. Assert.Equal ("Absolute(2)", view.X.ToString ());
  34. DriverAssert.AssertDriverContentsAre (
  35. """
  36. ๐ŸŽโ”Œโ”€โ”€โ”
  37. ๐ŸŽโ”‚ โ”‚
  38. ๐ŸŽโ”‚ โ”‚
  39. ๐ŸŽโ””โ”€โ”€โ”˜
  40. ๐ŸŽ๐ŸŽ๐ŸŽ
  41. """,
  42. output,
  43. app.Driver);
  44. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.F5.WithCtrl));
  45. app.LayoutAndDraw ();
  46. DriverAssert.AssertDriverContentsAre (
  47. """
  48. ๐ŸŽโ—Šโ”€โ”€โ”
  49. ๐ŸŽโ”‚ โ”‚
  50. ๐ŸŽโ”‚ โ”‚
  51. ๐ŸŽโ””โ”€โ”€โ†˜
  52. ๐ŸŽ๐ŸŽ๐ŸŽ
  53. """,
  54. output,
  55. app.Driver);
  56. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
  57. Assert.Equal ("Absolute(1)", view.X.ToString ());
  58. app.LayoutAndDraw ();
  59. DriverAssert.AssertDriverContentsAre (
  60. """
  61. ๏ฟฝโ—Šโ”€โ”€โ”
  62. ๏ฟฝโ”‚ โ”‚
  63. ๏ฟฝโ”‚ โ”‚
  64. ๏ฟฝโ””โ”€โ”€โ†˜
  65. ๐ŸŽ๐ŸŽ๐ŸŽ
  66. """,
  67. output,
  68. app.Driver);
  69. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
  70. Assert.Equal ("Absolute(0)", view.X.ToString ());
  71. app.LayoutAndDraw ();
  72. DriverAssert.AssertDriverContentsAre (
  73. """
  74. โ—Šโ”€โ”€โ”๐ŸŽ
  75. โ”‚ โ”‚๐ŸŽ
  76. โ”‚ โ”‚๐ŸŽ
  77. โ””โ”€โ”€โ†˜๐ŸŽ
  78. ๐ŸŽ๐ŸŽ๐ŸŽ
  79. """,
  80. output,
  81. app.Driver);
  82. }
  83. [Fact]
  84. public void Arrangement_With_SubView_In_Border_Handles_Wide_Glyphs_Correctly ()
  85. {
  86. IApplication app = Application.Create ();
  87. app.Init ("fake");
  88. app.Driver?.SetScreenSize (8, 7);
  89. // Using a replacement char to make sure wide glyphs are handled correctly
  90. // in the shadow area, to not confusing with a space char.
  91. app.Driver?.GetOutputBuffer ().SetWideGlyphReplacement (Rune.ReplacementChar);
  92. // Don't remove this array even if it seems unused, it is used to map the attributes indexes in the DriverAssert
  93. // Otherwise the test won't detect issues with attributes not visibly by the naked eye
  94. Attribute [] attributes =
  95. [
  96. new (ColorName16.Blue, ColorName16.BrightBlue, TextStyle.None),
  97. new (ColorName16.BrightBlue, ColorName16.Blue, TextStyle.None),
  98. new (ColorName16.Green, ColorName16.BrightGreen, TextStyle.None),
  99. new (ColorName16.Magenta, ColorName16.BrightMagenta, TextStyle.None),
  100. new (ColorName16.BrightMagenta, ColorName16.Magenta, TextStyle.None)
  101. ];
  102. Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
  103. superview.SetScheme (new () { Normal = attributes [0], Focus = attributes [1] });
  104. superview.Text = """
  105. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  106. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  107. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  108. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  109. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  110. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  111. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  112. """;
  113. View view = new () { X = 6, Width = 2, Height = 1, Text = "๐Ÿฆฎ" };
  114. view.SetScheme (new () { Normal = attributes [2] });
  115. View view2 = new ()
  116. {
  117. X = 2, Width = 6, Height = 6, Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, CanFocus = true
  118. };
  119. view2.Border!.Thickness = new (1);
  120. view2.Border.Add (new View { Height = Dim.Auto (), Width = Dim.Auto (), Text = "Hi" });
  121. view2.SetScheme (new () { Normal = attributes [3], HotNormal = attributes [4] });
  122. superview.Add (view, view2);
  123. app.Begin (superview);
  124. Assert.Equal ("Absolute(2)", view2.X.ToString ());
  125. DriverAssert.AssertDriverContentsAre (
  126. """
  127. ๐ŸŽHi
  128. ๐ŸŽ
  129. ๐ŸŽ
  130. ๐ŸŽ
  131. ๐ŸŽ
  132. ๐ŸŽ
  133. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  134. """,
  135. output,
  136. app.Driver);
  137. DriverAssert.AssertDriverAttributesAre (
  138. """
  139. 11333333
  140. 11333333
  141. 11333333
  142. 11333333
  143. 11333333
  144. 11333333
  145. 11111111
  146. """,
  147. output,
  148. app.Driver,
  149. attributes);
  150. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.F5.WithCtrl));
  151. app.LayoutAndDraw ();
  152. DriverAssert.AssertDriverContentsAre (
  153. """
  154. ๐ŸŽโ—Ši
  155. ๐ŸŽ
  156. ๐ŸŽ
  157. ๐ŸŽ
  158. ๐ŸŽ
  159. ๐ŸŽ โ†˜
  160. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  161. """,
  162. output,
  163. app.Driver);
  164. DriverAssert.AssertDriverAttributesAre (
  165. """
  166. 11433333
  167. 11333333
  168. 11333333
  169. 11333333
  170. 11333333
  171. 11333333
  172. 11111111
  173. """,
  174. output,
  175. app.Driver,
  176. attributes);
  177. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
  178. Assert.Equal ("Absolute(1)", view2.X.ToString ());
  179. app.LayoutAndDraw ();
  180. DriverAssert.AssertDriverContentsAre (
  181. """
  182. ๏ฟฝโ—Ši
  183. ๏ฟฝ
  184. ๏ฟฝ
  185. ๏ฟฝ
  186. ๏ฟฝ
  187. ๏ฟฝ โ†˜
  188. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  189. """,
  190. output,
  191. app.Driver);
  192. DriverAssert.AssertDriverAttributesAre (
  193. """
  194. 14333332
  195. 13333330
  196. 13333330
  197. 13333330
  198. 13333330
  199. 13333330
  200. 11111111
  201. """,
  202. output,
  203. app.Driver,
  204. attributes);
  205. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
  206. Assert.Equal ("Absolute(0)", view2.X.ToString ());
  207. app.LayoutAndDraw ();
  208. DriverAssert.AssertDriverContentsAre (
  209. """
  210. โ—Ši ๐Ÿฆฎ
  211. ๐ŸŽ
  212. ๐ŸŽ
  213. ๐ŸŽ
  214. ๐ŸŽ
  215. โ†˜๐ŸŽ
  216. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  217. """,
  218. output,
  219. app.Driver);
  220. DriverAssert.AssertDriverAttributesAre (
  221. """
  222. 43333322
  223. 33333311
  224. 33333311
  225. 33333311
  226. 33333311
  227. 33333311
  228. 11111111
  229. """,
  230. output,
  231. app.Driver,
  232. attributes);
  233. }
  234. }