BorderArrangementTests.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. app.Driver?.GetOutputBuffer ().SetWideGlyphReplacement (Rune.ReplacementChar);
  16. Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
  17. superview.Text = """
  18. ๐ŸŽ๐ŸŽ๐ŸŽ
  19. ๐ŸŽ๐ŸŽ๐ŸŽ
  20. ๐ŸŽ๐ŸŽ๐ŸŽ
  21. ๐ŸŽ๐ŸŽ๐ŸŽ
  22. ๐ŸŽ๐ŸŽ๐ŸŽ
  23. """;
  24. View view = new ()
  25. {
  26. X = 2, Width = 4, Height = 4, BorderStyle = LineStyle.Single,
  27. Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, CanFocus = true
  28. };
  29. superview.Add (view);
  30. app.Begin (superview);
  31. Assert.Equal ("Absolute(2)", view.X.ToString ());
  32. DriverAssert.AssertDriverContentsAre (
  33. """
  34. ๐ŸŽโ”Œโ”€โ”€โ”
  35. ๐ŸŽโ”‚ โ”‚
  36. ๐ŸŽโ”‚ โ”‚
  37. ๐ŸŽโ””โ”€โ”€โ”˜
  38. ๐ŸŽ๐ŸŽ๐ŸŽ
  39. """,
  40. output,
  41. app.Driver);
  42. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.F5.WithCtrl));
  43. app.LayoutAndDraw ();
  44. DriverAssert.AssertDriverContentsAre (
  45. """
  46. ๐ŸŽโ—Šโ”€โ”€โ”
  47. ๐ŸŽโ”‚ โ”‚
  48. ๐ŸŽโ”‚ โ”‚
  49. ๐ŸŽโ””โ”€โ”€โ†˜
  50. ๐ŸŽ๐ŸŽ๐ŸŽ
  51. """,
  52. output,
  53. app.Driver);
  54. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
  55. Assert.Equal ("Absolute(1)", view.X.ToString ());
  56. app.LayoutAndDraw ();
  57. DriverAssert.AssertDriverContentsAre (
  58. """
  59. ๏ฟฝโ—Šโ”€โ”€โ”
  60. ๏ฟฝโ”‚ โ”‚
  61. ๏ฟฝโ”‚ โ”‚
  62. ๏ฟฝโ””โ”€โ”€โ†˜
  63. ๐ŸŽ๐ŸŽ๐ŸŽ
  64. """,
  65. output,
  66. app.Driver);
  67. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
  68. Assert.Equal ("Absolute(0)", view.X.ToString ());
  69. app.LayoutAndDraw ();
  70. DriverAssert.AssertDriverContentsAre (
  71. """
  72. โ—Šโ”€โ”€โ”๐ŸŽ
  73. โ”‚ โ”‚๐ŸŽ
  74. โ”‚ โ”‚๐ŸŽ
  75. โ””โ”€โ”€โ†˜๐ŸŽ
  76. ๐ŸŽ๐ŸŽ๐ŸŽ
  77. """,
  78. output,
  79. app.Driver);
  80. }
  81. [Fact]
  82. public void Arrangement_With_SubView_In_Border_Handles_Wide_Glyphs_Correctly ()
  83. {
  84. IApplication app = Application.Create ();
  85. app.Init ("fake");
  86. app.Driver?.SetScreenSize (8, 7);
  87. app.Driver?.GetOutputBuffer ().SetWideGlyphReplacement (Rune.ReplacementChar);
  88. Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
  89. superview.Text = """
  90. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  91. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  92. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  93. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  94. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  95. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  96. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  97. """;
  98. View view = new ()
  99. {
  100. X = 2, Width = 6, Height = 6, Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, CanFocus = true
  101. };
  102. view.Border!.Thickness = new (1);
  103. view.Border.Add (new View { Height = Dim.Auto (), Width = Dim.Auto (), Text = "Hi" });
  104. superview.Add (view);
  105. app.Begin (superview);
  106. Assert.Equal ("Absolute(2)", view.X.ToString ());
  107. DriverAssert.AssertDriverContentsAre (
  108. """
  109. ๐ŸŽHi
  110. ๐ŸŽ
  111. ๐ŸŽ
  112. ๐ŸŽ
  113. ๐ŸŽ
  114. ๐ŸŽ
  115. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  116. """,
  117. output,
  118. app.Driver);
  119. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.F5.WithCtrl));
  120. app.LayoutAndDraw ();
  121. DriverAssert.AssertDriverContentsAre (
  122. """
  123. ๐ŸŽโ—Ši
  124. ๐ŸŽ
  125. ๐ŸŽ
  126. ๐ŸŽ
  127. ๐ŸŽ
  128. ๐ŸŽ โ†˜
  129. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  130. """,
  131. output,
  132. app.Driver);
  133. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
  134. Assert.Equal ("Absolute(1)", view.X.ToString ());
  135. app.LayoutAndDraw ();
  136. DriverAssert.AssertDriverContentsAre (
  137. """
  138. ๏ฟฝโ—Ši
  139. ๏ฟฝ
  140. ๏ฟฝ
  141. ๏ฟฝ
  142. ๏ฟฝ
  143. ๏ฟฝ โ†˜
  144. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  145. """,
  146. output,
  147. app.Driver);
  148. Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
  149. Assert.Equal ("Absolute(0)", view.X.ToString ());
  150. app.LayoutAndDraw ();
  151. DriverAssert.AssertDriverContentsAre (
  152. """
  153. โ—Ši ๐ŸŽ
  154. ๐ŸŽ
  155. ๐ŸŽ
  156. ๐ŸŽ
  157. ๐ŸŽ
  158. โ†˜๐ŸŽ
  159. ๐ŸŽ๐ŸŽ๐ŸŽ๐ŸŽ
  160. """,
  161. output,
  162. app.Driver);
  163. }
  164. }