Dim.Tests.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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 DimTests
  7. {
  8. private readonly ITestOutputHelper _output;
  9. public DimTests (ITestOutputHelper output)
  10. {
  11. _output = output;
  12. Console.OutputEncoding = Encoding.Default;
  13. // Change current culture
  14. var culture = CultureInfo.CreateSpecificCulture ("en-US");
  15. Thread.CurrentThread.CurrentCulture = culture;
  16. Thread.CurrentThread.CurrentUICulture = culture;
  17. }
  18. [Fact]
  19. public void DimAbsolute_Calculate_ReturnsCorrectValue ()
  20. {
  21. var dim = new DimAbsolute (10);
  22. int result = dim.Calculate (0, 100, null, Dimension.None);
  23. Assert.Equal (10, result);
  24. }
  25. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  26. // A new test that does not depend on Application is needed.
  27. [Fact]
  28. [AutoInitShutdown]
  29. public void Dim_Add_Operator ()
  30. {
  31. Toplevel top = new ();
  32. var view = new View { X = 0, Y = 0, Width = 20, Height = 0 };
  33. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  34. var count = 0;
  35. field.KeyDown += (s, k) =>
  36. {
  37. if (k.KeyCode == KeyCode.Enter)
  38. {
  39. field.Text = $"Label {count}";
  40. var label = new Label { X = 0, Y = view.Viewport.Height, /*Width = 20,*/ Text = field.Text };
  41. view.Add (label);
  42. Assert.Equal ($"Label {count}", label.Text);
  43. Assert.Equal ($"Absolute({count})", label.Y.ToString ());
  44. Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  45. view.Height += 1;
  46. count++;
  47. Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  48. }
  49. };
  50. Application.Iteration += (s, a) =>
  51. {
  52. while (count < 20)
  53. {
  54. field.NewKeyDownEvent (Key.Enter);
  55. }
  56. Application.RequestStop ();
  57. };
  58. var win = new Window ();
  59. win.Add (view);
  60. win.Add (field);
  61. top.Add (win);
  62. Application.Run (top);
  63. top.Dispose ();
  64. Assert.Equal (20, count);
  65. }
  66. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  67. // TODO: A new test that calls SetRelativeLayout directly is needed.
  68. [Fact]
  69. [AutoInitShutdown]
  70. public void Dim_Subtract_Operator ()
  71. {
  72. Toplevel top = new ();
  73. var view = new View { X = 0, Y = 0, Width = 20, Height = 0 };
  74. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  75. var count = 20;
  76. List<Label> listLabels = new ();
  77. for (var i = 0; i < count; i++)
  78. {
  79. field.Text = $"Label {i}";
  80. var label = new Label { X = 0, Y = view.Viewport.Height, /*Width = 20,*/ Text = field.Text };
  81. view.Add (label);
  82. Assert.Equal ($"Label {i}", label.Text);
  83. Assert.Equal ($"Absolute({i})", label.Y.ToString ());
  84. listLabels.Add (label);
  85. Assert.Equal ($"Absolute({i})", view.Height.ToString ());
  86. view.Height += 1;
  87. Assert.Equal ($"Absolute({i + 1})", view.Height.ToString ());
  88. }
  89. field.KeyDown += (s, k) =>
  90. {
  91. if (k.KeyCode == KeyCode.Enter)
  92. {
  93. Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
  94. view.Remove (listLabels [count - 1]);
  95. listLabels [count - 1].Dispose ();
  96. Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  97. view.Height -= 1;
  98. count--;
  99. Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  100. }
  101. };
  102. Application.Iteration += (s, a) =>
  103. {
  104. while (count > 0)
  105. {
  106. field.NewKeyDownEvent (Key.Enter);
  107. }
  108. Application.RequestStop ();
  109. };
  110. var win = new Window ();
  111. win.Add (view);
  112. win.Add (field);
  113. top.Add (win);
  114. Application.Run (top);
  115. Assert.Equal (0, count);
  116. top.Dispose ();
  117. }
  118. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  119. // TODO: A new test that calls SetRelativeLayout directly is needed.
  120. [Fact]
  121. [TestRespondersDisposed]
  122. public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Null ()
  123. {
  124. var t = new View { Width = 80, Height = 25, Text = "top" };
  125. var w = new Window
  126. {
  127. X = 1,
  128. Y = 2,
  129. Width = 4,
  130. Height = 5,
  131. Title = "w"
  132. };
  133. t.Add (w);
  134. t.LayoutSubviews ();
  135. Assert.Equal (3, w.Width = 3);
  136. Assert.Equal (4, w.Height = 4);
  137. t.Dispose ();
  138. }
  139. [Fact]
  140. public void DimHeight_Set_To_Null_Throws ()
  141. {
  142. Dim dim = Height (null);
  143. Assert.Throws<NullReferenceException> (() => dim.ToString ());
  144. }
  145. [Fact]
  146. [TestRespondersDisposed]
  147. public void DimHeight_SetsValue ()
  148. {
  149. var testVal = Rectangle.Empty;
  150. var testValview = new View { Frame = testVal };
  151. Dim dim = Height (testValview);
  152. Assert.Equal ($"View(Height,View(){testVal})", dim.ToString ());
  153. testValview.Dispose ();
  154. testVal = new (1, 2, 3, 4);
  155. testValview = new() { Frame = testVal };
  156. dim = Height (testValview);
  157. Assert.Equal ($"View(Height,View(){testVal})", dim.ToString ());
  158. testValview.Dispose ();
  159. }
  160. [Fact]
  161. [TestRespondersDisposed]
  162. public void Internal_Tests ()
  163. {
  164. var dimFactor = new DimPercent (10);
  165. Assert.Equal (10, dimFactor.GetAnchor (100));
  166. var dimAbsolute = new DimAbsolute (10);
  167. Assert.Equal (10, dimAbsolute.GetAnchor (0));
  168. var dimFill = new DimFill (1);
  169. Assert.Equal (99, dimFill.GetAnchor (100));
  170. var dimCombine = new DimCombine (AddOrSubtract.Add, dimFactor, dimAbsolute);
  171. Assert.Equal (dimCombine.Left, dimFactor);
  172. Assert.Equal (dimCombine.Right, dimAbsolute);
  173. Assert.Equal (20, dimCombine.GetAnchor (100));
  174. var view = new View { Frame = new (20, 10, 20, 1) };
  175. var dimViewHeight = new DimView (view, Dimension.Height);
  176. Assert.Equal (1, dimViewHeight.GetAnchor (0));
  177. var dimViewWidth = new DimView (view, Dimension.Width);
  178. Assert.Equal (20, dimViewWidth.GetAnchor (0));
  179. view.Dispose ();
  180. }
  181. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  182. // TODO: A new test that calls SetRelativeLayout directly is needed.
  183. [Fact]
  184. [AutoInitShutdown]
  185. public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assigning_Value_To_Width_Or_Height ()
  186. {
  187. // Override CM
  188. Button.DefaultShadow = ShadowStyle.None;
  189. // Testing with the Button because it properly handles the Dim class.
  190. Toplevel t = new ();
  191. var w = new Window { Width = 100, Height = 100 };
  192. var f1 = new FrameView
  193. {
  194. X = 0,
  195. Y = 0,
  196. Width = Percent (50),
  197. Height = 5,
  198. Title = "f1"
  199. };
  200. var f2 = new FrameView
  201. {
  202. X = Pos.Right (f1),
  203. Y = 0,
  204. Width = Fill (),
  205. Height = 5,
  206. Title = "f2"
  207. };
  208. var v1 = new Button
  209. {
  210. X = Pos.X (f1) + 2,
  211. Y = Pos.Bottom (f1) + 2,
  212. Width = Width (f1) - 2,
  213. Height = Fill () - 2,
  214. ValidatePosDim = true,
  215. Text = "v1"
  216. };
  217. var v2 = new Button
  218. {
  219. X = Pos.X (f2) + 2,
  220. Y = Pos.Bottom (f2) + 2,
  221. Width = Width (f2) - 2,
  222. Height = Fill () - 2,
  223. ValidatePosDim = true,
  224. Text = "v2"
  225. };
  226. var v3 = new Button
  227. {
  228. Width = Percent (10),
  229. Height = Percent (10),
  230. ValidatePosDim = true,
  231. Text = "v3"
  232. };
  233. var v4 = new Button
  234. {
  235. Width = Absolute (50),
  236. Height = Absolute (50),
  237. ValidatePosDim = true,
  238. Text = "v4"
  239. };
  240. var v5 = new Button
  241. {
  242. Width = Width (v1) - Width (v3),
  243. Height = Height (v1) - Height (v3),
  244. ValidatePosDim = true,
  245. Text = "v5"
  246. };
  247. var v6 = new Button
  248. {
  249. X = Pos.X (f2),
  250. Y = Pos.Bottom (f2) + 2,
  251. Width = Percent (20, DimPercentMode.Position),
  252. Height = Percent (20, DimPercentMode.Position),
  253. ValidatePosDim = true,
  254. Text = "v6"
  255. };
  256. w.Add (f1, f2, v1, v2, v3, v4, v5, v6);
  257. t.Add (w);
  258. t.Ready += (s, e) =>
  259. {
  260. Assert.Equal ("Absolute(100)", w.Width.ToString ());
  261. Assert.Equal ("Absolute(100)", w.Height.ToString ());
  262. Assert.Equal (100, w.Frame.Width);
  263. Assert.Equal (100, w.Frame.Height);
  264. Assert.Equal ("Absolute(5)", f1.Height.ToString ());
  265. Assert.Equal (49, f1.Frame.Width); // 50-1=49
  266. Assert.Equal (5, f1.Frame.Height);
  267. Assert.Equal ("Fill(Absolute(0))", f2.Width.ToString ());
  268. Assert.Equal ("Absolute(5)", f2.Height.ToString ());
  269. Assert.Equal (49, f2.Frame.Width); // 50-1=49
  270. Assert.Equal (5, f2.Frame.Height);
  271. #if DEBUG
  272. Assert.Equal ($"Combine(View(Width,FrameView(f1){f1.Border.Frame})-Absolute(2))", v1.Width.ToString ());
  273. #else
  274. Assert.Equal ($"Combine(View(Width,FrameView(){f1.Border.Frame})-Absolute(2))", v1.Width.ToString ());
  275. #endif
  276. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v1.Height.ToString ());
  277. Assert.Equal (47, v1.Frame.Width); // 49-2=47
  278. Assert.Equal (89, v1.Frame.Height); // 98-5-2-2=89
  279. #if DEBUG
  280. Assert.Equal (
  281. $"Combine(View(Width,FrameView(f2){f2.Frame})-Absolute(2))",
  282. v2.Width.ToString ()
  283. #else
  284. Assert.Equal (
  285. $"Combine(View(Width,FrameView(){f2.Frame})-Absolute(2))",
  286. v2.Width.ToString ()
  287. #endif
  288. );
  289. #if DEBUG
  290. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v2.Height.ToString ());
  291. #else
  292. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v2.Height.ToString ());
  293. #endif
  294. Assert.Equal (47, v2.Frame.Width); // 49-2=47
  295. Assert.Equal (89, v2.Frame.Height); // 98-5-2-2=89
  296. Assert.Equal (9, v3.Frame.Width); // 98*10%=9
  297. Assert.Equal (9, v3.Frame.Height); // 98*10%=9
  298. Assert.Equal ("Absolute(50)", v4.Width.ToString ());
  299. Assert.Equal ("Absolute(50)", v4.Height.ToString ());
  300. Assert.Equal (50, v4.Frame.Width);
  301. Assert.Equal (50, v4.Frame.Height);
  302. #if DEBUG
  303. Assert.Equal ($"Combine(View(Width,Button(v1){v1.Frame})-View(Width,Button(v3){v3.Viewport}))", v5.Width.ToString ());
  304. #else
  305. Assert.Equal ($"Combine(View(Height,Button(){v1.Frame})-View(Height,Button(){v3.Viewport}))", v5.Height.ToString ( ));
  306. #endif
  307. Assert.Equal (38, v5.Frame.Width); // 47-9=38
  308. Assert.Equal (80, v5.Frame.Height); // 89-9=80
  309. Assert.Equal (9, v6.Frame.Width); // 47*20%=9
  310. Assert.Equal (18, v6.Frame.Height); // 89*20%=18
  311. w.Width = 200;
  312. Assert.True (t.LayoutNeeded);
  313. w.Height = 200;
  314. t.LayoutSubviews ();
  315. Assert.Equal ("Absolute(200)", w.Width.ToString ());
  316. Assert.Equal ("Absolute(200)", w.Height.ToString ());
  317. Assert.Equal (200, w.Frame.Width);
  318. Assert.Equal (200, w.Frame.Height);
  319. f1.Text = "Frame1";
  320. Assert.Equal (99, f1.Frame.Width); // 100-1=99
  321. Assert.Equal (5, f1.Frame.Height);
  322. f2.Text = "Frame2";
  323. Assert.Equal ("Fill(Absolute(0))", f2.Width.ToString ());
  324. Assert.Equal ("Absolute(5)", f2.Height.ToString ());
  325. Assert.Equal (99, f2.Frame.Width); // 100-1=99
  326. Assert.Equal (5, f2.Frame.Height);
  327. v1.Text = "Button1";
  328. #if DEBUG
  329. Assert.Equal ($"Combine(View(Width,FrameView(f1){f1.Frame})-Absolute(2))", v1.Width.ToString ());
  330. #else
  331. Assert.Equal ($"Combine(View(Width,FrameView(){f1.Frame})-Absolute(2))", v1.Width.ToString ());
  332. #endif
  333. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v1.Height.ToString ());
  334. Assert.Equal (97, v1.Frame.Width); // 99-2=97
  335. Assert.Equal (189, v1.Frame.Height); // 198-2-7=189
  336. v2.Text = "Button2";
  337. #if DEBUG
  338. Assert.Equal ($"Combine(View(Width,FrameView(f2){f2.Frame})-Absolute(2))", v2.Width.ToString ());
  339. #else
  340. Assert.Equal ($"Combine(View(Width,FrameView(){f2.Frame})-Absolute(2))", v2.Width.ToString ());
  341. #endif
  342. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v2.Height.ToString ());
  343. Assert.Equal (97, v2.Frame.Width); // 99-2=97
  344. Assert.Equal (189, v2.Frame.Height); // 198-2-7=189
  345. v3.Text = "Button3";
  346. // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
  347. Assert.Equal (19, v3.Frame.Width);
  348. // 199*10%=19
  349. Assert.Equal (19, v3.Frame.Height);
  350. v4.Text = "Button4";
  351. v4.Width = Auto (DimAutoStyle.Text);
  352. v4.Height = Auto (DimAutoStyle.Text);
  353. Assert.Equal (Auto (DimAutoStyle.Text), v4.Width);
  354. Assert.Equal (Auto (DimAutoStyle.Text), v4.Height);
  355. Assert.Equal (11, v4.Frame.Width); // 11 is the text length and because is DimAbsolute
  356. Assert.Equal (1, v4.Frame.Height); // 1 because is DimAbsolute
  357. v5.Text = "Button5";
  358. #if DEBUG
  359. Assert.Equal ($"Combine(View(Width,Button(v1){v1.Frame})-View(Width,Button(v3){v3.Frame}))", v5.Width.ToString ());
  360. Assert.Equal ($"Combine(View(Height,Button(v1){v1.Frame})-View(Height,Button(v3){v3.Frame}))", v5.Height.ToString ());
  361. #else
  362. Assert.Equal ($"Combine(View(Width,Button(){v1.Frame})-View(Width,Button(){v3.Frame}))", v5.Width.ToString ());
  363. Assert.Equal ($"Combine(View(Height,Button(){v1.Frame})-View(Height,Button(){v3.Frame}))", v5.Height.ToString ());
  364. #endif
  365. Assert.Equal (78, v5.Frame.Width); // 97-9=78
  366. Assert.Equal (170, v5.Frame.Height); // 189-19=170
  367. v6.Text = "Button6";
  368. Assert.Equal (19, v6.Frame.Width); // 99*20%=19
  369. Assert.Equal (38, v6.Frame.Height); // 198-7*20=18
  370. };
  371. Application.Iteration += (s, a) => Application.RequestStop ();
  372. Application.Run (t);
  373. t.Dispose ();
  374. }
  375. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  376. // TODO: A new test that calls SetRelativeLayout directly is needed.
  377. [Fact]
  378. [TestRespondersDisposed]
  379. public void Referencing_SuperView_Does_Not_Throw ()
  380. {
  381. var super = new View { Width = 10, Height = 10, Text = "super" };
  382. var view = new View
  383. {
  384. Width = Width (super), // this is allowed
  385. Height = Height (super), // this is allowed
  386. Text = "view"
  387. };
  388. super.Add (view);
  389. super.BeginInit ();
  390. super.EndInit ();
  391. Exception exception = Record.Exception (super.LayoutSubviews);
  392. Assert.Null (exception);
  393. super.Dispose ();
  394. }
  395. [Fact]
  396. public void DimSized_Equals ()
  397. {
  398. var n1 = 0;
  399. var n2 = 0;
  400. Dim dim1 = Absolute (n1);
  401. Dim dim2 = Absolute (n2);
  402. Assert.Equal (dim1, dim2);
  403. n1 = n2 = 1;
  404. dim1 = Absolute (n1);
  405. dim2 = Absolute (n2);
  406. Assert.Equal (dim1, dim2);
  407. n1 = n2 = -1;
  408. dim1 = Absolute (n1);
  409. dim2 = Absolute (n2);
  410. Assert.Equal (dim1, dim2);
  411. n1 = 0;
  412. n2 = 1;
  413. dim1 = Absolute (n1);
  414. dim2 = Absolute (n2);
  415. Assert.NotEqual (dim1, dim2);
  416. }
  417. [Fact]
  418. public void DimSized_SetsValue ()
  419. {
  420. Dim dim = Absolute (0);
  421. Assert.Equal ("Absolute(0)", dim.ToString ());
  422. var testVal = 5;
  423. dim = Absolute (testVal);
  424. Assert.Equal ($"Absolute({testVal})", dim.ToString ());
  425. testVal = -1;
  426. dim = Absolute (testVal);
  427. Assert.Equal ($"Absolute({testVal})", dim.ToString ());
  428. }
  429. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  430. // TODO: A new test that calls SetRelativeLayout directly is needed.
  431. [Fact]
  432. [TestRespondersDisposed]
  433. public void SyperView_Referencing_SubView_Throws ()
  434. {
  435. var super = new View { Width = 10, Height = 10, Text = "super" };
  436. var view2 = new View { Width = 10, Height = 10, Text = "view2" };
  437. var view = new View
  438. {
  439. Width = Width (view2), // this is not allowed
  440. Height = Height (view2), // this is not allowed
  441. Text = "view"
  442. };
  443. view.Add (view2);
  444. super.Add (view);
  445. super.BeginInit ();
  446. super.EndInit ();
  447. Assert.Throws<InvalidOperationException> (super.LayoutSubviews);
  448. super.Dispose ();
  449. }
  450. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  451. // TODO: A new test that calls SetRelativeLayout directly is needed.
  452. [Fact]
  453. [TestRespondersDisposed]
  454. public void Validation_Does_Not_Throw_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Null ()
  455. {
  456. var t = new View { Width = 80, Height = 25, Text = "top" };
  457. var w = new Window
  458. {
  459. X = 1,
  460. Y = 2,
  461. Width = 4,
  462. Height = 5,
  463. Title = "w"
  464. };
  465. t.Add (w);
  466. t.LayoutSubviews ();
  467. Assert.Equal (3, w.Width = 3);
  468. Assert.Equal (4, w.Height = 4);
  469. t.Dispose ();
  470. }
  471. [Fact]
  472. [TestRespondersDisposed]
  473. public void DimWidth_Equals ()
  474. {
  475. var testRect1 = Rectangle.Empty;
  476. var view1 = new View { Frame = testRect1 };
  477. var testRect2 = Rectangle.Empty;
  478. var view2 = new View { Frame = testRect2 };
  479. Dim dim1 = Width (view1);
  480. Dim dim2 = Width (view1);
  481. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  482. Assert.Equal (dim1, dim2);
  483. dim2 = Width (view2);
  484. Assert.NotEqual (dim1, dim2);
  485. testRect1 = new (0, 1, 2, 3);
  486. view1 = new() { Frame = testRect1 };
  487. testRect2 = new (0, 1, 2, 3);
  488. dim1 = Width (view1);
  489. dim2 = Width (view1);
  490. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  491. Assert.Equal (dim1, dim2);
  492. testRect1 = new (0, -1, 2, 3);
  493. view1 = new() { Frame = testRect1 };
  494. testRect2 = new (0, -1, 2, 3);
  495. dim1 = Width (view1);
  496. dim2 = Width (view1);
  497. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  498. Assert.Equal (dim1, dim2);
  499. testRect1 = new (0, -1, 2, 3);
  500. view1 = new() { Frame = testRect1 };
  501. testRect2 = Rectangle.Empty;
  502. view2 = new() { Frame = testRect2 };
  503. dim1 = Width (view1);
  504. dim2 = Width (view2);
  505. Assert.NotEqual (dim1, dim2);
  506. #if DEBUG_IDISPOSABLE
  507. // HACK: Force clean up of Responders to avoid having to Dispose all the Views created above.
  508. Responder.Instances.Clear ();
  509. Assert.Empty (Responder.Instances);
  510. #endif
  511. }
  512. [Fact]
  513. public void DimWidth_Set_To_Null_Throws ()
  514. {
  515. Dim dim = Width (null);
  516. Assert.Throws<NullReferenceException> (() => dim.ToString ());
  517. }
  518. [Fact]
  519. [TestRespondersDisposed]
  520. public void DimWidth_SetsValue ()
  521. {
  522. var testVal = Rectangle.Empty;
  523. var testValView = new View { Frame = testVal };
  524. Dim dim = Width (testValView);
  525. Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
  526. testValView.Dispose ();
  527. testVal = new (1, 2, 3, 4);
  528. testValView = new() { Frame = testVal };
  529. dim = Width (testValView);
  530. Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
  531. testValView.Dispose ();
  532. }
  533. }