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