Dim.AutoTests.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. using System.Globalization;
  2. using System.Text;
  3. using Xunit.Abstractions;
  4. using static Terminal.Gui.Dim;
  5. // Alias Console to MockConsole so we don't accidentally use Console
  6. using Console = Terminal.Gui.FakeConsole;
  7. namespace Terminal.Gui.PosDimTests;
  8. public class DimAutoTests (ITestOutputHelper output)
  9. {
  10. private readonly ITestOutputHelper _output = output;
  11. // Test min - ensure that if min is specified in the DimAuto constructor it is honored
  12. [Fact]
  13. public void DimAuto_Min ()
  14. {
  15. var superView = new View
  16. {
  17. X = 0,
  18. Y = 0,
  19. Width = Dim.Auto (min: 10),
  20. Height = Dim.Auto (min: 10),
  21. ValidatePosDim = true
  22. };
  23. var subView = new View
  24. {
  25. X = 0,
  26. Y = 0,
  27. Width = 5,
  28. Height = 5
  29. };
  30. superView.Add (subView);
  31. superView.BeginInit ();
  32. superView.EndInit ();
  33. superView.SetRelativeLayout (new (10, 10));
  34. superView.LayoutSubviews (); // no throw
  35. Assert.Equal (10, superView.Frame.Width);
  36. Assert.Equal (10, superView.Frame.Height);
  37. }
  38. // what happens if DimAuto (min: 10) and the subview moves to a negative coord?
  39. [Fact]
  40. public void DimAuto_Min_Resets_If_Subview_Moves_Negative ()
  41. {
  42. var superView = new View
  43. {
  44. X = 0,
  45. Y = 0,
  46. Width = Dim.Auto (min: 10),
  47. Height = Dim.Auto (min: 10),
  48. ValidatePosDim = true
  49. };
  50. var subView = new View
  51. {
  52. X = 0,
  53. Y = 0,
  54. Width = 5,
  55. Height = 5
  56. };
  57. superView.Add (subView);
  58. superView.BeginInit ();
  59. superView.EndInit ();
  60. superView.SetRelativeLayout (new (10, 10));
  61. superView.LayoutSubviews (); // no throw
  62. Assert.Equal (10, superView.Frame.Width);
  63. Assert.Equal (10, superView.Frame.Height);
  64. subView.X = -1;
  65. subView.Y = -1;
  66. superView.SetRelativeLayout (new (10, 10));
  67. superView.LayoutSubviews (); // no throw
  68. Assert.Equal (5, subView.Frame.Width);
  69. Assert.Equal (5, subView.Frame.Height);
  70. Assert.Equal (10, superView.Frame.Width);
  71. Assert.Equal (10, superView.Frame.Height);
  72. }
  73. [Fact]
  74. public void DimAuto_Min_Resets_If_Subview_Shrinks ()
  75. {
  76. var superView = new View
  77. {
  78. X = 0,
  79. Y = 0,
  80. Width = Dim.Auto (min: 10),
  81. Height = Dim.Auto (min: 10),
  82. ValidatePosDim = true
  83. };
  84. var subView = new View
  85. {
  86. X = 0,
  87. Y = 0,
  88. Width = 5,
  89. Height = 5
  90. };
  91. superView.Add (subView);
  92. superView.BeginInit ();
  93. superView.EndInit ();
  94. superView.SetRelativeLayout (new (10, 10));
  95. superView.LayoutSubviews (); // no throw
  96. Assert.Equal (10, superView.Frame.Width);
  97. Assert.Equal (10, superView.Frame.Height);
  98. subView.Width = 3;
  99. subView.Height = 3;
  100. superView.SetRelativeLayout (new (10, 10));
  101. superView.LayoutSubviews (); // no throw
  102. Assert.Equal (3, subView.Frame.Width);
  103. Assert.Equal (3, subView.Frame.Height);
  104. Assert.Equal (10, superView.Frame.Width);
  105. Assert.Equal (10, superView.Frame.Height);
  106. }
  107. [Theory]
  108. [InlineData (0, 0, 0, 0, 0)]
  109. [InlineData (0, 0, 5, 0, 0)]
  110. [InlineData (0, 0, 0, 5, 5)]
  111. [InlineData (0, 0, 5, 5, 5)]
  112. [InlineData (1, 0, 5, 0, 0)]
  113. [InlineData (1, 0, 0, 5, 5)]
  114. [InlineData (1, 0, 5, 5, 5)]
  115. [InlineData (1, 1, 5, 5, 6)]
  116. [InlineData (-1, 0, 5, 0, 0)]
  117. [InlineData (-1, 0, 0, 5, 5)]
  118. [InlineData (-1, 0, 5, 5, 5)]
  119. [InlineData (-1, -1, 5, 5, 4)]
  120. public void Height_Auto_Width_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedHeight)
  121. {
  122. var superView = new View
  123. {
  124. X = 0,
  125. Y = 0,
  126. Width = 10,
  127. Height = Dim.Auto (),
  128. ValidatePosDim = true
  129. };
  130. var subView = new View
  131. {
  132. X = subX,
  133. Y = subY,
  134. Width = subWidth,
  135. Height = subHeight,
  136. ValidatePosDim = true
  137. };
  138. superView.Add (subView);
  139. superView.BeginInit ();
  140. superView.EndInit ();
  141. superView.SetRelativeLayout (new (10, 10));
  142. Assert.Equal (new Rectangle (0, 0, 10, expectedHeight), superView.Frame);
  143. }
  144. [Fact]
  145. public void NoSubViews_Does_Nothing ()
  146. {
  147. var superView = new View
  148. {
  149. X = 0,
  150. Y = 0,
  151. Width = Dim.Auto (),
  152. Height = Dim.Auto (),
  153. ValidatePosDim = true
  154. };
  155. superView.BeginInit ();
  156. superView.EndInit ();
  157. superView.SetRelativeLayout (new (10, 10));
  158. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  159. superView.SetRelativeLayout (new (10, 10));
  160. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  161. }
  162. [Fact]
  163. public void NoSubViews_Does_Nothing_Vertical ()
  164. {
  165. var superView = new View
  166. {
  167. X = 0,
  168. Y = 0,
  169. Width = Dim.Auto (),
  170. Height = Dim.Auto (),
  171. TextDirection = TextDirection.TopBottom_LeftRight,
  172. ValidatePosDim = true
  173. };
  174. superView.BeginInit ();
  175. superView.EndInit ();
  176. superView.SetRelativeLayout (new (10, 10));
  177. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  178. superView.SetRelativeLayout (new (10, 10));
  179. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  180. }
  181. [Theory]
  182. [InlineData (0, 0, 0, 0, 0, 0)]
  183. [InlineData (0, 0, 5, 0, 5, 0)]
  184. [InlineData (0, 0, 0, 5, 0, 5)]
  185. [InlineData (0, 0, 5, 5, 5, 5)]
  186. [InlineData (1, 0, 5, 0, 6, 0)]
  187. [InlineData (1, 0, 0, 5, 1, 5)]
  188. [InlineData (1, 0, 5, 5, 6, 5)]
  189. [InlineData (1, 1, 5, 5, 6, 6)]
  190. [InlineData (-1, 0, 5, 0, 4, 0)]
  191. [InlineData (-1, 0, 0, 5, 0, 5)]
  192. [InlineData (-1, 0, 5, 5, 4, 5)]
  193. [InlineData (-1, -1, 5, 5, 4, 4)]
  194. public void SubView_ChangesSuperViewSize (int subX, int subY, int subWidth, int subHeight, int expectedWidth, int expectedHeight)
  195. {
  196. var superView = new View
  197. {
  198. X = 0,
  199. Y = 0,
  200. Width = Dim.Auto (),
  201. Height = Dim.Auto (),
  202. ValidatePosDim = true
  203. };
  204. var subView = new View
  205. {
  206. X = subX,
  207. Y = subY,
  208. Width = subWidth,
  209. Height = subHeight,
  210. ValidatePosDim = true
  211. };
  212. superView.Add (subView);
  213. superView.BeginInit ();
  214. superView.EndInit ();
  215. superView.SetRelativeLayout (new (10, 10));
  216. Assert.Equal (new Rectangle (0, 0, expectedWidth, expectedHeight), superView.Frame);
  217. }
  218. // Test validation
  219. [Fact]
  220. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims ()
  221. {
  222. var superView = new View
  223. {
  224. X = 0,
  225. Y = 0,
  226. Width = Dim.Auto (),
  227. Height = Dim.Auto (),
  228. ValidatePosDim = true
  229. };
  230. var subView = new View
  231. {
  232. X = 0,
  233. Y = 0,
  234. Width = Dim.Fill (),
  235. Height = 10,
  236. ValidatePosDim = true
  237. };
  238. superView.BeginInit ();
  239. superView.EndInit ();
  240. Assert.Throws<InvalidOperationException> (() => superView.Add (subView));
  241. subView.Width = 10;
  242. superView.Add (subView);
  243. superView.SetRelativeLayout (new (10, 10));
  244. superView.LayoutSubviews (); // no throw
  245. subView.Width = Dim.Fill ();
  246. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  247. subView.Width = 10;
  248. subView.Height = Dim.Fill ();
  249. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  250. subView.Height = 10;
  251. subView.Height = Dim.Percent (50);
  252. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  253. subView.Height = 10;
  254. subView.X = Pos.Center ();
  255. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  256. subView.X = 0;
  257. subView.Y = Pos.Center ();
  258. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  259. subView.Y = 0;
  260. subView.Width = 10;
  261. subView.Height = 10;
  262. subView.X = 0;
  263. subView.Y = 0;
  264. superView.SetRelativeLayout (new (0, 0));
  265. superView.LayoutSubviews ();
  266. }
  267. // Test validation
  268. [Fact]
  269. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims_Combine ()
  270. {
  271. var superView = new View
  272. {
  273. X = 0,
  274. Y = 0,
  275. Width = Dim.Auto (),
  276. Height = Dim.Auto (),
  277. ValidatePosDim = true
  278. };
  279. var subView = new View
  280. {
  281. X = 0,
  282. Y = 0,
  283. Width = 10,
  284. Height = 10
  285. };
  286. var subView2 = new View
  287. {
  288. X = 0,
  289. Y = 0,
  290. Width = 10,
  291. Height = 10
  292. };
  293. superView.Add (subView, subView2);
  294. superView.BeginInit ();
  295. superView.EndInit ();
  296. superView.SetRelativeLayout (new (0, 0));
  297. superView.LayoutSubviews (); // no throw
  298. subView.Height = Dim.Fill () + 3;
  299. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  300. subView.Height = 0;
  301. subView.Height = 3 + Dim.Fill ();
  302. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  303. subView.Height = 0;
  304. subView.Height = 3 + 5 + Dim.Fill ();
  305. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  306. subView.Height = 0;
  307. subView.Height = 3 + 5 + Dim.Percent (10);
  308. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  309. subView.Height = 0;
  310. // Tests nested Combine
  311. subView.Height = 5 + new Dim.DimCombine (true, 3, new Dim.DimCombine (true, Dim.Percent (10), 9));
  312. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  313. }
  314. [Fact]
  315. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Pos_Combine ()
  316. {
  317. var superView = new View
  318. {
  319. X = 0,
  320. Y = 0,
  321. Width = Dim.Auto (),
  322. Height = Dim.Auto (),
  323. ValidatePosDim = true
  324. };
  325. var subView = new View
  326. {
  327. X = 0,
  328. Y = 0,
  329. Width = 10,
  330. Height = 10
  331. };
  332. var subView2 = new View
  333. {
  334. X = 0,
  335. Y = 0,
  336. Width = 10,
  337. Height = 10
  338. };
  339. superView.Add (subView, subView2);
  340. superView.BeginInit ();
  341. superView.EndInit ();
  342. superView.SetRelativeLayout (new (0, 0));
  343. superView.LayoutSubviews (); // no throw
  344. subView.X = Pos.Right (subView2);
  345. superView.SetRelativeLayout (new (0, 0));
  346. superView.LayoutSubviews (); // no throw
  347. subView.X = Pos.Right (subView2) + 3;
  348. superView.SetRelativeLayout (new (0, 0)); // no throw
  349. superView.LayoutSubviews (); // no throw
  350. subView.X = new Pos.PosCombine (true, Pos.Right (subView2), new Pos.PosCombine (true, 7, 9));
  351. superView.SetRelativeLayout (new (0, 0)); // no throw
  352. subView.X = Pos.Center () + 3;
  353. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  354. subView.X = 0;
  355. subView.X = 3 + Pos.Center ();
  356. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  357. subView.X = 0;
  358. subView.X = 3 + 5 + Pos.Center ();
  359. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  360. subView.X = 0;
  361. subView.X = 3 + 5 + Pos.Percent (10);
  362. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  363. subView.X = 0;
  364. subView.X = Pos.Percent (10) + Pos.Center ();
  365. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  366. subView.X = 0;
  367. // Tests nested Combine
  368. subView.X = 5 + new Pos.PosCombine (true, Pos.Right (subView2), new Pos.PosCombine (true, Pos.Center (), 9));
  369. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  370. subView.X = 0;
  371. }
  372. [Theory]
  373. [InlineData (0, 0, 0, 0, 0)]
  374. [InlineData (0, 0, 5, 0, 5)]
  375. [InlineData (0, 0, 0, 5, 0)]
  376. [InlineData (0, 0, 5, 5, 5)]
  377. [InlineData (1, 0, 5, 0, 6)]
  378. [InlineData (1, 0, 0, 5, 1)]
  379. [InlineData (1, 0, 5, 5, 6)]
  380. [InlineData (1, 1, 5, 5, 6)]
  381. [InlineData (-1, 0, 5, 0, 4)]
  382. [InlineData (-1, 0, 0, 5, 0)]
  383. [InlineData (-1, 0, 5, 5, 4)]
  384. [InlineData (-1, -1, 5, 5, 4)]
  385. public void Width_Auto_Height_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedWidth)
  386. {
  387. var superView = new View
  388. {
  389. X = 0,
  390. Y = 0,
  391. Width = Dim.Auto (),
  392. Height = 10,
  393. ValidatePosDim = true
  394. };
  395. var subView = new View
  396. {
  397. X = subX,
  398. Y = subY,
  399. Width = subWidth,
  400. Height = subHeight,
  401. ValidatePosDim = true
  402. };
  403. superView.Add (subView);
  404. superView.BeginInit ();
  405. superView.EndInit ();
  406. superView.SetRelativeLayout (new (10, 10));
  407. Assert.Equal (new Rectangle (0, 0, expectedWidth, 10), superView.Frame);
  408. }
  409. // Test that when a view has Width set to DimAuto (min: x) the width is never < x even if SetRelativeLayout is called with smaller bounds
  410. [Theory]
  411. [InlineData (0, 0)]
  412. [InlineData (1, 1)]
  413. [InlineData (3, 3)]
  414. [InlineData (4, 4)]
  415. [InlineData (5, 4)] // This is clearly invalid, but we choose to not throw but log a debug message
  416. public void Width_Auto_Min (int min, int expectedWidth)
  417. {
  418. var superView = new View
  419. {
  420. X = 0,
  421. Y = 0,
  422. Width = Dim.Auto (min: min),
  423. Height = 1,
  424. ValidatePosDim = true
  425. };
  426. superView.BeginInit ();
  427. superView.EndInit ();
  428. superView.SetRelativeLayout (new (4, 1));
  429. Assert.Equal (expectedWidth, superView.Frame.Width);
  430. }
  431. // Test Dim.Fill - Fill should not impact width of the DimAuto superview
  432. [Theory]
  433. [InlineData (0, 0, 0, 10, 10)]
  434. [InlineData (0, 1, 0, 10, 10)]
  435. [InlineData (0, 11, 0, 10, 10)]
  436. [InlineData (0, 10, 0, 10, 10)]
  437. [InlineData (0, 5, 0, 10, 10)]
  438. [InlineData (1, 5, 0, 10, 9)]
  439. [InlineData (1, 10, 0, 10, 9)]
  440. [InlineData (0, 0, 1, 10, 9)]
  441. [InlineData (0, 10, 1, 10, 9)]
  442. [InlineData (0, 5, 1, 10, 9)]
  443. [InlineData (1, 5, 1, 10, 8)]
  444. [InlineData (1, 10, 1, 10, 8)]
  445. public void Width_Fill_Fills (int subX, int superMinWidth, int fill, int expectedSuperWidth, int expectedSubWidth)
  446. {
  447. var superView = new View
  448. {
  449. X = 0,
  450. Y = 0,
  451. Width = Dim.Auto (min: superMinWidth),
  452. Height = 1,
  453. ValidatePosDim = true
  454. };
  455. var subView = new View
  456. {
  457. X = subX,
  458. Y = 0,
  459. Width = Dim.Fill (fill),
  460. Height = 1,
  461. ValidatePosDim = true
  462. };
  463. superView.Add (subView);
  464. superView.BeginInit ();
  465. superView.EndInit ();
  466. superView.SetRelativeLayout (new (10, 1));
  467. Assert.Equal (expectedSuperWidth, superView.Frame.Width);
  468. superView.LayoutSubviews ();
  469. Assert.Equal (expectedSubWidth, subView.Frame.Width);
  470. Assert.Equal (expectedSuperWidth, superView.Frame.Width);
  471. }
  472. [Theory]
  473. [InlineData (0, 1, 1)]
  474. [InlineData (1, 1, 1)]
  475. [InlineData (9, 1, 1)]
  476. [InlineData (10, 1, 1)]
  477. [InlineData (0, 10, 10)]
  478. [InlineData (1, 10, 10)]
  479. [InlineData (9, 10, 10)]
  480. [InlineData (10, 10, 10)]
  481. public void Width_Auto_Text_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth)
  482. {
  483. var superView = new View
  484. {
  485. X = 0,
  486. Y = 0,
  487. Width = 10,
  488. Height = 1,
  489. ValidatePosDim = true
  490. };
  491. var subView = new View
  492. {
  493. Text = new string ('*', textLen),
  494. X = subX,
  495. Y = 0,
  496. Width = Dim.Auto (Dim.DimAutoStyle.Text),
  497. Height = 1,
  498. ValidatePosDim = true
  499. };
  500. superView.Add (subView);
  501. superView.BeginInit ();
  502. superView.EndInit ();
  503. superView.SetRelativeLayout (superView.ContentSize);
  504. superView.LayoutSubviews ();
  505. Assert.Equal (expectedSubWidth, subView.Frame.Width);
  506. }
  507. [Theory]
  508. [InlineData (0, 1, 1)]
  509. [InlineData (1, 1, 1)]
  510. [InlineData (9, 1, 1)]
  511. [InlineData (10, 1, 1)]
  512. [InlineData (0, 10, 10)]
  513. [InlineData (1, 10, 10)]
  514. [InlineData (9, 10, 10)]
  515. [InlineData (10, 10, 10)]
  516. public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int subSubViewWidth, int expectedSubWidth)
  517. {
  518. var superView = new View
  519. {
  520. X = 0,
  521. Y = 0,
  522. Width = 10,
  523. Height = 1,
  524. ValidatePosDim = true
  525. };
  526. var subView = new View
  527. {
  528. X = subX,
  529. Y = 0,
  530. Width = Dim.Auto (Dim.DimAutoStyle.Subviews),
  531. Height = 1,
  532. ValidatePosDim = true
  533. };
  534. var subSubView = new View
  535. {
  536. X = 0,
  537. Y = 0,
  538. Width = subSubViewWidth,
  539. Height = 1,
  540. ValidatePosDim = true
  541. };
  542. subView.Add (subSubView);
  543. superView.Add (subView);
  544. superView.BeginInit ();
  545. superView.EndInit ();
  546. superView.SetRelativeLayout (superView.ContentSize);
  547. superView.LayoutSubviews ();
  548. Assert.Equal (expectedSubWidth, subView.Frame.Width);
  549. }
  550. [Fact]
  551. public void DimAuto_Text_Viewport_Stays_Set ()
  552. {
  553. var super = new View ()
  554. {
  555. Width = Dim.Fill (),
  556. Height = Dim.Fill ()
  557. };
  558. var view = new View ()
  559. {
  560. Text = "01234567",
  561. Width = Auto (DimAutoStyle.Text),
  562. Height = Auto (DimAutoStyle.Text),
  563. };
  564. super.Add (view);
  565. Rectangle expectedViewport = new (0, 0, 8, 1);
  566. Assert.Equal (expectedViewport.Size, view.ContentSize);
  567. Assert.Equal (expectedViewport, view.Frame);
  568. Assert.Equal (expectedViewport, view.Viewport);
  569. super.LayoutSubviews ();
  570. Assert.Equal (expectedViewport, view.Viewport);
  571. super.Dispose ();
  572. }
  573. // Test that changing TextFormatter does not impact View dimensions if Dim.Auto is not in play
  574. [Fact]
  575. public void DimAuto_Not_Used_TextFormatter_Does_Not_Change_View_Size ()
  576. {
  577. View view = new ()
  578. {
  579. Text = "_1234"
  580. };
  581. Assert.False (view.TextFormatter.AutoSize);
  582. Assert.Equal (Size.Empty, view.Frame.Size);
  583. view.TextFormatter.Text = "ABC";
  584. Assert.False (view.TextFormatter.AutoSize);
  585. Assert.Equal (Size.Empty, view.Frame.Size);
  586. view.TextFormatter.Alignment = TextAlignment.Justified;
  587. Assert.False (view.TextFormatter.AutoSize);
  588. Assert.Equal (Size.Empty, view.Frame.Size);
  589. view.TextFormatter.VerticalAlignment = VerticalTextAlignment.Middle;
  590. Assert.False (view.TextFormatter.AutoSize);
  591. Assert.Equal (Size.Empty, view.Frame.Size);
  592. view.TextFormatter.HotKeySpecifier = (Rune)'*';
  593. Assert.False (view.TextFormatter.AutoSize);
  594. Assert.Equal (Size.Empty, view.Frame.Size);
  595. view.TextFormatter.Text = "*ABC";
  596. Assert.False (view.TextFormatter.AutoSize);
  597. Assert.Equal (Size.Empty, view.Frame.Size);
  598. }
  599. [Fact]
  600. public void DimAuto_Not_Used_TextSettings_Do_Not_Change_View_Size ()
  601. {
  602. View view = new ()
  603. {
  604. Text = "_1234"
  605. };
  606. Assert.False (view.TextFormatter.AutoSize);
  607. Assert.Equal (Size.Empty, view.Frame.Size);
  608. view.TextAlignment = TextAlignment.Justified;
  609. Assert.False (view.TextFormatter.AutoSize);
  610. Assert.Equal (Size.Empty, view.Frame.Size);
  611. view.VerticalTextAlignment = VerticalTextAlignment.Middle;
  612. Assert.False (view.TextFormatter.AutoSize);
  613. Assert.Equal (Size.Empty, view.Frame.Size);
  614. view.HotKeySpecifier = (Rune)'*';
  615. Assert.False (view.TextFormatter.AutoSize);
  616. Assert.Equal (Size.Empty, view.Frame.Size);
  617. view.Text = "*ABC";
  618. Assert.False (view.TextFormatter.AutoSize);
  619. Assert.Equal (Size.Empty, view.Frame.Size);
  620. }
  621. [Fact]
  622. public void DimAuto_TextSettings_Change_View_Size ()
  623. {
  624. View view = new ()
  625. {
  626. Text = "_1234",
  627. Width = Dim.Auto ()
  628. };
  629. Assert.True (view.TextFormatter.AutoSize);
  630. Assert.NotEqual (Size.Empty, view.Frame.Size);
  631. view.TextAlignment = TextAlignment.Justified;
  632. Assert.True (view.TextFormatter.AutoSize);
  633. Assert.NotEqual (Size.Empty, view.Frame.Size);
  634. view = new ()
  635. {
  636. Text = "_1234",
  637. Width = Dim.Auto ()
  638. };
  639. view.VerticalTextAlignment = VerticalTextAlignment.Middle;
  640. Assert.True (view.TextFormatter.AutoSize);
  641. Assert.NotEqual (Size.Empty, view.Frame.Size);
  642. view = new ()
  643. {
  644. Text = "_1234",
  645. Width = Dim.Auto ()
  646. };
  647. view.HotKeySpecifier = (Rune)'*';
  648. Assert.True (view.TextFormatter.AutoSize);
  649. Assert.NotEqual (Size.Empty, view.Frame.Size);
  650. view = new ()
  651. {
  652. Text = "_1234",
  653. Width = Dim.Auto ()
  654. };
  655. view.Text = "*ABC";
  656. Assert.True (view.TextFormatter.AutoSize);
  657. Assert.NotEqual (Size.Empty, view.Frame.Size);
  658. }
  659. [Fact]
  660. public void DimAuto_TextFormatter_Is_Auto ()
  661. {
  662. View view = new ();
  663. Assert.False (view.TextFormatter.AutoSize);
  664. view.Width = Dim.Auto ();
  665. Assert.True (view.TextFormatter.AutoSize);
  666. view = new ();
  667. Assert.False (view.TextFormatter.AutoSize);
  668. view.Height = Dim.Auto ();
  669. Assert.True (view.TextFormatter.AutoSize);
  670. }
  671. // Test variations of Frame
  672. }