AutoSizeTextTests.cs 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using Terminal.Gui;
  4. using Xunit;
  5. using Xunit.Abstractions;
  6. namespace Terminal.Gui.ViewTests;
  7. /// <summary>
  8. /// Tests of the <see cref="View.AutoSize"/> property which auto sizes Views based on <see cref="Text"/>.
  9. /// </summary>
  10. public class AutoSizeTextTests {
  11. readonly ITestOutputHelper _output;
  12. public AutoSizeTextTests (ITestOutputHelper output) => _output = output;
  13. [Fact]
  14. [AutoInitShutdown]
  15. public void AutoSize_GetAutoSize_Horizontal ()
  16. {
  17. var text = "text";
  18. var view = new View {
  19. Text = text,
  20. AutoSize = true
  21. };
  22. var win = new Window {
  23. Width = Dim.Fill (),
  24. Height = Dim.Fill ()
  25. };
  26. win.Add (view);
  27. Application.Top.Add (win);
  28. Application.Begin (Application.Top);
  29. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  30. var size = view.GetAutoSize ();
  31. Assert.Equal (new Size (text.Length, 1), size);
  32. view.Text = $"{text}\n{text}";
  33. size = view.GetAutoSize ();
  34. Assert.Equal (new Size (text.Length, 2), size);
  35. view.Text = $"{text}\n{text}\n{text}+";
  36. size = view.GetAutoSize ();
  37. Assert.Equal (new Size (text.Length + 1, 3), size);
  38. text = string.Empty;
  39. view.Text = text;
  40. size = view.GetAutoSize ();
  41. Assert.Equal (new Size (0, 0), size);
  42. text = "1";
  43. view.Text = text;
  44. size = view.GetAutoSize ();
  45. Assert.Equal (new Size (1, 1), size);
  46. text = "界";
  47. view.Text = text;
  48. size = view.GetAutoSize ();
  49. Assert.Equal (new Size (2, 1), size);
  50. }
  51. [Fact]
  52. [AutoInitShutdown]
  53. public void AutoSize_GetAutoSize_Vertical ()
  54. {
  55. var text = "text";
  56. var view = new View {
  57. Text = text,
  58. TextDirection = TextDirection.TopBottom_LeftRight,
  59. AutoSize = true
  60. };
  61. var win = new Window {
  62. Width = Dim.Fill (),
  63. Height = Dim.Fill ()
  64. };
  65. win.Add (view);
  66. Application.Top.Add (win);
  67. Application.Begin (Application.Top);
  68. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  69. var size = view.GetAutoSize ();
  70. Assert.Equal (new Size (1, text.Length), size);
  71. view.Text = $"{text}\n{text}";
  72. size = view.GetAutoSize ();
  73. Assert.Equal (new Size (2, text.Length), size);
  74. view.Text = $"{text}\n{text}\n{text}+";
  75. size = view.GetAutoSize ();
  76. Assert.Equal (new Size (3, text.Length + 1), size);
  77. text = string.Empty;
  78. view.Text = text;
  79. size = view.GetAutoSize ();
  80. Assert.Equal (new Size (0, 0), size);
  81. text = "1";
  82. view.Text = text;
  83. size = view.GetAutoSize ();
  84. Assert.Equal (new Size (1, 1), size);
  85. text = "界";
  86. view.Text = text;
  87. size = view.GetAutoSize ();
  88. Assert.Equal (new Size (2, 1), size);
  89. }
  90. [Fact]
  91. [AutoInitShutdown]
  92. public void AutoSize_GetAutoSize_Left ()
  93. {
  94. var text = "This is some text.";
  95. var view = new View {
  96. Text = text,
  97. TextAlignment = TextAlignment.Left,
  98. AutoSize = true
  99. };
  100. var win = new Window {
  101. Width = Dim.Fill (),
  102. Height = Dim.Fill ()
  103. };
  104. win.Add (view);
  105. Application.Top.Add (win);
  106. Application.Begin (Application.Top);
  107. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  108. var size = view.GetAutoSize ();
  109. Assert.Equal (new Size (text.Length, 1), size);
  110. view.Text = $"{text}\n{text}";
  111. size = view.GetAutoSize ();
  112. Assert.Equal (new Size (text.Length, 2), size);
  113. view.Text = $"{text}\n{text}\n{text}+";
  114. size = view.GetAutoSize ();
  115. Assert.Equal (new Size (text.Length + 1, 3), size);
  116. text = string.Empty;
  117. view.Text = text;
  118. size = view.GetAutoSize ();
  119. Assert.Equal (new Size (0, 0), size);
  120. text = "1";
  121. view.Text = text;
  122. size = view.GetAutoSize ();
  123. Assert.Equal (new Size (1, 1), size);
  124. text = "界";
  125. view.Text = text;
  126. size = view.GetAutoSize ();
  127. Assert.Equal (new Size (2, 1), size);
  128. }
  129. [Fact]
  130. [AutoInitShutdown]
  131. public void AutoSize_GetAutoSize_Right ()
  132. {
  133. var text = "This is some text.";
  134. var view = new View {
  135. Text = text,
  136. TextAlignment = TextAlignment.Right,
  137. AutoSize = true
  138. };
  139. var win = new Window {
  140. Width = Dim.Fill (),
  141. Height = Dim.Fill ()
  142. };
  143. win.Add (view);
  144. Application.Top.Add (win);
  145. Application.Begin (Application.Top);
  146. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  147. var size = view.GetAutoSize ();
  148. Assert.Equal (new Size (text.Length, 1), size);
  149. view.Text = $"{text}\n{text}";
  150. size = view.GetAutoSize ();
  151. Assert.Equal (new Size (text.Length, 2), size);
  152. view.Text = $"{text}\n{text}\n{text}+";
  153. size = view.GetAutoSize ();
  154. Assert.Equal (new Size (text.Length + 1, 3), size);
  155. text = string.Empty;
  156. view.Text = text;
  157. size = view.GetAutoSize ();
  158. Assert.Equal (new Size (0, 0), size);
  159. text = "1";
  160. view.Text = text;
  161. size = view.GetAutoSize ();
  162. Assert.Equal (new Size (1, 1), size);
  163. text = "界";
  164. view.Text = text;
  165. size = view.GetAutoSize ();
  166. Assert.Equal (new Size (2, 1), size);
  167. }
  168. [Fact]
  169. [AutoInitShutdown]
  170. public void AutoSize_GetAutoSize_Centered ()
  171. {
  172. var text = "This is some text.";
  173. var view = new View {
  174. Text = text,
  175. TextAlignment = TextAlignment.Centered,
  176. AutoSize = true
  177. };
  178. var win = new Window {
  179. Width = Dim.Fill (),
  180. Height = Dim.Fill ()
  181. };
  182. win.Add (view);
  183. Application.Top.Add (win);
  184. Application.Begin (Application.Top);
  185. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  186. var size = view.GetAutoSize ();
  187. Assert.Equal (new Size (text.Length, 1), size);
  188. view.Text = $"{text}\n{text}";
  189. size = view.GetAutoSize ();
  190. Assert.Equal (new Size (text.Length, 2), size);
  191. view.Text = $"{text}\n{text}\n{text}+";
  192. size = view.GetAutoSize ();
  193. Assert.Equal (new Size (text.Length + 1, 3), size);
  194. text = string.Empty;
  195. view.Text = text;
  196. size = view.GetAutoSize ();
  197. Assert.Equal (new Size (0, 0), size);
  198. text = "1";
  199. view.Text = text;
  200. size = view.GetAutoSize ();
  201. Assert.Equal (new Size (1, 1), size);
  202. text = "界";
  203. view.Text = text;
  204. size = view.GetAutoSize ();
  205. Assert.Equal (new Size (2, 1), size);
  206. }
  207. [Fact]
  208. [AutoInitShutdown]
  209. public void AutoSize_True_Label_IsEmpty_False_Never_Return_Null_Lines ()
  210. {
  211. var text = "Label";
  212. var label = new Label {
  213. Width = Dim.Fill () - text.Length,
  214. Height = 1,
  215. Text = text
  216. };
  217. var win = new Window {
  218. Width = Dim.Fill (),
  219. Height = Dim.Fill ()
  220. };
  221. win.Add (label);
  222. Application.Top.Add (win);
  223. Application.Begin (Application.Top);
  224. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  225. Assert.Equal (5, text.Length);
  226. Assert.True (label.AutoSize);
  227. Assert.Equal (new Rect (0, 0, 5, 1), label.Frame);
  228. Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
  229. Assert.Equal (new List<string> { "Label" }, label.TextFormatter.Lines);
  230. Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
  231. Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
  232. var expected = @"
  233. ┌────────┐
  234. │Label │
  235. │ │
  236. └────────┘
  237. ";
  238. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  239. Assert.Equal (new Rect (0, 0, 10, 4), pos);
  240. text = "0123456789";
  241. Assert.Equal (10, text.Length);
  242. label.Width = Dim.Fill () - text.Length;
  243. Application.Refresh ();
  244. Assert.True (label.AutoSize);
  245. Assert.Equal (new Rect (0, 0, 5, 1), label.Frame);
  246. Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
  247. Assert.Single (label.TextFormatter.Lines);
  248. expected = @"
  249. ┌────────┐
  250. │Label │
  251. │ │
  252. └────────┘
  253. ";
  254. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  255. Assert.Equal (new Rect (0, 0, 10, 4), pos);
  256. }
  257. [Fact]
  258. [AutoInitShutdown]
  259. public void AutoSize_True_Label_IsEmpty_False_Minimum_Height ()
  260. {
  261. var text = "Label";
  262. var label = new Label {
  263. Width = Dim.Fill () - text.Length,
  264. Text = text
  265. };
  266. var win = new Window {
  267. Width = Dim.Fill (),
  268. Height = Dim.Fill ()
  269. };
  270. win.Add (label);
  271. Application.Top.Add (win);
  272. Application.Begin (Application.Top);
  273. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  274. Assert.Equal (5, text.Length);
  275. Assert.True (label.AutoSize);
  276. Assert.Equal (new Rect (0, 0, 5, 1), label.Frame);
  277. Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
  278. Assert.Equal (new List<string> { "Label" }, label.TextFormatter.Lines);
  279. Assert.Equal (new Rect (0, 0, 10, 4), win.Frame);
  280. Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame);
  281. var expected = @"
  282. ┌────────┐
  283. │Label │
  284. │ │
  285. └────────┘
  286. ";
  287. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  288. Assert.Equal (new Rect (0, 0, 10, 4), pos);
  289. text = "0123456789";
  290. Assert.Equal (10, text.Length);
  291. label.Width = Dim.Fill () - text.Length;
  292. Application.Refresh ();
  293. Assert.Equal (new Rect (0, 0, 5, 1), label.Frame);
  294. Assert.Equal (new Size (5, 1), label.TextFormatter.Size);
  295. var exception = Record.Exception (() => Assert.Single (label.TextFormatter.Lines));
  296. Assert.Null (exception);
  297. expected = @"
  298. ┌────────┐
  299. │Label │
  300. │ │
  301. └────────┘
  302. ";
  303. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  304. Assert.Equal (new Rect (0, 0, 10, 4), pos);
  305. }
  306. [Fact]
  307. [AutoInitShutdown]
  308. public void AutoSize_True_View_IsEmpty_False_Minimum_Width ()
  309. {
  310. var text = "Views";
  311. var view = new View {
  312. TextDirection = TextDirection.TopBottom_LeftRight,
  313. Height = Dim.Fill () - text.Length,
  314. Text = text,
  315. AutoSize = true
  316. };
  317. var win = new Window {
  318. Width = Dim.Fill (),
  319. Height = Dim.Fill ()
  320. };
  321. win.Add (view);
  322. Application.Top.Add (win);
  323. Application.Begin (Application.Top);
  324. ((FakeDriver)Application.Driver).SetBufferSize (4, 10);
  325. Assert.Equal (5, text.Length);
  326. Assert.True (view.AutoSize);
  327. Assert.Equal (new Rect (0, 0, 1, 5), view.Frame);
  328. Assert.Equal (new Size (1, 5), view.TextFormatter.Size);
  329. Assert.Equal (new List<string> { "Views" }, view.TextFormatter.Lines);
  330. Assert.Equal (new Rect (0, 0, 4, 10), win.Frame);
  331. Assert.Equal (new Rect (0, 0, 4, 10), Application.Top.Frame);
  332. var expected = @"
  333. ┌──┐
  334. │V │
  335. │i │
  336. │e │
  337. │w │
  338. │s │
  339. │ │
  340. │ │
  341. │ │
  342. └──┘
  343. ";
  344. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  345. Assert.Equal (new Rect (0, 0, 4, 10), pos);
  346. text = "0123456789";
  347. Assert.Equal (10, text.Length);
  348. view.Height = Dim.Fill () - text.Length;
  349. Application.Refresh ();
  350. Assert.Equal (new Rect (0, 0, 1, 5), view.Frame);
  351. Assert.Equal (new Size (1, 5), view.TextFormatter.Size);
  352. var exception = Record.Exception (() => Assert.Single (view.TextFormatter.Lines));
  353. Assert.Null (exception);
  354. expected = @"
  355. ┌──┐
  356. │V │
  357. │i │
  358. │e │
  359. │w │
  360. │s │
  361. │ │
  362. │ │
  363. │ │
  364. └──┘
  365. ";
  366. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  367. Assert.Equal (new Rect (0, 0, 4, 10), pos);
  368. }
  369. [Fact]
  370. [AutoInitShutdown]
  371. public void AutoSize_True_View_IsEmpty_False_Minimum_Width_Wide_Rune ()
  372. {
  373. var text = "界View";
  374. var view = new View {
  375. TextDirection = TextDirection.TopBottom_LeftRight,
  376. Height = Dim.Fill () - text.Length,
  377. Text = text,
  378. AutoSize = true
  379. };
  380. var win = new Window {
  381. Width = Dim.Fill (),
  382. Height = Dim.Fill ()
  383. };
  384. win.Add (view);
  385. Application.Top.Add (win);
  386. Application.Begin (Application.Top);
  387. ((FakeDriver)Application.Driver).SetBufferSize (4, 10);
  388. Assert.Equal (5, text.Length);
  389. Assert.True (view.AutoSize);
  390. Assert.Equal (new Rect (0, 0, 2, 5), view.Frame);
  391. Assert.Equal (new Size (2, 5), view.TextFormatter.Size);
  392. Assert.Equal (new List<string> { "界View" }, view.TextFormatter.Lines);
  393. Assert.Equal (new Rect (0, 0, 4, 10), win.Frame);
  394. Assert.Equal (new Rect (0, 0, 4, 10), Application.Top.Frame);
  395. var expected = @"
  396. ┌──┐
  397. │界│
  398. │V │
  399. │i │
  400. │e │
  401. │w │
  402. │ │
  403. │ │
  404. │ │
  405. └──┘
  406. ";
  407. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  408. Assert.Equal (new Rect (0, 0, 4, 10), pos);
  409. text = "0123456789";
  410. Assert.Equal (10, text.Length);
  411. view.Height = Dim.Fill () - text.Length;
  412. Application.Refresh ();
  413. Assert.Equal (new Rect (0, 0, 2, 5), view.Frame);
  414. Assert.Equal (new Size (2, 5), view.TextFormatter.Size);
  415. var exception = Record.Exception (() => Assert.Equal (new List<string> { "界View" }, view.TextFormatter.Lines));
  416. Assert.Null (exception);
  417. expected = @"
  418. ┌──┐
  419. │界│
  420. │V │
  421. │i │
  422. │e │
  423. │w │
  424. │ │
  425. │ │
  426. │ │
  427. └──┘
  428. ";
  429. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  430. Assert.Equal (new Rect (0, 0, 4, 10), pos);
  431. }
  432. [Fact]
  433. public void AutoSize_True_Label_If_Text_Emmpty ()
  434. {
  435. var label1 = new Label ();
  436. var label2 = new Label ("");
  437. var label3 = new Label { Text = "" };
  438. Assert.True (label1.AutoSize);
  439. Assert.True (label2.AutoSize);
  440. Assert.True (label3.AutoSize);
  441. label1.Dispose ();
  442. label2.Dispose ();
  443. label3.Dispose ();
  444. }
  445. [Fact]
  446. public void AutoSize_True_Label_If_Text_Is_Not_Emmpty ()
  447. {
  448. var label1 = new Label ();
  449. label1.Text = "Hello World";
  450. var label2 = new Label ("Hello World");
  451. var label3 = new Label { Text = "Hello World" };
  452. Assert.True (label1.AutoSize);
  453. Assert.True (label2.AutoSize);
  454. Assert.True (label3.AutoSize);
  455. label1.Dispose ();
  456. label2.Dispose ();
  457. label3.Dispose ();
  458. }
  459. [Fact]
  460. public void AutoSize_True_ResizeView_With_Dim_Absolute ()
  461. {
  462. var super = new View ();
  463. var label = new Label ();
  464. label.Text = "New text";
  465. // BUGBUG: v2 - label was never added to super, so it was never laid out.
  466. super.Add (label);
  467. super.LayoutSubviews ();
  468. Assert.True (label.AutoSize);
  469. Assert.Equal ("(0,0,8,1)", label.Bounds.ToString ());
  470. super.Dispose ();
  471. }
  472. [Fact]
  473. [AutoInitShutdown]
  474. public void AutoSize_True_Setting_With_Height_Horizontal ()
  475. {
  476. var label = new Label ("Hello") { Width = 10, Height = 2 };
  477. var viewX = new View ("X") { X = Pos.Right (label) };
  478. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  479. Application.Top.Add (label, viewX, viewY);
  480. var rs = Application.Begin (Application.Top);
  481. Assert.True (label.AutoSize);
  482. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  483. var expected = @"
  484. Hello X
  485. Y
  486. "
  487. ;
  488. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  489. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  490. label.AutoSize = false;
  491. Application.Refresh ();
  492. Assert.False (label.AutoSize);
  493. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  494. expected = @"
  495. Hello X
  496. Y
  497. "
  498. ;
  499. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  500. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  501. Application.End (rs);
  502. }
  503. [Fact]
  504. [AutoInitShutdown]
  505. public void AutoSize_True_Setting_With_Height_Vertical ()
  506. {
  507. var label = new Label ("Hello") { Width = 2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight };
  508. var viewX = new View ("X") { X = Pos.Right (label) };
  509. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  510. Application.Top.Add (label, viewX, viewY);
  511. var rs = Application.Begin (Application.Top);
  512. Assert.True (label.AutoSize);
  513. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  514. var expected = @"
  515. H X
  516. e
  517. l
  518. l
  519. o
  520. Y
  521. "
  522. ;
  523. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  524. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  525. label.AutoSize = false;
  526. Application.Refresh ();
  527. Assert.False (label.AutoSize);
  528. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  529. expected = @"
  530. H X
  531. e
  532. l
  533. l
  534. o
  535. Y
  536. "
  537. ;
  538. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  539. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  540. Application.End (rs);
  541. }
  542. [Fact]
  543. [AutoInitShutdown]
  544. public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
  545. {
  546. var lbl = new Label ("123");
  547. Application.Top.Add (lbl);
  548. var rs = Application.Begin (Application.Top);
  549. Assert.True (lbl.AutoSize);
  550. Assert.Equal ("123 ", GetContents ());
  551. lbl.Text = "12";
  552. // Here the AutoSize ensuring the right size with width 3 (Dim.Absolute)
  553. // that was set on the OnAdded method with the text length of 3
  554. // and height 1 because wasn't set and the text has 1 line
  555. Assert.Equal (new Rect (0, 0, 3, 1), lbl.Frame);
  556. Assert.Equal (new Rect (0, 0, 3, 1), lbl._needsDisplayRect);
  557. Assert.Equal (new Rect (0, 0, 0, 0), lbl.SuperView._needsDisplayRect);
  558. Assert.True (lbl.SuperView.LayoutNeeded);
  559. lbl.SuperView.Draw ();
  560. Assert.Equal ("12 ", GetContents ());
  561. string GetContents ()
  562. {
  563. var text = "";
  564. for (var i = 0; i < 4; i++) {
  565. text += Application.Driver.Contents [0, i].Rune;
  566. }
  567. return text;
  568. }
  569. Application.End (rs);
  570. }
  571. [Fact]
  572. [AutoInitShutdown]
  573. public void AutoSize_True_Equal_Before_And_After_IsInitialized_With_Different_Orders ()
  574. {
  575. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = true, Width = 10, Height = 5 };
  576. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = true };
  577. var view3 = new View () { AutoSize = true, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  578. var view4 = new View () {
  579. Text = "Say Hello view4 你",
  580. AutoSize = true,
  581. Width = 10,
  582. Height = 5,
  583. TextDirection = TextDirection.TopBottom_LeftRight
  584. };
  585. var view5 = new View () {
  586. Text = "Say Hello view5 你",
  587. Width = 10,
  588. Height = 5,
  589. AutoSize = true,
  590. TextDirection = TextDirection.TopBottom_LeftRight
  591. };
  592. var view6 = new View () {
  593. AutoSize = true,
  594. Width = 10,
  595. Height = 5,
  596. TextDirection = TextDirection.TopBottom_LeftRight,
  597. Text = "Say Hello view6 你"
  598. };
  599. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  600. Assert.False (view1.IsInitialized);
  601. Assert.False (view2.IsInitialized);
  602. Assert.False (view3.IsInitialized);
  603. Assert.False (view4.IsInitialized);
  604. Assert.False (view5.IsInitialized);
  605. Assert.True (view1.AutoSize);
  606. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  607. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  608. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  609. Assert.True (view2.AutoSize);
  610. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  611. //Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  612. //Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  613. //Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  614. //Assert.True (view3.AutoSize);
  615. //Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  616. //Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  617. //Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  618. //Assert.True (view4.AutoSize);
  619. //Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  620. //Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  621. //Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  622. //Assert.True (view5.AutoSize);
  623. //Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  624. //Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  625. //Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  626. //Assert.True (view6.AutoSize);
  627. //Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  628. //Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  629. //Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  630. var rs = Application.Begin (Application.Top);
  631. Assert.True (view1.IsInitialized);
  632. Assert.True (view2.IsInitialized);
  633. Assert.True (view3.IsInitialized);
  634. Assert.True (view4.IsInitialized);
  635. Assert.True (view5.IsInitialized);
  636. Assert.True (view1.AutoSize);
  637. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  638. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  639. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  640. Assert.True (view2.AutoSize);
  641. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  642. //Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  643. //Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  644. //Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  645. //Assert.True (view3.AutoSize);
  646. //Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  647. //Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  648. //Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  649. //Assert.True (view4.AutoSize);
  650. //Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  651. //Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  652. //Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  653. //Assert.True (view5.AutoSize);
  654. //Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  655. //Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  656. //Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  657. //Assert.True (view6.AutoSize);
  658. //Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  659. //Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  660. //Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  661. Application.End (rs);
  662. }
  663. [Fact]
  664. [AutoInitShutdown]
  665. public void Setting_Frame_Dont_Respect_AutoSize_True_On_Layout_Absolute ()
  666. {
  667. var view1 = new View (new Rect (0, 0, 10, 0)) { Text = "Say Hello view1 你", AutoSize = true };
  668. var view2 = new View (new Rect (0, 0, 0, 10)) {
  669. Text = "Say Hello view2 你",
  670. AutoSize = true,
  671. TextDirection = TextDirection.TopBottom_LeftRight
  672. };
  673. Application.Top.Add (view1, view2);
  674. var rs = Application.Begin (Application.Top);
  675. Assert.True (view1.AutoSize);
  676. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  677. Assert.Equal (new Rect (0, 0, 18, 1), view1.Frame);
  678. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  679. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  680. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  681. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  682. Assert.True (view2.AutoSize);
  683. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  684. //Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  685. //Assert.Equal (new Rect (0, 0, 2, 17), view2.Frame);
  686. //Assert.Equal ("Absolute(0)", view2.X.ToString ());
  687. //Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  688. //Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  689. //Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  690. view1.Frame = new Rect (0, 0, 25, 4);
  691. var firstIteration = false;
  692. Application.RunIteration (ref rs, ref firstIteration);
  693. Assert.True (view1.AutoSize);
  694. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  695. Assert.Equal (new Rect (0, 0, 25, 4), view1.Frame);
  696. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  697. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  698. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  699. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  700. view2.Frame = new Rect (0, 0, 1, 25);
  701. Application.RunIteration (ref rs, ref firstIteration);
  702. Assert.True (view2.AutoSize);
  703. Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  704. Assert.Equal (new Rect (0, 0, 1, 25), view2.Frame);
  705. Assert.Equal ("Absolute(0)", view2.X.ToString ());
  706. Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  707. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  708. //Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  709. //Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  710. Application.End (rs);
  711. }
  712. [Fact]
  713. [AutoInitShutdown]
  714. public void AutoSize_Stays_True_Center_HotKeySpecifier ()
  715. {
  716. var label = new Label () {
  717. X = Pos.Center (),
  718. Y = Pos.Center (),
  719. Text = "Say Hello 你"
  720. };
  721. var win = new Window () {
  722. Width = Dim.Fill (),
  723. Height = Dim.Fill (),
  724. Title = "Test Demo 你"
  725. };
  726. win.Add (label);
  727. Application.Top.Add (win);
  728. Assert.True (label.AutoSize);
  729. var rs = Application.Begin (Application.Top);
  730. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  731. var expected = @$"
  732. ┌┤Test Demo 你├──────────────┐
  733. │ │
  734. │ Say Hello 你 │
  735. │ │
  736. └────────────────────────────┘
  737. ";
  738. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  739. Assert.True (label.AutoSize);
  740. label.Text = "Say Hello 你 changed";
  741. Assert.True (label.AutoSize);
  742. Application.Refresh ();
  743. expected = @"
  744. ┌┤Test Demo 你├──────────────┐
  745. │ │
  746. │ Say Hello 你 changed │
  747. │ │
  748. └────────────────────────────┘
  749. ";
  750. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  751. Application.End (rs);
  752. }
  753. readonly string [] expecteds = new string [21] {
  754. @"
  755. ┌────────────────────┐
  756. │View with long text │
  757. │ │
  758. └────────────────────┘",
  759. @"
  760. ┌────────────────────┐
  761. │View with long text │
  762. │Label 0 │
  763. │Label 0 │
  764. └────────────────────┘",
  765. @"
  766. ┌────────────────────┐
  767. │View with long text │
  768. │Label 0 │
  769. │Label 1 │
  770. │Label 1 │
  771. └────────────────────┘",
  772. @"
  773. ┌────────────────────┐
  774. │View with long text │
  775. │Label 0 │
  776. │Label 1 │
  777. │Label 2 │
  778. │Label 2 │
  779. └────────────────────┘",
  780. @"
  781. ┌────────────────────┐
  782. │View with long text │
  783. │Label 0 │
  784. │Label 1 │
  785. │Label 2 │
  786. │Label 3 │
  787. │Label 3 │
  788. └────────────────────┘",
  789. @"
  790. ┌────────────────────┐
  791. │View with long text │
  792. │Label 0 │
  793. │Label 1 │
  794. │Label 2 │
  795. │Label 3 │
  796. │Label 4 │
  797. │Label 4 │
  798. └────────────────────┘",
  799. @"
  800. ┌────────────────────┐
  801. │View with long text │
  802. │Label 0 │
  803. │Label 1 │
  804. │Label 2 │
  805. │Label 3 │
  806. │Label 4 │
  807. │Label 5 │
  808. │Label 5 │
  809. └────────────────────┘",
  810. @"
  811. ┌────────────────────┐
  812. │View with long text │
  813. │Label 0 │
  814. │Label 1 │
  815. │Label 2 │
  816. │Label 3 │
  817. │Label 4 │
  818. │Label 5 │
  819. │Label 6 │
  820. │Label 6 │
  821. └────────────────────┘",
  822. @"
  823. ┌────────────────────┐
  824. │View with long text │
  825. │Label 0 │
  826. │Label 1 │
  827. │Label 2 │
  828. │Label 3 │
  829. │Label 4 │
  830. │Label 5 │
  831. │Label 6 │
  832. │Label 7 │
  833. │Label 7 │
  834. └────────────────────┘",
  835. @"
  836. ┌────────────────────┐
  837. │View with long text │
  838. │Label 0 │
  839. │Label 1 │
  840. │Label 2 │
  841. │Label 3 │
  842. │Label 4 │
  843. │Label 5 │
  844. │Label 6 │
  845. │Label 7 │
  846. │Label 8 │
  847. │Label 8 │
  848. └────────────────────┘",
  849. @"
  850. ┌────────────────────┐
  851. │View with long text │
  852. │Label 0 │
  853. │Label 1 │
  854. │Label 2 │
  855. │Label 3 │
  856. │Label 4 │
  857. │Label 5 │
  858. │Label 6 │
  859. │Label 7 │
  860. │Label 8 │
  861. │Label 9 │
  862. │Label 9 │
  863. └────────────────────┘",
  864. @"
  865. ┌────────────────────┐
  866. │View with long text │
  867. │Label 0 │
  868. │Label 1 │
  869. │Label 2 │
  870. │Label 3 │
  871. │Label 4 │
  872. │Label 5 │
  873. │Label 6 │
  874. │Label 7 │
  875. │Label 8 │
  876. │Label 9 │
  877. │Label 10 │
  878. │Label 10 │
  879. └────────────────────┘",
  880. @"
  881. ┌────────────────────┐
  882. │View with long text │
  883. │Label 0 │
  884. │Label 1 │
  885. │Label 2 │
  886. │Label 3 │
  887. │Label 4 │
  888. │Label 5 │
  889. │Label 6 │
  890. │Label 7 │
  891. │Label 8 │
  892. │Label 9 │
  893. │Label 10 │
  894. │Label 11 │
  895. │Label 11 │
  896. └────────────────────┘",
  897. @"
  898. ┌────────────────────┐
  899. │View with long text │
  900. │Label 0 │
  901. │Label 1 │
  902. │Label 2 │
  903. │Label 3 │
  904. │Label 4 │
  905. │Label 5 │
  906. │Label 6 │
  907. │Label 7 │
  908. │Label 8 │
  909. │Label 9 │
  910. │Label 10 │
  911. │Label 11 │
  912. │Label 12 │
  913. │Label 12 │
  914. └────────────────────┘",
  915. @"
  916. ┌────────────────────┐
  917. │View with long text │
  918. │Label 0 │
  919. │Label 1 │
  920. │Label 2 │
  921. │Label 3 │
  922. │Label 4 │
  923. │Label 5 │
  924. │Label 6 │
  925. │Label 7 │
  926. │Label 8 │
  927. │Label 9 │
  928. │Label 10 │
  929. │Label 11 │
  930. │Label 12 │
  931. │Label 13 │
  932. │Label 13 │
  933. └────────────────────┘",
  934. @"
  935. ┌────────────────────┐
  936. │View with long text │
  937. │Label 0 │
  938. │Label 1 │
  939. │Label 2 │
  940. │Label 3 │
  941. │Label 4 │
  942. │Label 5 │
  943. │Label 6 │
  944. │Label 7 │
  945. │Label 8 │
  946. │Label 9 │
  947. │Label 10 │
  948. │Label 11 │
  949. │Label 12 │
  950. │Label 13 │
  951. │Label 14 │
  952. │Label 14 │
  953. └────────────────────┘",
  954. @"
  955. ┌────────────────────┐
  956. │View with long text │
  957. │Label 0 │
  958. │Label 1 │
  959. │Label 2 │
  960. │Label 3 │
  961. │Label 4 │
  962. │Label 5 │
  963. │Label 6 │
  964. │Label 7 │
  965. │Label 8 │
  966. │Label 9 │
  967. │Label 10 │
  968. │Label 11 │
  969. │Label 12 │
  970. │Label 13 │
  971. │Label 14 │
  972. │Label 15 │
  973. │Label 15 │
  974. └────────────────────┘",
  975. @"
  976. ┌────────────────────┐
  977. │View with long text │
  978. │Label 0 │
  979. │Label 1 │
  980. │Label 2 │
  981. │Label 3 │
  982. │Label 4 │
  983. │Label 5 │
  984. │Label 6 │
  985. │Label 7 │
  986. │Label 8 │
  987. │Label 9 │
  988. │Label 10 │
  989. │Label 11 │
  990. │Label 12 │
  991. │Label 13 │
  992. │Label 14 │
  993. │Label 15 │
  994. │Label 16 │
  995. │Label 16 │
  996. └────────────────────┘",
  997. @"
  998. ┌────────────────────┐
  999. │View with long text │
  1000. │Label 0 │
  1001. │Label 1 │
  1002. │Label 2 │
  1003. │Label 3 │
  1004. │Label 4 │
  1005. │Label 5 │
  1006. │Label 6 │
  1007. │Label 7 │
  1008. │Label 8 │
  1009. │Label 9 │
  1010. │Label 10 │
  1011. │Label 11 │
  1012. │Label 12 │
  1013. │Label 13 │
  1014. │Label 14 │
  1015. │Label 15 │
  1016. │Label 16 │
  1017. │Label 17 │
  1018. │Label 17 │
  1019. └────────────────────┘",
  1020. @"
  1021. ┌────────────────────┐
  1022. │View with long text │
  1023. │Label 0 │
  1024. │Label 1 │
  1025. │Label 2 │
  1026. │Label 3 │
  1027. │Label 4 │
  1028. │Label 5 │
  1029. │Label 6 │
  1030. │Label 7 │
  1031. │Label 8 │
  1032. │Label 9 │
  1033. │Label 10 │
  1034. │Label 11 │
  1035. │Label 12 │
  1036. │Label 13 │
  1037. │Label 14 │
  1038. │Label 15 │
  1039. │Label 16 │
  1040. │Label 17 │
  1041. │Label 18 │
  1042. │Label 18 │
  1043. └────────────────────┘",
  1044. @"
  1045. ┌────────────────────┐
  1046. │View with long text │
  1047. │Label 0 │
  1048. │Label 1 │
  1049. │Label 2 │
  1050. │Label 3 │
  1051. │Label 4 │
  1052. │Label 5 │
  1053. │Label 6 │
  1054. │Label 7 │
  1055. │Label 8 │
  1056. │Label 9 │
  1057. │Label 10 │
  1058. │Label 11 │
  1059. │Label 12 │
  1060. │Label 13 │
  1061. │Label 14 │
  1062. │Label 15 │
  1063. │Label 16 │
  1064. │Label 17 │
  1065. │Label 18 │
  1066. │Label 19 │
  1067. │Label 19 │
  1068. └────────────────────┘"
  1069. };
  1070. [Fact]
  1071. [AutoInitShutdown]
  1072. public void AutoSize_Dim_Add_Operator_With_Text ()
  1073. {
  1074. var top = Application.Top;
  1075. var view = new View ("View with long text") { X = 0, Y = 0, Width = 20, Height = 1 };
  1076. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  1077. var count = 0;
  1078. // Label is AutoSize == true
  1079. var listLabels = new List<Label> ();
  1080. field.KeyDown += (s, k) => {
  1081. if (k.KeyCode == KeyCode.Enter) {
  1082. ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
  1083. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], _output);
  1084. Assert.Equal (new Rect (0, 0, 22, count + 4), pos);
  1085. if (count < 20) {
  1086. field.Text = $"Label {count}";
  1087. // Label is AutoSize = true
  1088. var label = new Label (field.Text) { X = 0, Y = view.Bounds.Height, Width = 10 };
  1089. view.Add (label);
  1090. Assert.Equal ($"Label {count}", label.Text);
  1091. Assert.Equal ($"Absolute({count + 1})", label.Y.ToString ());
  1092. listLabels.Add (label);
  1093. //if (count == 0) {
  1094. // Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  1095. // view.Height += 2;
  1096. //} else {
  1097. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1098. view.Height += 1;
  1099. //}
  1100. count++;
  1101. }
  1102. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1103. }
  1104. };
  1105. Application.Iteration += (s, a) => {
  1106. while (count < 21) {
  1107. field.NewKeyDownEvent (new Key (KeyCode.Enter));
  1108. if (count == 20) {
  1109. field.NewKeyDownEvent (new Key (KeyCode.Enter));
  1110. break;
  1111. }
  1112. }
  1113. Application.RequestStop ();
  1114. };
  1115. var win = new Window ();
  1116. win.Add (view);
  1117. win.Add (field);
  1118. top.Add (win);
  1119. Application.Run (top);
  1120. Assert.Equal (20, count);
  1121. Assert.Equal (count, listLabels.Count);
  1122. }
  1123. [Fact]
  1124. [AutoInitShutdown]
  1125. public void AutoSize_Dim_Subtract_Operator_With_Text ()
  1126. {
  1127. var top = Application.Top;
  1128. // BUGBUG: v2 - If a View's height is zero, it should not be drawn.
  1129. //// Although view height is zero the text it's draw due the SetMinWidthHeight method
  1130. var view = new View ("View with long text") { X = 0, Y = 0, Width = 20, Height = 1 };
  1131. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  1132. var count = 20;
  1133. // Label is AutoSize == true
  1134. var listLabels = new List<Label> ();
  1135. for (var i = 0; i < count; i++) {
  1136. field.Text = $"Label {i}";
  1137. // BUGBUG: v2 - view has not been initialied yet; view.Bounds is indeterminate
  1138. var label = new Label (field.Text) { X = 0, Y = i + 1, Width = 10 };
  1139. view.Add (label);
  1140. Assert.Equal ($"Label {i}", label.Text);
  1141. // BUGBUG: Bogus test; views have not been initialized yet
  1142. //Assert.Equal ($"Absolute({i + 1})", label.Y.ToString ());
  1143. listLabels.Add (label);
  1144. //if (i == 0) {
  1145. // BUGBUG: Bogus test; views have not been initialized yet
  1146. //Assert.Equal ($"Absolute({i})", view.Height.ToString ());
  1147. //view.Height += 2;
  1148. // BUGBUG: Bogus test; views have not been initialized yet
  1149. //Assert.Equal ($"Absolute({i + 2})", view.Height.ToString ());
  1150. //} else {
  1151. // BUGBUG: Bogus test; views have not been initialized yet
  1152. //Assert.Equal ($"Absolute({i + 1})", view.Height.ToString ());
  1153. view.Height += 1;
  1154. // BUGBUG: Bogus test; views have not been initialized yet
  1155. //Assert.Equal ($"Absolute({i + 2})", view.Height.ToString ());
  1156. //}
  1157. }
  1158. field.KeyDown += (s, k) => {
  1159. if (k.KeyCode == KeyCode.Enter) {
  1160. ((FakeDriver)Application.Driver).SetBufferSize (22, count + 4);
  1161. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expecteds [count], _output);
  1162. Assert.Equal (new Rect (0, 0, 22, count + 4), pos);
  1163. if (count > 0) {
  1164. Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
  1165. view.Remove (listLabels [count - 1]);
  1166. listLabels [count - 1].Dispose ();
  1167. listLabels.RemoveAt (count - 1);
  1168. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1169. view.Height -= 1;
  1170. count--;
  1171. if (listLabels.Count > 0) {
  1172. field.Text = listLabels [count - 1].Text;
  1173. } else {
  1174. field.Text = string.Empty;
  1175. }
  1176. }
  1177. Assert.Equal ($"Absolute({count + 1})", view.Height.ToString ());
  1178. }
  1179. };
  1180. Application.Iteration += (s, a) => {
  1181. while (count > -1) {
  1182. field.NewKeyDownEvent (new Key (KeyCode.Enter));
  1183. if (count == 0) {
  1184. field.NewKeyDownEvent (new Key (KeyCode.Enter));
  1185. break;
  1186. }
  1187. }
  1188. Application.RequestStop ();
  1189. };
  1190. var win = new Window ();
  1191. win.Add (view);
  1192. win.Add (field);
  1193. top.Add (win);
  1194. Application.Run (top);
  1195. Assert.Equal (0, count);
  1196. Assert.Equal (count, listLabels.Count);
  1197. }
  1198. [Fact]
  1199. [AutoInitShutdown]
  1200. public void AutoSize_AnchorEnd_Better_Than_Bottom_Equal_Inside_Window ()
  1201. {
  1202. var win = new Window ();
  1203. // Label is AutoSize == true
  1204. var label = new Label ("This should be the last line.") {
  1205. ColorScheme = Colors.Menu,
  1206. Width = Dim.Fill (),
  1207. X = 0, // keep unit test focused; don't use Center here
  1208. Y = Pos.AnchorEnd (1)
  1209. };
  1210. win.Add (label);
  1211. var top = Application.Top;
  1212. top.Add (win);
  1213. var rs = Application.Begin (top);
  1214. ((FakeDriver)Application.Driver).SetBufferSize (40, 10);
  1215. Assert.True (label.AutoSize);
  1216. Assert.Equal (29, label.Text.Length);
  1217. Assert.Equal (new Rect (0, 0, 40, 10), top.Frame);
  1218. Assert.Equal (new Rect (0, 0, 40, 10), win.Frame);
  1219. Assert.Equal (new Rect (0, 7, 38, 1), label.Frame);
  1220. var expected = @"
  1221. ┌──────────────────────────────────────┐
  1222. │ │
  1223. │ │
  1224. │ │
  1225. │ │
  1226. │ │
  1227. │ │
  1228. │ │
  1229. │This should be the last line. │
  1230. └──────────────────────────────────────┘
  1231. ";
  1232. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1233. Application.End (rs);
  1234. }
  1235. [Fact]
  1236. [AutoInitShutdown]
  1237. public void AutoSize_Bottom_Equal_Inside_Window ()
  1238. {
  1239. var win = new Window ();
  1240. // Label is AutoSize == true
  1241. var label = new Label ("This should be the last line.") {
  1242. ColorScheme = Colors.Menu,
  1243. Width = Dim.Fill (),
  1244. X = 0,
  1245. Y = Pos.Bottom (win) - 3 // two lines top and bottom borders more one line above the bottom border
  1246. };
  1247. win.Add (label);
  1248. var top = Application.Top;
  1249. top.Add (win);
  1250. var rs = Application.Begin (top);
  1251. ((FakeDriver)Application.Driver).SetBufferSize (40, 10);
  1252. Assert.True (label.AutoSize);
  1253. Assert.Equal (new Rect (0, 0, 40, 10), top.Frame);
  1254. Assert.Equal (new Rect (0, 0, 40, 10), win.Frame);
  1255. Assert.Equal (new Rect (0, 7, 38, 1), label.Frame);
  1256. var expected = @"
  1257. ┌──────────────────────────────────────┐
  1258. │ │
  1259. │ │
  1260. │ │
  1261. │ │
  1262. │ │
  1263. │ │
  1264. │ │
  1265. │This should be the last line. │
  1266. └──────────────────────────────────────┘
  1267. ";
  1268. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1269. Application.End (rs);
  1270. }
  1271. [Fact]
  1272. [AutoInitShutdown]
  1273. public void AutoSize_Bottom_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
  1274. {
  1275. var win = new Window ();
  1276. // Label is AutoSize == true
  1277. var label = new Label ("This should be the last line.") {
  1278. ColorScheme = Colors.Menu,
  1279. Width = Dim.Fill (),
  1280. X = 0,
  1281. Y = Pos.Bottom (win) - 4 // two lines top and bottom borders more two lines above border
  1282. };
  1283. win.Add (label);
  1284. var menu = new MenuBar (new MenuBarItem [] { new ("Menu", "", null) });
  1285. var status = new StatusBar (new StatusItem [] { new (KeyCode.F1, "~F1~ Help", null) });
  1286. var top = Application.Top;
  1287. top.Add (win, menu, status);
  1288. var rs = Application.Begin (top);
  1289. Assert.True (label.AutoSize);
  1290. Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
  1291. Assert.Equal (new Rect (0, 0, 80, 1), menu.Frame);
  1292. Assert.Equal (new Rect (0, 24, 80, 1), status.Frame);
  1293. Assert.Equal (new Rect (0, 1, 80, 23), win.Frame);
  1294. Assert.Equal (new Rect (0, 20, 78, 1), label.Frame);
  1295. var expected = @"
  1296. Menu
  1297. ┌──────────────────────────────────────────────────────────────────────────────┐
  1298. │ │
  1299. │ │
  1300. │ │
  1301. │ │
  1302. │ │
  1303. │ │
  1304. │ │
  1305. │ │
  1306. │ │
  1307. │ │
  1308. │ │
  1309. │ │
  1310. │ │
  1311. │ │
  1312. │ │
  1313. │ │
  1314. │ │
  1315. │ │
  1316. │ │
  1317. │ │
  1318. │This should be the last line. │
  1319. └──────────────────────────────────────────────────────────────────────────────┘
  1320. F1 Help
  1321. ";
  1322. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1323. Application.End (rs);
  1324. }
  1325. [Fact]
  1326. [AutoInitShutdown]
  1327. public void AutoSize_AnchorEnd_Better_Than_Bottom_Equal_Inside_Window_With_MenuBar_And_StatusBar_On_Toplevel ()
  1328. {
  1329. var win = new Window ();
  1330. // Label is AutoSize == true
  1331. var label = new Label ("This should be the last line.") {
  1332. ColorScheme = Colors.Menu,
  1333. Width = Dim.Fill (),
  1334. X = 0,
  1335. Y = Pos.AnchorEnd (1)
  1336. };
  1337. win.Add (label);
  1338. var menu = new MenuBar (new MenuBarItem [] { new ("Menu", "", null) });
  1339. var status = new StatusBar (new StatusItem [] { new (KeyCode.F1, "~F1~ Help", null) });
  1340. var top = Application.Top;
  1341. top.Add (win, menu, status);
  1342. var rs = Application.Begin (top);
  1343. Assert.True (label.AutoSize);
  1344. Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
  1345. Assert.Equal (new Rect (0, 0, 80, 1), menu.Frame);
  1346. Assert.Equal (new Rect (0, 24, 80, 1), status.Frame);
  1347. Assert.Equal (new Rect (0, 1, 80, 23), win.Frame);
  1348. Assert.Equal (new Rect (0, 20, 78, 1), label.Frame);
  1349. var expected = @"
  1350. Menu
  1351. ┌──────────────────────────────────────────────────────────────────────────────┐
  1352. │ │
  1353. │ │
  1354. │ │
  1355. │ │
  1356. │ │
  1357. │ │
  1358. │ │
  1359. │ │
  1360. │ │
  1361. │ │
  1362. │ │
  1363. │ │
  1364. │ │
  1365. │ │
  1366. │ │
  1367. │ │
  1368. │ │
  1369. │ │
  1370. │ │
  1371. │ │
  1372. │This should be the last line. │
  1373. └──────────────────────────────────────────────────────────────────────────────┘
  1374. F1 Help
  1375. ";
  1376. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1377. Application.End (rs);
  1378. }
  1379. [Fact]
  1380. [AutoInitShutdown]
  1381. public void AutoSize_True_TextDirection_Toggle ()
  1382. {
  1383. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  1384. // View is AutoSize == true
  1385. var view = new View ();
  1386. win.Add (view);
  1387. Application.Top.Add (win);
  1388. var rs = Application.Begin (Application.Top);
  1389. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  1390. Assert.Equal (new Rect (0, 0, 22, 22), win.Frame);
  1391. Assert.Equal (new Rect (0, 0, 22, 22), win.Margin.Frame);
  1392. Assert.Equal (new Rect (0, 0, 22, 22), win.Border.Frame);
  1393. Assert.Equal (new Rect (1, 1, 20, 20), win.Padding.Frame);
  1394. Assert.False (view.AutoSize);
  1395. Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
  1396. Assert.Equal (Rect.Empty, view.Frame);
  1397. Assert.Equal ("Absolute(0)", view.X.ToString ());
  1398. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  1399. Assert.Equal ("Absolute(0)", view.Width.ToString ());
  1400. Assert.Equal ("Absolute(0)", view.Height.ToString ());
  1401. var expected = @"
  1402. ┌────────────────────┐
  1403. │ │
  1404. │ │
  1405. │ │
  1406. │ │
  1407. │ │
  1408. │ │
  1409. │ │
  1410. │ │
  1411. │ │
  1412. │ │
  1413. │ │
  1414. │ │
  1415. │ │
  1416. │ │
  1417. │ │
  1418. │ │
  1419. │ │
  1420. │ │
  1421. │ │
  1422. │ │
  1423. └────────────────────┘
  1424. ";
  1425. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1426. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1427. view.Text = "Hello World";
  1428. view.Width = 11;
  1429. view.Height = 1;
  1430. win.LayoutSubviews ();
  1431. Application.Refresh ();
  1432. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  1433. Assert.Equal ("Absolute(0)", view.X.ToString ());
  1434. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  1435. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  1436. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  1437. expected = @"
  1438. ┌────────────────────┐
  1439. │Hello World │
  1440. │ │
  1441. │ │
  1442. │ │
  1443. │ │
  1444. │ │
  1445. │ │
  1446. │ │
  1447. │ │
  1448. │ │
  1449. │ │
  1450. │ │
  1451. │ │
  1452. │ │
  1453. │ │
  1454. │ │
  1455. │ │
  1456. │ │
  1457. │ │
  1458. │ │
  1459. └────────────────────┘
  1460. ";
  1461. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1462. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1463. view.AutoSize = true;
  1464. view.Text = "Hello Worlds";
  1465. Application.Refresh ();
  1466. Assert.Equal (new Rect (0, 0, 12, 1), view.Frame);
  1467. Assert.Equal ("Absolute(0)", view.X.ToString ());
  1468. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  1469. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  1470. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  1471. expected = @"
  1472. ┌────────────────────┐
  1473. │Hello Worlds │
  1474. │ │
  1475. │ │
  1476. │ │
  1477. │ │
  1478. │ │
  1479. │ │
  1480. │ │
  1481. │ │
  1482. │ │
  1483. │ │
  1484. │ │
  1485. │ │
  1486. │ │
  1487. │ │
  1488. │ │
  1489. │ │
  1490. │ │
  1491. │ │
  1492. │ │
  1493. └────────────────────┘
  1494. ";
  1495. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1496. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1497. view.TextDirection = TextDirection.TopBottom_LeftRight;
  1498. Application.Refresh ();
  1499. Assert.Equal (new Rect (0, 0, 11, 12), view.Frame);
  1500. Assert.Equal ("Absolute(0)", view.X.ToString ());
  1501. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  1502. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  1503. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  1504. expected = @"
  1505. ┌────────────────────┐
  1506. │H │
  1507. │e │
  1508. │l │
  1509. │l │
  1510. │o │
  1511. │ │
  1512. │W │
  1513. │o │
  1514. │r │
  1515. │l │
  1516. │d │
  1517. │s │
  1518. │ │
  1519. │ │
  1520. │ │
  1521. │ │
  1522. │ │
  1523. │ │
  1524. │ │
  1525. │ │
  1526. └────────────────────┘
  1527. ";
  1528. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1529. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1530. view.AutoSize = false;
  1531. view.Height = 1;
  1532. Application.Refresh ();
  1533. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  1534. Assert.Equal ("Absolute(0)", view.X.ToString ());
  1535. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  1536. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  1537. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  1538. expected = @"
  1539. ┌────────────────────┐
  1540. │HelloWorlds │
  1541. │ │
  1542. │ │
  1543. │ │
  1544. │ │
  1545. │ │
  1546. │ │
  1547. │ │
  1548. │ │
  1549. │ │
  1550. │ │
  1551. │ │
  1552. │ │
  1553. │ │
  1554. │ │
  1555. │ │
  1556. │ │
  1557. │ │
  1558. │ │
  1559. │ │
  1560. └────────────────────┘
  1561. ";
  1562. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1563. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1564. view.PreserveTrailingSpaces = true;
  1565. Application.Refresh ();
  1566. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  1567. Assert.Equal ("Absolute(0)", view.X.ToString ());
  1568. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  1569. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  1570. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  1571. expected = @"
  1572. ┌────────────────────┐
  1573. │Hello World │
  1574. │ │
  1575. │ │
  1576. │ │
  1577. │ │
  1578. │ │
  1579. │ │
  1580. │ │
  1581. │ │
  1582. │ │
  1583. │ │
  1584. │ │
  1585. │ │
  1586. │ │
  1587. │ │
  1588. │ │
  1589. │ │
  1590. │ │
  1591. │ │
  1592. │ │
  1593. └────────────────────┘
  1594. ";
  1595. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1596. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1597. view.PreserveTrailingSpaces = false;
  1598. var f = view.Frame;
  1599. view.Width = f.Height;
  1600. view.Height = f.Width;
  1601. view.TextDirection = TextDirection.TopBottom_LeftRight;
  1602. Application.Refresh ();
  1603. Assert.Equal (new Rect (0, 0, 1, 11), view.Frame);
  1604. Assert.Equal ("Absolute(0)", view.X.ToString ());
  1605. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  1606. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  1607. Assert.Equal ("Absolute(11)", view.Height.ToString ());
  1608. expected = @"
  1609. ┌────────────────────┐
  1610. │H │
  1611. │e │
  1612. │l │
  1613. │l │
  1614. │o │
  1615. │ │
  1616. │W │
  1617. │o │
  1618. │r │
  1619. │l │
  1620. │d │
  1621. │ │
  1622. │ │
  1623. │ │
  1624. │ │
  1625. │ │
  1626. │ │
  1627. │ │
  1628. │ │
  1629. │ │
  1630. └────────────────────┘
  1631. ";
  1632. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1633. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1634. view.AutoSize = true;
  1635. Application.Refresh ();
  1636. Assert.Equal (new Rect (0, 0, 1, 12), view.Frame);
  1637. Assert.Equal ("Absolute(0)", view.X.ToString ());
  1638. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  1639. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  1640. Assert.Equal ("Absolute(12)", view.Height.ToString ());
  1641. expected = @"
  1642. ┌────────────────────┐
  1643. │H │
  1644. │e │
  1645. │l │
  1646. │l │
  1647. │o │
  1648. │ │
  1649. │W │
  1650. │o │
  1651. │r │
  1652. │l │
  1653. │d │
  1654. │s │
  1655. │ │
  1656. │ │
  1657. │ │
  1658. │ │
  1659. │ │
  1660. │ │
  1661. │ │
  1662. │ │
  1663. └────────────────────┘
  1664. ";
  1665. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1666. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1667. Application.End (rs);
  1668. }
  1669. [Fact]
  1670. [AutoInitShutdown]
  1671. public void AutoSize_True_Width_Height_Stay_True_If_TextFormatter_Size_Fit ()
  1672. {
  1673. var text = $"Fi_nish 終";
  1674. var horizontalView = new View () {
  1675. Id = "horizontalView",
  1676. AutoSize = true,
  1677. HotKeySpecifier = (Rune)'_',
  1678. Text = text
  1679. };
  1680. var verticalView = new View () {
  1681. Id = "verticalView",
  1682. Y = 3,
  1683. AutoSize = true,
  1684. HotKeySpecifier = (Rune)'_',
  1685. Text = text,
  1686. TextDirection = TextDirection.TopBottom_LeftRight
  1687. };
  1688. var win = new Window () {
  1689. Id = "win",
  1690. Width = Dim.Fill (),
  1691. Height = Dim.Fill (),
  1692. Text = "Window"
  1693. };
  1694. win.Add (horizontalView, verticalView);
  1695. Application.Top.Add (win);
  1696. var rs = Application.Begin (Application.Top);
  1697. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  1698. Assert.True (horizontalView.AutoSize);
  1699. Assert.True (verticalView.AutoSize);
  1700. Assert.Equal (new Size (10, 1), horizontalView.TextFormatter.Size);
  1701. Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size);
  1702. Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame);
  1703. Assert.Equal ("Absolute(0)", horizontalView.X.ToString ());
  1704. Assert.Equal ("Absolute(0)", horizontalView.Y.ToString ());
  1705. // BUGBUG - v2 - With v1 AutoSize = true Width/Height should always grow or keep initial value,
  1706. // but in v2, autosize will be replaced by Dim.Fit. Disabling test for now.
  1707. Assert.Equal ("Absolute(9)", horizontalView.Width.ToString ());
  1708. Assert.Equal ("Absolute(1)", horizontalView.Height.ToString ());
  1709. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  1710. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  1711. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  1712. Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  1713. Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  1714. var expected = @"
  1715. ┌────────────────────┐
  1716. │Finish 終 │
  1717. │ │
  1718. │ │
  1719. │F │
  1720. │i │
  1721. │n │
  1722. │i │
  1723. │s │
  1724. │h │
  1725. │ │
  1726. │終 │
  1727. │ │
  1728. │ │
  1729. │ │
  1730. │ │
  1731. │ │
  1732. │ │
  1733. │ │
  1734. │ │
  1735. │ │
  1736. └────────────────────┘
  1737. ";
  1738. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1739. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1740. verticalView.Text = $"最初_の行二行目";
  1741. Application.Top.Draw ();
  1742. Assert.True (horizontalView.AutoSize);
  1743. Assert.True (verticalView.AutoSize);
  1744. // height was initialized with 8 and can only grow or keep initial value
  1745. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  1746. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  1747. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  1748. Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  1749. Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  1750. expected = @"
  1751. ┌────────────────────┐
  1752. │Finish 終 │
  1753. │ │
  1754. │ │
  1755. │最 │
  1756. │初 │
  1757. │の │
  1758. │行 │
  1759. │二 │
  1760. │行 │
  1761. │目 │
  1762. │ │
  1763. │ │
  1764. │ │
  1765. │ │
  1766. │ │
  1767. │ │
  1768. │ │
  1769. │ │
  1770. │ │
  1771. │ │
  1772. └────────────────────┘
  1773. ";
  1774. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  1775. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  1776. Application.End (rs);
  1777. }
  1778. }