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. ใƒข
  254. ใ‚จ
  255. ใƒ 
  256. ใƒ
  257. ใƒณ
  258. ใ‚บ
  259. ";
  260. Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  261. Assert.Equal (new (0, 0, 2, 7), pos);
  262. top.Dispose ();
  263. }
  264. [Fact]
  265. public void Label_HotKeyChanged_EventFires ()
  266. {
  267. var label = new Label { Text = "Yar" };
  268. label.HotKey = 'Y';
  269. object sender = null;
  270. KeyChangedEventArgs args = null;
  271. label.HotKeyChanged += (s, e) =>
  272. {
  273. sender = s;
  274. args = e;
  275. };
  276. label.HotKey = Key.R;
  277. Assert.Same (label, sender);
  278. Assert.Equal (KeyCode.Y | KeyCode.ShiftMask, args.OldKey);
  279. Assert.Equal (Key.R, args.NewKey);
  280. }
  281. [Fact]
  282. public void Label_HotKeyChanged_EventFires_WithNone ()
  283. {
  284. var label = new Label ();
  285. object sender = null;
  286. KeyChangedEventArgs args = null;
  287. label.HotKeyChanged += (s, e) =>
  288. {
  289. sender = s;
  290. args = e;
  291. };
  292. label.HotKey = KeyCode.R;
  293. Assert.Same (label, sender);
  294. Assert.Equal (KeyCode.Null, args.OldKey);
  295. Assert.Equal (KeyCode.R, args.NewKey);
  296. }
  297. [Fact]
  298. public void TestAssignTextToLabel ()
  299. {
  300. View b = new Label { Text = "heya" };
  301. Assert.Equal ("heya", b.Text);
  302. Assert.Contains ("heya", b.TextFormatter.Text);
  303. b.Text = "heyb";
  304. Assert.Equal ("heyb", b.Text);
  305. Assert.Contains ("heyb", b.TextFormatter.Text);
  306. // with cast
  307. Assert.Equal ("heyb", ((Label)b).Text);
  308. }
  309. [Fact]
  310. [AutoInitShutdown]
  311. public void Update_Only_On_Or_After_Initialize ()
  312. {
  313. var label = new Label { X = Pos.Center (), Y = Pos.Center (), Text = "Say Hello ไฝ " };
  314. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  315. win.Add (label);
  316. var top = new Toplevel ();
  317. top.Add (win);
  318. Assert.False (label.IsInitialized);
  319. Application.Begin (top);
  320. ((FakeDriver)Application.Driver!).SetBufferSize (30, 5);
  321. Assert.True (label.IsInitialized);
  322. Assert.Equal ("Say Hello ไฝ ", label.Text);
  323. Assert.Equal ("Say Hello ไฝ ", label.TextFormatter.Text);
  324. Assert.Equal (new (0, 0, 12, 1), label.Viewport);
  325. var expected = @"
  326. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  327. โ”‚ โ”‚
  328. โ”‚ Say Hello ไฝ  โ”‚
  329. โ”‚ โ”‚
  330. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  331. ";
  332. Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  333. Assert.Equal (new (0, 0, 30, 5), pos);
  334. top.Dispose ();
  335. }
  336. [Fact]
  337. [AutoInitShutdown]
  338. public void Update_Parameterless_Only_On_Or_After_Initialize ()
  339. {
  340. var label = new Label { X = Pos.Center (), Y = Pos.Center (), Text = "Say Hello ไฝ " };
  341. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  342. win.Add (label);
  343. var top = new Toplevel ();
  344. top.Add (win);
  345. Assert.False (label.IsInitialized);
  346. Application.Begin (top);
  347. ((FakeDriver)Application.Driver!).SetBufferSize (30, 5);
  348. Assert.True (label.IsInitialized);
  349. Assert.Equal ("Say Hello ไฝ ", label.Text);
  350. Assert.Equal ("Say Hello ไฝ ", label.TextFormatter.Text);
  351. Assert.Equal (new (0, 0, 12, 1), label.Viewport);
  352. var expected = @"
  353. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  354. โ”‚ โ”‚
  355. โ”‚ Say Hello ไฝ  โ”‚
  356. โ”‚ โ”‚
  357. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  358. ";
  359. Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  360. Assert.Equal (new (0, 0, 30, 5), pos);
  361. top.Dispose ();
  362. }
  363. [Fact]
  364. [SetupFakeDriver]
  365. public void Full_Border ()
  366. {
  367. var label = new Label { BorderStyle = LineStyle.Single, Text = "Test" };
  368. label.BeginInit ();
  369. label.EndInit ();
  370. label.SetRelativeLayout (Application.Screen.Size);
  371. Assert.Equal (new (0, 0, 4, 1), label.Viewport);
  372. Assert.Equal (new (0, 0, 6, 3), label.Frame);
  373. label.Draw ();
  374. DriverAssert.AssertDriverContentsWithFrameAre (
  375. @"
  376. โ”Œโ”คTeโ”œโ”
  377. โ”‚Testโ”‚
  378. โ””โ”€โ”€โ”€โ”€โ”˜",
  379. output
  380. );
  381. label.Dispose ();
  382. }
  383. [Fact]
  384. [AutoInitShutdown]
  385. public void With_Top_Margin_Without_Top_Border ()
  386. {
  387. var label = new Label { Text = "Test", /*Width = 6, Height = 3,*/ BorderStyle = LineStyle.Single };
  388. label.Margin.Thickness = new (0, 1, 0, 0);
  389. label.Border.Thickness = new (1, 0, 1, 1);
  390. var top = new Toplevel ();
  391. top.Add (label);
  392. Application.Begin (top);
  393. Application.LayoutAndDraw ();
  394. Assert.Equal (new (0, 0, 6, 3), label.Frame);
  395. Assert.Equal (new (0, 0, 4, 1), label.Viewport);
  396. Application.Begin (top);
  397. DriverAssert.AssertDriverContentsWithFrameAre (
  398. @"
  399. โ”‚Testโ”‚
  400. โ””โ”€โ”€โ”€โ”€โ”˜",
  401. output
  402. );
  403. top.Dispose ();
  404. }
  405. [Fact]
  406. [AutoInitShutdown]
  407. public void Without_Top_Border ()
  408. {
  409. var label = new Label { Text = "Test", /* Width = 6, Height = 3, */BorderStyle = LineStyle.Single };
  410. label.Border.Thickness = new (1, 0, 1, 1);
  411. var top = new Toplevel ();
  412. top.Add (label);
  413. Application.Begin (top);
  414. Application.LayoutAndDraw ();
  415. Assert.Equal (new (0, 0, 6, 2), label.Frame);
  416. Assert.Equal (new (0, 0, 4, 1), label.Viewport);
  417. Application.Begin (top);
  418. DriverAssert.AssertDriverContentsWithFrameAre (
  419. @"
  420. โ”‚Testโ”‚
  421. โ””โ”€โ”€โ”€โ”€โ”˜",
  422. output
  423. );
  424. top.Dispose ();
  425. }
  426. // These tests were formally in AutoSizetrue.cs. They are (poor) Label tests.
  427. private readonly string [] _expecteds = new string [21]
  428. {
  429. @"
  430. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  431. โ”‚View with long text โ”‚
  432. โ”‚ โ”‚
  433. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  434. @"
  435. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  436. โ”‚View with long text โ”‚
  437. โ”‚Label 0 โ”‚
  438. โ”‚Label 0 โ”‚
  439. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  440. @"
  441. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  442. โ”‚View with long text โ”‚
  443. โ”‚Label 0 โ”‚
  444. โ”‚Label 1 โ”‚
  445. โ”‚Label 1 โ”‚
  446. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  447. @"
  448. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  449. โ”‚View with long text โ”‚
  450. โ”‚Label 0 โ”‚
  451. โ”‚Label 1 โ”‚
  452. โ”‚Label 2 โ”‚
  453. โ”‚Label 2 โ”‚
  454. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  455. @"
  456. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  457. โ”‚View with long text โ”‚
  458. โ”‚Label 0 โ”‚
  459. โ”‚Label 1 โ”‚
  460. โ”‚Label 2 โ”‚
  461. โ”‚Label 3 โ”‚
  462. โ”‚Label 3 โ”‚
  463. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  464. @"
  465. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  466. โ”‚View with long text โ”‚
  467. โ”‚Label 0 โ”‚
  468. โ”‚Label 1 โ”‚
  469. โ”‚Label 2 โ”‚
  470. โ”‚Label 3 โ”‚
  471. โ”‚Label 4 โ”‚
  472. โ”‚Label 4 โ”‚
  473. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  474. @"
  475. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  476. โ”‚View with long text โ”‚
  477. โ”‚Label 0 โ”‚
  478. โ”‚Label 1 โ”‚
  479. โ”‚Label 2 โ”‚
  480. โ”‚Label 3 โ”‚
  481. โ”‚Label 4 โ”‚
  482. โ”‚Label 5 โ”‚
  483. โ”‚Label 5 โ”‚
  484. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  485. @"
  486. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  487. โ”‚View with long text โ”‚
  488. โ”‚Label 0 โ”‚
  489. โ”‚Label 1 โ”‚
  490. โ”‚Label 2 โ”‚
  491. โ”‚Label 3 โ”‚
  492. โ”‚Label 4 โ”‚
  493. โ”‚Label 5 โ”‚
  494. โ”‚Label 6 โ”‚
  495. โ”‚Label 6 โ”‚
  496. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  497. @"
  498. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  499. โ”‚View with long text โ”‚
  500. โ”‚Label 0 โ”‚
  501. โ”‚Label 1 โ”‚
  502. โ”‚Label 2 โ”‚
  503. โ”‚Label 3 โ”‚
  504. โ”‚Label 4 โ”‚
  505. โ”‚Label 5 โ”‚
  506. โ”‚Label 6 โ”‚
  507. โ”‚Label 7 โ”‚
  508. โ”‚Label 7 โ”‚
  509. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  510. @"
  511. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  512. โ”‚View with long text โ”‚
  513. โ”‚Label 0 โ”‚
  514. โ”‚Label 1 โ”‚
  515. โ”‚Label 2 โ”‚
  516. โ”‚Label 3 โ”‚
  517. โ”‚Label 4 โ”‚
  518. โ”‚Label 5 โ”‚
  519. โ”‚Label 6 โ”‚
  520. โ”‚Label 7 โ”‚
  521. โ”‚Label 8 โ”‚
  522. โ”‚Label 8 โ”‚
  523. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  524. @"
  525. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  526. โ”‚View with long text โ”‚
  527. โ”‚Label 0 โ”‚
  528. โ”‚Label 1 โ”‚
  529. โ”‚Label 2 โ”‚
  530. โ”‚Label 3 โ”‚
  531. โ”‚Label 4 โ”‚
  532. โ”‚Label 5 โ”‚
  533. โ”‚Label 6 โ”‚
  534. โ”‚Label 7 โ”‚
  535. โ”‚Label 8 โ”‚
  536. โ”‚Label 9 โ”‚
  537. โ”‚Label 9 โ”‚
  538. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  539. @"
  540. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  541. โ”‚View with long text โ”‚
  542. โ”‚Label 0 โ”‚
  543. โ”‚Label 1 โ”‚
  544. โ”‚Label 2 โ”‚
  545. โ”‚Label 3 โ”‚
  546. โ”‚Label 4 โ”‚
  547. โ”‚Label 5 โ”‚
  548. โ”‚Label 6 โ”‚
  549. โ”‚Label 7 โ”‚
  550. โ”‚Label 8 โ”‚
  551. โ”‚Label 9 โ”‚
  552. โ”‚Label 10 โ”‚
  553. โ”‚Label 10 โ”‚
  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 11 โ”‚
  571. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  572. @"
  573. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  574. โ”‚View with long text โ”‚
  575. โ”‚Label 0 โ”‚
  576. โ”‚Label 1 โ”‚
  577. โ”‚Label 2 โ”‚
  578. โ”‚Label 3 โ”‚
  579. โ”‚Label 4 โ”‚
  580. โ”‚Label 5 โ”‚
  581. โ”‚Label 6 โ”‚
  582. โ”‚Label 7 โ”‚
  583. โ”‚Label 8 โ”‚
  584. โ”‚Label 9 โ”‚
  585. โ”‚Label 10 โ”‚
  586. โ”‚Label 11 โ”‚
  587. โ”‚Label 12 โ”‚
  588. โ”‚Label 12 โ”‚
  589. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  590. @"
  591. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  592. โ”‚View with long text โ”‚
  593. โ”‚Label 0 โ”‚
  594. โ”‚Label 1 โ”‚
  595. โ”‚Label 2 โ”‚
  596. โ”‚Label 3 โ”‚
  597. โ”‚Label 4 โ”‚
  598. โ”‚Label 5 โ”‚
  599. โ”‚Label 6 โ”‚
  600. โ”‚Label 7 โ”‚
  601. โ”‚Label 8 โ”‚
  602. โ”‚Label 9 โ”‚
  603. โ”‚Label 10 โ”‚
  604. โ”‚Label 11 โ”‚
  605. โ”‚Label 12 โ”‚
  606. โ”‚Label 13 โ”‚
  607. โ”‚Label 13 โ”‚
  608. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  609. @"
  610. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  611. โ”‚View with long text โ”‚
  612. โ”‚Label 0 โ”‚
  613. โ”‚Label 1 โ”‚
  614. โ”‚Label 2 โ”‚
  615. โ”‚Label 3 โ”‚
  616. โ”‚Label 4 โ”‚
  617. โ”‚Label 5 โ”‚
  618. โ”‚Label 6 โ”‚
  619. โ”‚Label 7 โ”‚
  620. โ”‚Label 8 โ”‚
  621. โ”‚Label 9 โ”‚
  622. โ”‚Label 10 โ”‚
  623. โ”‚Label 11 โ”‚
  624. โ”‚Label 12 โ”‚
  625. โ”‚Label 13 โ”‚
  626. โ”‚Label 14 โ”‚
  627. โ”‚Label 14 โ”‚
  628. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  629. @"
  630. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  631. โ”‚View with long text โ”‚
  632. โ”‚Label 0 โ”‚
  633. โ”‚Label 1 โ”‚
  634. โ”‚Label 2 โ”‚
  635. โ”‚Label 3 โ”‚
  636. โ”‚Label 4 โ”‚
  637. โ”‚Label 5 โ”‚
  638. โ”‚Label 6 โ”‚
  639. โ”‚Label 7 โ”‚
  640. โ”‚Label 8 โ”‚
  641. โ”‚Label 9 โ”‚
  642. โ”‚Label 10 โ”‚
  643. โ”‚Label 11 โ”‚
  644. โ”‚Label 12 โ”‚
  645. โ”‚Label 13 โ”‚
  646. โ”‚Label 14 โ”‚
  647. โ”‚Label 15 โ”‚
  648. โ”‚Label 15 โ”‚
  649. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  650. @"
  651. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  652. โ”‚View with long text โ”‚
  653. โ”‚Label 0 โ”‚
  654. โ”‚Label 1 โ”‚
  655. โ”‚Label 2 โ”‚
  656. โ”‚Label 3 โ”‚
  657. โ”‚Label 4 โ”‚
  658. โ”‚Label 5 โ”‚
  659. โ”‚Label 6 โ”‚
  660. โ”‚Label 7 โ”‚
  661. โ”‚Label 8 โ”‚
  662. โ”‚Label 9 โ”‚
  663. โ”‚Label 10 โ”‚
  664. โ”‚Label 11 โ”‚
  665. โ”‚Label 12 โ”‚
  666. โ”‚Label 13 โ”‚
  667. โ”‚Label 14 โ”‚
  668. โ”‚Label 15 โ”‚
  669. โ”‚Label 16 โ”‚
  670. โ”‚Label 16 โ”‚
  671. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  672. @"
  673. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  674. โ”‚View with long text โ”‚
  675. โ”‚Label 0 โ”‚
  676. โ”‚Label 1 โ”‚
  677. โ”‚Label 2 โ”‚
  678. โ”‚Label 3 โ”‚
  679. โ”‚Label 4 โ”‚
  680. โ”‚Label 5 โ”‚
  681. โ”‚Label 6 โ”‚
  682. โ”‚Label 7 โ”‚
  683. โ”‚Label 8 โ”‚
  684. โ”‚Label 9 โ”‚
  685. โ”‚Label 10 โ”‚
  686. โ”‚Label 11 โ”‚
  687. โ”‚Label 12 โ”‚
  688. โ”‚Label 13 โ”‚
  689. โ”‚Label 14 โ”‚
  690. โ”‚Label 15 โ”‚
  691. โ”‚Label 16 โ”‚
  692. โ”‚Label 17 โ”‚
  693. โ”‚Label 17 โ”‚
  694. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  695. @"
  696. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  697. โ”‚View with long text โ”‚
  698. โ”‚Label 0 โ”‚
  699. โ”‚Label 1 โ”‚
  700. โ”‚Label 2 โ”‚
  701. โ”‚Label 3 โ”‚
  702. โ”‚Label 4 โ”‚
  703. โ”‚Label 5 โ”‚
  704. โ”‚Label 6 โ”‚
  705. โ”‚Label 7 โ”‚
  706. โ”‚Label 8 โ”‚
  707. โ”‚Label 9 โ”‚
  708. โ”‚Label 10 โ”‚
  709. โ”‚Label 11 โ”‚
  710. โ”‚Label 12 โ”‚
  711. โ”‚Label 13 โ”‚
  712. โ”‚Label 14 โ”‚
  713. โ”‚Label 15 โ”‚
  714. โ”‚Label 16 โ”‚
  715. โ”‚Label 17 โ”‚
  716. โ”‚Label 18 โ”‚
  717. โ”‚Label 18 โ”‚
  718. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜",
  719. @"
  720. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  721. โ”‚View with long text โ”‚
  722. โ”‚Label 0 โ”‚
  723. โ”‚Label 1 โ”‚
  724. โ”‚Label 2 โ”‚
  725. โ”‚Label 3 โ”‚
  726. โ”‚Label 4 โ”‚
  727. โ”‚Label 5 โ”‚
  728. โ”‚Label 6 โ”‚
  729. โ”‚Label 7 โ”‚
  730. โ”‚Label 8 โ”‚
  731. โ”‚Label 9 โ”‚
  732. โ”‚Label 10 โ”‚
  733. โ”‚Label 11 โ”‚
  734. โ”‚Label 12 โ”‚
  735. โ”‚Label 13 โ”‚
  736. โ”‚Label 14 โ”‚
  737. โ”‚Label 15 โ”‚
  738. โ”‚Label 16 โ”‚
  739. โ”‚Label 17 โ”‚
  740. โ”‚Label 18 โ”‚
  741. โ”‚Label 19 โ”‚
  742. โ”‚Label 19 โ”‚
  743. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜"
  744. };
  745. // TODO: This is a Label test. Move to label tests if there's not already a test for this.
  746. [Fact]
  747. [AutoInitShutdown]
  748. public void AnchorEnd_Better_Than_Bottom_Equal_Inside_Window ()
  749. {
  750. var win = new Window ();
  751. var label = new Label
  752. {
  753. Text = "This should be the last line.",
  754. ColorScheme = Colors.ColorSchemes ["Menu"],
  755. //Width = Dim.Fill (),
  756. X = 0, // keep unit test focused; don't use Center here
  757. Y = Pos.AnchorEnd (1)
  758. };
  759. win.Add (label);
  760. Toplevel top = new ();
  761. top.Add (win);
  762. RunState rs = Application.Begin (top);
  763. ((FakeDriver)Application.Driver!).SetBufferSize (40, 10);
  764. Assert.Equal (29, label.Text.Length);
  765. Assert.Equal (new (0, 0, 40, 10), top.Frame);
  766. Assert.Equal (new (0, 0, 40, 10), win.Frame);
  767. Assert.Equal (new (0, 7, 29, 1), label.Frame);
  768. var expected = @"
  769. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  770. โ”‚ โ”‚
  771. โ”‚ โ”‚
  772. โ”‚ โ”‚
  773. โ”‚ โ”‚
  774. โ”‚ โ”‚
  775. โ”‚ โ”‚
  776. โ”‚ โ”‚
  777. โ”‚This should be the last line. โ”‚
  778. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  779. "
  780. ;
  781. DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  782. Application.End (rs);
  783. top.Dispose ();
  784. }
  785. // TODO: This is a Label test. Move to label tests if there's not already a test for this.
  786. [Fact]
  787. [AutoInitShutdown]
  788. public void Bottom_Equal_Inside_Window ()
  789. {
  790. var win = new Window ();
  791. var label = new Label
  792. {
  793. Text = "This should be the last line.",
  794. ColorScheme = Colors.ColorSchemes ["Menu"],
  795. //Width = Dim.Fill (),
  796. X = 0,
  797. Y = Pos.Bottom (win)
  798. - 3 // two lines top and bottom borders more one line above the bottom border
  799. };
  800. win.Add (label);
  801. Toplevel top = new ();
  802. top.Add (win);
  803. RunState rs = Application.Begin (top);
  804. ((FakeDriver)Application.Driver!).SetBufferSize (40, 10);
  805. Assert.Equal (new (0, 0, 40, 10), top.Frame);
  806. Assert.Equal (new (0, 0, 40, 10), win.Frame);
  807. Assert.Equal (new (0, 7, 29, 1), label.Frame);
  808. var expected = @"
  809. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  810. โ”‚ โ”‚
  811. โ”‚ โ”‚
  812. โ”‚ โ”‚
  813. โ”‚ โ”‚
  814. โ”‚ โ”‚
  815. โ”‚ โ”‚
  816. โ”‚ โ”‚
  817. โ”‚This should be the last line. โ”‚
  818. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  819. ";
  820. DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  821. Application.End (rs);
  822. top.Dispose ();
  823. }
  824. // TODO: This is a Dim test. Move to Dim tests.
  825. [Fact]
  826. [AutoInitShutdown]
  827. public void Dim_Subtract_Operator_With_Text ()
  828. {
  829. Toplevel top = new ();
  830. var view = new View
  831. {
  832. Text = "View with long text",
  833. X = 0,
  834. Y = 0,
  835. Width = 20,
  836. Height = 1
  837. };
  838. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  839. var count = 20;
  840. List<Label> listLabels = new ();
  841. for (var i = 0; i < count; i++)
  842. {
  843. field.Text = $"Label {i}";
  844. var label = new Label { Text = field.Text, X = 0, Y = i + 1 /*, Width = 10*/ };
  845. view.Add (label);
  846. Assert.Equal ($"Label {i}", label.Text);
  847. Assert.Equal ($"Absolute({i + 1})", label.Y.ToString ());
  848. listLabels.Add (label);
  849. if (i == 0)
  850. {
  851. Assert.Equal ($"Absolute({i + 1})", view.Height.ToString ());
  852. view.Height += 1;
  853. Assert.Equal ($"Absolute({i + 2})", view.Height.ToString ());
  854. }
  855. else
  856. {
  857. Assert.Equal ($"Absolute({i + 1})", view.Height.ToString ());
  858. view.Height += 1;
  859. Assert.Equal ($"Absolute({i + 2})", view.Height.ToString ());
  860. }
  861. }
  862. field.KeyDown += (s, k) =>
  863. {
  864. if (k.KeyCode == KeyCode.Enter)
  865. {
  866. ((FakeDriver)Application.Driver!).SetBufferSize (22, count + 4);
  867. Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (_expecteds [count], output);
  868. Assert.Equal (new (0, 0, 22, count + 4), pos);
  869. if (count > 0)
  870. {
  871. Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
  872. view.Remove (listLabels [count - 1]);
  873. listLabels [count - 1].Dispose ();
  874. listLabels.RemoveAt (count - 1);
  875. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  876. view.Height -= 1;
  877. count--;
  878. if (listLabels.Count > 0)
  879. {
  880. field.Text = listLabels [count - 1].Text;
  881. }
  882. else
  883. {
  884. field.Text = string.Empty;
  885. }
  886. }
  887. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  888. }
  889. };
  890. Application.Iteration += (s, a) =>
  891. {
  892. while (count > -1)
  893. {
  894. field.NewKeyDownEvent (Key.Enter);
  895. if (count == 0)
  896. {
  897. field.NewKeyDownEvent (Key.Enter);
  898. break;
  899. }
  900. }
  901. Application.RequestStop ();
  902. };
  903. var win = new Window ();
  904. win.Add (view);
  905. win.Add (field);
  906. top.Add (win);
  907. Application.Run (top);
  908. Assert.Equal (0, count);
  909. Assert.Equal (count, listLabels.Count);
  910. top.Dispose ();
  911. }
  912. // TODO: This is a Label test. Move to Label tests.
  913. [Fact]
  914. [SetupFakeDriver]
  915. public void Label_Height_Zero_Stays_Zero ()
  916. {
  917. ((FakeDriver)Application.Driver!).SetBufferSize (10, 4);
  918. var text = "Label";
  919. var label = new Label
  920. {
  921. Text = text
  922. };
  923. label.Width = Dim.Fill () - text.Length;
  924. label.Height = 0;
  925. var win = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () };
  926. win.Add (label);
  927. win.BeginInit ();
  928. win.EndInit ();
  929. win.LayoutSubViews ();
  930. win.Draw ();
  931. Assert.Equal (5, text.Length);
  932. Assert.Equal (new (0, 0, 3, 0), label.Frame);
  933. //Assert.Equal (new (5, 1), label.TextFormatter.Size);
  934. Assert.Single (label.TextFormatter.GetLines ());
  935. Assert.Equal (new (0, 0, 10, 4), win.Frame);
  936. var expected = @"
  937. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  938. โ”‚ โ”‚
  939. โ”‚ โ”‚
  940. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  941. ";
  942. Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  943. Assert.Equal (new (0, 0, 10, 4), pos);
  944. text = "0123456789";
  945. Assert.Equal (10, text.Length);
  946. label.Width = Dim.Fill () - text.Length;
  947. win.LayoutSubViews ();
  948. win.ClearViewport ();
  949. win.Draw ();
  950. Assert.Equal (Rectangle.Empty, label.Frame);
  951. // Assert.Equal (new (5, 1), label.TextFormatter.Size);
  952. //Exception exception = Record.Exception (
  953. // () => Assert.Equal (
  954. // new List<string> { string.Empty },
  955. // label.TextFormatter.GetLines ()
  956. // )
  957. // );
  958. //Assert.Null (exception);
  959. expected = @"
  960. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  961. โ”‚ โ”‚
  962. โ”‚ โ”‚
  963. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  964. ";
  965. pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  966. Assert.Equal (new (0, 0, 10, 4), pos);
  967. }
  968. [Fact]
  969. [AutoInitShutdown]
  970. public void Dim_Add_Operator_With_Text ()
  971. {
  972. Toplevel top = new ();
  973. var view = new View
  974. {
  975. Text = "View with long text",
  976. X = 0,
  977. Y = 0,
  978. Width = 20,
  979. Height = 1
  980. };
  981. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  982. var count = 0;
  983. List<Label> listLabels = new ();
  984. field.KeyDown += (s, k) =>
  985. {
  986. if (k.KeyCode == KeyCode.Enter)
  987. {
  988. ((FakeDriver)Application.Driver!).SetBufferSize (22, count + 4);
  989. Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (_expecteds [count], output);
  990. Assert.Equal (new (0, 0, 22, count + 4), pos);
  991. if (count < 20)
  992. {
  993. field.Text = $"Label {count}";
  994. var label = new Label { Text = field.Text, X = 0, Y = view.Viewport.Height /*, Width = 10*/ };
  995. view.Add (label);
  996. Assert.Equal ($"Label {count}", label.Text);
  997. Assert.Equal ($"Absolute({count + 1})", label.Y.ToString ());
  998. listLabels.Add (label);
  999. //if (count == 0) {
  1000. // Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  1001. // view.Height += 2;
  1002. //} else {
  1003. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1004. view.Height += 1;
  1005. //}
  1006. count++;
  1007. }
  1008. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1009. }
  1010. };
  1011. Application.Iteration += (s, a) =>
  1012. {
  1013. while (count < 21)
  1014. {
  1015. field.NewKeyDownEvent (Key.Enter);
  1016. if (count == 20)
  1017. {
  1018. field.NewKeyDownEvent (Key.Enter);
  1019. break;
  1020. }
  1021. }
  1022. Application.RequestStop ();
  1023. };
  1024. var win = new Window ();
  1025. win.Add (view);
  1026. win.Add (field);
  1027. top.Add (win);
  1028. Application.Run (top);
  1029. Assert.Equal (20, count);
  1030. Assert.Equal (count, listLabels.Count);
  1031. top.Dispose ();
  1032. }
  1033. [Fact]
  1034. [AutoInitShutdown]
  1035. public void Label_IsEmpty_False_Minimum_Height ()
  1036. {
  1037. var text = "Label";
  1038. var label = new Label
  1039. {
  1040. //Width = Dim.Fill () - text.Length,
  1041. Text = text
  1042. };
  1043. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  1044. win.Add (label);
  1045. var top = new Toplevel ();
  1046. top.Add (win);
  1047. Application.Begin (top);
  1048. ((FakeDriver)Application.Driver!).SetBufferSize (10, 4);
  1049. Assert.Equal (5, text.Length);
  1050. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  1051. Assert.Equal (new (5, 1), label.TextFormatter.ConstrainToSize);
  1052. Assert.Equal (["Label"], label.TextFormatter.GetLines ());
  1053. Assert.Equal (new (0, 0, 10, 4), win.Frame);
  1054. Assert.Equal (new (0, 0, 10, 4), Application.Top.Frame);
  1055. var expected = @"
  1056. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1057. โ”‚Label โ”‚
  1058. โ”‚ โ”‚
  1059. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1060. ";
  1061. Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  1062. Assert.Equal (new (0, 0, 10, 4), pos);
  1063. text = "0123456789";
  1064. Assert.Equal (10, text.Length);
  1065. //label.Width = Dim.Fill () - text.Length;
  1066. Application.LayoutAndDraw ();
  1067. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  1068. Assert.Equal (new (5, 1), label.TextFormatter.ConstrainToSize);
  1069. Exception exception = Record.Exception (() => Assert.Single (label.TextFormatter.GetLines ()));
  1070. Assert.Null (exception);
  1071. expected = @"
  1072. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1073. โ”‚Label โ”‚
  1074. โ”‚ โ”‚
  1075. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1076. ";
  1077. pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  1078. Assert.Equal (new (0, 0, 10, 4), pos);
  1079. top.Dispose ();
  1080. }
  1081. [Fact]
  1082. [AutoInitShutdown]
  1083. public void Label_IsEmpty_False_Never_Return_Null_Lines ()
  1084. {
  1085. var text = "Label";
  1086. var label = new Label
  1087. {
  1088. //Width = Dim.Fill () - text.Length,
  1089. //Height = 1,
  1090. Text = text
  1091. };
  1092. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  1093. win.Add (label);
  1094. var top = new Toplevel ();
  1095. top.Add (win);
  1096. Application.Begin (top);
  1097. ((FakeDriver)Application.Driver!).SetBufferSize (10, 4);
  1098. Assert.Equal (5, text.Length);
  1099. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  1100. Assert.Equal (new (5, 1), label.TextFormatter.ConstrainToSize);
  1101. Assert.Equal (["Label"], label.TextFormatter.GetLines ());
  1102. Assert.Equal (new (0, 0, 10, 4), win.Frame);
  1103. Assert.Equal (new (0, 0, 10, 4), Application.Top.Frame);
  1104. var expected = @"
  1105. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1106. โ”‚Label โ”‚
  1107. โ”‚ โ”‚
  1108. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1109. ";
  1110. Rectangle pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  1111. Assert.Equal (new (0, 0, 10, 4), pos);
  1112. text = "0123456789";
  1113. Assert.Equal (10, text.Length);
  1114. //label.Width = Dim.Fill () - text.Length;
  1115. Application.LayoutAndDraw ();
  1116. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  1117. Assert.Equal (new (5, 1), label.TextFormatter.ConstrainToSize);
  1118. Assert.Single (label.TextFormatter.GetLines ());
  1119. expected = @"
  1120. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1121. โ”‚Label โ”‚
  1122. โ”‚ โ”‚
  1123. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1124. ";
  1125. pos = DriverAssert.AssertDriverContentsWithFrameAre (expected, output);
  1126. Assert.Equal (new (0, 0, 10, 4), pos);
  1127. top.Dispose ();
  1128. }
  1129. [Fact]
  1130. public void Label_ResizeView_With_Dim_Absolute ()
  1131. {
  1132. var super = new View
  1133. {
  1134. Width = Dim.Fill (),
  1135. Height = Dim.Fill ()
  1136. };
  1137. var label = new Label ();
  1138. label.Text = "New text";
  1139. super.Add (label);
  1140. super.LayoutSubViews ();
  1141. Rectangle expectedLabelBounds = new (0, 0, 8, 1);
  1142. Assert.Equal (expectedLabelBounds, label.Viewport);
  1143. super.Dispose ();
  1144. }
  1145. [Fact]
  1146. public void CanFocus_False_HotKey_SetsFocus_Next ()
  1147. {
  1148. View otherView = new ()
  1149. {
  1150. Text = "otherView",
  1151. CanFocus = true
  1152. };
  1153. Label label = new ()
  1154. {
  1155. Text = "_label"
  1156. };
  1157. View nextView = new ()
  1158. {
  1159. Text = "nextView",
  1160. CanFocus = true
  1161. };
  1162. Application.Navigation = new ();
  1163. Application.Top = new ();
  1164. Application.Top.Add (otherView, label, nextView);
  1165. Application.Top.SetFocus ();
  1166. Assert.True (otherView.HasFocus);
  1167. Assert.True (Application.RaiseKeyDownEvent (label.HotKey));
  1168. Assert.False (otherView.HasFocus);
  1169. Assert.False (label.HasFocus);
  1170. Assert.True (nextView.HasFocus);
  1171. Application.Top.Dispose ();
  1172. Application.ResetState ();
  1173. }
  1174. [Fact]
  1175. public void CanFocus_False_MouseClick_SetsFocus_Next ()
  1176. {
  1177. View otherView = new () { X = 0, Y = 0, Width = 1, Height = 1, Id = "otherView", CanFocus = true };
  1178. Label label = new () { X = 0, Y = 1, Text = "_label" };
  1179. View nextView = new () { X = Pos.Right (label), Y = Pos.Top (label), Width = 1, Height = 1, Id = "nextView", CanFocus = true };
  1180. Application.Navigation = new ();
  1181. Application.Top = new ();
  1182. Application.Top.Add (otherView, label, nextView);
  1183. Application.Top.Layout ();
  1184. Application.Top.SetFocus ();
  1185. // click on label
  1186. Application.RaiseMouseEvent (new () { ScreenPosition = label.Frame.Location, Flags = MouseFlags.Button1Clicked });
  1187. Assert.False (label.HasFocus);
  1188. Assert.True (nextView.HasFocus);
  1189. Application.Top.Dispose ();
  1190. Application.ResetState ();
  1191. }
  1192. [Fact]
  1193. public void CanFocus_True_HotKey_SetsFocus ()
  1194. {
  1195. Label label = new ()
  1196. {
  1197. Text = "_label",
  1198. CanFocus = true
  1199. };
  1200. View view = new ()
  1201. {
  1202. Text = "view",
  1203. CanFocus = true
  1204. };
  1205. Application.Navigation = new ();
  1206. Application.Top = new ();
  1207. Application.Top.Add (label, view);
  1208. view.SetFocus ();
  1209. Assert.True (label.CanFocus);
  1210. Assert.False (label.HasFocus);
  1211. Assert.True (view.CanFocus);
  1212. Assert.True (view.HasFocus);
  1213. // No focused view accepts Tab, and there's no other view to focus, so OnKeyDown returns false
  1214. Assert.True (Application.RaiseKeyDownEvent (label.HotKey));
  1215. Assert.True (label.HasFocus);
  1216. Assert.False (view.HasFocus);
  1217. Application.Top.Dispose ();
  1218. Application.ResetState ();
  1219. }
  1220. [Fact]
  1221. public void CanFocus_True_MouseClick_Focuses ()
  1222. {
  1223. Application.Navigation = new ();
  1224. Label label = new ()
  1225. {
  1226. Text = "label",
  1227. X = 0,
  1228. Y = 0,
  1229. CanFocus = true
  1230. };
  1231. View otherView = new ()
  1232. {
  1233. Text = "view",
  1234. X = 0,
  1235. Y = 1,
  1236. Width = 4,
  1237. Height = 1,
  1238. CanFocus = true
  1239. };
  1240. Application.Top = new ()
  1241. {
  1242. Width = 10,
  1243. Height = 10
  1244. };
  1245. Application.Top.Add (label, otherView);
  1246. Application.Top.SetFocus ();
  1247. Application.Top.Layout ();
  1248. Assert.True (label.CanFocus);
  1249. Assert.True (label.HasFocus);
  1250. Assert.True (otherView.CanFocus);
  1251. Assert.False (otherView.HasFocus);
  1252. otherView.SetFocus ();
  1253. Assert.True (otherView.HasFocus);
  1254. // label can focus, so clicking on it set focus
  1255. Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Clicked });
  1256. Assert.True (label.HasFocus);
  1257. Assert.False (otherView.HasFocus);
  1258. // click on view
  1259. Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 1), Flags = MouseFlags.Button1Clicked });
  1260. Assert.False (label.HasFocus);
  1261. Assert.True (otherView.HasFocus);
  1262. Application.Top.Dispose ();
  1263. Application.ResetState ();
  1264. }
  1265. // https://github.com/gui-cs/Terminal.Gui/issues/3893
  1266. [Fact]
  1267. [SetupFakeDriver]
  1268. public void TestLabelUnderscoreMinus ()
  1269. {
  1270. var lbl = new Label
  1271. {
  1272. Text = "TextView with some more test_- text. Unicode shouldn't ๐”นAโ„๐”ฝ!"
  1273. };
  1274. lbl.Draw ();
  1275. }
  1276. }