LabelTests.cs 47 KB

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