TextFormatterDrawTests.cs 22 KB

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