LineCanvasTests.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. using System.Text;
  2. using UnitTests;
  3. using Xunit.Abstractions;
  4. namespace Terminal.Gui.DrawingTests;
  5. public class LineCanvasTests (ITestOutputHelper output)
  6. {
  7. [Theory]
  8. // Horizontal lines with a vertical zero-length
  9. [InlineData (
  10. 0,
  11. 0,
  12. 1,
  13. Orientation.Horizontal,
  14. LineStyle.Double,
  15. 0,
  16. 0,
  17. 0,
  18. Orientation.Vertical,
  19. LineStyle.Single,
  20. "╞"
  21. )]
  22. [InlineData (
  23. 0,
  24. 0,
  25. -1,
  26. Orientation.Horizontal,
  27. LineStyle.Double,
  28. 0,
  29. 0,
  30. 0,
  31. Orientation.Vertical,
  32. LineStyle.Single,
  33. "╡"
  34. )]
  35. [InlineData (
  36. 0,
  37. 0,
  38. 1,
  39. Orientation.Horizontal,
  40. LineStyle.Single,
  41. 0,
  42. 0,
  43. 0,
  44. Orientation.Vertical,
  45. LineStyle.Double,
  46. "╟"
  47. )]
  48. [InlineData (
  49. 0,
  50. 0,
  51. -1,
  52. Orientation.Horizontal,
  53. LineStyle.Single,
  54. 0,
  55. 0,
  56. 0,
  57. Orientation.Vertical,
  58. LineStyle.Double,
  59. "╢"
  60. )]
  61. [InlineData (
  62. 0,
  63. 0,
  64. 1,
  65. Orientation.Horizontal,
  66. LineStyle.Single,
  67. 0,
  68. 0,
  69. 0,
  70. Orientation.Vertical,
  71. LineStyle.Single,
  72. "├"
  73. )]
  74. [InlineData (
  75. 0,
  76. 0,
  77. -1,
  78. Orientation.Horizontal,
  79. LineStyle.Single,
  80. 0,
  81. 0,
  82. 0,
  83. Orientation.Vertical,
  84. LineStyle.Single,
  85. "┤"
  86. )]
  87. [InlineData (
  88. 0,
  89. 0,
  90. 1,
  91. Orientation.Horizontal,
  92. LineStyle.Double,
  93. 0,
  94. 0,
  95. 0,
  96. Orientation.Vertical,
  97. LineStyle.Double,
  98. "╠"
  99. )]
  100. [InlineData (
  101. 0,
  102. 0,
  103. -1,
  104. Orientation.Horizontal,
  105. LineStyle.Double,
  106. 0,
  107. 0,
  108. 0,
  109. Orientation.Vertical,
  110. LineStyle.Double,
  111. "╣"
  112. )]
  113. // Vertical lines with a horizontal zero-length
  114. [InlineData (
  115. 0,
  116. 0,
  117. 1,
  118. Orientation.Vertical,
  119. LineStyle.Double,
  120. 0,
  121. 0,
  122. 0,
  123. Orientation.Horizontal,
  124. LineStyle.Single,
  125. "╥"
  126. )]
  127. [InlineData (
  128. 0,
  129. 0,
  130. -1,
  131. Orientation.Vertical,
  132. LineStyle.Double,
  133. 0,
  134. 0,
  135. 0,
  136. Orientation.Horizontal,
  137. LineStyle.Single,
  138. "╨"
  139. )]
  140. [InlineData (
  141. 0,
  142. 0,
  143. 1,
  144. Orientation.Vertical,
  145. LineStyle.Single,
  146. 0,
  147. 0,
  148. 0,
  149. Orientation.Horizontal,
  150. LineStyle.Double,
  151. "╤"
  152. )]
  153. [InlineData (
  154. 0,
  155. 0,
  156. -1,
  157. Orientation.Vertical,
  158. LineStyle.Single,
  159. 0,
  160. 0,
  161. 0,
  162. Orientation.Horizontal,
  163. LineStyle.Double,
  164. "╧"
  165. )]
  166. [InlineData (
  167. 0,
  168. 0,
  169. 1,
  170. Orientation.Vertical,
  171. LineStyle.Single,
  172. 0,
  173. 0,
  174. 0,
  175. Orientation.Horizontal,
  176. LineStyle.Single,
  177. "┬"
  178. )]
  179. [InlineData (
  180. 0,
  181. 0,
  182. -1,
  183. Orientation.Vertical,
  184. LineStyle.Single,
  185. 0,
  186. 0,
  187. 0,
  188. Orientation.Horizontal,
  189. LineStyle.Single,
  190. "┴"
  191. )]
  192. [InlineData (
  193. 0,
  194. 0,
  195. 1,
  196. Orientation.Vertical,
  197. LineStyle.Double,
  198. 0,
  199. 0,
  200. 0,
  201. Orientation.Horizontal,
  202. LineStyle.Double,
  203. "╦"
  204. )]
  205. [InlineData (
  206. 0,
  207. 0,
  208. -1,
  209. Orientation.Vertical,
  210. LineStyle.Double,
  211. 0,
  212. 0,
  213. 0,
  214. Orientation.Horizontal,
  215. LineStyle.Double,
  216. "╩"
  217. )]
  218. // Crosses (two zero-length)
  219. [InlineData (
  220. 0,
  221. 0,
  222. 0,
  223. Orientation.Vertical,
  224. LineStyle.Double,
  225. 0,
  226. 0,
  227. 0,
  228. Orientation.Horizontal,
  229. LineStyle.Single,
  230. "╫"
  231. )]
  232. [InlineData (
  233. 0,
  234. 0,
  235. 0,
  236. Orientation.Vertical,
  237. LineStyle.Single,
  238. 0,
  239. 0,
  240. 0,
  241. Orientation.Horizontal,
  242. LineStyle.Double,
  243. "╪"
  244. )]
  245. [InlineData (
  246. 0,
  247. 0,
  248. 0,
  249. Orientation.Vertical,
  250. LineStyle.Single,
  251. 0,
  252. 0,
  253. 0,
  254. Orientation.Horizontal,
  255. LineStyle.Single,
  256. "┼"
  257. )]
  258. [InlineData (
  259. 0,
  260. 0,
  261. 0,
  262. Orientation.Vertical,
  263. LineStyle.Double,
  264. 0,
  265. 0,
  266. 0,
  267. Orientation.Horizontal,
  268. LineStyle.Double,
  269. "╬"
  270. )]
  271. public void Add_2_Lines (
  272. int x1,
  273. int y1,
  274. int len1,
  275. Orientation o1,
  276. LineStyle s1,
  277. int x2,
  278. int y2,
  279. int len2,
  280. Orientation o2,
  281. LineStyle s2,
  282. string expected
  283. )
  284. {
  285. View v = GetCanvas (out LineCanvas lc);
  286. v.Width = 10;
  287. v.Height = 10;
  288. v.Viewport = new (0, 0, 10, 10);
  289. lc.AddLine (new (x1, y1), len1, o1, s1);
  290. lc.AddLine (new (x2, y2), len2, o2, s2);
  291. OutputAssert.AssertEqual (output, expected, lc.ToString ());
  292. v.Dispose ();
  293. }
  294. [Fact]
  295. [SetupFakeDriver]
  296. public void Viewport_Specific ()
  297. {
  298. // Draw at 1,1 within client area of View (i.e. leave a top and left margin of 1)
  299. // This proves we aren't drawing excess above
  300. var x = 1;
  301. var y = 2;
  302. var width = 3;
  303. var height = 2;
  304. var lc = new LineCanvas ();
  305. // 01230
  306. // ╔╡╞╗1
  307. // ║ ║2
  308. // Add a short horiz line for ╔╡
  309. lc.AddLine (new (x, y), 2, Orientation.Horizontal, LineStyle.Double);
  310. Assert.Equal (new (x, y, 2, 1), lc.Bounds);
  311. //LHS line down
  312. lc.AddLine (new (x, y), height, Orientation.Vertical, LineStyle.Double);
  313. Assert.Equal (new (x, y, 2, 2), lc.Bounds);
  314. //Vertical line before Title, results in a ╡
  315. lc.AddLine (new (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
  316. Assert.Equal (new (x, y, 2, 2), lc.Bounds);
  317. //Vertical line after Title, results in a ╞
  318. lc.AddLine (new (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
  319. Assert.Equal (new (x, y, 3, 2), lc.Bounds);
  320. // remainder of top line
  321. lc.AddLine (new (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
  322. Assert.Equal (new (x, y, 4, 2), lc.Bounds);
  323. //RHS line down
  324. lc.AddLine (new (x + width, y), height, Orientation.Vertical, LineStyle.Double);
  325. Assert.Equal (new (x, y, 4, 2), lc.Bounds);
  326. OutputAssert.AssertEqual (
  327. output,
  328. @"
  329. ╔╡╞╗
  330. ║ ║",
  331. $"{Environment.NewLine}{lc}"
  332. );
  333. }
  334. [Fact]
  335. [SetupFakeDriver]
  336. public void Viewport_Specific_With_Ustring ()
  337. {
  338. // Draw at 1,1 within client area of View (i.e. leave a top and left margin of 1)
  339. // This proves we aren't drawing excess above
  340. var x = 1;
  341. var y = 2;
  342. var width = 3;
  343. var height = 2;
  344. var lc = new LineCanvas ();
  345. // 01230
  346. // ╔╡╞╗1
  347. // ║ ║2
  348. // Add a short horiz line for ╔╡
  349. lc.AddLine (new (x, y), 2, Orientation.Horizontal, LineStyle.Double);
  350. Assert.Equal (new (x, y, 2, 1), lc.Bounds);
  351. //LHS line down
  352. lc.AddLine (new (x, y), height, Orientation.Vertical, LineStyle.Double);
  353. Assert.Equal (new (x, y, 2, 2), lc.Bounds);
  354. //Vertical line before Title, results in a ╡
  355. lc.AddLine (new (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
  356. Assert.Equal (new (x, y, 2, 2), lc.Bounds);
  357. //Vertical line after Title, results in a ╞
  358. lc.AddLine (new (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
  359. Assert.Equal (new (x, y, 3, 2), lc.Bounds);
  360. // remainder of top line
  361. lc.AddLine (new (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
  362. Assert.Equal (new (x, y, 4, 2), lc.Bounds);
  363. //RHS line down
  364. lc.AddLine (new (x + width, y), height, Orientation.Vertical, LineStyle.Double);
  365. Assert.Equal (new (x, y, 4, 2), lc.Bounds);
  366. OutputAssert.AssertEqual (
  367. output,
  368. @"
  369. ╔╡╞╗
  370. ║ ║",
  371. $"{Environment.NewLine}{lc}"
  372. );
  373. }
  374. [Fact]
  375. [SetupFakeDriver]
  376. public void Canvas_Updates_On_Changes ()
  377. {
  378. var lc = new LineCanvas ();
  379. Assert.Equal (Rectangle.Empty, lc.Bounds);
  380. lc.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Double);
  381. Assert.NotEqual (Rectangle.Empty, lc.Bounds);
  382. lc.Clear ();
  383. Assert.Equal (Rectangle.Empty, lc.Bounds);
  384. }
  385. [InlineData (0, 0, Orientation.Horizontal, "─")]
  386. [InlineData (1, 0, Orientation.Horizontal, "─")]
  387. [InlineData (0, 1, Orientation.Horizontal, "─")]
  388. [InlineData (-1, 0, Orientation.Horizontal, "─")]
  389. [InlineData (0, -1, Orientation.Horizontal, "─")]
  390. [InlineData (-1, -1, Orientation.Horizontal, "─")]
  391. [InlineData (0, 0, Orientation.Vertical, "│")]
  392. [InlineData (1, 0, Orientation.Vertical, "│")]
  393. [InlineData (0, 1, Orientation.Vertical, "│")]
  394. [InlineData (0, -1, Orientation.Vertical, "│")]
  395. [InlineData (-1, 0, Orientation.Vertical, "│")]
  396. [InlineData (-1, -1, Orientation.Vertical, "│")]
  397. [Theory]
  398. [SetupFakeDriver]
  399. public void Length_0_Is_1_Long (int x, int y, Orientation orientation, string expected)
  400. {
  401. var canvas = new LineCanvas ();
  402. // Add a line at 5, 5 that's has length of 1
  403. canvas.AddLine (new (x, y), 1, orientation, LineStyle.Single);
  404. OutputAssert.AssertEqual (output, $"{expected}", $"{canvas}");
  405. }
  406. // X is offset by 2
  407. [InlineData (0, 0, 1, Orientation.Horizontal, "─")]
  408. [InlineData (1, 0, 1, Orientation.Horizontal, "─")]
  409. [InlineData (0, 1, 1, Orientation.Horizontal, "─")]
  410. [InlineData (0, 0, 1, Orientation.Vertical, "│")]
  411. [InlineData (1, 0, 1, Orientation.Vertical, "│")]
  412. [InlineData (0, 1, 1, Orientation.Vertical, "│")]
  413. [InlineData (-1, 0, 1, Orientation.Horizontal, "─")]
  414. [InlineData (0, -1, 1, Orientation.Horizontal, "─")]
  415. [InlineData (-1, 0, 1, Orientation.Vertical, "│")]
  416. [InlineData (0, -1, 1, Orientation.Vertical, "│")]
  417. [InlineData (0, 0, -1, Orientation.Horizontal, "─")]
  418. [InlineData (1, 0, -1, Orientation.Horizontal, "─")]
  419. [InlineData (0, 1, -1, Orientation.Horizontal, "─")]
  420. [InlineData (0, 0, -1, Orientation.Vertical, "│")]
  421. [InlineData (1, 0, -1, Orientation.Vertical, "│")]
  422. [InlineData (0, 1, -1, Orientation.Vertical, "│")]
  423. [InlineData (-1, 0, -1, Orientation.Horizontal, "─")]
  424. [InlineData (0, -1, -1, Orientation.Horizontal, "─")]
  425. [InlineData (-1, 0, -1, Orientation.Vertical, "│")]
  426. [InlineData (0, -1, -1, Orientation.Vertical, "│")]
  427. [InlineData (0, 0, 2, Orientation.Horizontal, "──")]
  428. [InlineData (1, 0, 2, Orientation.Horizontal, "──")]
  429. [InlineData (0, 1, 2, Orientation.Horizontal, "──")]
  430. [InlineData (1, 1, 2, Orientation.Horizontal, "──")]
  431. [InlineData (0, 0, 2, Orientation.Vertical, "│\r\n│")]
  432. [InlineData (1, 0, 2, Orientation.Vertical, "│\r\n│")]
  433. [InlineData (0, 1, 2, Orientation.Vertical, "│\r\n│")]
  434. [InlineData (1, 1, 2, Orientation.Vertical, "│\r\n│")]
  435. [InlineData (-1, 0, 2, Orientation.Horizontal, "──")]
  436. [InlineData (0, -1, 2, Orientation.Horizontal, "──")]
  437. [InlineData (-1, 0, 2, Orientation.Vertical, "│\r\n│")]
  438. [InlineData (0, -1, 2, Orientation.Vertical, "│\r\n│")]
  439. [InlineData (-1, -1, 2, Orientation.Vertical, "│\r\n│")]
  440. [InlineData (0, 0, -2, Orientation.Horizontal, "──")]
  441. [InlineData (1, 0, -2, Orientation.Horizontal, "──")]
  442. [InlineData (0, 1, -2, Orientation.Horizontal, "──")]
  443. [InlineData (0, 0, -2, Orientation.Vertical, "│\r\n│")]
  444. [InlineData (1, 0, -2, Orientation.Vertical, "│\r\n│")]
  445. [InlineData (0, 1, -2, Orientation.Vertical, "│\r\n│")]
  446. [InlineData (1, 1, -2, Orientation.Vertical, "│\r\n│")]
  447. [InlineData (-1, 0, -2, Orientation.Horizontal, "──")]
  448. [InlineData (0, -1, -2, Orientation.Horizontal, "──")]
  449. [InlineData (-1, 0, -2, Orientation.Vertical, "│\r\n│")]
  450. [InlineData (0, -1, -2, Orientation.Vertical, "│\r\n│")]
  451. [InlineData (-1, -1, -2, Orientation.Vertical, "│\r\n│")]
  452. [Theory]
  453. [SetupFakeDriver]
  454. public void Length_n_Is_n_Long (int x, int y, int length, Orientation orientation, string expected)
  455. {
  456. var canvas = new LineCanvas ();
  457. canvas.AddLine (new (x, y), length, orientation, LineStyle.Single);
  458. var result = canvas.ToString ();
  459. OutputAssert.AssertEqual (output, expected, result);
  460. }
  461. [Fact]
  462. [SetupFakeDriver]
  463. public void Length_Negative ()
  464. {
  465. var offset = new Point (5, 5);
  466. var canvas = new LineCanvas ();
  467. canvas.AddLine (offset, -3, Orientation.Horizontal, LineStyle.Single);
  468. var looksLike = "───";
  469. Assert.Equal (looksLike, $"{canvas}");
  470. }
  471. [InlineData (Orientation.Horizontal, "─")]
  472. [InlineData (Orientation.Vertical, "│")]
  473. [Theory]
  474. [SetupFakeDriver]
  475. public void Length_Zero_Alone_Is_Line (Orientation orientation, string expected)
  476. {
  477. var lc = new LineCanvas ();
  478. // Add a line at 0, 0 that's has length of 0
  479. lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single);
  480. OutputAssert.AssertEqual (output, expected, $"{lc}");
  481. }
  482. [InlineData (Orientation.Horizontal, "┼")]
  483. [InlineData (Orientation.Vertical, "┼")]
  484. [Theory]
  485. [SetupFakeDriver]
  486. public void Length_Zero_Cross_Is_Cross (Orientation orientation, string expected)
  487. {
  488. var lc = new LineCanvas ();
  489. // Add point at opposite orientation
  490. lc.AddLine (
  491. Point.Empty,
  492. 0,
  493. orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal,
  494. LineStyle.Single
  495. );
  496. // Add a line at 0, 0 that's has length of 0
  497. lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single);
  498. OutputAssert.AssertEqual (output, expected, $"{lc}");
  499. }
  500. [InlineData (Orientation.Horizontal, "╥")]
  501. [InlineData (Orientation.Vertical, "╞")]
  502. [Theory]
  503. [SetupFakeDriver]
  504. public void Length_Zero_NextTo_Opposite_Is_T (Orientation orientation, string expected)
  505. {
  506. var lc = new LineCanvas ();
  507. // Add line with length of 1 in opposite orientation starting at same location
  508. if (orientation == Orientation.Horizontal)
  509. {
  510. lc.AddLine (Point.Empty, 1, Orientation.Vertical, LineStyle.Double);
  511. }
  512. else
  513. {
  514. lc.AddLine (Point.Empty, 1, Orientation.Horizontal, LineStyle.Double);
  515. }
  516. // Add a line at 0, 0 that's has length of 0
  517. lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single);
  518. OutputAssert.AssertEqual (output, expected, $"{lc}");
  519. }
  520. [Fact]
  521. public void TestLineCanvas_LeaveMargin_Top1_Left1 ()
  522. {
  523. var canvas = new LineCanvas ();
  524. // Upper box
  525. canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single);
  526. canvas.AddLine (Point.Empty, 2, Orientation.Vertical, LineStyle.Single);
  527. var looksLike =
  528. @"
  529. ┌─
  530. │ ";
  531. OutputAssert.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
  532. }
  533. [Fact]
  534. [SetupFakeDriver]
  535. public void TestLineCanvas_Window_Heavy ()
  536. {
  537. View v = GetCanvas (out LineCanvas canvas);
  538. // outer box
  539. canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Heavy);
  540. canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Heavy);
  541. canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy);
  542. canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Heavy);
  543. canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Heavy);
  544. canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Heavy);
  545. v.Draw ();
  546. var looksLike =
  547. @"
  548. ┏━━━━┳━━━┓
  549. ┃ ┃ ┃
  550. ┣━━━━╋━━━┫
  551. ┃ ┃ ┃
  552. ┗━━━━┻━━━┛";
  553. DriverAssert.AssertDriverContentsAre (looksLike, output);
  554. v.Dispose ();
  555. }
  556. [Theory]
  557. [SetupFakeDriver]
  558. [InlineData (LineStyle.Single)]
  559. [InlineData (LineStyle.Rounded)]
  560. public void TestLineCanvas_Window_HeavyTop_ThinSides (LineStyle thinStyle)
  561. {
  562. View v = GetCanvas (out LineCanvas canvas);
  563. // outer box
  564. canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Heavy);
  565. canvas.AddLine (new (9, 0), 5, Orientation.Vertical, thinStyle);
  566. canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy);
  567. canvas.AddLine (new (0, 4), -5, Orientation.Vertical, thinStyle);
  568. canvas.AddLine (new (5, 0), 5, Orientation.Vertical, thinStyle);
  569. canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Heavy);
  570. v.Draw ();
  571. var looksLike =
  572. @"
  573. ┍━━━━┯━━━┑
  574. │ │ │
  575. ┝━━━━┿━━━┥
  576. │ │ │
  577. ┕━━━━┷━━━┙
  578. ";
  579. DriverAssert.AssertDriverContentsAre (looksLike, output);
  580. v.Dispose ();
  581. }
  582. [Theory]
  583. [SetupFakeDriver]
  584. [InlineData (LineStyle.Single)]
  585. [InlineData (LineStyle.Rounded)]
  586. public void TestLineCanvas_Window_ThinTop_HeavySides (LineStyle thinStyle)
  587. {
  588. View v = GetCanvas (out LineCanvas canvas);
  589. // outer box
  590. canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, thinStyle);
  591. canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Heavy);
  592. canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, thinStyle);
  593. canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Heavy);
  594. canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Heavy);
  595. canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, thinStyle);
  596. v.Draw ();
  597. var looksLike =
  598. @"
  599. ┎────┰───┒
  600. ┃ ┃ ┃
  601. ┠────╂───┨
  602. ┃ ┃ ┃
  603. ┖────┸───┚
  604. ";
  605. DriverAssert.AssertDriverContentsAre (looksLike, output);
  606. v.Dispose ();
  607. }
  608. [Fact]
  609. [SetupFakeDriver]
  610. public void Top_Left_From_TopRight_LeftUp ()
  611. {
  612. var canvas = new LineCanvas ();
  613. // Upper box
  614. canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single);
  615. canvas.AddLine (new (0, 1), -2, Orientation.Vertical, LineStyle.Single);
  616. var looksLike =
  617. @"
  618. ┌─
  619. │ ";
  620. OutputAssert.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
  621. }
  622. [Fact]
  623. [SetupFakeDriver]
  624. public void Top_With_1Down ()
  625. {
  626. var canvas = new LineCanvas ();
  627. // Top ─
  628. canvas.AddLine (Point.Empty, 1, Orientation.Horizontal, LineStyle.Single);
  629. // Bottom ─
  630. canvas.AddLine (new (1, 1), -1, Orientation.Horizontal, LineStyle.Single);
  631. //// Right down
  632. //canvas.AddLine (new Point (9, 0), 3, Orientation.Vertical, LineStyle.Single);
  633. //// Bottom
  634. //canvas.AddLine (new Point (9, 3), -10, Orientation.Horizontal, LineStyle.Single);
  635. //// Left Up
  636. //canvas.AddLine (new Point (0, 3), -3, Orientation.Vertical, LineStyle.Single);
  637. Assert.Equal (new (0, 0, 2, 2), canvas.Bounds);
  638. Dictionary<Point, Rune> map = canvas.GetMap ();
  639. Assert.Equal (2, map.Count);
  640. OutputAssert.AssertEqual (
  641. output,
  642. @"
  643. ─",
  644. $"{Environment.NewLine}{canvas}"
  645. );
  646. }
  647. [Fact]
  648. [SetupFakeDriver]
  649. public void ToString_Empty ()
  650. {
  651. var lc = new LineCanvas ();
  652. OutputAssert.AssertEqual (output, string.Empty, lc.ToString ());
  653. }
  654. // 012
  655. [InlineData (0, 0, "═══")]
  656. [InlineData (1, 0, "═══")]
  657. [InlineData (0, 1, "═══")]
  658. [InlineData (1, 1, "═══")]
  659. [InlineData (2, 2, "═══")]
  660. [InlineData (-1, 0, "═══")]
  661. [InlineData (0, -1, "═══")]
  662. [InlineData (-1, -1, "═══")]
  663. [InlineData (-2, -2, "═══")]
  664. [Theory]
  665. [SetupFakeDriver]
  666. public void ToString_Positive_Horizontal_1Line_Offset (int x, int y, string expected)
  667. {
  668. var lc = new LineCanvas ();
  669. lc.AddLine (new (x, y), 3, Orientation.Horizontal, LineStyle.Double);
  670. OutputAssert.AssertEqual (output, expected, $"{lc}");
  671. }
  672. [InlineData (0, 0, 0, 0, "═══")]
  673. [InlineData (1, 0, 1, 0, "═══")]
  674. [InlineData (-1, 0, -1, 0, "═══")]
  675. [InlineData (0, 0, 1, 0, "════")]
  676. [InlineData (1, 0, 3, 0, "═════")]
  677. [InlineData (1, 0, 4, 0, "══════")]
  678. [InlineData (1, 0, 5, 0, "═══ ═══")]
  679. [InlineData (0, 0, 0, 1, "\u2550\u2550\u2550\r\n\u2550\u2550\u2550")]
  680. [InlineData (0, 0, 1, 1, "═══ \r\n ═══")]
  681. [InlineData (0, 0, 2, 1, "═══ \r\n ═══")]
  682. [InlineData (1, 0, 0, 1, " ═══\r\n═══ ")]
  683. [InlineData (0, 1, 0, 1, "═══")]
  684. [InlineData (1, 1, 0, 1, "════")]
  685. [InlineData (2, 2, 0, 1, "═══ \r\n ═══")]
  686. [Theory]
  687. [SetupFakeDriver]
  688. public void ToString_Positive_Horizontal_2Line_Offset (int x1, int y1, int x2, int y2, string expected)
  689. {
  690. var lc = new LineCanvas ();
  691. lc.AddLine (new (x1, y1), 3, Orientation.Horizontal, LineStyle.Double);
  692. lc.AddLine (new (x2, y2), 3, Orientation.Horizontal, LineStyle.Double);
  693. OutputAssert.AssertEqual (output, expected, $"{lc}");
  694. }
  695. // [Fact, SetupFakeDriver]
  696. // public void LeaveMargin_Top1_Left1 ()
  697. // {
  698. // var canvas = new LineCanvas ();
  699. // // Upper box
  700. // canvas.AddLine (Point.Empty, 9, Orientation.Horizontal, LineStyle.Single);
  701. // canvas.AddLine (new Point (8, 0), 3, Orientation.Vertical, LineStyle.Single);
  702. // canvas.AddLine (new Point (8, 3), -9, Orientation.Horizontal, LineStyle.Single);
  703. // canvas.AddLine (new Point (0, 2), -3, Orientation.Vertical, LineStyle.Single);
  704. // // Lower Box
  705. // canvas.AddLine (new Point (5, 0), 2, Orientation.Vertical, LineStyle.Single);
  706. // canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, LineStyle.Single);
  707. // string looksLike =
  708. //@"
  709. //┌────┬──┐
  710. //│ │ │
  711. //├────┼──┤
  712. //└────┴──┘
  713. //";
  714. // Assert.Equal (looksLike, $"{Environment.NewLine}{canvas}");
  715. // }
  716. [InlineData (0, 0, 0, Orientation.Horizontal, LineStyle.Double, "═")]
  717. [InlineData (0, 0, 0, Orientation.Vertical, LineStyle.Double, "║")]
  718. [InlineData (0, 0, 0, Orientation.Horizontal, LineStyle.Single, "─")]
  719. [InlineData (0, 0, 0, Orientation.Vertical, LineStyle.Single, "│")]
  720. [InlineData (0, 0, 1, Orientation.Horizontal, LineStyle.Double, "═")]
  721. [InlineData (0, 0, 1, Orientation.Vertical, LineStyle.Double, "║")]
  722. [InlineData (0, 0, 1, Orientation.Horizontal, LineStyle.Single, "─")]
  723. [InlineData (0, 0, 1, Orientation.Vertical, LineStyle.Single, "│")]
  724. [InlineData (0, 0, 2, Orientation.Horizontal, LineStyle.Double, "══")]
  725. [InlineData (0, 0, 2, Orientation.Vertical, LineStyle.Double, "║\n║")]
  726. [InlineData (0, 0, 2, Orientation.Horizontal, LineStyle.Single, "──")]
  727. [InlineData (0, 0, 2, Orientation.Vertical, LineStyle.Single, "│\n│")]
  728. [SetupFakeDriver]
  729. [Theory]
  730. public void View_Draws_1LineTests (
  731. int x1,
  732. int y1,
  733. int length,
  734. Orientation o1,
  735. LineStyle s1,
  736. string expected
  737. )
  738. {
  739. View v = GetCanvas (out LineCanvas lc);
  740. v.Width = 10;
  741. v.Height = 10;
  742. v.Viewport = new (0, 0, 10, 10);
  743. lc.AddLine (new (x1, y1), length, o1, s1);
  744. v.Draw ();
  745. DriverAssert.AssertDriverContentsAre (expected, output);
  746. v.Dispose ();
  747. }
  748. /// <summary>This test demonstrates how to correctly trigger a corner. By overlapping the lines in the same cell</summary>
  749. [Fact]
  750. [SetupFakeDriver]
  751. public void View_Draws_Corner_Correct ()
  752. {
  753. View v = GetCanvas (out LineCanvas canvas);
  754. canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single);
  755. canvas.AddLine (Point.Empty, 2, Orientation.Vertical, LineStyle.Single);
  756. v.Draw ();
  757. var looksLike =
  758. @"
  759. ┌─
  760. │";
  761. DriverAssert.AssertDriverContentsAre (looksLike, output);
  762. v.Dispose ();
  763. }
  764. /// <summary>
  765. /// This test demonstrates that corners are only drawn when lines overlap. Not when they terminate adjacent to one
  766. /// another.
  767. /// </summary>
  768. [Fact]
  769. [SetupFakeDriver]
  770. public void View_Draws_Corner_NoOverlap ()
  771. {
  772. View v = GetCanvas (out LineCanvas canvas);
  773. canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single);
  774. canvas.AddLine (new (0, 1), 2, Orientation.Vertical, LineStyle.Single);
  775. v.Draw ();
  776. var looksLike =
  777. @"
  778. ──
  779. │";
  780. DriverAssert.AssertDriverContentsAre (looksLike, output);
  781. v.Dispose ();
  782. }
  783. [InlineData (LineStyle.Single)]
  784. [InlineData (LineStyle.Rounded)]
  785. [Theory]
  786. [SetupFakeDriver]
  787. public void View_Draws_Horizontal (LineStyle style)
  788. {
  789. View v = GetCanvas (out LineCanvas canvas);
  790. canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, style);
  791. v.Draw ();
  792. var looksLike =
  793. @"
  794. ──";
  795. DriverAssert.AssertDriverContentsAre (looksLike, output);
  796. v.Dispose ();
  797. }
  798. [Fact]
  799. [SetupFakeDriver]
  800. public void View_Draws_Horizontal_Double ()
  801. {
  802. View v = GetCanvas (out LineCanvas canvas);
  803. canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Double);
  804. v.Draw ();
  805. var looksLike =
  806. @"
  807. ══";
  808. DriverAssert.AssertDriverContentsAre (looksLike, output);
  809. v.Dispose ();
  810. }
  811. [InlineData (LineStyle.Single)]
  812. [InlineData (LineStyle.Rounded)]
  813. [Theory]
  814. [SetupFakeDriver]
  815. public void View_Draws_Vertical (LineStyle style)
  816. {
  817. View v = GetCanvas (out LineCanvas canvas);
  818. canvas.AddLine (Point.Empty, 2, Orientation.Vertical, style);
  819. v.Draw ();
  820. var looksLike =
  821. @"
  822. │";
  823. DriverAssert.AssertDriverContentsAre (looksLike, output);
  824. v.Dispose ();
  825. }
  826. [Fact]
  827. [SetupFakeDriver]
  828. public void View_Draws_Vertical_Double ()
  829. {
  830. View v = GetCanvas (out LineCanvas canvas);
  831. canvas.AddLine (Point.Empty, 2, Orientation.Vertical, LineStyle.Double);
  832. v.Draw ();
  833. var looksLike =
  834. @"
  835. ║";
  836. DriverAssert.AssertDriverContentsAre (looksLike, output);
  837. v.Dispose ();
  838. }
  839. [Fact]
  840. [SetupFakeDriver]
  841. public void View_Draws_Window_Double ()
  842. {
  843. View v = GetCanvas (out LineCanvas canvas);
  844. // outer box
  845. canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Double);
  846. canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Double);
  847. canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Double);
  848. canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Double);
  849. canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Double);
  850. canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Double);
  851. v.Draw ();
  852. var looksLike =
  853. @"
  854. ╔════╦═══╗
  855. ║ ║ ║
  856. ╠════╬═══╣
  857. ║ ║ ║
  858. ╚════╩═══╝";
  859. DriverAssert.AssertDriverContentsAre (looksLike, output);
  860. v.Dispose ();
  861. }
  862. [Theory]
  863. [SetupFakeDriver]
  864. [InlineData (LineStyle.Single)]
  865. [InlineData (LineStyle.Rounded)]
  866. public void View_Draws_Window_DoubleTop_SingleSides (LineStyle thinStyle)
  867. {
  868. View v = GetCanvas (out LineCanvas canvas);
  869. // outer box
  870. canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Double);
  871. canvas.AddLine (new (9, 0), 5, Orientation.Vertical, thinStyle);
  872. canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Double);
  873. canvas.AddLine (new (0, 4), -5, Orientation.Vertical, thinStyle);
  874. canvas.AddLine (new (5, 0), 5, Orientation.Vertical, thinStyle);
  875. canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Double);
  876. v.Draw ();
  877. var looksLike =
  878. @"
  879. ╒════╤═══╕
  880. │ │ │
  881. ╞════╪═══╡
  882. │ │ │
  883. ╘════╧═══╛
  884. ";
  885. DriverAssert.AssertDriverContentsAre (looksLike, output);
  886. v.Dispose ();
  887. }
  888. /// <summary>
  889. /// Demonstrates when <see cref="LineStyle.Rounded"/> corners are used. Notice how not all lines declare rounded.
  890. /// If there are 1+ lines intersecting and a corner is to be used then if any of them are rounded a rounded corner is
  891. /// used.
  892. /// </summary>
  893. [Fact]
  894. [SetupFakeDriver]
  895. public void View_Draws_Window_Rounded ()
  896. {
  897. View v = GetCanvas (out LineCanvas canvas);
  898. // outer box
  899. canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Rounded);
  900. // LineStyle.Single is ignored because corner overlaps with the above line which is Rounded
  901. // this results in a rounded corner being used.
  902. canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Single);
  903. canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Rounded);
  904. canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Single);
  905. // These lines say rounded but they will result in the T sections which are never rounded.
  906. canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Rounded);
  907. canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Rounded);
  908. v.Draw ();
  909. var looksLike =
  910. @"
  911. ╭────┬───╮
  912. │ │ │
  913. ├────┼───┤
  914. │ │ │
  915. ╰────┴───╯";
  916. DriverAssert.AssertDriverContentsAre (looksLike, output);
  917. v.Dispose ();
  918. }
  919. [Theory]
  920. [InlineData (LineStyle.Single)]
  921. [InlineData (LineStyle.Rounded)]
  922. [SetupFakeDriver]
  923. public void View_Draws_Window_SingleTop_DoubleSides (LineStyle thinStyle)
  924. {
  925. View v = GetCanvas (out LineCanvas canvas);
  926. // outer box
  927. canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, thinStyle);
  928. canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Double);
  929. canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, thinStyle);
  930. canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Double);
  931. canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Double);
  932. canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, thinStyle);
  933. v.Draw ();
  934. var looksLike =
  935. @"
  936. ╓────╥───╖
  937. ║ ║ ║
  938. ╟────╫───╢
  939. ║ ║ ║
  940. ╙────╨───╜
  941. ";
  942. DriverAssert.AssertDriverContentsAre (looksLike, output);
  943. v.Dispose ();
  944. }
  945. [Fact]
  946. [SetupFakeDriver]
  947. public void Window ()
  948. {
  949. var canvas = new LineCanvas ();
  950. // Frame
  951. canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Single);
  952. canvas.AddLine (new (9, 0), 5, Orientation.Vertical, LineStyle.Single);
  953. canvas.AddLine (new (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
  954. canvas.AddLine (new (0, 4), -5, Orientation.Vertical, LineStyle.Single);
  955. // Cross
  956. canvas.AddLine (new (5, 0), 5, Orientation.Vertical, LineStyle.Single);
  957. canvas.AddLine (new (0, 2), 10, Orientation.Horizontal, LineStyle.Single);
  958. var looksLike =
  959. @"
  960. ┌────┬───┐
  961. │ │ │
  962. ├────┼───┤
  963. │ │ │
  964. └────┴───┘";
  965. OutputAssert.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
  966. }
  967. [Fact]
  968. [SetupFakeDriver]
  969. public void Zero_Length_Intersections ()
  970. {
  971. // Draw at 1,2 within client area of View (i.e. leave a top and left margin of 1)
  972. // This proves we aren't drawing excess above
  973. var x = 1;
  974. var y = 2;
  975. var width = 5;
  976. var height = 2;
  977. var lc = new LineCanvas ();
  978. // ╔╡╞═════╗
  979. // Add a short horiz line for ╔╡
  980. lc.AddLine (new (x, y), 2, Orientation.Horizontal, LineStyle.Double);
  981. //LHS line down
  982. lc.AddLine (new (x, y), height, Orientation.Vertical, LineStyle.Double);
  983. //Vertical line before Title, results in a ╡
  984. lc.AddLine (new (x + 1, y), 0, Orientation.Vertical, LineStyle.Single);
  985. //Vertical line after Title, results in a ╞
  986. lc.AddLine (new (x + 2, y), 0, Orientation.Vertical, LineStyle.Single);
  987. // remainder of top line
  988. lc.AddLine (new (x + 2, y), width - 1, Orientation.Horizontal, LineStyle.Double);
  989. //RHS line down
  990. lc.AddLine (new (x + width, y), height, Orientation.Vertical, LineStyle.Double);
  991. var looksLike = @"
  992. ╔╡╞══╗
  993. ║ ║";
  994. OutputAssert.AssertEqual (output, looksLike, $"{Environment.NewLine}{lc}");
  995. }
  996. [Fact]
  997. public void LineCanvas_UsesFillCorrectly ()
  998. {
  999. // Arrange
  1000. var foregroundColor = new Color (255, 0); // Red
  1001. var backgroundColor = new Color (0, 0); // Black
  1002. var foregroundFill = new SolidFill (foregroundColor);
  1003. var backgroundFill = new SolidFill (backgroundColor);
  1004. var fillPair = new FillPair (foregroundFill, backgroundFill);
  1005. var lineCanvas = new LineCanvas
  1006. {
  1007. Fill = fillPair
  1008. };
  1009. // Act
  1010. lineCanvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
  1011. Dictionary<Point, Cell?> cellMap = lineCanvas.GetCellMap ();
  1012. // Assert
  1013. foreach (Cell? cell in cellMap.Values)
  1014. {
  1015. Assert.NotNull (cell);
  1016. Assert.Equal (foregroundColor, cell.Value.Attribute.Value.Foreground);
  1017. Assert.Equal (backgroundColor, cell.Value.Attribute.Value.Background);
  1018. }
  1019. }
  1020. [Fact]
  1021. public void LineCanvas_LineColorIgnoredBecauseOfFill ()
  1022. {
  1023. // Arrange
  1024. var foregroundColor = new Color (255, 0); // Red
  1025. var backgroundColor = new Color (0, 0); // Black
  1026. var lineColor = new Attribute (new Color (0, 255), new Color (255, 255, 255)); // Green on White
  1027. var foregroundFill = new SolidFill (foregroundColor);
  1028. var backgroundFill = new SolidFill (backgroundColor);
  1029. var fillPair = new FillPair (foregroundFill, backgroundFill);
  1030. var lineCanvas = new LineCanvas
  1031. {
  1032. Fill = fillPair
  1033. };
  1034. // Act
  1035. lineCanvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single, lineColor);
  1036. Dictionary<Point, Cell?> cellMap = lineCanvas.GetCellMap ();
  1037. // Assert
  1038. foreach (Cell? cell in cellMap.Values)
  1039. {
  1040. Assert.NotNull (cell);
  1041. Assert.Equal (foregroundColor, cell.Value.Attribute.Value.Foreground);
  1042. Assert.Equal (backgroundColor, cell.Value.Attribute.Value.Background);
  1043. }
  1044. }
  1045. [Fact]
  1046. public void LineCanvas_IntersectingLinesUseFillCorrectly ()
  1047. {
  1048. // Arrange
  1049. var foregroundColor = new Color (255, 0); // Red
  1050. var backgroundColor = new Color (0, 0); // Black
  1051. var foregroundFill = new SolidFill (foregroundColor);
  1052. var backgroundFill = new SolidFill (backgroundColor);
  1053. var fillPair = new FillPair (foregroundFill, backgroundFill);
  1054. var lineCanvas = new LineCanvas
  1055. {
  1056. Fill = fillPair
  1057. };
  1058. // Act
  1059. lineCanvas.AddLine (new (0, 0), 5, Orientation.Horizontal, LineStyle.Single);
  1060. lineCanvas.AddLine (new (2, -2), 5, Orientation.Vertical, LineStyle.Single);
  1061. Dictionary<Point, Cell?> cellMap = lineCanvas.GetCellMap ();
  1062. // Assert
  1063. foreach (Cell? cell in cellMap.Values)
  1064. {
  1065. Assert.NotNull (cell);
  1066. Assert.Equal (foregroundColor, cell.Value.Attribute.Value.Foreground);
  1067. Assert.Equal (backgroundColor, cell.Value.Attribute.Value.Background);
  1068. }
  1069. }
  1070. // TODO: Remove this and make all LineCanvas tests independent of View
  1071. /// <summary>
  1072. /// Creates a new <see cref="View"/> into which a <see cref="LineCanvas"/> is rendered at
  1073. /// <see cref="View.DrawComplete"/> time.
  1074. /// </summary>
  1075. /// <param name="canvas">The <see cref="LineCanvas"/> you can draw into.</param>
  1076. /// <param name="offsetX">How far to offset drawing in X</param>
  1077. /// <param name="offsetY">How far to offset drawing in Y</param>
  1078. /// <returns></returns>
  1079. private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0)
  1080. {
  1081. var v = new View { Width = 10, Height = 5, Viewport = new (0, 0, 10, 5) };
  1082. LineCanvas canvasCopy = canvas = new ();
  1083. v.DrawComplete += (s, e) =>
  1084. {
  1085. v.FillRect (v.Viewport);
  1086. foreach (KeyValuePair<Point, Rune> p in canvasCopy.GetMap ())
  1087. {
  1088. v.AddRune (
  1089. offsetX + p.Key.X,
  1090. offsetY + p.Key.Y,
  1091. p.Value
  1092. );
  1093. }
  1094. canvasCopy.Clear ();
  1095. };
  1096. return v;
  1097. }
  1098. }