Dim.AutoTests.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. using System.Globalization;
  2. using System.Text;
  3. using Xunit.Abstractions;
  4. using static Terminal.Gui.Dim;
  5. namespace Terminal.Gui.LayoutTests;
  6. public class DimAutoTests (ITestOutputHelper output)
  7. {
  8. private readonly ITestOutputHelper _output = output;
  9. private class DimAutoTestView : View
  10. {
  11. public DimAutoTestView ()
  12. {
  13. ValidatePosDim = true;
  14. Width = Dim.Auto ();
  15. Height = Dim.Auto ();
  16. }
  17. public DimAutoTestView (Dim width, Dim height)
  18. {
  19. ValidatePosDim = true;
  20. Width = width;
  21. Height = height;
  22. }
  23. public DimAutoTestView (string text, Dim width, Dim height)
  24. {
  25. ValidatePosDim = true;
  26. Text = text;
  27. Width = width;
  28. Height = height;
  29. }
  30. }
  31. // Test min - ensure that if min is specified in the DimAuto constructor it is honored
  32. [Fact]
  33. public void Min_Is_Honored ()
  34. {
  35. var superView = new View
  36. {
  37. X = 0,
  38. Y = 0,
  39. Width = Dim.Auto (minimumContentDim: 10),
  40. Height = Dim.Auto (minimumContentDim: 10),
  41. ValidatePosDim = true
  42. };
  43. var subView = new View
  44. {
  45. X = 0,
  46. Y = 0,
  47. Width = 5,
  48. Height = 5
  49. };
  50. superView.Add (subView);
  51. superView.BeginInit ();
  52. superView.EndInit ();
  53. superView.SetRelativeLayout (new (10, 10));
  54. superView.LayoutSubviews (); // no throw
  55. Assert.Equal (10, superView.Frame.Width);
  56. Assert.Equal (10, superView.Frame.Height);
  57. }
  58. [Theory]
  59. [InlineData (0, 2, 4)]
  60. [InlineData (1, 2, 4)]
  61. [InlineData (2, 2, 4)]
  62. [InlineData (3, 2, 5)]
  63. [InlineData (1, 0, 3)]
  64. public void Min_Absolute_Is_Content_Relative (int contentSize, int minAbsolute, int expected)
  65. {
  66. var view = new View
  67. {
  68. X = 0,
  69. Y = 0,
  70. Width = Dim.Auto (minimumContentDim: minAbsolute),
  71. BorderStyle = LineStyle.Single, // a 1 thick adornment
  72. ValidatePosDim = true
  73. };
  74. view.SetContentSize (new (contentSize, 0));
  75. Assert.Equal (expected, view.Frame.Width);
  76. }
  77. [Theory]
  78. [InlineData (1, 100, 100)]
  79. [InlineData (1, 50, 50)]
  80. public void Min_Percent (int contentSize, int minPercent, int expected)
  81. {
  82. var view = new View
  83. {
  84. X = 0,
  85. Y = 0,
  86. Width = Dim.Auto (minimumContentDim: Dim.Percent (minPercent)),
  87. ValidatePosDim = true
  88. };
  89. view.SetContentSize (new (contentSize, 0));
  90. view.SetRelativeLayout (new (100, 100));
  91. Assert.Equal (expected, view.Frame.Width);
  92. }
  93. [Theory]
  94. [InlineData (1, 100, 102)]
  95. [InlineData (1, 50, 52)] // 50% of 100 is 50, but the border adds 2
  96. [InlineData (1, 30, 32)] // 30% of 100 is 30, but the border adds 2
  97. [InlineData (2, 30, 32)] // 30% of 100 is 30, but the border adds 2
  98. public void Min_Percent_Is_Content_Relative (int contentSize, int minPercent, int expected)
  99. {
  100. var view = new View
  101. {
  102. X = 0,
  103. Y = 0,
  104. Width = Dim.Auto (minimumContentDim: Dim.Percent (minPercent)),
  105. BorderStyle = LineStyle.Single, // a 1 thick adornment
  106. ValidatePosDim = true
  107. };
  108. view.SetContentSize (new (contentSize, 0));
  109. view.SetRelativeLayout (new (100, 100));
  110. Assert.Equal (expected, view.Frame.Width);
  111. }
  112. // what happens if DimAuto (min: 10) and the subview moves to a negative coord?
  113. [Fact]
  114. public void Min_Resets_If_Subview_Moves_Negative ()
  115. {
  116. var superView = new View
  117. {
  118. X = 0,
  119. Y = 0,
  120. Width = Dim.Auto (minimumContentDim: 10),
  121. Height = Dim.Auto (minimumContentDim: 10),
  122. ValidatePosDim = true
  123. };
  124. var subView = new View
  125. {
  126. X = 0,
  127. Y = 0,
  128. Width = 5,
  129. Height = 5
  130. };
  131. superView.Add (subView);
  132. superView.BeginInit ();
  133. superView.EndInit ();
  134. superView.SetRelativeLayout (new (10, 10));
  135. superView.LayoutSubviews (); // no throw
  136. Assert.Equal (10, superView.Frame.Width);
  137. Assert.Equal (10, superView.Frame.Height);
  138. subView.X = -1;
  139. subView.Y = -1;
  140. superView.SetRelativeLayout (new (10, 10));
  141. superView.LayoutSubviews (); // no throw
  142. Assert.Equal (5, subView.Frame.Width);
  143. Assert.Equal (5, subView.Frame.Height);
  144. Assert.Equal (10, superView.Frame.Width);
  145. Assert.Equal (10, superView.Frame.Height);
  146. }
  147. [Fact]
  148. public void Min_Resets_If_Subview_Shrinks ()
  149. {
  150. var superView = new View
  151. {
  152. X = 0,
  153. Y = 0,
  154. Width = Dim.Auto (minimumContentDim: 10),
  155. Height = Dim.Auto (minimumContentDim: 10),
  156. ValidatePosDim = true
  157. };
  158. var subView = new View
  159. {
  160. X = 0,
  161. Y = 0,
  162. Width = 5,
  163. Height = 5
  164. };
  165. superView.Add (subView);
  166. superView.BeginInit ();
  167. superView.EndInit ();
  168. superView.SetRelativeLayout (new (10, 10));
  169. superView.LayoutSubviews (); // no throw
  170. Assert.Equal (10, superView.Frame.Width);
  171. Assert.Equal (10, superView.Frame.Height);
  172. subView.Width = 3;
  173. subView.Height = 3;
  174. superView.SetRelativeLayout (new (10, 10));
  175. superView.LayoutSubviews (); // no throw
  176. Assert.Equal (3, subView.Frame.Width);
  177. Assert.Equal (3, subView.Frame.Height);
  178. Assert.Equal (10, superView.Frame.Width);
  179. Assert.Equal (10, superView.Frame.Height);
  180. }
  181. [Theory]
  182. [InlineData (0, 0, 0, 0, 0)]
  183. [InlineData (0, 0, 5, 0, 0)]
  184. [InlineData (0, 0, 0, 5, 5)]
  185. [InlineData (0, 0, 5, 5, 5)]
  186. [InlineData (1, 0, 5, 0, 0)]
  187. [InlineData (1, 0, 0, 5, 5)]
  188. [InlineData (1, 0, 5, 5, 5)]
  189. [InlineData (1, 1, 5, 5, 6)]
  190. [InlineData (-1, 0, 5, 0, 0)]
  191. [InlineData (-1, 0, 0, 5, 5)]
  192. [InlineData (-1, 0, 5, 5, 5)]
  193. [InlineData (-1, -1, 5, 5, 4)]
  194. public void Height_Auto_Width_Absolute_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedHeight)
  195. {
  196. var superView = new View
  197. {
  198. X = 0,
  199. Y = 0,
  200. Width = 10,
  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, 10, expectedHeight), superView.Frame);
  217. }
  218. [Fact]
  219. public void NoSubViews_Does_Nothing ()
  220. {
  221. var superView = new View
  222. {
  223. X = 0,
  224. Y = 0,
  225. Width = Dim.Auto (),
  226. Height = Dim.Auto (),
  227. ValidatePosDim = true
  228. };
  229. superView.BeginInit ();
  230. superView.EndInit ();
  231. superView.SetRelativeLayout (new (10, 10));
  232. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  233. superView.SetRelativeLayout (new (10, 10));
  234. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  235. }
  236. [Fact]
  237. public void NoSubViews_Does_Nothing_Vertical ()
  238. {
  239. var superView = new View
  240. {
  241. X = 0,
  242. Y = 0,
  243. Width = Dim.Auto (),
  244. Height = Dim.Auto (),
  245. TextDirection = TextDirection.TopBottom_LeftRight,
  246. ValidatePosDim = true
  247. };
  248. superView.BeginInit ();
  249. superView.EndInit ();
  250. superView.SetRelativeLayout (new (10, 10));
  251. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  252. superView.SetRelativeLayout (new (10, 10));
  253. Assert.Equal (new Rectangle (0, 0, 0, 0), superView.Frame);
  254. }
  255. [Theory]
  256. [InlineData (0, 0, 0, 0, 0, 0)]
  257. [InlineData (0, 0, 5, 0, 5, 0)]
  258. [InlineData (0, 0, 0, 5, 0, 5)]
  259. [InlineData (0, 0, 5, 5, 5, 5)]
  260. [InlineData (1, 0, 5, 0, 6, 0)]
  261. [InlineData (1, 0, 0, 5, 1, 5)]
  262. [InlineData (1, 0, 5, 5, 6, 5)]
  263. [InlineData (1, 1, 5, 5, 6, 6)]
  264. [InlineData (-1, 0, 5, 0, 4, 0)]
  265. [InlineData (-1, 0, 0, 5, 0, 5)]
  266. [InlineData (-1, 0, 5, 5, 4, 5)]
  267. [InlineData (-1, -1, 5, 5, 4, 4)]
  268. public void SubView_Changes_SuperView_Size (int subX, int subY, int subWidth, int subHeight, int expectedWidth, int expectedHeight)
  269. {
  270. var superView = new View
  271. {
  272. X = 0,
  273. Y = 0,
  274. Width = Dim.Auto (),
  275. Height = Dim.Auto (),
  276. ValidatePosDim = true
  277. };
  278. var subView = new View
  279. {
  280. X = subX,
  281. Y = subY,
  282. Width = subWidth,
  283. Height = subHeight,
  284. ValidatePosDim = true
  285. };
  286. superView.Add (subView);
  287. superView.BeginInit ();
  288. superView.EndInit ();
  289. superView.SetRelativeLayout (new (10, 10));
  290. Assert.Equal (new Rectangle (0, 0, expectedWidth, expectedHeight), superView.Frame);
  291. }
  292. // Test validation
  293. [Fact]
  294. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims ()
  295. {
  296. var superView = new View
  297. {
  298. X = 0,
  299. Y = 0,
  300. Width = Dim.Auto (),
  301. Height = Dim.Auto (),
  302. ValidatePosDim = true
  303. };
  304. var subView = new View
  305. {
  306. X = 0,
  307. Y = 0,
  308. Width = Dim.Fill (),
  309. Height = 10,
  310. ValidatePosDim = true
  311. };
  312. superView.BeginInit ();
  313. superView.EndInit ();
  314. superView.Add (subView);
  315. subView.Width = 10;
  316. superView.Add (subView);
  317. superView.SetRelativeLayout (new (10, 10));
  318. superView.LayoutSubviews (); // no throw
  319. subView.Width = Dim.Fill ();
  320. superView.SetRelativeLayout (new (0, 0));
  321. subView.Width = 10;
  322. subView.Height = Dim.Fill ();
  323. superView.SetRelativeLayout (new (0, 0));
  324. subView.Height = 10;
  325. subView.Height = Dim.Percent (50);
  326. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  327. subView.Height = 10;
  328. subView.X = Pos.Center ();
  329. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  330. subView.X = 0;
  331. subView.Y = Pos.Center ();
  332. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  333. subView.Y = 0;
  334. subView.Width = 10;
  335. subView.Height = 10;
  336. subView.X = 0;
  337. subView.Y = 0;
  338. superView.SetRelativeLayout (new (0, 0));
  339. superView.LayoutSubviews ();
  340. }
  341. // Test validation
  342. [Fact]
  343. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Dims_Combine ()
  344. {
  345. var superView = new View
  346. {
  347. X = 0,
  348. Y = 0,
  349. Width = Dim.Auto (),
  350. Height = Dim.Auto (),
  351. ValidatePosDim = true
  352. };
  353. var subView = new View
  354. {
  355. X = 0,
  356. Y = 0,
  357. Width = 10,
  358. Height = 10
  359. };
  360. var subView2 = new View
  361. {
  362. X = 0,
  363. Y = 0,
  364. Width = 10,
  365. Height = 10
  366. };
  367. superView.Add (subView, subView2);
  368. superView.BeginInit ();
  369. superView.EndInit ();
  370. superView.SetRelativeLayout (new (0, 0));
  371. superView.LayoutSubviews (); // no throw
  372. subView.Height = Dim.Fill () + 3;
  373. superView.SetRelativeLayout (new (0, 0));
  374. subView.Height = 0;
  375. subView.Height = 3 + Dim.Fill ();
  376. superView.SetRelativeLayout (new (0, 0));
  377. subView.Height = 0;
  378. subView.Height = 3 + 5 + Dim.Fill ();
  379. superView.SetRelativeLayout (new (0, 0));
  380. subView.Height = 0;
  381. subView.Height = 3 + 5 + Dim.Percent (10);
  382. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  383. subView.Height = 0;
  384. // Tests nested Combine
  385. subView.Height = 5 + new DimCombine (AddOrSubtract.Add, 3, new DimCombine (AddOrSubtract.Add, Dim.Percent (10), 9));
  386. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  387. }
  388. [Fact]
  389. public void ValidatePosDim_True_Throws_When_SubView_Uses_SuperView_Pos_Combine ()
  390. {
  391. var superView = new View
  392. {
  393. X = 0,
  394. Y = 0,
  395. Width = Dim.Auto (),
  396. Height = Dim.Auto (),
  397. ValidatePosDim = true
  398. };
  399. var subView = new View
  400. {
  401. X = 0,
  402. Y = 0,
  403. Width = 10,
  404. Height = 10
  405. };
  406. var subView2 = new View
  407. {
  408. X = 0,
  409. Y = 0,
  410. Width = 10,
  411. Height = 10
  412. };
  413. superView.Add (subView, subView2);
  414. superView.BeginInit ();
  415. superView.EndInit ();
  416. superView.SetRelativeLayout (new (0, 0));
  417. superView.LayoutSubviews (); // no throw
  418. subView.X = Pos.Right (subView2);
  419. superView.SetRelativeLayout (new (0, 0));
  420. superView.LayoutSubviews (); // no throw
  421. subView.X = Pos.Right (subView2) + 3;
  422. superView.SetRelativeLayout (new (0, 0)); // no throw
  423. superView.LayoutSubviews (); // no throw
  424. subView.X = new PosCombine (AddOrSubtract.Add, Pos.Right (subView2), new PosCombine (AddOrSubtract.Add, 7, 9));
  425. superView.SetRelativeLayout (new (0, 0)); // no throw
  426. subView.X = Pos.Center () + 3;
  427. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  428. subView.X = 0;
  429. subView.X = 3 + Pos.Center ();
  430. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  431. subView.X = 0;
  432. subView.X = 3 + 5 + Pos.Center ();
  433. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  434. subView.X = 0;
  435. subView.X = 3 + 5 + Pos.Percent (10);
  436. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  437. subView.X = 0;
  438. subView.X = Pos.Percent (10) + Pos.Center ();
  439. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  440. subView.X = 0;
  441. // Tests nested Combine
  442. subView.X = 5 + new PosCombine (AddOrSubtract.Add, Pos.Right (subView2), new PosCombine (AddOrSubtract.Add, Pos.Center (), 9));
  443. Assert.Throws<InvalidOperationException> (() => superView.SetRelativeLayout (new (0, 0)));
  444. subView.X = 0;
  445. }
  446. [Theory]
  447. [InlineData (0, 0, 0, 0, 0)]
  448. [InlineData (0, 0, 5, 0, 5)]
  449. [InlineData (0, 0, 0, 5, 0)]
  450. [InlineData (0, 0, 5, 5, 5)]
  451. [InlineData (1, 0, 5, 0, 6)]
  452. [InlineData (1, 0, 0, 5, 1)]
  453. [InlineData (1, 0, 5, 5, 6)]
  454. [InlineData (1, 1, 5, 5, 6)]
  455. [InlineData (-1, 0, 5, 0, 4)]
  456. [InlineData (-1, 0, 0, 5, 0)]
  457. [InlineData (-1, 0, 5, 5, 4)]
  458. [InlineData (-1, -1, 5, 5, 4)]
  459. public void Width_Auto_Height_Absolute_NotChanged (int subX, int subY, int subWidth, int subHeight, int expectedWidth)
  460. {
  461. var superView = new View
  462. {
  463. X = 0,
  464. Y = 0,
  465. Width = Dim.Auto (),
  466. Height = 10,
  467. ValidatePosDim = true
  468. };
  469. var subView = new View
  470. {
  471. X = subX,
  472. Y = subY,
  473. Width = subWidth,
  474. Height = subHeight,
  475. ValidatePosDim = true
  476. };
  477. superView.Add (subView);
  478. superView.BeginInit ();
  479. superView.EndInit ();
  480. superView.SetRelativeLayout (new (10, 10));
  481. Assert.Equal (new Rectangle (0, 0, expectedWidth, 10), superView.Frame);
  482. }
  483. // Test that when a view has Width set to DimAuto (min: x)
  484. // the width is never < x even if SetRelativeLayout is called with smaller bounds
  485. [Theory]
  486. [InlineData (0, 0)]
  487. [InlineData (1, 1)]
  488. [InlineData (3, 3)]
  489. [InlineData (4, 4)]
  490. [InlineData (5, 5)] // No reason why it can exceed container
  491. public void Width_Auto_Min_Honored (int min, int expectedWidth)
  492. {
  493. var superView = new View
  494. {
  495. X = 0,
  496. Y = 0,
  497. Width = Dim.Auto (minimumContentDim: min),
  498. Height = 1,
  499. ValidatePosDim = true
  500. };
  501. superView.BeginInit ();
  502. superView.EndInit ();
  503. superView.SetRelativeLayout (new (4, 1));
  504. Assert.Equal (expectedWidth, superView.Frame.Width);
  505. }
  506. //// Test Dim.Fill - Fill should not impact width of the DimAuto superview
  507. //[Theory]
  508. //[InlineData (0, 0, 0, 10, 10)]
  509. //[InlineData (0, 1, 0, 10, 10)]
  510. //[InlineData (0, 11, 0, 10, 10)]
  511. //[InlineData (0, 10, 0, 10, 10)]
  512. //[InlineData (0, 5, 0, 10, 10)]
  513. //[InlineData (1, 5, 0, 10, 9)]
  514. //[InlineData (1, 10, 0, 10, 9)]
  515. //[InlineData (0, 0, 1, 10, 9)]
  516. //[InlineData (0, 10, 1, 10, 9)]
  517. //[InlineData (0, 5, 1, 10, 9)]
  518. //[InlineData (1, 5, 1, 10, 8)]
  519. //[InlineData (1, 10, 1, 10, 8)]
  520. //public void Width_Fill_Fills (int subX, int superMinWidth, int fill, int expectedSuperWidth, int expectedSubWidth)
  521. //{
  522. // var superView = new View
  523. // {
  524. // X = 0,
  525. // Y = 0,
  526. // Width = Dim.Auto (minimumContentDim: superMinWidth),
  527. // Height = 1,
  528. // ValidatePosDim = true
  529. // };
  530. // var subView = new View
  531. // {
  532. // X = subX,
  533. // Y = 0,
  534. // Width = Dim.Fill (fill),
  535. // Height = 1,
  536. // ValidatePosDim = true
  537. // };
  538. // superView.Add (subView);
  539. // superView.BeginInit ();
  540. // superView.EndInit ();
  541. // superView.SetRelativeLayout (new (10, 1));
  542. // Assert.Equal (expectedSuperWidth, superView.Frame.Width);
  543. // superView.LayoutSubviews ();
  544. // Assert.Equal (expectedSubWidth, subView.Frame.Width);
  545. // Assert.Equal (expectedSuperWidth, superView.Frame.Width);
  546. //}
  547. [Theory]
  548. [InlineData (0, 1, 1)]
  549. [InlineData (1, 1, 1)]
  550. [InlineData (9, 1, 1)]
  551. [InlineData (10, 1, 1)]
  552. [InlineData (0, 10, 10)]
  553. [InlineData (1, 10, 10)]
  554. [InlineData (9, 10, 10)]
  555. [InlineData (10, 10, 10)]
  556. public void Width_Auto_Text_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth)
  557. {
  558. var superView = new View
  559. {
  560. X = 0,
  561. Y = 0,
  562. Width = 10,
  563. Height = 1,
  564. ValidatePosDim = true
  565. };
  566. var subView = new View
  567. {
  568. Text = new string ('*', textLen),
  569. X = subX,
  570. Y = 0,
  571. Width = Dim.Auto (DimAutoStyle.Text),
  572. Height = 1,
  573. ValidatePosDim = true
  574. };
  575. superView.Add (subView);
  576. superView.BeginInit ();
  577. superView.EndInit ();
  578. superView.SetRelativeLayout (superView.GetContentSize ());
  579. superView.LayoutSubviews ();
  580. Assert.Equal (expectedSubWidth, subView.Frame.Width);
  581. }
  582. [Theory]
  583. [InlineData (0, 1, 1)]
  584. [InlineData (1, 1, 1)]
  585. [InlineData (9, 1, 1)]
  586. [InlineData (10, 1, 1)]
  587. [InlineData (0, 10, 10)]
  588. [InlineData (1, 10, 10)]
  589. [InlineData (9, 10, 10)]
  590. [InlineData (10, 10, 10)]
  591. public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int subSubViewWidth, int expectedSubWidth)
  592. {
  593. var superView = new View
  594. {
  595. X = 0,
  596. Y = 0,
  597. Width = 10,
  598. Height = 1,
  599. ValidatePosDim = true
  600. };
  601. var subView = new View
  602. {
  603. X = subX,
  604. Y = 0,
  605. Width = Dim.Auto (DimAutoStyle.Content),
  606. Height = 1,
  607. ValidatePosDim = true
  608. };
  609. var subSubView = new View
  610. {
  611. X = 0,
  612. Y = 0,
  613. Width = subSubViewWidth,
  614. Height = 1,
  615. ValidatePosDim = true
  616. };
  617. subView.Add (subSubView);
  618. superView.Add (subView);
  619. superView.BeginInit ();
  620. superView.EndInit ();
  621. superView.SetRelativeLayout (superView.GetContentSize ());
  622. superView.LayoutSubviews ();
  623. Assert.Equal (expectedSubWidth, subView.Frame.Width);
  624. }
  625. [Fact]
  626. public void DimAutoStyle_Text_Viewport_Stays_Set ()
  627. {
  628. var super = new View ()
  629. {
  630. Width = Dim.Fill (),
  631. Height = Dim.Fill ()
  632. };
  633. var view = new View ()
  634. {
  635. Text = "01234567",
  636. Width = Auto (DimAutoStyle.Text),
  637. Height = Auto (DimAutoStyle.Text),
  638. };
  639. super.Add (view);
  640. Rectangle expectedViewport = new (0, 0, 8, 1);
  641. Assert.Equal (expectedViewport.Size, view.GetContentSize ());
  642. Assert.Equal (expectedViewport, view.Frame);
  643. Assert.Equal (expectedViewport, view.Viewport);
  644. super.LayoutSubviews ();
  645. Assert.Equal (expectedViewport, view.Viewport);
  646. super.Dispose ();
  647. }
  648. // TextFormatter.Size normally tracks ContentSize, but with DimAuto, tracks the text size
  649. [Theory]
  650. [InlineData ("", 0, 0)]
  651. [InlineData (" ", 1, 1)]
  652. [InlineData ("01234", 5, 1)]
  653. public void DimAutoStyle_Text_TextFormatter_Size_Ignores_ContentSize (string text, int expectedW, int expectedH)
  654. {
  655. var view = new View ();
  656. view.Width = Auto (DimAutoStyle.Text);
  657. view.Height = Auto (DimAutoStyle.Text);
  658. view.SetContentSize (new (1, 1));
  659. view.Text = text;
  660. Assert.Equal (new (expectedW, expectedH), view.TextFormatter.Size);
  661. }
  662. // Test that changing TextFormatter does not impact View dimensions if Dim.Auto is not in play
  663. [Fact]
  664. public void Not_Used_TextFormatter_Does_Not_Change_View_Size ()
  665. {
  666. View view = new ()
  667. {
  668. Text = "_1234"
  669. };
  670. Assert.False (view.TextFormatter.AutoSize);
  671. Assert.Equal (Size.Empty, view.Frame.Size);
  672. view.TextFormatter.Text = "ABC";
  673. Assert.False (view.TextFormatter.AutoSize);
  674. Assert.Equal (Size.Empty, view.Frame.Size);
  675. view.TextFormatter.Alignment = Alignment.Fill;
  676. Assert.False (view.TextFormatter.AutoSize);
  677. Assert.Equal (Size.Empty, view.Frame.Size);
  678. view.TextFormatter.VerticalAlignment = Alignment.Center;
  679. Assert.False (view.TextFormatter.AutoSize);
  680. Assert.Equal (Size.Empty, view.Frame.Size);
  681. view.TextFormatter.HotKeySpecifier = (Rune)'*';
  682. Assert.False (view.TextFormatter.AutoSize);
  683. Assert.Equal (Size.Empty, view.Frame.Size);
  684. view.TextFormatter.Text = "*ABC";
  685. Assert.False (view.TextFormatter.AutoSize);
  686. Assert.Equal (Size.Empty, view.Frame.Size);
  687. }
  688. [Fact]
  689. public void Not_Used_TextSettings_Do_Not_Change_View_Size ()
  690. {
  691. View view = new ()
  692. {
  693. Text = "_1234"
  694. };
  695. Assert.False (view.TextFormatter.AutoSize);
  696. Assert.Equal (Size.Empty, view.Frame.Size);
  697. view.TextAlignment = Alignment.Fill;
  698. Assert.False (view.TextFormatter.AutoSize);
  699. Assert.Equal (Size.Empty, view.Frame.Size);
  700. view.VerticalTextAlignment = Alignment.Center;
  701. Assert.False (view.TextFormatter.AutoSize);
  702. Assert.Equal (Size.Empty, view.Frame.Size);
  703. view.HotKeySpecifier = (Rune)'*';
  704. Assert.False (view.TextFormatter.AutoSize);
  705. Assert.Equal (Size.Empty, view.Frame.Size);
  706. view.Text = "*ABC";
  707. Assert.False (view.TextFormatter.AutoSize);
  708. Assert.Equal (Size.Empty, view.Frame.Size);
  709. }
  710. [Fact]
  711. public void TextFormatter_Settings_Change_View_Size ()
  712. {
  713. View view = new ()
  714. {
  715. Text = "_1234",
  716. Width = Dim.Auto ()
  717. };
  718. Assert.False (view.TextFormatter.AutoSize);
  719. Assert.NotEqual (Size.Empty, view.Frame.Size);
  720. view.TextAlignment = Alignment.Fill;
  721. Assert.False (view.TextFormatter.AutoSize);
  722. Assert.NotEqual (Size.Empty, view.Frame.Size);
  723. view = new ()
  724. {
  725. Text = "_1234",
  726. Width = Dim.Auto ()
  727. };
  728. view.VerticalTextAlignment = Alignment.Center;
  729. Assert.False (view.TextFormatter.AutoSize);
  730. Assert.NotEqual (Size.Empty, view.Frame.Size);
  731. view = new ()
  732. {
  733. Text = "_1234",
  734. Width = Dim.Auto ()
  735. };
  736. view.HotKeySpecifier = (Rune)'*';
  737. Assert.False (view.TextFormatter.AutoSize);
  738. Assert.NotEqual (Size.Empty, view.Frame.Size);
  739. view = new ()
  740. {
  741. Text = "_1234",
  742. Width = Dim.Auto ()
  743. };
  744. view.Text = "*ABC";
  745. Assert.False (view.TextFormatter.AutoSize);
  746. Assert.NotEqual (Size.Empty, view.Frame.Size);
  747. }
  748. // Ensure TextFormatter.AutoSize is never used for View.Text
  749. [Fact]
  750. public void TextFormatter_Is_Not_Auto ()
  751. {
  752. View view = new ();
  753. Assert.False (view.TextFormatter.AutoSize);
  754. view.Width = Dim.Auto ();
  755. Assert.False (view.TextFormatter.AutoSize);
  756. view = new ();
  757. Assert.False (view.TextFormatter.AutoSize);
  758. view.Height = Dim.Auto ();
  759. Assert.False (view.TextFormatter.AutoSize);
  760. }
  761. [Theory]
  762. [InlineData ("1234", 4)]
  763. [InlineData ("_1234", 4)]
  764. public void Width_Auto_HotKey_TextFormatter_Size_Correct (string text, int expected)
  765. {
  766. View view = new ()
  767. {
  768. Text = text,
  769. Height = 1,
  770. Width = Dim.Auto ()
  771. };
  772. Assert.Equal (new (expected, 1), view.TextFormatter.Size);
  773. }
  774. [Theory]
  775. [InlineData ("1234", 4)]
  776. [InlineData ("_1234", 4)]
  777. public void Height_Auto_HotKey_TextFormatter_Size_Correct (string text, int expected)
  778. {
  779. View view = new ()
  780. {
  781. HotKeySpecifier = (Rune)'_',
  782. Text = text,
  783. Width = Auto (),
  784. Height = 1,
  785. };
  786. Assert.Equal (new (expected, 1), view.TextFormatter.Size);
  787. view = new ()
  788. {
  789. HotKeySpecifier = (Rune)'_',
  790. TextDirection = TextDirection.TopBottom_LeftRight,
  791. Text = text,
  792. Width = 1,
  793. Height = Auto (),
  794. };
  795. Assert.Equal (new (1, expected), view.TextFormatter.Size);
  796. }
  797. [SetupFakeDriver]
  798. [Fact]
  799. public void Change_To_Non_Auto_Resets_ContentSize ()
  800. {
  801. View view = new ()
  802. {
  803. Width = Auto (),
  804. Height = Auto (),
  805. Text = "01234"
  806. };
  807. Assert.Equal (new Rectangle (0, 0, 5, 1), view.Frame);
  808. Assert.Equal (new Size (5, 1), view.GetContentSize ());
  809. // Change text to a longer string
  810. view.Text = "0123456789";
  811. Assert.Equal (new Rectangle (0, 0, 10, 1), view.Frame);
  812. Assert.Equal (new Size (10, 1), view.GetContentSize ());
  813. // If ContentSize was reset, these should cause it to update
  814. view.Width = 5;
  815. view.Height = 1;
  816. Assert.Equal (new Size (5, 1), view.GetContentSize ());
  817. }
  818. // DimAutoStyle.Content tests
  819. [Fact]
  820. public void DimAutoStyle_Content_UsesContentSize_WhenSet ()
  821. {
  822. var view = new View ();
  823. view.SetContentSize (new (10, 5));
  824. var dim = Dim.Auto (DimAutoStyle.Content);
  825. int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
  826. Assert.Equal (10, calculatedWidth);
  827. }
  828. [Fact]
  829. public void DimAutoStyle_Content_IgnoresSubviews_When_ContentSize_Is_Set ()
  830. {
  831. var view = new View ();
  832. var subview = new View () {
  833. Frame = new Rectangle (50, 50, 1, 1)
  834. };
  835. view.SetContentSize (new (10, 5));
  836. var dim = Dim.Auto (DimAutoStyle.Content);
  837. int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
  838. Assert.Equal (10, calculatedWidth);
  839. }
  840. [Fact]
  841. public void DimAutoStyle_Content_IgnoresText_WhenContentSizeNotSet ()
  842. {
  843. var view = new View () { Text = "This is a test" };
  844. var dim = Dim.Auto (DimAutoStyle.Content);
  845. int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
  846. Assert.Equal (0, calculatedWidth); // Assuming 0 is the default when no ContentSize or Subviews are set
  847. }
  848. [Fact]
  849. public void DimAutoStyle_Content_UsesLargestSubview_WhenContentSizeNotSet ()
  850. {
  851. var view = new View ();
  852. view.Add (new View () { Frame = new Rectangle (0, 0, 5, 5) }); // Smaller subview
  853. view.Add (new View () { Frame = new Rectangle (0, 0, 10, 10) }); // Larger subview
  854. var dim = Dim.Auto (DimAutoStyle.Content);
  855. int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
  856. Assert.Equal (10, calculatedWidth); // Expecting the size of the largest subview
  857. }
  858. // All the Dim types
  859. [Theory]
  860. [InlineData (0, 15, 15)]
  861. [InlineData (1, 15, 16)]
  862. [InlineData (-1, 15, 14)]
  863. public void With_Subview_Using_DimAbsolute (int subViewOffset, int dimAbsoluteSize, int expectedSize)
  864. {
  865. var view = new View ();
  866. var subview = new View ()
  867. {
  868. X = subViewOffset,
  869. Y = subViewOffset,
  870. Width = Dim.Absolute (dimAbsoluteSize),
  871. Height = Dim.Absolute (dimAbsoluteSize)
  872. };
  873. view.Add (subview);
  874. var dim = Dim.Auto (DimAutoStyle.Content);
  875. int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
  876. int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height);
  877. Assert.Equal (expectedSize, calculatedWidth);
  878. Assert.Equal (expectedSize, calculatedHeight);
  879. }
  880. [Theory]
  881. [InlineData (0, 50, 50)]
  882. [InlineData (1, 50, 51)]
  883. [InlineData (0, 25, 25)]
  884. [InlineData (-1, 50, 49)]
  885. public void With_Subview_Using_DimFactor (int subViewOffset, int dimFactor, int expectedSize)
  886. {
  887. var view = new View () { Width = 100, Height = 100 };
  888. var subview = new View ()
  889. {
  890. X = subViewOffset,
  891. Y = subViewOffset,
  892. Width = Dim.Percent (dimFactor),
  893. Height = Dim.Percent (dimFactor)
  894. };
  895. view.Add (subview);
  896. subview.SetRelativeLayout (new (100, 100));
  897. var dim = Dim.Auto (DimAutoStyle.Content);
  898. int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
  899. int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height);
  900. Assert.Equal (expectedSize, calculatedWidth);
  901. Assert.Equal (expectedSize, calculatedHeight);
  902. }
  903. [Theory]
  904. [InlineData (0, 0, 100)]
  905. [InlineData (1, 0, 100)]
  906. [InlineData (0, 1, 100)]
  907. [InlineData (1, 1, 100)]
  908. public void With_Subview_Using_DimFill (int subViewOffset, int dimFillMargin, int expectedSize)
  909. {
  910. // BUGBUG: THis test is totally bogus. Dim.Fill isnot working right yet.
  911. var view = new View ()
  912. {
  913. Width = Dim.Auto (DimAutoStyle.Content, minimumContentDim: 100, maximumContentDim: 100),
  914. Height = Dim.Auto (DimAutoStyle.Content, minimumContentDim: 100, maximumContentDim: 100),
  915. };
  916. var subview = new View ()
  917. {
  918. X = subViewOffset,
  919. Y = subViewOffset,
  920. Width = Dim.Fill (dimFillMargin),
  921. Height = Dim.Fill (dimFillMargin)
  922. };
  923. view.Add (subview);
  924. //view.LayoutSubviews ();
  925. view.SetRelativeLayout(new (200,200));
  926. Assert.Equal (expectedSize, view.Frame.Width);
  927. }
  928. [Fact]
  929. public void With_Subview_Using_DimFunc ()
  930. {
  931. var view = new View ();
  932. var subview = new View () { Width = Dim.Func (() => 20), Height = Dim.Func (() => 25) };
  933. view.Add (subview);
  934. subview.SetRelativeLayout (new (100, 100));
  935. var dim = Dim.Auto (DimAutoStyle.Content);
  936. int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
  937. int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height);
  938. Assert.Equal (20, calculatedWidth);
  939. Assert.Equal (25, calculatedHeight);
  940. }
  941. [Fact]
  942. public void With_Subview_Using_DimView ()
  943. {
  944. var view = new View ();
  945. var subview = new View () { Width = 30, Height = 40 };
  946. var subSubview = new View () { Width = Dim.Width (subview), Height = Dim.Height (subview) };
  947. view.Add (subview);
  948. view.Add (subSubview);
  949. subview.SetRelativeLayout (new (100, 100));
  950. var dim = Dim.Auto (DimAutoStyle.Content);
  951. int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
  952. int calculatedHeight = dim.Calculate (0, 100, view, Dimension.Height);
  953. // Expecting the size to match the subview, which is the largest
  954. Assert.Equal (30, calculatedWidth);
  955. Assert.Equal (40, calculatedHeight);
  956. }
  957. // Testing all Pos combinations
  958. [Fact]
  959. public void With_Subview_At_PosAt ()
  960. {
  961. var view = new View ();
  962. var subview = new View () { X = Pos.Absolute (10), Y = Pos.Absolute (5), Width = 20, Height = 10 };
  963. view.Add (subview);
  964. var dimWidth = Dim.Auto ();
  965. var dimHeight = Dim.Auto ();
  966. int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width);
  967. int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height);
  968. // Expecting the size to include the subview's position and size
  969. Assert.Equal (30, calculatedWidth); // 10 (X position) + 20 (Width)
  970. Assert.Equal (15, calculatedHeight); // 5 (Y position) + 10 (Height)
  971. }
  972. [Fact (Skip = "TextOnly")]
  973. public void With_Subview_At_PosPercent ()
  974. {
  975. var view = new View () { Width = 100, Height = 100 };
  976. var subview = new View () { X = Pos.Percent (50), Y = Pos.Percent (50), Width = 20, Height = 10 };
  977. view.Add (subview);
  978. var dimWidth = Dim.Auto ();
  979. var dimHeight = Dim.Auto ();
  980. // Assuming the calculation is done after layout
  981. int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width);
  982. int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height);
  983. // Expecting the size to include the subview's position as a percentage of the parent view's size plus the subview's size
  984. Assert.Equal (70, calculatedWidth); // 50% of 100 (Width) + 20
  985. Assert.Equal (60, calculatedHeight); // 50% of 100 (Height) + 10
  986. }
  987. [Fact (Skip = "TextOnly")]
  988. public void With_Subview_At_PosCenter ()
  989. {
  990. var view = new View () { Width = 100, Height = 100 };
  991. var subview = new View () { X = Pos.Center (), Y = Pos.Center (), Width = 20, Height = 10 };
  992. view.Add (subview);
  993. var dimWidth = Dim.Auto ();
  994. var dimHeight = Dim.Auto ();
  995. // Assuming the calculation is done after layout
  996. int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width);
  997. int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height);
  998. // Expecting the size to include the subview's position at the center of the parent view plus the subview's size
  999. Assert.Equal (70, calculatedWidth); // Centered in 100 (Width) + 20
  1000. Assert.Equal (60, calculatedHeight); // Centered in 100 (Height) + 10
  1001. }
  1002. [Fact]
  1003. public void With_Subview_At_PosAnchorEnd ()
  1004. {
  1005. var dimWidth = Dim.Auto ();
  1006. var dimHeight = Dim.Auto ();
  1007. var view = new View ()
  1008. {
  1009. Width = dimWidth,
  1010. Height = dimHeight
  1011. };
  1012. var subview = new View ()
  1013. {
  1014. X = Pos.AnchorEnd (),
  1015. Y = Pos.AnchorEnd (),
  1016. Width = 20,
  1017. Height = 10
  1018. };
  1019. view.Add (subview);
  1020. // Assuming the calculation is done after layout
  1021. int calculatedWidth = dimWidth.Calculate (0, 100, view, Dimension.Width);
  1022. int calculatedHeight = dimHeight.Calculate (0, 100, view, Dimension.Height);
  1023. // Expecting the size to include the subview's position at the end of the parent view minus the offset plus the subview's size
  1024. Assert.Equal (20, calculatedWidth);
  1025. Assert.Equal (10, calculatedHeight);
  1026. }
  1027. [Fact]
  1028. public void DimAutoStyle_Text_Pos_AnchorEnd_Locates_Correctly ()
  1029. {
  1030. DimAutoTestView view = new ("01234", Auto (DimAutoStyle.Text), Auto (DimAutoStyle.Text));
  1031. view.SetRelativeLayout (new (10, 10));
  1032. Assert.Equal (new (5, 1), view.Frame.Size);
  1033. Assert.Equal (new (0, 0), view.Frame.Location);
  1034. view.X = 0;
  1035. view.Y = Pos.AnchorEnd (1);
  1036. view.SetRelativeLayout (new (10, 10));
  1037. Assert.Equal (new (5, 1), view.Frame.Size);
  1038. Assert.Equal (new (0, 9), view.Frame.Location);
  1039. view.Y = Pos.AnchorEnd ();
  1040. view.SetRelativeLayout (new (10, 10));
  1041. Assert.Equal (new (5, 1), view.Frame.Size);
  1042. Assert.Equal (new (0, 9), view.Frame.Location);
  1043. view.Y = Pos.AnchorEnd () - 1;
  1044. view.SetRelativeLayout (new (10, 10));
  1045. Assert.Equal (new (5, 1), view.Frame.Size);
  1046. Assert.Equal (new (0, 8), view.Frame.Location);
  1047. }
  1048. [Fact]
  1049. public void DimAutoStyle_Content_Pos_AnchorEnd_Locates_Correctly ()
  1050. {
  1051. DimAutoTestView view = new (Auto (DimAutoStyle.Content), Auto (DimAutoStyle.Content));
  1052. View subView = new ()
  1053. {
  1054. Width = 5,
  1055. Height = 1
  1056. };
  1057. view.Add (subView);
  1058. view.SetRelativeLayout (new (10, 10));
  1059. Assert.Equal (new (5, 1), view.Frame.Size);
  1060. Assert.Equal (new (0, 0), view.Frame.Location);
  1061. view.X = 0;
  1062. view.Y = Pos.AnchorEnd (1);
  1063. view.SetRelativeLayout (new (10, 10));
  1064. Assert.Equal (new (5, 1), view.Frame.Size);
  1065. Assert.Equal (new (0, 9), view.Frame.Location);
  1066. view.Y = Pos.AnchorEnd ();
  1067. view.SetRelativeLayout (new (10, 10));
  1068. Assert.Equal (new (5, 1), view.Frame.Size);
  1069. Assert.Equal (new (0, 9), view.Frame.Location);
  1070. view.Y = Pos.AnchorEnd () - 1;
  1071. view.SetRelativeLayout (new (10, 10));
  1072. Assert.Equal (new (5, 1), view.Frame.Size);
  1073. Assert.Equal (new (0, 8), view.Frame.Location);
  1074. }
  1075. [Theory]
  1076. [InlineData ("01234", 5, 5)]
  1077. [InlineData ("01234", 6, 6)]
  1078. [InlineData ("01234", 4, 5)]
  1079. [InlineData ("01234", 0, 5)]
  1080. [InlineData ("", 5, 5)]
  1081. [InlineData ("", 0, 0)]
  1082. public void DimAutoStyle_Auto_Larger_Wins (string text, int dimension, int expected)
  1083. {
  1084. View view = new ()
  1085. {
  1086. Width = Auto (),
  1087. Text = text
  1088. };
  1089. View subView = new ()
  1090. {
  1091. Width = dimension,
  1092. };
  1093. view.Add (subView);
  1094. view.SetRelativeLayout (new (10, 10));
  1095. Assert.Equal (expected, view.Frame.Width);
  1096. }
  1097. [Fact]
  1098. public void DimAutoStyle_Content_UsesContentSize_If_No_Subviews ()
  1099. {
  1100. DimAutoTestView view = new (Auto (DimAutoStyle.Content), Auto (DimAutoStyle.Content));
  1101. view.SetContentSize (new (5, 5));
  1102. view.SetRelativeLayout (new (10, 10));
  1103. Assert.Equal (new (5, 5), view.Frame.Size);
  1104. }
  1105. // Test variations of Frame
  1106. }