LineCanvasTests.cs 42 KB

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