TextFormatterDrawTests.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. #nullable enable
  2. using System.Text;
  3. using UICatalog;
  4. using UnitTests;
  5. using Xunit.Abstractions;
  6. // Alias Console to MockConsole so we don't accidentally use Console
  7. namespace UnitTests_Parallelizable.TextTests;
  8. public class TextFormatterDrawTests (ITestOutputHelper output) : FakeDriverBase
  9. {
  10. public static IEnumerable<object []> CMGlyphs =>
  11. new List<object []> { new object [] { $"{Glyphs.LeftBracket} Say Hello 你 {Glyphs.RightBracket}", 16, 15 } };
  12. [Theory]
  13. [InlineData ("A", 1, 0, "")]
  14. [InlineData ("A", 0, 1, "")]
  15. [InlineData ("AB1 2", 2, 1, "2")]
  16. [InlineData ("AB12", 5, 1, "21BA")]
  17. [InlineData ("AB\n12", 5, 2, "21\nBA")]
  18. [InlineData ("ABC 123 456", 7, 2, "CBA \n654 321")]
  19. [InlineData ("こんにちは", 1, 1, "")]
  20. [InlineData ("こんにちは", 2, 1, "は")]
  21. [InlineData ("こんにちは", 5, 1, "はち")]
  22. [InlineData ("こんにちは", 10, 1, "はちにんこ")]
  23. [InlineData ("こんにちは\nAB\n12", 10, 3, "21 \nBA \nはちにんこ")]
  24. public void Draw_Horizontal_RightLeft_BottomTop (string text, int width, int height, string expectedText)
  25. {
  26. IDriver driver = CreateFakeDriver ();
  27. TextFormatter tf = new ()
  28. {
  29. Text = text,
  30. Direction = TextDirection.RightLeft_BottomTop
  31. };
  32. tf.ConstrainToWidth = width;
  33. tf.ConstrainToHeight = height;
  34. tf.Draw (driver: driver, screen: new (0, 0, width, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  35. DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  36. }
  37. [Theory]
  38. [InlineData ("A", 1, 0, "")]
  39. [InlineData ("A", 0, 1, "")]
  40. [InlineData ("AB1 2", 2, 1, "2")]
  41. [InlineData ("AB12", 5, 1, "21BA")]
  42. [InlineData ("AB\n12", 5, 2, "BA\n21")]
  43. [InlineData ("ABC 123 456", 7, 2, "654 321\nCBA ")]
  44. [InlineData ("こんにちは", 1, 1, "")]
  45. [InlineData ("こんにちは", 2, 1, "は")]
  46. [InlineData ("こんにちは", 5, 1, "はち")]
  47. [InlineData ("こんにちは", 10, 1, "はちにんこ")]
  48. [InlineData ("こんにちは\nAB\n12", 10, 3, "はちにんこ\nBA \n21 ")]
  49. public void Draw_Horizontal_RightLeft_TopBottom (string text, int width, int height, string expectedText)
  50. {
  51. IDriver driver = CreateFakeDriver ();
  52. TextFormatter tf = new ()
  53. {
  54. Text = text,
  55. Direction = TextDirection.RightLeft_TopBottom
  56. };
  57. tf.ConstrainToWidth = width;
  58. tf.ConstrainToHeight = height;
  59. tf.Draw (driver: driver, screen: new (0, 0, width, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  60. DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  61. }
  62. [Theory]
  63. [InlineData ("A", 0, 1, "", 0)]
  64. [InlineData ("A", 1, 1, "A", 0)]
  65. [InlineData ("A", 2, 2, " A", 1)]
  66. [InlineData ("AB", 1, 1, "B", 0)]
  67. [InlineData ("AB", 2, 2, " A\n B", 0)]
  68. [InlineData ("ABC", 3, 2, " B\n C", 0)]
  69. [InlineData ("ABC", 4, 2, " B\n C", 0)]
  70. [InlineData ("ABC", 6, 2, " B\n C", 0)]
  71. [InlineData ("こんにちは", 0, 1, "", 0)]
  72. [InlineData ("こんにちは", 1, 0, "", 0)]
  73. [InlineData ("こんにちは", 1, 1, "", 0)]
  74. [InlineData ("こんにちは", 2, 1, "は", 0)]
  75. [InlineData ("こんにちは", 2, 2, "ち\nは", 0)]
  76. [InlineData ("こんにちは", 2, 3, "に\nち\nは", 0)]
  77. [InlineData ("こんにちは", 2, 4, "ん\nに\nち\nは", 0)]
  78. [InlineData ("こんにちは", 2, 5, "こ\nん\nに\nち\nは", 0)]
  79. [InlineData ("こんにちは", 2, 6, "こ\nん\nに\nち\nは", 1)]
  80. [InlineData ("ABCD\nこんにちは", 4, 7, " こ\n Aん\n Bに\n Cち\n Dは", 2)]
  81. [InlineData ("こんにちは\nABCD", 3, 7, "こ \nんA\nにB\nちC\nはD", 2)]
  82. public void Draw_Vertical_Bottom_Horizontal_Right (string text, int width, int height, string expectedText, int expectedY)
  83. {
  84. IDriver driver = CreateFakeDriver ();
  85. TextFormatter tf = new ()
  86. {
  87. Text = text,
  88. Alignment = Alignment.End,
  89. Direction = TextDirection.TopBottom_LeftRight,
  90. VerticalAlignment = Alignment.End
  91. };
  92. tf.ConstrainToWidth = width;
  93. tf.ConstrainToHeight = height;
  94. tf.Draw (driver: driver, screen: new (Point.Empty, new (width, height)), normalColor: Attribute.Default, hotColor: Attribute.Default);
  95. Rectangle rect = DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  96. Assert.Equal (expectedY, rect.Y);
  97. }
  98. [Theory]
  99. [InlineData ("A", 1, 0, "")]
  100. [InlineData ("A", 0, 1, "")]
  101. [InlineData ("AB1 2", 1, 2, "2")]
  102. [InlineData ("AB12", 1, 5, "2\n1\nB\nA")]
  103. [InlineData ("AB\n12", 2, 5, "B2\nA1")]
  104. [InlineData ("ABC 123 456", 2, 7, "6C\n5B\n4A\n \n3 \n2 \n1 ")]
  105. [InlineData ("こんにちは", 1, 1, "")]
  106. [InlineData ("こんにちは", 2, 1, "は")]
  107. [InlineData ("こんにちは", 2, 5, "は\nち\nに\nん\nこ")]
  108. [InlineData ("こんにちは", 2, 10, "は\nち\nに\nん\nこ")]
  109. [InlineData ("こんにちは\nAB\n12", 4, 10, "はB2\nちA1\nに \nん \nこ ")]
  110. public void Draw_Vertical_BottomTop_LeftRight (string text, int width, int height, string expectedText)
  111. {
  112. IDriver driver = CreateFakeDriver ();
  113. TextFormatter tf = new ()
  114. {
  115. Text = text,
  116. Direction = TextDirection.BottomTop_LeftRight
  117. };
  118. tf.ConstrainToWidth = width;
  119. tf.ConstrainToHeight = height;
  120. tf.Draw (driver: driver, screen: new (0, 0, width, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  121. DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  122. }
  123. [Theory]
  124. [InlineData ("A", 1, 0, "")]
  125. [InlineData ("A", 0, 1, "")]
  126. [InlineData ("AB1 2", 1, 2, "2")]
  127. [InlineData ("AB12", 1, 5, "2\n1\nB\nA")]
  128. [InlineData ("AB\n12", 2, 5, "2B\n1A")]
  129. [InlineData ("ABC 123 456", 2, 7, "C6\nB5\nA4\n \n 3\n 2\n 1")]
  130. [InlineData ("こんにちは", 1, 1, "")]
  131. [InlineData ("こんにちは", 2, 1, "は")]
  132. [InlineData ("こんにちは", 2, 5, "は\nち\nに\nん\nこ")]
  133. [InlineData ("こんにちは", 2, 10, "は\nち\nに\nん\nこ")]
  134. [InlineData ("こんにちは\nAB\n12", 4, 10, "2Bは\n1Aち\n に\n ん\n こ")]
  135. public void Draw_Vertical_BottomTop_RightLeft (string text, int width, int height, string expectedText)
  136. {
  137. IDriver driver = CreateFakeDriver ();
  138. TextFormatter tf = new ()
  139. {
  140. Text = text,
  141. Direction = TextDirection.BottomTop_RightLeft
  142. };
  143. tf.ConstrainToWidth = width;
  144. tf.ConstrainToHeight = height;
  145. tf.Draw (driver: driver, screen: new (0, 0, width, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  146. DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  147. }
  148. [Theory]
  149. [InlineData ("A", 5, 5, "A")]
  150. [InlineData (
  151. "AB12",
  152. 5,
  153. 5,
  154. @"
  155. A
  156. B
  157. 1
  158. 2")]
  159. [InlineData (
  160. "AB\n12",
  161. 5,
  162. 5,
  163. @"
  164. A1
  165. B2")]
  166. [InlineData ("", 5, 1, "")]
  167. [InlineData (
  168. "Hello Worlds",
  169. 1,
  170. 12,
  171. @"
  172. H
  173. e
  174. l
  175. l
  176. o
  177. W
  178. o
  179. r
  180. l
  181. d
  182. s")]
  183. [InlineData ("Hello Worlds", 12, 1, @"HelloWorlds")]
  184. public void Draw_Vertical_TopBottom_LeftRight (string text, int width, int height, string expectedText)
  185. {
  186. IDriver driver = CreateFakeDriver ();
  187. TextFormatter tf = new ()
  188. {
  189. Text = text,
  190. Direction = TextDirection.TopBottom_LeftRight
  191. };
  192. tf.ConstrainToWidth = width;
  193. tf.ConstrainToHeight = height;
  194. tf.Draw (driver: driver, screen: new (0, 0, 20, 20), normalColor: Attribute.Default, hotColor: Attribute.Default);
  195. DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  196. }
  197. [Theory]
  198. // The expectedY param is to probe that the expectedText param start at that Y coordinate
  199. [InlineData ("A", 0, "", 0)]
  200. [InlineData ("A", 1, "A", 0)]
  201. [InlineData ("A", 2, "A", 0)]
  202. [InlineData ("A", 3, "A", 1)]
  203. [InlineData ("AB", 1, "A", 0)]
  204. [InlineData ("AB", 2, "A\nB", 0)]
  205. [InlineData ("ABC", 2, "A\nB", 0)]
  206. [InlineData ("ABC", 3, "A\nB\nC", 0)]
  207. [InlineData ("ABC", 4, "A\nB\nC", 0)]
  208. [InlineData ("ABC", 5, "A\nB\nC", 1)]
  209. [InlineData ("ABC", 6, "A\nB\nC", 1)]
  210. [InlineData ("ABC", 9, "A\nB\nC", 3)]
  211. [InlineData ("ABCD", 2, "B\nC", 0)]
  212. [InlineData ("こんにちは", 0, "", 0)]
  213. [InlineData ("こんにちは", 1, "に", 0)]
  214. [InlineData ("こんにちは", 2, "ん\nに", 0)]
  215. [InlineData ("こんにちは", 3, "ん\nに\nち", 0)]
  216. [InlineData ("こんにちは", 4, "こ\nん\nに\nち", 0)]
  217. [InlineData ("こんにちは", 5, "こ\nん\nに\nち\nは", 0)]
  218. [InlineData ("こんにちは", 6, "こ\nん\nに\nち\nは", 0)]
  219. [InlineData ("ABCD\nこんにちは", 7, "Aこ\nBん\nCに\nDち\n は", 1)]
  220. [InlineData ("こんにちは\nABCD", 7, "こA\nんB\nにC\nちD\nは ", 1)]
  221. public void Draw_Vertical_TopBottom_LeftRight_Middle (string text, int height, string expectedText, int expectedY)
  222. {
  223. IDriver driver = CreateFakeDriver ();
  224. TextFormatter tf = new ()
  225. {
  226. Text = text,
  227. Direction = TextDirection.TopBottom_LeftRight,
  228. VerticalAlignment = Alignment.Center
  229. };
  230. int width = text.ToRunes ().Max (r => r.GetColumns ());
  231. if (text.Contains ("\n"))
  232. {
  233. width++;
  234. }
  235. tf.ConstrainToWidth = width;
  236. tf.ConstrainToHeight = height;
  237. tf.Draw (driver: driver, screen: new (0, 0, 5, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  238. Rectangle rect = DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  239. Assert.Equal (expectedY, rect.Y);
  240. }
  241. [Theory]
  242. [InlineData ("A", 5, "A")]
  243. [InlineData (
  244. "AB12",
  245. 5,
  246. @"
  247. A
  248. B
  249. 1
  250. 2")]
  251. [InlineData (
  252. "AB\n12",
  253. 5,
  254. @"
  255. A1
  256. B2")]
  257. [InlineData ("", 1, "")]
  258. [InlineData (
  259. "AB1 2",
  260. 2,
  261. @"
  262. A12
  263. B ")]
  264. [InlineData (
  265. "こんにちは",
  266. 1,
  267. @"
  268. こん")]
  269. [InlineData (
  270. "こんにちは",
  271. 2,
  272. @"
  273. こに
  274. んち")]
  275. [InlineData (
  276. "こんにちは",
  277. 5,
  278. @"
  279. は")]
  280. public void Draw_Vertical_TopBottom_LeftRight_Top (string text, int height, string expectedText)
  281. {
  282. IDriver driver = CreateFakeDriver ();
  283. TextFormatter tf = new ()
  284. {
  285. Text = text,
  286. Direction = TextDirection.TopBottom_LeftRight
  287. };
  288. tf.ConstrainToWidth = 5;
  289. tf.ConstrainToHeight = height;
  290. tf.Draw (driver: driver, screen: new (0, 0, 5, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  291. DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  292. }
  293. [Fact]
  294. public void FillRemaining_True_False ()
  295. {
  296. IDriver driver = CreateFakeDriver ();
  297. driver.SetScreenSize (22, 5);
  298. Attribute [] attrs =
  299. {
  300. Attribute.Default, new (ColorName16.Green, ColorName16.BrightMagenta),
  301. new (ColorName16.Blue, ColorName16.Cyan)
  302. };
  303. var tf = new TextFormatter { ConstrainToSize = new (14, 3), Text = "Test\nTest long\nTest long long\n", MultiLine = true };
  304. tf.Draw (driver: driver, screen: new (1, 1, 19, 3), normalColor: attrs [1], hotColor: attrs [2]);
  305. Assert.False (tf.FillRemaining);
  306. DriverAssert.AssertDriverContentsWithFrameAre (
  307. @"
  308. Test
  309. Test long
  310. Test long long",
  311. output,
  312. driver);
  313. DriverAssert.AssertDriverAttributesAre (
  314. @"
  315. 000000000000000000000
  316. 011110000000000000000
  317. 011111111100000000000
  318. 011111111111111000000
  319. 000000000000000000000",
  320. output,
  321. driver,
  322. attrs);
  323. tf.FillRemaining = true;
  324. tf.Draw (driver: driver, screen: new (1, 1, 19, 3), normalColor: attrs [1], hotColor: attrs [2]);
  325. DriverAssert.AssertDriverAttributesAre (
  326. @"
  327. 000000000000000000000
  328. 011111111111111111110
  329. 011111111111111111110
  330. 011111111111111111110
  331. 000000000000000000000",
  332. output,
  333. driver,
  334. attrs);
  335. }
  336. [Theory]
  337. [InlineData ("Hello World", 15, 1, "Hello World")]
  338. [InlineData (
  339. "Well Done\nNice Work",
  340. 15,
  341. 2,
  342. @"
  343. Well Done
  344. Nice Work")]
  345. [InlineData ("你好 世界", 15, 1, "你好 世界")]
  346. [InlineData (
  347. "做 得好\n幹 得好",
  348. 15,
  349. 2,
  350. @"
  351. 做 得好
  352. 幹 得好")]
  353. public void Justify_Horizontal (string text, int width, int height, string expectedText)
  354. {
  355. IDriver driver = CreateFakeDriver ();
  356. TextFormatter tf = new ()
  357. {
  358. Text = text,
  359. Alignment = Alignment.Fill,
  360. ConstrainToSize = new Size (width, height),
  361. MultiLine = true
  362. };
  363. tf.Draw (driver: driver, screen: new (0, 0, width, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  364. DriverAssert.AssertDriverContentsWithFrameAre (expectedText, output, driver);
  365. }
  366. [Fact]
  367. public void UICatalog_AboutBox_Text ()
  368. {
  369. IDriver? driver = CreateFakeDriver ();
  370. TextFormatter tf = new ()
  371. {
  372. Text = UICatalogTop.GetAboutBoxMessage (),
  373. Alignment = Alignment.Center,
  374. VerticalAlignment = Alignment.Start,
  375. WordWrap = false,
  376. MultiLine = true,
  377. HotKeySpecifier = (Rune)0xFFFF
  378. };
  379. Size tfSize = tf.FormatAndGetSize ();
  380. Assert.Equal (new (59, 13), tfSize);
  381. driver!.SetScreenSize (tfSize.Width, tfSize.Height);
  382. driver.FillRect (driver.Screen, (Rune)'*');
  383. tf.Draw (driver: driver, screen: driver.Screen, normalColor: Attribute.Default, hotColor: Attribute.Default);
  384. var expectedText = """
  385. UI Catalog: A comprehensive sample library and test app for
  386. ***********************************************************
  387. _______ _ _ _____ _ *
  388. |__ __| (_) | | / ____| (_)*
  389. | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _ *
  390. | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |*
  391. | | __/ | | | | | | | | | | | (_| | || |__| | |_| | |*
  392. |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|*
  393. ***********************************************************
  394. **********************v2 - Pre-Alpha***********************
  395. ***********************************************************
  396. **********https://github.com/gui-cs/Terminal.Gui***********
  397. ***********************************************************
  398. """;
  399. DriverAssert.AssertDriverContentsAre (expectedText.ReplaceLineEndings (), output, driver);
  400. }
  401. #region FormatAndGetSizeTests
  402. // TODO: Add multi-line examples
  403. // TODO: Add other TextDirection examples
  404. [Theory]
  405. [InlineData ("界1234", 10, 10, TextDirection.LeftRight_TopBottom, 6, 1, @"界1234")]
  406. [InlineData ("01234", 10, 10, TextDirection.LeftRight_TopBottom, 5, 1, @"01234")]
  407. [InlineData (
  408. "界1234",
  409. 10,
  410. 10,
  411. TextDirection.TopBottom_LeftRight,
  412. 2,
  413. 5,
  414. """
  415. 1
  416. 2
  417. 3
  418. 4
  419. """)]
  420. [InlineData (
  421. "01234",
  422. 10,
  423. 10,
  424. TextDirection.TopBottom_LeftRight,
  425. 1,
  426. 5,
  427. """
  428. 0
  429. 1
  430. 2
  431. 3
  432. 4
  433. """)]
  434. [InlineData (
  435. "界1234",
  436. 3,
  437. 3,
  438. TextDirection.LeftRight_TopBottom,
  439. 3,
  440. 2,
  441. """
  442. 界1
  443. 234
  444. """)]
  445. [InlineData (
  446. "01234",
  447. 3,
  448. 3,
  449. TextDirection.LeftRight_TopBottom,
  450. 3,
  451. 2,
  452. """
  453. 012
  454. 34
  455. """)]
  456. [InlineData (
  457. "界1234",
  458. 3,
  459. 3,
  460. TextDirection.TopBottom_LeftRight,
  461. 3,
  462. 3,
  463. """
  464. 界3
  465. 1 4
  466. 2
  467. """)]
  468. [InlineData (
  469. "01234",
  470. 3,
  471. 3,
  472. TextDirection.TopBottom_LeftRight,
  473. 2,
  474. 3,
  475. """
  476. 03
  477. 14
  478. 2
  479. """)]
  480. [InlineData ("01234", 2, 1, TextDirection.LeftRight_TopBottom, 2, 1, @"01")]
  481. public void FormatAndGetSize_Returns_Correct_Size (
  482. string text,
  483. int width,
  484. int height,
  485. TextDirection direction,
  486. int expectedWidth,
  487. int expectedHeight,
  488. string expectedDraw
  489. )
  490. {
  491. IDriver driver = CreateFakeDriver ();
  492. TextFormatter tf = new ()
  493. {
  494. Direction = direction,
  495. ConstrainToWidth = width,
  496. ConstrainToHeight = height,
  497. Text = text
  498. };
  499. Assert.True (tf.WordWrap);
  500. Size size = tf.FormatAndGetSize ();
  501. Assert.Equal (new (expectedWidth, expectedHeight), size);
  502. tf.Draw (driver: driver, screen: new (0, 0, width, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  503. DriverAssert.AssertDriverContentsWithFrameAre (expectedDraw, output, driver);
  504. }
  505. [Theory]
  506. [InlineData ("界1234", 10, 10, TextDirection.LeftRight_TopBottom, 6, 1, @"界1234")]
  507. [InlineData ("01234", 10, 10, TextDirection.LeftRight_TopBottom, 5, 1, @"01234")]
  508. [InlineData (
  509. "界1234",
  510. 10,
  511. 10,
  512. TextDirection.TopBottom_LeftRight,
  513. 2,
  514. 5,
  515. """
  516. 1
  517. 2
  518. 3
  519. 4
  520. """)]
  521. [InlineData (
  522. "01234",
  523. 10,
  524. 10,
  525. TextDirection.TopBottom_LeftRight,
  526. 1,
  527. 5,
  528. """
  529. 0
  530. 1
  531. 2
  532. 3
  533. 4
  534. """)]
  535. [InlineData ("界1234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 1, @"界1")]
  536. [InlineData ("01234", 3, 3, TextDirection.LeftRight_TopBottom, 3, 1, @"012")]
  537. [InlineData (
  538. "界1234",
  539. 3,
  540. 3,
  541. TextDirection.TopBottom_LeftRight,
  542. 2,
  543. 3,
  544. """
  545. 1
  546. 2
  547. """)]
  548. [InlineData (
  549. "01234",
  550. 3,
  551. 3,
  552. TextDirection.TopBottom_LeftRight,
  553. 1,
  554. 3,
  555. """
  556. 0
  557. 1
  558. 2
  559. """)]
  560. public void FormatAndGetSize_WordWrap_False_Returns_Correct_Size (
  561. string text,
  562. int width,
  563. int height,
  564. TextDirection direction,
  565. int expectedWidth,
  566. int expectedHeight,
  567. string expectedDraw
  568. )
  569. {
  570. IDriver driver = CreateFakeDriver ();
  571. TextFormatter tf = new ()
  572. {
  573. Direction = direction,
  574. ConstrainToSize = new (width, height),
  575. Text = text,
  576. WordWrap = false
  577. };
  578. Assert.False (tf.WordWrap);
  579. Size size = tf.FormatAndGetSize ();
  580. Assert.Equal (new (expectedWidth, expectedHeight), size);
  581. tf.Draw (driver: driver, screen: new (0, 0, width, height), normalColor: Attribute.Default, hotColor: Attribute.Default);
  582. DriverAssert.AssertDriverContentsWithFrameAre (expectedDraw, output, driver);
  583. }
  584. [Theory]
  585. [InlineData ("\U0001F468\u200D\U0001F469\u200D\U0001F467\u200D\U0001F466", 2, 1, TextDirection.LeftRight_TopBottom, "👨‍👩‍👧‍👦")]
  586. [InlineData ("\U0001F468\u200D\U0001F469\u200D\U0001F467\u200D\U0001F466", 2, 1, TextDirection.TopBottom_LeftRight, "👨‍👩‍👧‍👦")]
  587. public void Draw_Emojis_With_Zero_Width_Joiner (
  588. string text,
  589. int width,
  590. int height,
  591. TextDirection direction,
  592. string expectedDraw
  593. )
  594. {
  595. IDriver driver = CreateFakeDriver ();
  596. TextFormatter tf = new ()
  597. {
  598. Direction = direction,
  599. ConstrainToSize = new (width, height),
  600. Text = text,
  601. WordWrap = false
  602. };
  603. Assert.Equal (width, text.GetColumns ());
  604. tf.Draw (driver, new (0, 0, width, height), Attribute.Default, Attribute.Default);
  605. DriverAssert.AssertDriverContentsWithFrameAre (expectedDraw, output, driver);
  606. }
  607. #endregion
  608. }