2
0

LabelTests.cs 46 KB

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