LabelTests.cs 47 KB

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