Pos.CenterTests.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. using static Terminal.Gui.Dim;
  4. using static Terminal.Gui.Pos;
  5. namespace Terminal.Gui.LayoutTests;
  6. public class PosCenterTests (ITestOutputHelper output)
  7. {
  8. private readonly ITestOutputHelper _output = output;
  9. [Theory]
  10. [AutoInitShutdown]
  11. [InlineData (1)]
  12. [InlineData (2)]
  13. [InlineData (3)]
  14. [InlineData (4)]
  15. [InlineData (5)]
  16. [InlineData (6)]
  17. [InlineData (7)]
  18. [InlineData (8)]
  19. [InlineData (9)]
  20. [InlineData (10)]
  21. public void PosCenter_SubView_85_Percent_Height (int height)
  22. {
  23. var win = new Window { Width = Fill (), Height = Fill () };
  24. var subview = new Window
  25. {
  26. X = Center (), Y = Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
  27. };
  28. win.Add (subview);
  29. RunState rs = Application.Begin (win);
  30. var firstIteration = false;
  31. ((FakeDriver)Application.Driver!).SetBufferSize (20, height);
  32. Application.RunIteration (ref rs, firstIteration);
  33. var expected = string.Empty;
  34. switch (height)
  35. {
  36. case 1:
  37. //Assert.Equal (new (0, 0, 17, 0), subview.Frame);
  38. expected = @"
  39. ────────────────────";
  40. break;
  41. case 2:
  42. //Assert.Equal (new (0, 0, 17, 1), subview.Frame);
  43. expected = @"
  44. ┌──────────────────┐
  45. └──────────────────┘
  46. ";
  47. break;
  48. case 3:
  49. //Assert.Equal (new (0, 0, 17, 2), subview.Frame);
  50. expected = @"
  51. ┌──────────────────┐
  52. │ │
  53. └──────────────────┘
  54. ";
  55. break;
  56. case 4:
  57. //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
  58. expected = @"
  59. ┌──────────────────┐
  60. │ ─────────────── │
  61. │ │
  62. └──────────────────┘";
  63. break;
  64. case 5:
  65. //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
  66. expected = @"
  67. ┌──────────────────┐
  68. │ ┌─────────────┐ │
  69. │ └─────────────┘ │
  70. │ │
  71. └──────────────────┘";
  72. break;
  73. case 6:
  74. //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
  75. expected = @"
  76. ┌──────────────────┐
  77. │ ┌─────────────┐ │
  78. │ │ │ │
  79. │ └─────────────┘ │
  80. │ │
  81. └──────────────────┘";
  82. break;
  83. case 7:
  84. //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
  85. expected = @"
  86. ┌──────────────────┐
  87. │ ┌─────────────┐ │
  88. │ │ │ │
  89. │ │ │ │
  90. │ └─────────────┘ │
  91. │ │
  92. └──────────────────┘";
  93. break;
  94. case 8:
  95. //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
  96. expected = @"
  97. ┌──────────────────┐
  98. │ ┌─────────────┐ │
  99. │ │ │ │
  100. │ │ │ │
  101. │ │ │ │
  102. │ └─────────────┘ │
  103. │ │
  104. └──────────────────┘";
  105. break;
  106. case 9:
  107. //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
  108. expected = @"
  109. ┌──────────────────┐
  110. │ │
  111. │ ┌─────────────┐ │
  112. │ │ │ │
  113. │ │ │ │
  114. │ │ │ │
  115. │ └─────────────┘ │
  116. │ │
  117. └──────────────────┘";
  118. break;
  119. case 10:
  120. //Assert.Equal (new (0, 0, 17, 3), subview.Frame);
  121. expected = @"
  122. ┌──────────────────┐
  123. │ │
  124. │ ┌─────────────┐ │
  125. │ │ │ │
  126. │ │ │ │
  127. │ │ │ │
  128. │ │ │ │
  129. │ └─────────────┘ │
  130. │ │
  131. └──────────────────┘"
  132. ;
  133. break;
  134. }
  135. _ = DriverAssert.AssertDriverContentsWithFrameAre (expected, _output);
  136. Application.End (rs);
  137. win.Dispose ();
  138. }
  139. [Theory]
  140. [AutoInitShutdown]
  141. [InlineData (1)]
  142. [InlineData (2)]
  143. [InlineData (3)]
  144. [InlineData (4)]
  145. [InlineData (5)]
  146. [InlineData (6)]
  147. [InlineData (7)]
  148. [InlineData (8)]
  149. [InlineData (9)]
  150. [InlineData (10)]
  151. public void PosCenter_SubView_85_Percent_Width (int width)
  152. {
  153. var win = new Window { Width = Fill (), Height = Fill () };
  154. var subview = new Window
  155. {
  156. X = Center (), Y = Center (), Width = Dim.Percent (85), Height = Dim.Percent (85)
  157. };
  158. win.Add (subview);
  159. RunState rs = Application.Begin (win);
  160. var firstIteration = false;
  161. ((FakeDriver)Application.Driver!).SetBufferSize (width, 7);
  162. Application.RunIteration (ref rs, firstIteration);
  163. var expected = string.Empty;
  164. switch (width)
  165. {
  166. case 1:
  167. Assert.Equal (new (0, 0, 0, 4), subview.Frame);
  168. expected = @"
  169. │";
  170. break;
  171. case 2:
  172. Assert.Equal (new (0, 0, 0, 4), subview.Frame);
  173. expected = @"
  174. ┌┐
  175. ││
  176. ││
  177. ││
  178. ││
  179. ││
  180. └┘";
  181. break;
  182. case 3:
  183. Assert.Equal (new (0, 0, 0, 4), subview.Frame);
  184. expected = @"
  185. ┌─┐
  186. │ │
  187. │ │
  188. │ │
  189. │ │
  190. │ │
  191. └─┘";
  192. break;
  193. case 4:
  194. Assert.Equal (new (0, 0, 1, 4), subview.Frame);
  195. expected = @"
  196. ┌──┐
  197. ││ │
  198. ││ │
  199. ││ │
  200. ││ │
  201. │ │
  202. └──┘";
  203. break;
  204. case 5:
  205. Assert.Equal (new (0, 0, 2, 4), subview.Frame);
  206. expected = @"
  207. ┌───┐
  208. │┌┐ │
  209. │││ │
  210. │││ │
  211. │└┘ │
  212. │ │
  213. └───┘";
  214. break;
  215. case 6:
  216. Assert.Equal (new (0, 0, 3, 4), subview.Frame);
  217. expected = @"
  218. ┌────┐
  219. │┌─┐ │
  220. ││ │ │
  221. ││ │ │
  222. │└─┘ │
  223. │ │
  224. └────┘";
  225. break;
  226. case 7:
  227. Assert.Equal (new (0, 0, 4, 4), subview.Frame);
  228. expected = @"
  229. ┌─────┐
  230. │┌──┐ │
  231. ││ │ │
  232. ││ │ │
  233. │└──┘ │
  234. │ │
  235. └─────┘";
  236. break;
  237. case 8:
  238. Assert.Equal (new (0, 0, 5, 4), subview.Frame);
  239. expected = @"
  240. ┌──────┐
  241. │┌───┐ │
  242. ││ │ │
  243. ││ │ │
  244. │└───┘ │
  245. │ │
  246. └──────┘";
  247. break;
  248. case 9:
  249. Assert.Equal (new (1, 0, 5, 4), subview.Frame);
  250. expected = @"
  251. ┌───────┐
  252. │ ┌───┐ │
  253. │ │ │ │
  254. │ │ │ │
  255. │ └───┘ │
  256. │ │
  257. └───────┘";
  258. break;
  259. case 10:
  260. Assert.Equal (new (1, 0, 6, 4), subview.Frame);
  261. expected = @"
  262. ┌────────┐
  263. │ ┌────┐ │
  264. │ │ │ │
  265. │ │ │ │
  266. │ └────┘ │
  267. │ │
  268. └────────┘"
  269. ;
  270. break;
  271. }
  272. _ = DriverAssert.AssertDriverContentsWithFrameAre (expected, _output);
  273. Application.End (rs);
  274. win.Dispose ();
  275. }
  276. }