TextTests.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. ๏ปฟusing System.Runtime.CompilerServices;
  2. using System.Text;
  3. using Xunit.Abstractions;
  4. namespace Terminal.Gui.ViewTests;
  5. /// <summary>
  6. /// Tests of the <see cref="View.Text"/> and <see cref="View.TextFormatter"/> properties.
  7. /// </summary>
  8. public class TextTests (ITestOutputHelper output)
  9. {
  10. // TextFormatter.Size should be empty unless DimAuto is set or ContentSize is set
  11. [Theory]
  12. [InlineData ("", 0, 0)]
  13. [InlineData (" ", 0, 0)]
  14. [InlineData ("01234", 0, 0)]
  15. public void TextFormatter_Size_Default (string text, int expectedW, int expectedH)
  16. {
  17. var view = new View ();
  18. view.Text = text;
  19. view.Layout ();
  20. Assert.Equal (new (expectedW, expectedH), view.TextFormatter.ConstrainToSize);
  21. }
  22. // TextFormatter.Size should track ContentSize (without DimAuto)
  23. [Theory]
  24. [InlineData ("", 1, 1)]
  25. [InlineData (" ", 1, 1)]
  26. [InlineData ("01234", 1, 1)]
  27. public void TextFormatter_Size_Tracks_ContentSize (string text, int expectedW, int expectedH)
  28. {
  29. var view = new View ();
  30. view.SetContentSize (new (1, 1));
  31. view.Text = text;
  32. view.Layout ();
  33. Assert.Equal (new (expectedW, expectedH), view.TextFormatter.ConstrainToSize);
  34. }
  35. [Fact]
  36. [SetupFakeDriver]
  37. public void Setting_With_Height_Horizontal ()
  38. {
  39. var top = new View { Width = 25, Height = 25 };
  40. var label = new Label { Text = "Hello", /* Width = 10, Height = 2, */ ValidatePosDim = true };
  41. var viewX = new View { Text = "X", X = Pos.Right (label), Width = 1, Height = 1 };
  42. var viewY = new View { Text = "Y", Y = Pos.Bottom (label), Width = 1, Height = 1 };
  43. top.Add (label, viewX, viewY);
  44. top.Layout ();
  45. Assert.Equal (new (0, 0, 5, 1), label.Frame);
  46. top.LayoutSubviews ();
  47. top.Draw ();
  48. var expected = @"
  49. HelloX
  50. Y
  51. ";
  52. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  53. label.Width = 10;
  54. label.Height = 2;
  55. Assert.Equal (new (0, 0, 10, 2), label.Frame);
  56. top.LayoutSubviews ();
  57. top.Draw ();
  58. expected = @"
  59. Hello X
  60. Y
  61. ";
  62. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  63. }
  64. [Fact]
  65. [AutoInitShutdown]
  66. public void Setting_With_Height_Vertical ()
  67. {
  68. // BUGBUG: Label is Width = Dim.Auto (), Height = Dim.Auto (), so Width & Height are ignored
  69. var label = new Label
  70. { /*Width = 2, Height = 10, */
  71. TextDirection = TextDirection.TopBottom_LeftRight, ValidatePosDim = true
  72. };
  73. var viewX = new View { Text = "X", X = Pos.Right (label), Width = 1, Height = 1 };
  74. var viewY = new View { Text = "Y", Y = Pos.Bottom (label), Width = 1, Height = 1 };
  75. var top = new Toplevel ();
  76. top.Add (label, viewX, viewY);
  77. RunState rs = Application.Begin (top);
  78. label.Text = "Hello";
  79. Application.RunIteration (ref rs);
  80. Assert.Equal (new (0, 0, 1, 5), label.Frame);
  81. var expected = @"
  82. HX
  83. e
  84. l
  85. l
  86. o
  87. Y
  88. ";
  89. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  90. label.Width = 2;
  91. label.Height = 10;
  92. Application.RunIteration (ref rs);
  93. Assert.Equal (new (0, 0, 2, 10), label.Frame);
  94. expected = @"
  95. H X
  96. e
  97. l
  98. l
  99. o
  100. Y
  101. "
  102. ;
  103. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  104. Application.End (rs);
  105. top.Dispose ();
  106. }
  107. [Fact]
  108. [AutoInitShutdown]
  109. public void TextDirection_Toggle ()
  110. {
  111. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  112. var view = new View ();
  113. win.Add (view);
  114. var top = new Toplevel ();
  115. top.Add (win);
  116. RunState rs = Application.Begin (top);
  117. ((FakeDriver)Application.Driver!).SetBufferSize (15, 15);
  118. Assert.Equal (new (0, 0, 15, 15), win.Frame);
  119. Assert.Equal (new (0, 0, 15, 15), win.Margin.Frame);
  120. Assert.Equal (new (0, 0, 15, 15), win.Border.Frame);
  121. Assert.Equal (new (1, 1, 13, 13), win.Padding.Frame);
  122. Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
  123. Assert.Equal (Rectangle.Empty, view.Frame);
  124. Assert.Equal ("Absolute(0)", view.X.ToString ());
  125. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  126. Assert.Equal ("Absolute(0)", view.Width.ToString ());
  127. Assert.Equal ("Absolute(0)", view.Height.ToString ());
  128. var expected = @"
  129. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  130. โ”‚ โ”‚
  131. โ”‚ โ”‚
  132. โ”‚ โ”‚
  133. โ”‚ โ”‚
  134. โ”‚ โ”‚
  135. โ”‚ โ”‚
  136. โ”‚ โ”‚
  137. โ”‚ โ”‚
  138. โ”‚ โ”‚
  139. โ”‚ โ”‚
  140. โ”‚ โ”‚
  141. โ”‚ โ”‚
  142. โ”‚ โ”‚
  143. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  144. ";
  145. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  146. view.Text = "Hello World";
  147. view.Width = 11;
  148. view.Height = 1;
  149. Application.RunIteration (ref rs);
  150. Assert.Equal (new (0, 0, 11, 1), view.Frame);
  151. Assert.Equal ("Absolute(0)", view.X.ToString ());
  152. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  153. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  154. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  155. expected = @"
  156. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  157. โ”‚Hello World โ”‚
  158. โ”‚ โ”‚
  159. โ”‚ โ”‚
  160. โ”‚ โ”‚
  161. โ”‚ โ”‚
  162. โ”‚ โ”‚
  163. โ”‚ โ”‚
  164. โ”‚ โ”‚
  165. โ”‚ โ”‚
  166. โ”‚ โ”‚
  167. โ”‚ โ”‚
  168. โ”‚ โ”‚
  169. โ”‚ โ”‚
  170. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  171. ";
  172. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  173. view.Width = Dim.Auto ();
  174. view.Height = Dim.Auto ();
  175. view.Text = "Hello Worlds";
  176. Application.RunIteration (ref rs);
  177. int len = "Hello Worlds".Length;
  178. Assert.Equal (12, len);
  179. Assert.Equal (new (0, 0, len, 1), view.Frame);
  180. expected = @"
  181. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  182. โ”‚Hello Worlds โ”‚
  183. โ”‚ โ”‚
  184. โ”‚ โ”‚
  185. โ”‚ โ”‚
  186. โ”‚ โ”‚
  187. โ”‚ โ”‚
  188. โ”‚ โ”‚
  189. โ”‚ โ”‚
  190. โ”‚ โ”‚
  191. โ”‚ โ”‚
  192. โ”‚ โ”‚
  193. โ”‚ โ”‚
  194. โ”‚ โ”‚
  195. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  196. ";
  197. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  198. view.TextDirection = TextDirection.TopBottom_LeftRight;
  199. Application.RunIteration (ref rs);
  200. Assert.Equal (new (0, 0, 1, 12), view.Frame);
  201. Assert.Equal (new (0, 0, 1, 12), view.Frame);
  202. expected = @"
  203. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  204. โ”‚H โ”‚
  205. โ”‚e โ”‚
  206. โ”‚l โ”‚
  207. โ”‚l โ”‚
  208. โ”‚o โ”‚
  209. โ”‚ โ”‚
  210. โ”‚W โ”‚
  211. โ”‚o โ”‚
  212. โ”‚r โ”‚
  213. โ”‚l โ”‚
  214. โ”‚d โ”‚
  215. โ”‚s โ”‚
  216. โ”‚ โ”‚
  217. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  218. ";
  219. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  220. // Setting to false causes Width and Height to be set to the current ContentSize
  221. view.Width = 1;
  222. view.Height = 12;
  223. Application.RunIteration (ref rs);
  224. Assert.Equal (new (0, 0, 1, 12), view.Frame);
  225. view.Width = 12;
  226. view.Height = 1;
  227. view.TextFormatter.ConstrainToSize = new (12, 1);
  228. Application.RunIteration (ref rs);
  229. Assert.Equal (new (12, 1), view.TextFormatter.ConstrainToSize);
  230. Assert.Equal (new (0, 0, 12, 1), view.Frame);
  231. top.ClearViewport ();
  232. view.SetNeedsDisplay ();
  233. view.Draw ();
  234. expected = @" HelloWorlds";
  235. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  236. Application.RunIteration (ref rs);
  237. // TextDirection.TopBottom_LeftRight - Height of 1 and Width of 12 means
  238. // that the text will be spread "vertically" across 1 line.
  239. // Hence no space.
  240. expected = @"
  241. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  242. โ”‚HelloWorlds โ”‚
  243. โ”‚ โ”‚
  244. โ”‚ โ”‚
  245. โ”‚ โ”‚
  246. โ”‚ โ”‚
  247. โ”‚ โ”‚
  248. โ”‚ โ”‚
  249. โ”‚ โ”‚
  250. โ”‚ โ”‚
  251. โ”‚ โ”‚
  252. โ”‚ โ”‚
  253. โ”‚ โ”‚
  254. โ”‚ โ”‚
  255. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  256. ";
  257. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  258. view.PreserveTrailingSpaces = true;
  259. Application.RunIteration (ref rs);
  260. Assert.Equal (new (0, 0, 12, 1), view.Frame);
  261. expected = @"
  262. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  263. โ”‚Hello Worlds โ”‚
  264. โ”‚ โ”‚
  265. โ”‚ โ”‚
  266. โ”‚ โ”‚
  267. โ”‚ โ”‚
  268. โ”‚ โ”‚
  269. โ”‚ โ”‚
  270. โ”‚ โ”‚
  271. โ”‚ โ”‚
  272. โ”‚ โ”‚
  273. โ”‚ โ”‚
  274. โ”‚ โ”‚
  275. โ”‚ โ”‚
  276. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  277. ";
  278. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  279. view.PreserveTrailingSpaces = false;
  280. Rectangle f = view.Frame;
  281. view.Width = f.Height;
  282. view.Height = f.Width;
  283. view.TextDirection = TextDirection.TopBottom_LeftRight;
  284. Application.RunIteration (ref rs);
  285. Assert.Equal (new (0, 0, 1, 12), view.Frame);
  286. expected = @"
  287. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  288. โ”‚H โ”‚
  289. โ”‚e โ”‚
  290. โ”‚l โ”‚
  291. โ”‚l โ”‚
  292. โ”‚o โ”‚
  293. โ”‚ โ”‚
  294. โ”‚W โ”‚
  295. โ”‚o โ”‚
  296. โ”‚r โ”‚
  297. โ”‚l โ”‚
  298. โ”‚d โ”‚
  299. โ”‚s โ”‚
  300. โ”‚ โ”‚
  301. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  302. ";
  303. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  304. view.Width = Dim.Auto ();
  305. view.Height = Dim.Auto ();
  306. Application.RunIteration (ref rs);
  307. Assert.Equal (new (0, 0, 1, 12), view.Frame);
  308. expected = @"
  309. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  310. โ”‚H โ”‚
  311. โ”‚e โ”‚
  312. โ”‚l โ”‚
  313. โ”‚l โ”‚
  314. โ”‚o โ”‚
  315. โ”‚ โ”‚
  316. โ”‚W โ”‚
  317. โ”‚o โ”‚
  318. โ”‚r โ”‚
  319. โ”‚l โ”‚
  320. โ”‚d โ”‚
  321. โ”‚s โ”‚
  322. โ”‚ โ”‚
  323. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  324. ";
  325. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  326. Application.End (rs);
  327. top.Dispose ();
  328. }
  329. [Fact]
  330. [AutoInitShutdown]
  331. public void View_IsEmpty_False_Minimum_Width ()
  332. {
  333. var text = "Views";
  334. var view = new View
  335. {
  336. TextDirection = TextDirection.TopBottom_LeftRight,
  337. Height = Dim.Fill () - text.Length,
  338. Text = text
  339. };
  340. view.Width = Dim.Auto ();
  341. view.Height = Dim.Auto ();
  342. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  343. win.Add (view);
  344. var top = new Toplevel ();
  345. top.Add (win);
  346. RunState rs = Application.Begin (top);
  347. ((FakeDriver)Application.Driver!).SetBufferSize (4, 10);
  348. Assert.Equal (5, text.Length);
  349. Assert.Equal (new (0, 0, 1, 5), view.Frame);
  350. Assert.Equal (new (1, 5), view.TextFormatter.ConstrainToSize);
  351. Assert.Equal (new () { "Views" }, view.TextFormatter.GetLines ());
  352. Assert.Equal (new (0, 0, 4, 10), win.Frame);
  353. Assert.Equal (new (0, 0, 4, 10), Application.Top.Frame);
  354. var expected = @"
  355. โ”Œโ”€โ”€โ”
  356. โ”‚V โ”‚
  357. โ”‚i โ”‚
  358. โ”‚e โ”‚
  359. โ”‚w โ”‚
  360. โ”‚s โ”‚
  361. โ”‚ โ”‚
  362. โ”‚ โ”‚
  363. โ”‚ โ”‚
  364. โ””โ”€โ”€โ”˜
  365. ";
  366. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  367. Assert.Equal (new (0, 0, 4, 10), pos);
  368. text = "0123456789";
  369. Assert.Equal (10, text.Length);
  370. //view.Height = Dim.Fill () - text.Length;
  371. Application.RunIteration (ref rs);
  372. Assert.Equal (new (0, 0, 1, 5), view.Frame);
  373. Assert.Equal (new (1, 5), view.TextFormatter.ConstrainToSize);
  374. Exception exception = Record.Exception (() => Assert.Single (view.TextFormatter.GetLines ()));
  375. Assert.Null (exception);
  376. expected = @"
  377. โ”Œโ”€โ”€โ”
  378. โ”‚V โ”‚
  379. โ”‚i โ”‚
  380. โ”‚e โ”‚
  381. โ”‚w โ”‚
  382. โ”‚s โ”‚
  383. โ”‚ โ”‚
  384. โ”‚ โ”‚
  385. โ”‚ โ”‚
  386. โ””โ”€โ”€โ”˜
  387. ";
  388. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  389. Assert.Equal (new (0, 0, 4, 10), pos);
  390. top.Dispose ();
  391. }
  392. [Fact]
  393. [SetupFakeDriver]
  394. public void DimAuto_Vertical_TextDirection_Wide_Rune ()
  395. {
  396. var text = "็•ŒView";
  397. var view = new View
  398. {
  399. TextDirection = TextDirection.TopBottom_LeftRight,
  400. Text = text,
  401. Width = Dim.Auto (),
  402. Height = Dim.Auto ()
  403. };
  404. view.SetRelativeLayout (new Size (4, 10));
  405. Assert.Equal (5, text.Length);
  406. // Vertical text - 2 wide, 5 down
  407. Assert.Equal (new (0, 0, 2, 5), view.Frame);
  408. Assert.Equal (new (2, 5), view.TextFormatter.ConstrainToSize);
  409. Assert.Equal (new () { "็•ŒView" }, view.TextFormatter.GetLines ());
  410. view.Draw ();
  411. var expected = @"
  412. ็•Œ
  413. V
  414. i
  415. e
  416. w ";
  417. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  418. }
  419. [Fact]
  420. [AutoInitShutdown]
  421. public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
  422. {
  423. var text = $"0123456789{Environment.NewLine}01234567891";
  424. var horizontalView = new View
  425. {
  426. Width = Dim.Auto (),
  427. Height = Dim.Auto (),
  428. Text = text
  429. };
  430. var verticalView = new View
  431. {
  432. Width = Dim.Auto (),
  433. Height = Dim.Auto (),
  434. Y = 3,
  435. //Height = 11,
  436. //Width = 2,
  437. Text = text,
  438. TextDirection = TextDirection.TopBottom_LeftRight
  439. };
  440. var win = new Window
  441. {
  442. Width = Dim.Fill (),
  443. Height = Dim.Fill (),
  444. Text = "Window"
  445. };
  446. win.Add (horizontalView, verticalView);
  447. var top = new Toplevel ();
  448. top.Add (win);
  449. RunState rs = Application.Begin (top);
  450. ((FakeDriver)Application.Driver!).SetBufferSize (20, 20);
  451. Assert.Equal (new (0, 0, 11, 2), horizontalView.Frame);
  452. Assert.Equal (new (0, 3, 2, 11), verticalView.Frame);
  453. var expected = @"
  454. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  455. โ”‚0123456789 โ”‚
  456. โ”‚01234567891 โ”‚
  457. โ”‚ โ”‚
  458. โ”‚00 โ”‚
  459. โ”‚11 โ”‚
  460. โ”‚22 โ”‚
  461. โ”‚33 โ”‚
  462. โ”‚44 โ”‚
  463. โ”‚55 โ”‚
  464. โ”‚66 โ”‚
  465. โ”‚77 โ”‚
  466. โ”‚88 โ”‚
  467. โ”‚99 โ”‚
  468. โ”‚ 1 โ”‚
  469. โ”‚ โ”‚
  470. โ”‚ โ”‚
  471. โ”‚ โ”‚
  472. โ”‚ โ”‚
  473. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  474. ";
  475. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  476. verticalView.Text = $"ๆœ€ๅˆใฎ่กŒ{Environment.NewLine}ไบŒ่กŒ็›ฎ";
  477. Application.RunIteration (ref rs);
  478. Assert.Equal (new (0, 3, 4, 4), verticalView.Frame);
  479. expected = @"
  480. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  481. โ”‚0123456789 โ”‚
  482. โ”‚01234567891 โ”‚
  483. โ”‚ โ”‚
  484. โ”‚ๆœ€ไบŒ โ”‚
  485. โ”‚ๅˆ่กŒ โ”‚
  486. โ”‚ใฎ็›ฎ โ”‚
  487. โ”‚่กŒ โ”‚
  488. โ”‚ โ”‚
  489. โ”‚ โ”‚
  490. โ”‚ โ”‚
  491. โ”‚ โ”‚
  492. โ”‚ โ”‚
  493. โ”‚ โ”‚
  494. โ”‚ โ”‚
  495. โ”‚ โ”‚
  496. โ”‚ โ”‚
  497. โ”‚ โ”‚
  498. โ”‚ โ”‚
  499. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  500. ";
  501. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  502. Application.End (rs);
  503. top.Dispose ();
  504. }
  505. [Fact]
  506. [AutoInitShutdown]
  507. public void Width_Height_Stay_True_If_TextFormatter_Size_Fit ()
  508. {
  509. var text = "Finish ็ต‚";
  510. var horizontalView = new View
  511. {
  512. Id = "horizontalView",
  513. Width = Dim.Auto (), Height = Dim.Auto (), Text = text
  514. };
  515. var verticalView = new View
  516. {
  517. Id = "verticalView",
  518. Y = 3,
  519. Width = Dim.Auto (),
  520. Height = Dim.Auto (),
  521. Text = text,
  522. TextDirection = TextDirection.TopBottom_LeftRight
  523. };
  524. var win = new Window { Id = "win", Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window" };
  525. win.Add (horizontalView, verticalView);
  526. var top = new Toplevel ();
  527. top.Add (win);
  528. RunState rs = Application.Begin (top);
  529. ((FakeDriver)Application.Driver!).SetBufferSize (22, 22);
  530. Assert.Equal (new (text.GetColumns (), 1), horizontalView.TextFormatter.ConstrainToSize);
  531. Assert.Equal (new (2, 8), verticalView.TextFormatter.ConstrainToSize);
  532. //Assert.Equal (new (0, 0, 10, 1), horizontalView.Frame);
  533. //Assert.Equal (new (0, 3, 10, 9), verticalView.Frame);
  534. var expected = @"
  535. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  536. โ”‚Finish ็ต‚ โ”‚
  537. โ”‚ โ”‚
  538. โ”‚ โ”‚
  539. โ”‚F โ”‚
  540. โ”‚i โ”‚
  541. โ”‚n โ”‚
  542. โ”‚i โ”‚
  543. โ”‚s โ”‚
  544. โ”‚h โ”‚
  545. โ”‚ โ”‚
  546. โ”‚็ต‚ โ”‚
  547. โ”‚ โ”‚
  548. โ”‚ โ”‚
  549. โ”‚ โ”‚
  550. โ”‚ โ”‚
  551. โ”‚ โ”‚
  552. โ”‚ โ”‚
  553. โ”‚ โ”‚
  554. โ”‚ โ”‚
  555. โ”‚ โ”‚
  556. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  557. ";
  558. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  559. verticalView.Text = "ๆœ€ๅˆใฎ่กŒไบŒ่กŒ็›ฎ";
  560. Application.RunIteration (ref rs);
  561. // height was initialized with 8 and can only grow or keep initial value
  562. Assert.Equal (new (0, 3, 2, 7), verticalView.Frame);
  563. expected = @"
  564. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  565. โ”‚Finish ็ต‚ โ”‚
  566. โ”‚ โ”‚
  567. โ”‚ โ”‚
  568. โ”‚ๆœ€ โ”‚
  569. โ”‚ๅˆ โ”‚
  570. โ”‚ใฎ โ”‚
  571. โ”‚่กŒ โ”‚
  572. โ”‚ไบŒ โ”‚
  573. โ”‚่กŒ โ”‚
  574. โ”‚็›ฎ โ”‚
  575. โ”‚ โ”‚
  576. โ”‚ โ”‚
  577. โ”‚ โ”‚
  578. โ”‚ โ”‚
  579. โ”‚ โ”‚
  580. โ”‚ โ”‚
  581. โ”‚ โ”‚
  582. โ”‚ โ”‚
  583. โ”‚ โ”‚
  584. โ”‚ โ”‚
  585. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  586. ";
  587. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  588. Application.End (rs);
  589. top.Dispose ();
  590. }
  591. [Fact]
  592. [AutoInitShutdown]
  593. public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
  594. {
  595. var lbl = new Label { Text = "123" };
  596. var top = new Toplevel ();
  597. top.Add (lbl);
  598. RunState rs = Application.Begin (top);
  599. Application.RunIteration (ref rs);
  600. Assert.Equal (new (0, 0, 3, 1), lbl.Frame);
  601. Assert.Equal ("123 ", GetContents ());
  602. lbl.Text = "12";
  603. lbl.Layout ();
  604. Assert.Equal (new (0, 0, 2, 1), lbl.Frame);
  605. Assert.Equal (new (0, 0, 2, 1), lbl._needsDisplayRect);
  606. Assert.Equal (new (0, 0, 80, 25), lbl.SuperView._needsDisplayRect);
  607. Assert.True (lbl.SuperView.NeedsLayout);
  608. Application.RunIteration (ref rs);
  609. Assert.Equal ("12 ", GetContents ());
  610. string GetContents ()
  611. {
  612. var text = "";
  613. for (var i = 0; i < 4; i++)
  614. {
  615. text += Application.Driver?.Contents [0, i].Rune;
  616. }
  617. return text;
  618. }
  619. Application.End (rs);
  620. top.Dispose ();
  621. }
  622. [Theory]
  623. [AutoInitShutdown]
  624. [InlineData (true)]
  625. [InlineData (false)]
  626. public void View_Draw_Horizontal_Simple_TextAlignments (bool autoSize)
  627. {
  628. var text = "Hello World";
  629. var width = 20;
  630. var lblLeft = new View
  631. {
  632. Text = text,
  633. Width = width,
  634. Height = 1
  635. };
  636. if (autoSize)
  637. {
  638. lblLeft.Width = Dim.Auto ();
  639. lblLeft.Height = Dim.Auto ();
  640. }
  641. var lblCenter = new View
  642. {
  643. Text = text,
  644. Y = 1,
  645. Width = width,
  646. Height = 1,
  647. TextAlignment = Alignment.Center
  648. };
  649. if (autoSize)
  650. {
  651. lblCenter.Width = Dim.Auto ();
  652. lblCenter.Height = Dim.Auto ();
  653. }
  654. var lblRight = new View
  655. {
  656. Text = text,
  657. Y = 2,
  658. Width = width,
  659. Height = 1,
  660. TextAlignment = Alignment.End
  661. };
  662. if (autoSize)
  663. {
  664. lblRight.Width = Dim.Auto ();
  665. lblRight.Height = Dim.Auto ();
  666. }
  667. var lblJust = new View
  668. {
  669. Text = text,
  670. Y = 3,
  671. Width = width,
  672. Height = 1,
  673. TextAlignment = Alignment.Fill
  674. };
  675. if (autoSize)
  676. {
  677. lblJust.Width = Dim.Auto ();
  678. lblJust.Height = Dim.Auto ();
  679. }
  680. var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () };
  681. frame.Add (lblLeft, lblCenter, lblRight, lblJust);
  682. var top = new Toplevel ();
  683. top.Add (frame);
  684. Application.Begin (top);
  685. ((FakeDriver)Application.Driver).SetBufferSize (width + 2, 6);
  686. // frame.Width is width + border wide (20 + 2) and 6 high
  687. if (autoSize)
  688. {
  689. Size expectedSize = new (11, 1);
  690. Assert.Equal (expectedSize, lblLeft.TextFormatter.ConstrainToSize);
  691. Assert.Equal (expectedSize, lblCenter.TextFormatter.ConstrainToSize);
  692. Assert.Equal (expectedSize, lblRight.TextFormatter.ConstrainToSize);
  693. Assert.Equal (expectedSize, lblJust.TextFormatter.ConstrainToSize);
  694. }
  695. else
  696. {
  697. Size expectedSize = new (width, 1);
  698. Assert.Equal (expectedSize, lblLeft.TextFormatter.ConstrainToSize);
  699. Assert.Equal (expectedSize, lblCenter.TextFormatter.ConstrainToSize);
  700. Assert.Equal (expectedSize, lblRight.TextFormatter.ConstrainToSize);
  701. Assert.Equal (expectedSize, lblJust.TextFormatter.ConstrainToSize);
  702. }
  703. Assert.Equal (new (0, 0, width + 2, 6), frame.Frame);
  704. string expected;
  705. if (autoSize)
  706. {
  707. expected = @"
  708. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  709. โ”‚Hello World โ”‚
  710. โ”‚Hello World โ”‚
  711. โ”‚Hello World โ”‚
  712. โ”‚Hello World โ”‚
  713. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  714. ";
  715. }
  716. else
  717. {
  718. expected = @"
  719. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  720. โ”‚Hello World โ”‚
  721. โ”‚ Hello World โ”‚
  722. โ”‚ Hello Worldโ”‚
  723. โ”‚Hello Worldโ”‚
  724. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  725. ";
  726. }
  727. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  728. Assert.Equal (new (0, 0, width + 2, 6), pos);
  729. top.Dispose ();
  730. }
  731. [Theory]
  732. [AutoInitShutdown]
  733. [InlineData (true)]
  734. [InlineData (false)]
  735. public void View_Draw_Vertical_Simple_TextAlignments (bool autoSize)
  736. {
  737. var text = "Hello World";
  738. var height = 20;
  739. var lblLeft = new View
  740. {
  741. Text = text,
  742. Width = 1,
  743. Height = height,
  744. TextDirection = TextDirection.TopBottom_LeftRight
  745. };
  746. if (autoSize)
  747. {
  748. lblLeft.Width = Dim.Auto ();
  749. lblLeft.Height = Dim.Auto ();
  750. }
  751. var lblCenter = new View
  752. {
  753. Text = text,
  754. X = 2,
  755. Width = 1,
  756. Height = height,
  757. TextDirection = TextDirection.TopBottom_LeftRight,
  758. VerticalTextAlignment = Alignment.Center
  759. };
  760. if (autoSize)
  761. {
  762. lblCenter.Width = Dim.Auto ();
  763. lblCenter.Height = Dim.Auto ();
  764. }
  765. var lblRight = new View
  766. {
  767. Text = text,
  768. X = 4,
  769. Width = 1,
  770. Height = height,
  771. TextDirection = TextDirection.TopBottom_LeftRight,
  772. VerticalTextAlignment = Alignment.End
  773. };
  774. if (autoSize)
  775. {
  776. lblRight.Width = Dim.Auto ();
  777. lblRight.Height = Dim.Auto ();
  778. }
  779. var lblJust = new View
  780. {
  781. Text = text,
  782. X = 6,
  783. Width = 1,
  784. Height = height,
  785. TextDirection = TextDirection.TopBottom_LeftRight,
  786. VerticalTextAlignment = Alignment.Fill
  787. };
  788. if (autoSize)
  789. {
  790. lblJust.Width = Dim.Auto ();
  791. lblJust.Height = Dim.Auto ();
  792. }
  793. var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill () };
  794. frame.Add (lblLeft, lblCenter, lblRight, lblJust);
  795. var top = new Toplevel ();
  796. top.Add (frame);
  797. Application.Begin (top);
  798. ((FakeDriver)Application.Driver!).SetBufferSize (9, height + 2);
  799. if (autoSize)
  800. {
  801. Assert.Equal (new (1, 11), lblLeft.TextFormatter.ConstrainToSize);
  802. Assert.Equal (new (1, 11), lblCenter.TextFormatter.ConstrainToSize);
  803. Assert.Equal (new (1, 11), lblRight.TextFormatter.ConstrainToSize);
  804. Assert.Equal (new (1, 11), lblJust.TextFormatter.ConstrainToSize);
  805. Assert.Equal (new (0, 0, 9, height + 2), frame.Frame);
  806. }
  807. else
  808. {
  809. Assert.Equal (new (1, height), lblLeft.TextFormatter.ConstrainToSize);
  810. Assert.Equal (new (1, height), lblCenter.TextFormatter.ConstrainToSize);
  811. Assert.Equal (new (1, height), lblRight.TextFormatter.ConstrainToSize);
  812. Assert.Equal (new (1, height), lblJust.TextFormatter.ConstrainToSize);
  813. Assert.Equal (new (0, 0, 9, height + 2), frame.Frame);
  814. }
  815. string expected;
  816. if (autoSize)
  817. {
  818. expected = @"
  819. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  820. โ”‚H H H Hโ”‚
  821. โ”‚e e e eโ”‚
  822. โ”‚l l l lโ”‚
  823. โ”‚l l l lโ”‚
  824. โ”‚o o o oโ”‚
  825. โ”‚ โ”‚
  826. โ”‚W W W Wโ”‚
  827. โ”‚o o o oโ”‚
  828. โ”‚r r r rโ”‚
  829. โ”‚l l l lโ”‚
  830. โ”‚d d d dโ”‚
  831. โ”‚ โ”‚
  832. โ”‚ โ”‚
  833. โ”‚ โ”‚
  834. โ”‚ โ”‚
  835. โ”‚ โ”‚
  836. โ”‚ โ”‚
  837. โ”‚ โ”‚
  838. โ”‚ โ”‚
  839. โ”‚ โ”‚
  840. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  841. ";
  842. }
  843. else
  844. {
  845. expected = @"
  846. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  847. โ”‚H Hโ”‚
  848. โ”‚e eโ”‚
  849. โ”‚l lโ”‚
  850. โ”‚l lโ”‚
  851. โ”‚o H oโ”‚
  852. โ”‚ e โ”‚
  853. โ”‚W l โ”‚
  854. โ”‚o l โ”‚
  855. โ”‚r o โ”‚
  856. โ”‚l H โ”‚
  857. โ”‚d W e โ”‚
  858. โ”‚ o l โ”‚
  859. โ”‚ r l โ”‚
  860. โ”‚ l o โ”‚
  861. โ”‚ d โ”‚
  862. โ”‚ W Wโ”‚
  863. โ”‚ o oโ”‚
  864. โ”‚ r rโ”‚
  865. โ”‚ l lโ”‚
  866. โ”‚ d dโ”‚
  867. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  868. ";
  869. }
  870. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  871. Assert.Equal (new (0, 0, 9, height + 2), pos);
  872. top.Dispose ();
  873. }
  874. // Test that View.PreserveTrailingSpaces removes trailing spaces
  875. [Fact]
  876. public void PreserveTrailingSpaces_Removes_Trailing_Spaces ()
  877. {
  878. var view = new View { Text = "Hello World " };
  879. Assert.Equal ("Hello World ", view.TextFormatter.Text);
  880. view.TextFormatter.WordWrap = true;
  881. view.TextFormatter.ConstrainToSize = new (5, 3);
  882. view.PreserveTrailingSpaces = false;
  883. Assert.Equal ($"Hello{Environment.NewLine}World", view.TextFormatter.Format ());
  884. view.PreserveTrailingSpaces = true;
  885. Assert.Equal ($"Hello{Environment.NewLine} {Environment.NewLine}World", view.TextFormatter.Format ());
  886. }
  887. // View.PreserveTrailingSpaces Gets or sets whether trailing spaces at the end of word-wrapped lines are preserved
  888. // or not when <see cref="TextFormatter.WordWrap"/> is enabled.
  889. // If <see langword="true"/> trailing spaces at the end of wrapped lines will be removed when
  890. // <see cref = "Text" / > is formatted for display.The default is <see langword = "false" / >.
  891. [Fact]
  892. public void PreserveTrailingSpaces_Set_Get ()
  893. {
  894. var view = new View { Text = "Hello World" };
  895. Assert.False (view.PreserveTrailingSpaces);
  896. view.PreserveTrailingSpaces = true;
  897. Assert.True (view.PreserveTrailingSpaces);
  898. }
  899. // Setting TextFormatter DOES NOT update Text
  900. [Fact]
  901. public void SettingTextFormatterDoesNotUpdateText ()
  902. {
  903. var view = new View ();
  904. view.TextFormatter.Text = "Hello World";
  905. Assert.True (string.IsNullOrEmpty (view.Text));
  906. }
  907. // Setting Text updates TextFormatter
  908. [Fact]
  909. public void SettingTextUpdatesTextFormatter ()
  910. {
  911. var view = new View { Text = "Hello World" };
  912. Assert.Equal ("Hello World", view.Text);
  913. Assert.Equal ("Hello World", view.TextFormatter.Text);
  914. }
  915. // Setting Text does NOT set the HotKey
  916. [Fact]
  917. public void Text_Does_Not_Set_HotKey ()
  918. {
  919. var view = new View { HotKeySpecifier = (Rune)'_', Text = "_Hello World" };
  920. Assert.NotEqual (Key.H, view.HotKey);
  921. }
  922. // Test that TextFormatter is init only
  923. [Fact]
  924. public void TextFormatterIsInitOnly ()
  925. {
  926. var view = new View ();
  927. // Use reflection to ensure the TextFormatter property is `init` only
  928. Assert.Contains (
  929. typeof (IsExternalInit),
  930. typeof (View).GetMethod ("set_TextFormatter")
  931. .ReturnParameter.GetRequiredCustomModifiers ());
  932. }
  933. // Test that the Text property is set correctly.
  934. [Fact]
  935. public void TextProperty ()
  936. {
  937. var view = new View { Text = "Hello World" };
  938. Assert.Equal ("Hello World", view.Text);
  939. }
  940. // Test view.UpdateTextFormatterText overridden in a subclass updates TextFormatter.Text
  941. [Fact]
  942. public void UpdateTextFormatterText_Overridden ()
  943. {
  944. var view = new TestView { Text = "Hello World" };
  945. Assert.Equal ("Hello World", view.Text);
  946. Assert.Equal (">Hello World<", view.TextFormatter.Text);
  947. }
  948. private class TestView : View
  949. {
  950. protected override void UpdateTextFormatterText () { TextFormatter.Text = $">{Text}<"; }
  951. }
  952. [Fact]
  953. public void TextDirection_Horizontal_Dims_Correct ()
  954. {
  955. // Initializes a view with a vertical direction
  956. var view = new View
  957. {
  958. Text = "01234",
  959. TextDirection = TextDirection.LeftRight_TopBottom,
  960. Width = Dim.Auto (DimAutoStyle.Text),
  961. Height = Dim.Auto (DimAutoStyle.Text)
  962. };
  963. Assert.True (view.NeedsLayout);
  964. view.Layout ();
  965. Assert.Equal (new (0, 0, 5, 1), view.Frame);
  966. Assert.Equal (new (0, 0, 5, 1), view.Viewport);
  967. view.BeginInit ();
  968. view.EndInit ();
  969. Assert.Equal (new (0, 0, 5, 1), view.Frame);
  970. Assert.Equal (new (0, 0, 5, 1), view.Viewport);
  971. }
  972. // BUGBUG: this is a temporary test that helped identify #3469 - It needs to be expanded upon (and renamed)
  973. [Fact]
  974. public void TextDirection_Horizontal_Dims_Correct_WidthAbsolute ()
  975. {
  976. var view = new View
  977. {
  978. Text = "01234",
  979. TextDirection = TextDirection.LeftRight_TopBottom,
  980. TextAlignment = Alignment.Center,
  981. Width = 10,
  982. Height = Dim.Auto (DimAutoStyle.Text)
  983. };
  984. view.BeginInit ();
  985. view.EndInit ();
  986. Assert.Equal (new (0, 0, 10, 1), view.Frame);
  987. Assert.Equal (new (0, 0, 10, 1), view.Viewport);
  988. Assert.Equal (new (10, 1), view.TextFormatter.ConstrainToSize);
  989. }
  990. [Fact]
  991. public void TextDirection_Vertical_Dims_Correct ()
  992. {
  993. // Initializes a view with a vertical direction
  994. var view = new View
  995. {
  996. TextDirection = TextDirection.TopBottom_LeftRight,
  997. Text = "01234",
  998. Width = Dim.Auto (DimAutoStyle.Text),
  999. Height = Dim.Auto (DimAutoStyle.Text)
  1000. };
  1001. view.Layout ();
  1002. Assert.Equal (new (0, 0, 1, 5), view.Frame);
  1003. Assert.Equal (new (0, 0, 1, 5), view.Viewport);
  1004. }
  1005. [Fact]
  1006. [SetupFakeDriver]
  1007. public void Narrow_Wide_Runes ()
  1008. {
  1009. ((FakeDriver)Application.Driver!).SetBufferSize (32, 32);
  1010. var top = new View { Width = 32, Height = 32 };
  1011. var text = $"First line{Environment.NewLine}Second line";
  1012. var horizontalView = new View { Width = 20, Height = 1, Text = text };
  1013. // Autosize is off, so we have to explicitly set TextFormatter.Size
  1014. horizontalView.TextFormatter.ConstrainToSize = new (20, 1);
  1015. var verticalView = new View
  1016. {
  1017. Y = 3,
  1018. Height = 20,
  1019. Width = 1,
  1020. Text = text,
  1021. TextDirection = TextDirection.TopBottom_LeftRight
  1022. };
  1023. // Autosize is off, so we have to explicitly set TextFormatter.Size
  1024. verticalView.TextFormatter.ConstrainToSize = new (1, 20);
  1025. var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window" };
  1026. frame.Add (horizontalView, verticalView);
  1027. top.Add (frame);
  1028. top.BeginInit ();
  1029. top.EndInit ();
  1030. Assert.Equal (new (0, 0, 20, 1), horizontalView.Frame);
  1031. Assert.Equal (new (0, 3, 1, 20), verticalView.Frame);
  1032. top.Draw ();
  1033. var expected = @"
  1034. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1035. โ”‚First line Second li โ”‚
  1036. โ”‚ โ”‚
  1037. โ”‚ โ”‚
  1038. โ”‚F โ”‚
  1039. โ”‚i โ”‚
  1040. โ”‚r โ”‚
  1041. โ”‚s โ”‚
  1042. โ”‚t โ”‚
  1043. โ”‚ โ”‚
  1044. โ”‚l โ”‚
  1045. โ”‚i โ”‚
  1046. โ”‚n โ”‚
  1047. โ”‚e โ”‚
  1048. โ”‚ โ”‚
  1049. โ”‚S โ”‚
  1050. โ”‚e โ”‚
  1051. โ”‚c โ”‚
  1052. โ”‚o โ”‚
  1053. โ”‚n โ”‚
  1054. โ”‚d โ”‚
  1055. โ”‚ โ”‚
  1056. โ”‚l โ”‚
  1057. โ”‚i โ”‚
  1058. โ”‚ โ”‚
  1059. โ”‚ โ”‚
  1060. โ”‚ โ”‚
  1061. โ”‚ โ”‚
  1062. โ”‚ โ”‚
  1063. โ”‚ โ”‚
  1064. โ”‚ โ”‚
  1065. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1066. ";
  1067. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1068. verticalView.Text = $"ๆœ€ๅˆใฎ่กŒ{Environment.NewLine}ไบŒ่กŒ็›ฎ";
  1069. Assert.True (verticalView.TextFormatter.NeedsFormat);
  1070. // Autosize is off, so we have to explicitly set TextFormatter.Size
  1071. // We know these glpyhs are 2 cols wide, so we need to widen the view
  1072. verticalView.Width = 2;
  1073. verticalView.TextFormatter.ConstrainToSize = new (2, 20);
  1074. Assert.True (verticalView.TextFormatter.NeedsFormat);
  1075. top.Draw ();
  1076. Assert.Equal (new (0, 3, 2, 20), verticalView.Frame);
  1077. expected = @"
  1078. โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  1079. โ”‚First line Second li โ”‚
  1080. โ”‚ โ”‚
  1081. โ”‚ โ”‚
  1082. โ”‚ๆœ€ โ”‚
  1083. โ”‚ๅˆ โ”‚
  1084. โ”‚ใฎ โ”‚
  1085. โ”‚่กŒ โ”‚
  1086. โ”‚ โ”‚
  1087. โ”‚ไบŒ โ”‚
  1088. โ”‚่กŒ โ”‚
  1089. โ”‚็›ฎ โ”‚
  1090. โ”‚ โ”‚
  1091. โ”‚ โ”‚
  1092. โ”‚ โ”‚
  1093. โ”‚ โ”‚
  1094. โ”‚ โ”‚
  1095. โ”‚ โ”‚
  1096. โ”‚ โ”‚
  1097. โ”‚ โ”‚
  1098. โ”‚ โ”‚
  1099. โ”‚ โ”‚
  1100. โ”‚ โ”‚
  1101. โ”‚ โ”‚
  1102. โ”‚ โ”‚
  1103. โ”‚ โ”‚
  1104. โ”‚ โ”‚
  1105. โ”‚ โ”‚
  1106. โ”‚ โ”‚
  1107. โ”‚ โ”‚
  1108. โ”‚ โ”‚
  1109. โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1110. ";
  1111. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1112. }
  1113. }