LabelTests.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481
  1. using System.ComponentModel;
  2. using Microsoft.VisualStudio.TestPlatform.Utilities;
  3. using Xunit.Abstractions;
  4. namespace Terminal.Gui.ViewsTests;
  5. public class LabelTests
  6. {
  7. private readonly ITestOutputHelper _output;
  8. public LabelTests (ITestOutputHelper output) { _output = output; }
  9. // Test that Title and Text are the same
  10. [Fact]
  11. public void Text_Mirrors_Title ()
  12. {
  13. var label = new Label ();
  14. label.Title = "Hello";
  15. Assert.Equal ("Hello", label.Title);
  16. Assert.Equal ("Hello", label.TitleTextFormatter.Text);
  17. Assert.Equal ("Hello", label.Text);
  18. Assert.Equal ("Hello", label.TextFormatter.Text);
  19. }
  20. [Fact]
  21. public void Title_Mirrors_Text ()
  22. {
  23. var label = new Label ();
  24. label.Text = "Hello";
  25. Assert.Equal ("Hello", label.Text);
  26. Assert.Equal ("Hello", label.TextFormatter.Text);
  27. Assert.Equal ("Hello", label.Title);
  28. Assert.Equal ("Hello", label.TitleTextFormatter.Text);
  29. }
  30. [Fact]
  31. public void HotKey_Command_SetsFocus_OnNextSubview ()
  32. {
  33. var superView = new View () { CanFocus = true };
  34. var label = new Label ();
  35. var nextSubview = new View () { CanFocus = true };
  36. superView.Add (label, nextSubview);
  37. superView.BeginInit ();
  38. superView.EndInit ();
  39. Assert.False (label.HasFocus);
  40. Assert.False (nextSubview.HasFocus);
  41. label.InvokeCommand (Command.HotKey);
  42. Assert.False (label.HasFocus);
  43. Assert.True (nextSubview.HasFocus);
  44. }
  45. [Fact]
  46. public void MouseClick_SetsFocus_OnNextSubview ()
  47. {
  48. var superView = new View () { CanFocus = true, Height = 1, Width = 15 };
  49. var focusedView = new View () { CanFocus = true, Width = 1, Height = 1 };
  50. var label = new Label () { X = 2, Title = "_x" };
  51. var nextSubview = new View () { CanFocus = true, X = 4, Width = 4, Height = 1 };
  52. superView.Add (focusedView, label, nextSubview);
  53. superView.BeginInit ();
  54. superView.EndInit ();
  55. Assert.False (focusedView.HasFocus);
  56. Assert.False (label.HasFocus);
  57. Assert.False (nextSubview.HasFocus);
  58. label.NewMouseEvent (new MouseEvent () { Position = new (0, 0), Flags = MouseFlags.Button1Clicked });
  59. Assert.False (label.HasFocus);
  60. Assert.True (nextSubview.HasFocus);
  61. }
  62. [Fact]
  63. public void HotKey_Command_Does_Not_Accept ()
  64. {
  65. var label = new Label ();
  66. var accepted = false;
  67. label.Accept += LabelOnAccept;
  68. label.InvokeCommand (Command.HotKey);
  69. Assert.False (accepted);
  70. return;
  71. void LabelOnAccept (object sender, CancelEventArgs e) { accepted = true; }
  72. }
  73. [Fact]
  74. [AutoInitShutdown]
  75. public void AutoSize_Stays_True_AnchorEnd ()
  76. {
  77. var label = new Label { Y = Pos.Center (), Text = "Say Hello 你" };
  78. label.X = Pos.AnchorEnd (0) - Pos.Func (() => label.TextFormatter.Text.GetColumns ());
  79. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  80. win.Add (label);
  81. var top = new Toplevel ();
  82. top.Add (win);
  83. Application.Begin (top);
  84. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  85. var expected = @"
  86. ┌────────────────────────────┐
  87. │ │
  88. │ Say Hello 你│
  89. │ │
  90. └────────────────────────────┘
  91. ";
  92. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  93. label.Text = "Say Hello 你 changed";
  94. Application.Refresh ();
  95. expected = @"
  96. ┌────────────────────────────┐
  97. │ │
  98. │ Say Hello 你 changed│
  99. │ │
  100. └────────────────────────────┘
  101. ";
  102. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  103. }
  104. [Fact]
  105. [AutoInitShutdown]
  106. public void AutoSize_Stays_True_Center ()
  107. {
  108. var label = new Label { X = Pos.Center (), Y = Pos.Center (), Text = "Say Hello 你" };
  109. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  110. win.Add (label);
  111. var top = new Toplevel ();
  112. top.Add (win);
  113. Application.Begin (top);
  114. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  115. var expected = @"
  116. ┌────────────────────────────┐
  117. │ │
  118. │ Say Hello 你 │
  119. │ │
  120. └────────────────────────────┘
  121. ";
  122. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  123. label.Text = "Say Hello 你 changed";
  124. Application.Refresh ();
  125. expected = @"
  126. ┌────────────────────────────┐
  127. │ │
  128. │ Say Hello 你 changed │
  129. │ │
  130. └────────────────────────────┘
  131. ";
  132. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  133. }
  134. [Fact]
  135. [AutoInitShutdown]
  136. public void AutoSize_Stays_True_With_EmptyText ()
  137. {
  138. var label = new Label { X = Pos.Center (), Y = Pos.Center () };
  139. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  140. win.Add (label);
  141. var top = new Toplevel ();
  142. top.Add (win);
  143. label.Text = "Say Hello 你";
  144. Application.Begin (top);
  145. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  146. var expected = @"
  147. ┌────────────────────────────┐
  148. │ │
  149. │ Say Hello 你 │
  150. │ │
  151. └────────────────────────────┘
  152. ";
  153. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  154. }
  155. [Fact]
  156. public void Constructors_Defaults ()
  157. {
  158. var label = new Label ();
  159. Assert.Equal (string.Empty, label.Text);
  160. Assert.Equal (Alignment.Start, label.TextAlignment);
  161. Assert.False (label.CanFocus);
  162. Assert.Equal (new Rectangle (0, 0, 0, 0), label.Frame);
  163. Assert.Equal (KeyCode.Null, label.HotKey);
  164. }
  165. [Fact]
  166. [AutoInitShutdown]
  167. public void Label_Draw_Fill_Remaining_AutoSize_False ()
  168. {
  169. Size tfSize = new Size (80, 1);
  170. var label = new Label { Text = "This label needs to be cleared before rewritten.", Width = tfSize.Width, Height = tfSize.Height };
  171. var tf1 = new TextFormatter { Direction = TextDirection.LeftRight_TopBottom, Size = tfSize };
  172. tf1.Text = "This TextFormatter (tf1) without fill will not be cleared on rewritten.";
  173. var tf2 = new TextFormatter { Direction = TextDirection.LeftRight_TopBottom, Size = tfSize, FillRemaining = true };
  174. tf2.Text = "This TextFormatter (tf2) with fill will be cleared on rewritten.";
  175. var top = new Toplevel ();
  176. top.Add (label);
  177. Application.Begin (top);
  178. Assert.False (label.TextFormatter.AutoSize);
  179. Assert.False (tf1.AutoSize);
  180. Assert.False (tf2.AutoSize);
  181. Assert.False (label.TextFormatter.FillRemaining);
  182. Assert.False (tf1.FillRemaining);
  183. Assert.True (tf2.FillRemaining);
  184. tf1.Draw (new Rectangle (new Point (0, 1), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
  185. tf2.Draw (new Rectangle (new Point (0, 2), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
  186. TestHelpers.AssertDriverContentsWithFrameAre (
  187. @"
  188. This label needs to be cleared before rewritten.
  189. This TextFormatter (tf1) without fill will not be cleared on rewritten.
  190. This TextFormatter (tf2) with fill will be cleared on rewritten. ",
  191. _output
  192. );
  193. Assert.False (label.NeedsDisplay);
  194. Assert.False (label.LayoutNeeded);
  195. Assert.False (label.SubViewNeedsDisplay);
  196. label.Text = "This label is rewritten.";
  197. Assert.True (label.NeedsDisplay);
  198. Assert.True (label.LayoutNeeded);
  199. Assert.False (label.SubViewNeedsDisplay);
  200. label.Draw ();
  201. tf1.Text = "This TextFormatter (tf1) is rewritten.";
  202. tf1.Draw (new Rectangle (new Point (0, 1), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
  203. tf2.Text = "This TextFormatter (tf2) is rewritten.";
  204. tf2.Draw (new Rectangle (new Point (0, 2), tfSize), label.GetNormalColor (), label.ColorScheme.HotNormal);
  205. TestHelpers.AssertDriverContentsWithFrameAre (
  206. @"
  207. This label is rewritten.
  208. This TextFormatter (tf1) is rewritten.will not be cleared on rewritten.
  209. This TextFormatter (tf2) is rewritten. ",
  210. _output
  211. );
  212. }
  213. [Fact]
  214. [AutoInitShutdown]
  215. public void Label_Draw_Horizontal_Simple_Runes ()
  216. {
  217. var label = new Label { Text = "Demo Simple Rune" };
  218. var top = new Toplevel ();
  219. top.Add (label);
  220. Application.Begin (top);
  221. Assert.Equal (new Rectangle (0, 0, 16, 1), label.Frame);
  222. var expected = @"
  223. Demo Simple Rune
  224. ";
  225. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  226. Assert.Equal (new Rectangle (0, 0, 16, 1), pos);
  227. }
  228. [Fact]
  229. [AutoInitShutdown]
  230. public void Label_Draw_Vertical_Simple_Runes ()
  231. {
  232. var label = new Label { TextDirection = TextDirection.TopBottom_LeftRight, Text = "Demo Simple Rune" };
  233. var top = new Toplevel ();
  234. top.Add (label);
  235. Application.Begin (top);
  236. Assert.NotNull (label.Width);
  237. Assert.NotNull (label.Height);
  238. var expected = @"
  239. D
  240. e
  241. m
  242. o
  243. S
  244. i
  245. m
  246. p
  247. l
  248. e
  249. R
  250. u
  251. n
  252. e
  253. ";
  254. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  255. Assert.Equal (new Rectangle (0, 0, 1, 16), pos);
  256. }
  257. [Fact]
  258. [AutoInitShutdown]
  259. public void Label_Draw_Vertical_Wide_Runes ()
  260. {
  261. var label = new Label { TextDirection = TextDirection.TopBottom_LeftRight, Text = "デモエムポンズ" };
  262. var top = new Toplevel ();
  263. top.Add (label);
  264. Application.Begin (top);
  265. var expected = @"
  266. ";
  267. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  268. Assert.Equal (new Rectangle (0, 0, 2, 7), pos);
  269. }
  270. [Fact]
  271. [AutoInitShutdown]
  272. public void Label_HotKeyChanged_EventFires ()
  273. {
  274. var label = new Label { Text = "Yar" };
  275. label.HotKey = 'Y';
  276. object sender = null;
  277. KeyChangedEventArgs args = null;
  278. label.HotKeyChanged += (s, e) =>
  279. {
  280. sender = s;
  281. args = e;
  282. };
  283. label.HotKey = Key.R;
  284. Assert.Same (label, sender);
  285. Assert.Equal (KeyCode.Y | KeyCode.ShiftMask, args.OldKey);
  286. Assert.Equal (Key.R, args.NewKey);
  287. }
  288. [Fact]
  289. [AutoInitShutdown]
  290. public void Label_HotKeyChanged_EventFires_WithNone ()
  291. {
  292. var label = new Label ();
  293. object sender = null;
  294. KeyChangedEventArgs args = null;
  295. label.HotKeyChanged += (s, e) =>
  296. {
  297. sender = s;
  298. args = e;
  299. };
  300. label.HotKey = KeyCode.R;
  301. Assert.Same (label, sender);
  302. Assert.Equal (KeyCode.Null, args.OldKey);
  303. Assert.Equal (KeyCode.R, args.NewKey);
  304. }
  305. [Fact]
  306. public void TestAssignTextToLabel ()
  307. {
  308. View b = new Label { Text = "heya" };
  309. Assert.Equal ("heya", b.Text);
  310. Assert.Contains ("heya", b.TextFormatter.Text);
  311. b.Text = "heyb";
  312. Assert.Equal ("heyb", b.Text);
  313. Assert.Contains ("heyb", b.TextFormatter.Text);
  314. // with cast
  315. Assert.Equal ("heyb", ((Label)b).Text);
  316. }
  317. [Fact]
  318. [AutoInitShutdown]
  319. public void Update_Only_On_Or_After_Initialize ()
  320. {
  321. var label = new Label { X = Pos.Center (), Y = Pos.Center (), Text = "Say Hello 你" };
  322. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  323. win.Add (label);
  324. var top = new Toplevel ();
  325. top.Add (win);
  326. Assert.False (label.IsInitialized);
  327. Application.Begin (top);
  328. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  329. Assert.True (label.IsInitialized);
  330. Assert.Equal ("Say Hello 你", label.Text);
  331. Assert.Equal ("Say Hello 你", label.TextFormatter.Text);
  332. Assert.Equal (new Rectangle (0, 0, 12, 1), label.Viewport);
  333. var expected = @"
  334. ┌────────────────────────────┐
  335. │ │
  336. │ Say Hello 你 │
  337. │ │
  338. └────────────────────────────┘
  339. ";
  340. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  341. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  342. }
  343. [Fact]
  344. [AutoInitShutdown]
  345. public void Update_Parameterless_Only_On_Or_After_Initialize ()
  346. {
  347. var label = new Label { X = Pos.Center (), Y = Pos.Center (), Text = "Say Hello 你" };
  348. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  349. win.Add (label);
  350. var top = new Toplevel ();
  351. top.Add (win);
  352. Assert.False (label.IsInitialized);
  353. Application.Begin (top);
  354. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  355. Assert.True (label.IsInitialized);
  356. Assert.Equal ("Say Hello 你", label.Text);
  357. Assert.Equal ("Say Hello 你", label.TextFormatter.Text);
  358. Assert.Equal (new Rectangle (0, 0, 12, 1), label.Viewport);
  359. var expected = @"
  360. ┌────────────────────────────┐
  361. │ │
  362. │ Say Hello 你 │
  363. │ │
  364. └────────────────────────────┘
  365. ";
  366. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  367. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  368. }
  369. [Fact]
  370. [SetupFakeDriver]
  371. public void Full_Border ()
  372. {
  373. var label = new Label { BorderStyle = LineStyle.Single , Text = "Test",} ;
  374. label.BeginInit();
  375. label.EndInit();
  376. label.SetRelativeLayout (Application.Driver.Screen.Size);
  377. Assert.Equal (new (0, 0, 4, 1), label.Viewport);
  378. Assert.Equal (new (0, 0, 6, 3), label.Frame);
  379. label.Draw ();
  380. TestHelpers.AssertDriverContentsWithFrameAre (
  381. @"
  382. ┌┤Te├┐
  383. │Test│
  384. └────┘",
  385. _output
  386. );
  387. label.Dispose ();
  388. }
  389. [Fact]
  390. [AutoInitShutdown]
  391. public void With_Top_Margin_Without_Top_Border ()
  392. {
  393. var label = new Label { Text = "Test", /*Width = 6, Height = 3,*/ BorderStyle = LineStyle.Single };
  394. label.Margin.Thickness = new Thickness (0, 1, 0, 0);
  395. label.Border.Thickness = new Thickness (1, 0, 1, 1);
  396. var top = new Toplevel ();
  397. top.Add (label);
  398. Application.Begin (top);
  399. Assert.Equal (new (0, 0, 6, 3), label.Frame);
  400. Assert.Equal (new (0, 0, 4, 1), label.Viewport);
  401. Application.Begin (top);
  402. TestHelpers.AssertDriverContentsWithFrameAre (
  403. @"
  404. │Test│
  405. └────┘",
  406. _output
  407. );
  408. }
  409. [Fact]
  410. [AutoInitShutdown]
  411. public void Without_Top_Border ()
  412. {
  413. var label = new Label { Text = "Test", /* Width = 6, Height = 3, */BorderStyle = LineStyle.Single };
  414. label.Border.Thickness = new Thickness (1, 0, 1, 1);
  415. var top = new Toplevel ();
  416. top.Add (label);
  417. Application.Begin (top);
  418. Assert.Equal (new (0, 0, 6, 2), label.Frame);
  419. Assert.Equal (new (0, 0, 4, 1), label.Viewport);
  420. Application.Begin (top);
  421. TestHelpers.AssertDriverContentsWithFrameAre (
  422. @"
  423. │Test│
  424. └────┘",
  425. _output
  426. );
  427. }
  428. // These tests were formally in AutoSizetrue.cs. They are (poor) Label tests.
  429. private readonly string [] expecteds = new string [21]
  430. {
  431. @"
  432. ┌────────────────────┐
  433. │View with long text │
  434. │ │
  435. └────────────────────┘",
  436. @"
  437. ┌────────────────────┐
  438. │View with long text │
  439. │Label 0 │
  440. │Label 0 │
  441. └────────────────────┘",
  442. @"
  443. ┌────────────────────┐
  444. │View with long text │
  445. │Label 0 │
  446. │Label 1 │
  447. │Label 1 │
  448. └────────────────────┘",
  449. @"
  450. ┌────────────────────┐
  451. │View with long text │
  452. │Label 0 │
  453. │Label 1 │
  454. │Label 2 │
  455. │Label 2 │
  456. └────────────────────┘",
  457. @"
  458. ┌────────────────────┐
  459. │View with long text │
  460. │Label 0 │
  461. │Label 1 │
  462. │Label 2 │
  463. │Label 3 │
  464. │Label 3 │
  465. └────────────────────┘",
  466. @"
  467. ┌────────────────────┐
  468. │View with long text │
  469. │Label 0 │
  470. │Label 1 │
  471. │Label 2 │
  472. │Label 3 │
  473. │Label 4 │
  474. │Label 4 │
  475. └────────────────────┘",
  476. @"
  477. ┌────────────────────┐
  478. │View with long text │
  479. │Label 0 │
  480. │Label 1 │
  481. │Label 2 │
  482. │Label 3 │
  483. │Label 4 │
  484. │Label 5 │
  485. │Label 5 │
  486. └────────────────────┘",
  487. @"
  488. ┌────────────────────┐
  489. │View with long text │
  490. │Label 0 │
  491. │Label 1 │
  492. │Label 2 │
  493. │Label 3 │
  494. │Label 4 │
  495. │Label 5 │
  496. │Label 6 │
  497. │Label 6 │
  498. └────────────────────┘",
  499. @"
  500. ┌────────────────────┐
  501. │View with long text │
  502. │Label 0 │
  503. │Label 1 │
  504. │Label 2 │
  505. │Label 3 │
  506. │Label 4 │
  507. │Label 5 │
  508. │Label 6 │
  509. │Label 7 │
  510. │Label 7 │
  511. └────────────────────┘",
  512. @"
  513. ┌────────────────────┐
  514. │View with long text │
  515. │Label 0 │
  516. │Label 1 │
  517. │Label 2 │
  518. │Label 3 │
  519. │Label 4 │
  520. │Label 5 │
  521. │Label 6 │
  522. │Label 7 │
  523. │Label 8 │
  524. │Label 8 │
  525. └────────────────────┘",
  526. @"
  527. ┌────────────────────┐
  528. │View with long text │
  529. │Label 0 │
  530. │Label 1 │
  531. │Label 2 │
  532. │Label 3 │
  533. │Label 4 │
  534. │Label 5 │
  535. │Label 6 │
  536. │Label 7 │
  537. │Label 8 │
  538. │Label 9 │
  539. │Label 9 │
  540. └────────────────────┘",
  541. @"
  542. ┌────────────────────┐
  543. │View with long text │
  544. │Label 0 │
  545. │Label 1 │
  546. │Label 2 │
  547. │Label 3 │
  548. │Label 4 │
  549. │Label 5 │
  550. │Label 6 │
  551. │Label 7 │
  552. │Label 8 │
  553. │Label 9 │
  554. │Label 10 │
  555. │Label 10 │
  556. └────────────────────┘",
  557. @"
  558. ┌────────────────────┐
  559. │View with long text │
  560. │Label 0 │
  561. │Label 1 │
  562. │Label 2 │
  563. │Label 3 │
  564. │Label 4 │
  565. │Label 5 │
  566. │Label 6 │
  567. │Label 7 │
  568. │Label 8 │
  569. │Label 9 │
  570. │Label 10 │
  571. │Label 11 │
  572. │Label 11 │
  573. └────────────────────┘",
  574. @"
  575. ┌────────────────────┐
  576. │View with long text │
  577. │Label 0 │
  578. │Label 1 │
  579. │Label 2 │
  580. │Label 3 │
  581. │Label 4 │
  582. │Label 5 │
  583. │Label 6 │
  584. │Label 7 │
  585. │Label 8 │
  586. │Label 9 │
  587. │Label 10 │
  588. │Label 11 │
  589. │Label 12 │
  590. │Label 12 │
  591. └────────────────────┘",
  592. @"
  593. ┌────────────────────┐
  594. │View with long text │
  595. │Label 0 │
  596. │Label 1 │
  597. │Label 2 │
  598. │Label 3 │
  599. │Label 4 │
  600. │Label 5 │
  601. │Label 6 │
  602. │Label 7 │
  603. │Label 8 │
  604. │Label 9 │
  605. │Label 10 │
  606. │Label 11 │
  607. │Label 12 │
  608. │Label 13 │
  609. │Label 13 │
  610. └────────────────────┘",
  611. @"
  612. ┌────────────────────┐
  613. │View with long text │
  614. │Label 0 │
  615. │Label 1 │
  616. │Label 2 │
  617. │Label 3 │
  618. │Label 4 │
  619. │Label 5 │
  620. │Label 6 │
  621. │Label 7 │
  622. │Label 8 │
  623. │Label 9 │
  624. │Label 10 │
  625. │Label 11 │
  626. │Label 12 │
  627. │Label 13 │
  628. │Label 14 │
  629. │Label 14 │
  630. └────────────────────┘",
  631. @"
  632. ┌────────────────────┐
  633. │View with long text │
  634. │Label 0 │
  635. │Label 1 │
  636. │Label 2 │
  637. │Label 3 │
  638. │Label 4 │
  639. │Label 5 │
  640. │Label 6 │
  641. │Label 7 │
  642. │Label 8 │
  643. │Label 9 │
  644. │Label 10 │
  645. │Label 11 │
  646. │Label 12 │
  647. │Label 13 │
  648. │Label 14 │
  649. │Label 15 │
  650. │Label 15 │
  651. └────────────────────┘",
  652. @"
  653. ┌────────────────────┐
  654. │View with long text │
  655. │Label 0 │
  656. │Label 1 │
  657. │Label 2 │
  658. │Label 3 │
  659. │Label 4 │
  660. │Label 5 │
  661. │Label 6 │
  662. │Label 7 │
  663. │Label 8 │
  664. │Label 9 │
  665. │Label 10 │
  666. │Label 11 │
  667. │Label 12 │
  668. │Label 13 │
  669. │Label 14 │
  670. │Label 15 │
  671. │Label 16 │
  672. │Label 16 │
  673. └────────────────────┘",
  674. @"
  675. ┌────────────────────┐
  676. │View with long text │
  677. │Label 0 │
  678. │Label 1 │
  679. │Label 2 │
  680. │Label 3 │
  681. │Label 4 │
  682. │Label 5 │
  683. │Label 6 │
  684. │Label 7 │
  685. │Label 8 │
  686. │Label 9 │
  687. │Label 10 │
  688. │Label 11 │
  689. │Label 12 │
  690. │Label 13 │
  691. │Label 14 │
  692. │Label 15 │
  693. │Label 16 │
  694. │Label 17 │
  695. │Label 17 │
  696. └────────────────────┘",
  697. @"
  698. ┌────────────────────┐
  699. │View with long text │
  700. │Label 0 │
  701. │Label 1 │
  702. │Label 2 │
  703. │Label 3 │
  704. │Label 4 │
  705. │Label 5 │
  706. │Label 6 │
  707. │Label 7 │
  708. │Label 8 │
  709. │Label 9 │
  710. │Label 10 │
  711. │Label 11 │
  712. │Label 12 │
  713. │Label 13 │
  714. │Label 14 │
  715. │Label 15 │
  716. │Label 16 │
  717. │Label 17 │
  718. │Label 18 │
  719. │Label 18 │
  720. └────────────────────┘",
  721. @"
  722. ┌────────────────────┐
  723. │View with long text │
  724. │Label 0 │
  725. │Label 1 │
  726. │Label 2 │
  727. │Label 3 │
  728. │Label 4 │
  729. │Label 5 │
  730. │Label 6 │
  731. │Label 7 │
  732. │Label 8 │
  733. │Label 9 │
  734. │Label 10 │
  735. │Label 11 │
  736. │Label 12 │
  737. │Label 13 │
  738. │Label 14 │
  739. │Label 15 │
  740. │Label 16 │
  741. │Label 17 │
  742. │Label 18 │
  743. │Label 19 │
  744. │Label 19 │
  745. └────────────────────┘"
  746. };
  747. private static readonly Size _size1x1 = new (1, 1);
  748. // TODO: This is a Label test. Move to label tests if there's not already a test for this.
  749. [Fact]
  750. [AutoInitShutdown]
  751. public void AnchorEnd_Better_Than_Bottom_Equal_Inside_Window ()
  752. {
  753. var win = new Window ();
  754. var label = new Label
  755. {
  756. Text = "This should be the last line.",
  757. ColorScheme = Colors.ColorSchemes ["Menu"],
  758. //Width = Dim.Fill (),
  759. X = 0, // keep unit test focused; don't use Center here
  760. Y = Pos.AnchorEnd (1)
  761. };
  762. win.Add (label);
  763. Toplevel top = new ();
  764. top.Add (win);
  765. RunState rs = Application.Begin (top);
  766. ((FakeDriver)Application.Driver).SetBufferSize (40, 10);
  767. Assert.Equal (29, label.Text.Length);
  768. Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame);
  769. Assert.Equal (new Rectangle (0, 0, 40, 10), win.Frame);
  770. Assert.Equal (new Rectangle (0, 7, 29, 1), label.Frame);
  771. var expected = @"
  772. ┌──────────────────────────────────────┐
  773. │ │
  774. │ │
  775. │ │
  776. │ │
  777. │ │
  778. │ │
  779. │ │
  780. │This should be the last line. │
  781. └──────────────────────────────────────┘
  782. "
  783. ;
  784. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  785. Application.End (rs);
  786. }
  787. [Fact]
  788. [AutoInitShutdown]
  789. public void AnchorEnd_Better_Than_Bottom_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
  790. {
  791. var win = new Window ();
  792. // Label is AutoSize == true
  793. var label = new Label
  794. {
  795. Text = "This should be the last line.",
  796. ColorScheme = Colors.ColorSchemes ["Menu"],
  797. X = 0,
  798. Y = Pos.AnchorEnd (1)
  799. };
  800. win.Add (label);
  801. var menu = new MenuBar { Menus = new MenuBarItem [] { new ("Menu", "", null) } };
  802. var status = new StatusBar (new StatusItem [] { new (KeyCode.F1, "~F1~ Help", null) });
  803. Toplevel top = new ();
  804. top.Add (win, menu, status);
  805. RunState rs = Application.Begin (top);
  806. Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
  807. Assert.Equal (new Rectangle (0, 0, 80, 1), menu.Frame);
  808. Assert.Equal (new Rectangle (0, 24, 80, 1), status.Frame);
  809. Assert.Equal (new Rectangle (0, 1, 80, 23), win.Frame);
  810. Assert.Equal (new Rectangle (0, 20, 29, 1), label.Frame);
  811. var expected = @"
  812. Menu
  813. ┌──────────────────────────────────────────────────────────────────────────────┐
  814. │ │
  815. │ │
  816. │ │
  817. │ │
  818. │ │
  819. │ │
  820. │ │
  821. │ │
  822. │ │
  823. │ │
  824. │ │
  825. │ │
  826. │ │
  827. │ │
  828. │ │
  829. │ │
  830. │ │
  831. │ │
  832. │ │
  833. │ │
  834. │This should be the last line. │
  835. └──────────────────────────────────────────────────────────────────────────────┘
  836. F1 Help
  837. ";
  838. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  839. Application.End (rs);
  840. }
  841. // TODO: This is a Label test. Move to label tests if there's not already a test for this.
  842. [Fact]
  843. [AutoInitShutdown]
  844. public void Bottom_Equal_Inside_Window ()
  845. {
  846. var win = new Window ();
  847. // Label is AutoSize == true
  848. var label = new Label
  849. {
  850. Text = "This should be the last line.",
  851. ColorScheme = Colors.ColorSchemes ["Menu"],
  852. //Width = Dim.Fill (),
  853. X = 0,
  854. Y = Pos.Bottom (win)
  855. - 3 // two lines top and bottom borders more one line above the bottom border
  856. };
  857. win.Add (label);
  858. Toplevel top = new ();
  859. top.Add (win);
  860. RunState rs = Application.Begin (top);
  861. ((FakeDriver)Application.Driver).SetBufferSize (40, 10);
  862. Assert.Equal (new Rectangle (0, 0, 40, 10), top.Frame);
  863. Assert.Equal (new Rectangle (0, 0, 40, 10), win.Frame);
  864. Assert.Equal (new Rectangle (0, 7, 29, 1), label.Frame);
  865. var expected = @"
  866. ┌──────────────────────────────────────┐
  867. │ │
  868. │ │
  869. │ │
  870. │ │
  871. │ │
  872. │ │
  873. │ │
  874. │This should be the last line. │
  875. └──────────────────────────────────────┘
  876. ";
  877. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  878. Application.End (rs);
  879. }
  880. // TODO: This is a Label test. Move to label tests if there's not already a test for this.
  881. [Fact]
  882. [AutoInitShutdown]
  883. public void Bottom_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
  884. {
  885. var win = new Window ();
  886. // Label is AutoSize == true
  887. var label = new Label
  888. {
  889. Text = "This should be the last line.",
  890. ColorScheme = Colors.ColorSchemes ["Menu"],
  891. //Width = Dim.Fill (),
  892. X = 0,
  893. Y = Pos.Bottom (win) - 4 // two lines top and bottom borders more two lines above border
  894. };
  895. win.Add (label);
  896. var menu = new MenuBar { Menus = new MenuBarItem [] { new ("Menu", "", null) } };
  897. var status = new StatusBar (new StatusItem [] { new (KeyCode.F1, "~F1~ Help", null) });
  898. Toplevel top = new ();
  899. top.Add (win, menu, status);
  900. RunState rs = Application.Begin (top);
  901. Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame);
  902. Assert.Equal (new Rectangle (0, 0, 80, 1), menu.Frame);
  903. Assert.Equal (new Rectangle (0, 24, 80, 1), status.Frame);
  904. Assert.Equal (new Rectangle (0, 1, 80, 23), win.Frame);
  905. Assert.Equal (new Rectangle (0, 20, 29, 1), label.Frame);
  906. var expected = @"
  907. Menu
  908. ┌──────────────────────────────────────────────────────────────────────────────┐
  909. │ │
  910. │ │
  911. │ │
  912. │ │
  913. │ │
  914. │ │
  915. │ │
  916. │ │
  917. │ │
  918. │ │
  919. │ │
  920. │ │
  921. │ │
  922. │ │
  923. │ │
  924. │ │
  925. │ │
  926. │ │
  927. │ │
  928. │ │
  929. │This should be the last line. │
  930. └──────────────────────────────────────────────────────────────────────────────┘
  931. F1 Help
  932. ";
  933. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  934. Application.End (rs);
  935. }
  936. // TODO: This is a Dim test. Move to Dim tests.
  937. [Fact]
  938. [AutoInitShutdown]
  939. public void Dim_Subtract_Operator_With_Text ()
  940. {
  941. Toplevel top = new ();
  942. var view = new View
  943. {
  944. Text = "View with long text",
  945. X = 0,
  946. Y = 0,
  947. Width = 20,
  948. Height = 1
  949. };
  950. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  951. var count = 20;
  952. // Label is AutoSize == true
  953. List<Label> listLabels = new ();
  954. for (var i = 0; i < count; i++)
  955. {
  956. field.Text = $"Label {i}";
  957. var label = new Label { Text = field.Text, X = 0, Y = i + 1 /*, Width = 10*/ };
  958. view.Add (label);
  959. Assert.Equal ($"Label {i}", label.Text);
  960. Assert.Equal ($"Absolute({i + 1})", label.Y.ToString ());
  961. listLabels.Add (label);
  962. if (i == 0)
  963. {
  964. Assert.Equal ($"Absolute({i + 1})", view.Height.ToString ());
  965. view.Height += 1;
  966. Assert.Equal ($"Absolute({i + 2})", view.Height.ToString ());
  967. }
  968. else
  969. {
  970. Assert.Equal ($"Absolute({i + 1})", view.Height.ToString ());
  971. view.Height += 1;
  972. Assert.Equal ($"Absolute({i + 2})", view.Height.ToString ());
  973. }
  974. }
  975. field.KeyDown += (s, k) =>
  976. {
  977. if (k.KeyCode == KeyCode.Enter)
  978. {
  979. ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
  980. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], _output);
  981. Assert.Equal (new Rectangle (0, 0, 22, count + 4), pos);
  982. if (count > 0)
  983. {
  984. Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
  985. view.Remove (listLabels [count - 1]);
  986. listLabels [count - 1].Dispose ();
  987. listLabels.RemoveAt (count - 1);
  988. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  989. view.Height -= 1;
  990. count--;
  991. if (listLabels.Count > 0)
  992. {
  993. field.Text = listLabels [count - 1].Text;
  994. }
  995. else
  996. {
  997. field.Text = string.Empty;
  998. }
  999. }
  1000. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1001. }
  1002. };
  1003. Application.Iteration += (s, a) =>
  1004. {
  1005. while (count > -1)
  1006. {
  1007. field.NewKeyDownEvent (Key.Enter);
  1008. if (count == 0)
  1009. {
  1010. field.NewKeyDownEvent (Key.Enter);
  1011. break;
  1012. }
  1013. }
  1014. Application.RequestStop ();
  1015. };
  1016. var win = new Window ();
  1017. win.Add (view);
  1018. win.Add (field);
  1019. top.Add (win);
  1020. Application.Run (top);
  1021. Assert.Equal (0, count);
  1022. Assert.Equal (count, listLabels.Count);
  1023. }
  1024. // TODO: This is a Label test. Move to Label tests.
  1025. [Fact]
  1026. [SetupFakeDriver]
  1027. public void Label_Height_Zero_Stays_Zero ()
  1028. {
  1029. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  1030. var text = "Label";
  1031. var label = new Label
  1032. {
  1033. Text = text,
  1034. };
  1035. label.Width = Dim.Fill () - text.Length;
  1036. label.Height = 0;
  1037. var win = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () };
  1038. win.Add (label);
  1039. win.BeginInit ();
  1040. win.EndInit ();
  1041. win.LayoutSubviews ();
  1042. win.Draw ();
  1043. Assert.Equal (5, text.Length);
  1044. Assert.Equal (new (0, 0, 3, 0), label.Frame);
  1045. //Assert.Equal (new (5, 1), label.TextFormatter.Size);
  1046. Assert.Single (label.TextFormatter.GetLines ());
  1047. Assert.Equal (new (0, 0, 10, 4), win.Frame);
  1048. var expected = @"
  1049. ┌────────┐
  1050. │ │
  1051. │ │
  1052. └────────┘
  1053. ";
  1054. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1055. Assert.Equal (new (0, 0, 10, 4), pos);
  1056. text = "0123456789";
  1057. Assert.Equal (10, text.Length);
  1058. label.Width = Dim.Fill () - text.Length;
  1059. win.LayoutSubviews ();
  1060. win.Clear ();
  1061. win.Draw ();
  1062. Assert.Equal (Rectangle.Empty, label.Frame);
  1063. // Assert.Equal (new (5, 1), label.TextFormatter.Size);
  1064. //Exception exception = Record.Exception (
  1065. // () => Assert.Equal (
  1066. // new List<string> { string.Empty },
  1067. // label.TextFormatter.GetLines ()
  1068. // )
  1069. // );
  1070. //Assert.Null (exception);
  1071. expected = @"
  1072. ┌────────┐
  1073. │ │
  1074. │ │
  1075. └────────┘
  1076. ";
  1077. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1078. Assert.Equal (new (0, 0, 10, 4), pos);
  1079. }
  1080. [Fact]
  1081. [AutoInitShutdown]
  1082. public void Dim_Add_Operator_With_Text ()
  1083. {
  1084. Toplevel top = new ();
  1085. var view = new View
  1086. {
  1087. Text = "View with long text",
  1088. X = 0,
  1089. Y = 0,
  1090. Width = 20,
  1091. Height = 1
  1092. };
  1093. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  1094. var count = 0;
  1095. // Label is AutoSize == true
  1096. List<Label> listLabels = new ();
  1097. field.KeyDown += (s, k) =>
  1098. {
  1099. if (k.KeyCode == KeyCode.Enter)
  1100. {
  1101. ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
  1102. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], _output);
  1103. Assert.Equal (new Rectangle (0, 0, 22, count + 4), pos);
  1104. if (count < 20)
  1105. {
  1106. field.Text = $"Label {count}";
  1107. // Label is AutoSize = true
  1108. var label = new Label { Text = field.Text, X = 0, Y = view.Viewport.Height /*, Width = 10*/ };
  1109. view.Add (label);
  1110. Assert.Equal ($"Label {count}", label.Text);
  1111. Assert.Equal ($"Absolute({count + 1})", label.Y.ToString ());
  1112. listLabels.Add (label);
  1113. //if (count == 0) {
  1114. // Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  1115. // view.Height += 2;
  1116. //} else {
  1117. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1118. view.Height += 1;
  1119. //}
  1120. count++;
  1121. }
  1122. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1123. }
  1124. };
  1125. Application.Iteration += (s, a) =>
  1126. {
  1127. while (count < 21)
  1128. {
  1129. field.NewKeyDownEvent (Key.Enter);
  1130. if (count == 20)
  1131. {
  1132. field.NewKeyDownEvent (Key.Enter);
  1133. break;
  1134. }
  1135. }
  1136. Application.RequestStop ();
  1137. };
  1138. var win = new Window ();
  1139. win.Add (view);
  1140. win.Add (field);
  1141. top.Add (win);
  1142. Application.Run (top);
  1143. Assert.Equal (20, count);
  1144. Assert.Equal (count, listLabels.Count);
  1145. }
  1146. [Fact]
  1147. [AutoInitShutdown]
  1148. public void Label_IsEmpty_False_Minimum_Height ()
  1149. {
  1150. var text = "Label";
  1151. var label = new Label
  1152. {
  1153. //Width = Dim.Fill () - text.Length,
  1154. Text = text
  1155. };
  1156. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  1157. win.Add (label);
  1158. var top = new Toplevel ();
  1159. top.Add (win);
  1160. Application.Begin (top);
  1161. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  1162. Assert.Equal (5, text.Length);
  1163. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  1164. Assert.Equal (new (5, 1), label.TextFormatter.Size);
  1165. Assert.Equal (["Label"], label.TextFormatter.GetLines ());
  1166. Assert.Equal (new (0, 0, 10, 4), win.Frame);
  1167. Assert.Equal (new (0, 0, 10, 4), Application.Top.Frame);
  1168. var expected = @"
  1169. ┌────────┐
  1170. │Label │
  1171. │ │
  1172. └────────┘
  1173. ";
  1174. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1175. Assert.Equal (new (0, 0, 10, 4), pos);
  1176. text = "0123456789";
  1177. Assert.Equal (10, text.Length);
  1178. //label.Width = Dim.Fill () - text.Length;
  1179. Application.Refresh ();
  1180. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  1181. Assert.Equal (new (5, 1), label.TextFormatter.Size);
  1182. Exception exception = Record.Exception (() => Assert.Single (label.TextFormatter.GetLines ()));
  1183. Assert.Null (exception);
  1184. expected = @"
  1185. ┌────────┐
  1186. │Label │
  1187. │ │
  1188. └────────┘
  1189. ";
  1190. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1191. Assert.Equal (new (0, 0, 10, 4), pos);
  1192. }
  1193. [Fact]
  1194. [AutoInitShutdown]
  1195. public void Label_IsEmpty_False_Never_Return_Null_Lines ()
  1196. {
  1197. var text = "Label";
  1198. var label = new Label
  1199. {
  1200. //Width = Dim.Fill () - text.Length,
  1201. //Height = 1,
  1202. Text = text
  1203. };
  1204. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  1205. win.Add (label);
  1206. var top = new Toplevel ();
  1207. top.Add (win);
  1208. Application.Begin (top);
  1209. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  1210. Assert.Equal (5, text.Length);
  1211. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  1212. Assert.Equal (new (5, 1), label.TextFormatter.Size);
  1213. Assert.Equal (["Label"], label.TextFormatter.GetLines ());
  1214. Assert.Equal (new (0, 0, 10, 4), win.Frame);
  1215. Assert.Equal (new (0, 0, 10, 4), Application.Top.Frame);
  1216. var expected = @"
  1217. ┌────────┐
  1218. │Label │
  1219. │ │
  1220. └────────┘
  1221. ";
  1222. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1223. Assert.Equal (new (0, 0, 10, 4), pos);
  1224. text = "0123456789";
  1225. Assert.Equal (10, text.Length);
  1226. //label.Width = Dim.Fill () - text.Length;
  1227. Application.Refresh ();
  1228. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  1229. Assert.Equal (new (5, 1), label.TextFormatter.Size);
  1230. Assert.Single (label.TextFormatter.GetLines ());
  1231. expected = @"
  1232. ┌────────┐
  1233. │Label │
  1234. │ │
  1235. └────────┘
  1236. ";
  1237. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1238. Assert.Equal (new (0, 0, 10, 4), pos);
  1239. }
  1240. [Fact]
  1241. public void Label_ResizeView_With_Dim_Absolute ()
  1242. {
  1243. var super = new View ()
  1244. {
  1245. Width = Dim.Fill (),
  1246. Height = Dim.Fill ()
  1247. };
  1248. var label = new Label ();
  1249. label.Text = "New text";
  1250. super.Add (label);
  1251. super.LayoutSubviews ();
  1252. Rectangle expectedLabelBounds = new (0, 0, 8, 1);
  1253. Assert.Equal (expectedLabelBounds, label.Viewport);
  1254. super.Dispose ();
  1255. }
  1256. }