DrawTests.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. #nullable enable
  2. using System.Text;
  3. using Xunit.Abstractions;
  4. namespace Terminal.Gui.ViewTests;
  5. [Trait ("Category", "Output")]
  6. public class DrawTests (ITestOutputHelper output)
  7. {
  8. [Fact]
  9. [SetupFakeDriver]
  10. public void Move_Is_Constrained_To_Viewport ()
  11. {
  12. var view = new View
  13. {
  14. X = 1,
  15. Y = 1,
  16. Width = 3, Height = 3
  17. };
  18. view.Margin.Thickness = new Thickness (1);
  19. // Only valid location w/in Viewport is 0, 0 (view) - 2, 2 (screen)
  20. view.Move (0, 0);
  21. Assert.Equal(new Point(2, 2), new Point (Application.Driver.Col, Application.Driver.Row));
  22. view.Move (-1, -1);
  23. Assert.Equal (new Point (2, 2), new Point (Application.Driver.Col, Application.Driver.Row));
  24. view.Move (1, 1);
  25. Assert.Equal (new Point (2, 2), new Point (Application.Driver.Col, Application.Driver.Row));
  26. }
  27. [Fact]
  28. [SetupFakeDriver]
  29. public void AddRune_Is_Constrained_To_Viewport ()
  30. {
  31. var view = new View
  32. {
  33. X = 1,
  34. Y = 1,
  35. Width = 3, Height = 3
  36. };
  37. view.Margin.Thickness = new Thickness (1);
  38. View.Diagnostics = ViewDiagnosticFlags.Padding;
  39. view.BeginInit();
  40. view.EndInit();
  41. view.Draw();
  42. // Only valid location w/in Viewport is 0, 0 (view) - 2, 2 (screen)
  43. Assert.Equal ((Rune)' ', Application.Driver.Contents [2, 2].Rune);
  44. view.AddRune(0, 0, Rune.ReplacementChar);
  45. Assert.Equal (Rune.ReplacementChar, Application.Driver.Contents [2, 2].Rune);
  46. view.AddRune (-1, -1, Rune.ReplacementChar);
  47. Assert.Equal ((Rune)'M', Application.Driver.Contents [1, 1].Rune);
  48. view.AddRune (1, 1, Rune.ReplacementChar);
  49. Assert.Equal ((Rune)'M', Application.Driver.Contents [3, 3].Rune);
  50. View.Diagnostics = ViewDiagnosticFlags.Off;
  51. }
  52. [Theory]
  53. [InlineData (0, 0, 1, 1)]
  54. [InlineData (0, 0, 2, 2)]
  55. [InlineData (-1, -1, 2, 2)]
  56. [SetupFakeDriver]
  57. public void Clear_Clears_Only_Viewport (int x, int y, int width, int height)
  58. {
  59. var superView = new View { Width = Dim.Fill (), Height = Dim.Fill () };
  60. var view = new View
  61. {
  62. Text = "X",
  63. X = 1, Y = 1,
  64. Width = 3, Height = 3,
  65. BorderStyle = LineStyle.Single
  66. };
  67. superView.Add (view);
  68. superView.BeginInit ();
  69. superView.EndInit ();
  70. superView.LayoutSubviews ();
  71. superView.Draw ();
  72. TestHelpers.AssertDriverContentsWithFrameAre (
  73. @"
  74. ┌─┐
  75. │X│
  76. └─┘",
  77. output);
  78. Rectangle toClear = new (x, y, width, height);
  79. view.Clear (toClear);
  80. TestHelpers.AssertDriverContentsWithFrameAre (
  81. @"
  82. ┌─┐
  83. │ │
  84. └─┘",
  85. output);
  86. // Now try to clear beyond Viewport (invalid)
  87. superView.SetNeedsDisplay ();
  88. superView.Draw ();
  89. TestHelpers.AssertDriverContentsWithFrameAre (
  90. @"
  91. ┌─┐
  92. │X│
  93. └─┘",
  94. output);
  95. toClear = new (-width, -height, width, height);
  96. view.Clear (toClear);
  97. TestHelpers.AssertDriverContentsWithFrameAre (
  98. @"
  99. ┌─┐
  100. │X│
  101. └─┘",
  102. output);
  103. // Now try to clear beyond Viewport (valid)
  104. superView.SetNeedsDisplay ();
  105. superView.Draw ();
  106. TestHelpers.AssertDriverContentsWithFrameAre (
  107. @"
  108. ┌─┐
  109. │X│
  110. └─┘",
  111. output);
  112. toClear = new (-1, -1, width + 1, height + 1);
  113. view.Clear (toClear);
  114. TestHelpers.AssertDriverContentsWithFrameAre (
  115. @"
  116. ┌─┐
  117. │ │
  118. └─┘",
  119. output);
  120. // Now clear too much size
  121. superView.SetNeedsDisplay ();
  122. superView.Draw ();
  123. TestHelpers.AssertDriverContentsWithFrameAre (
  124. @"
  125. ┌─┐
  126. │X│
  127. └─┘",
  128. output);
  129. toClear = new (0, 0, width * 2, height * 2);
  130. view.Clear (toClear);
  131. TestHelpers.AssertDriverContentsWithFrameAre (
  132. @"
  133. ┌─┐
  134. │ │
  135. └─┘",
  136. output);
  137. }
  138. [Fact]
  139. [AutoInitShutdown]
  140. [Trait ("Category", "Unicode")]
  141. public void CJK_Compatibility_Ideographs_ConsoleWidth_ColumnWidth_Equal_Two ()
  142. {
  143. const string us = "\U0000f900";
  144. var r = (Rune)0xf900;
  145. Assert.Equal ("豈", us);
  146. Assert.Equal ("豈", r.ToString ());
  147. Assert.Equal (us, r.ToString ());
  148. Assert.Equal (2, us.GetColumns ());
  149. Assert.Equal (2, r.GetColumns ());
  150. var win = new Window { Title = us };
  151. var view = new View { Text = r.ToString (), Height = Dim.Fill (), Width = Dim.Fill () };
  152. var tf = new TextField { Text = us, Y = 1, Width = 3 };
  153. win.Add (view, tf);
  154. Toplevel top = new ();
  155. top.Add (win);
  156. Application.Begin (top);
  157. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  158. const string expectedOutput = """
  159. ┌┤豈├────┐
  160. │豈 │
  161. │豈 │
  162. └────────┘
  163. """;
  164. TestHelpers.AssertDriverContentsWithFrameAre (expectedOutput, output);
  165. TestHelpers.AssertDriverContentsAre (expectedOutput, output);
  166. Attribute [] expectedColors =
  167. {
  168. // 0
  169. Colors.ColorSchemes ["Base"].Normal,
  170. // 1
  171. Colors.ColorSchemes ["Base"].Focus,
  172. // 2
  173. Colors.ColorSchemes ["Base"].HotNormal
  174. };
  175. TestHelpers.AssertDriverAttributesAre (
  176. """
  177. 0011000000
  178. 0000000000
  179. 0111000000
  180. 0000000000
  181. """,
  182. Application.Driver,
  183. expectedColors
  184. );
  185. }
  186. // TODO: Refactor this test to not depend on TextView etc... Make it as primitive as possible
  187. [Fact]
  188. [AutoInitShutdown]
  189. [Trait ("Category", "Unicode")]
  190. public void Clipping_AddRune_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space ()
  191. {
  192. var tv = new TextView
  193. {
  194. Width = Dim.Fill (),
  195. Height = Dim.Fill (),
  196. Text = """
  197. これは広いルーンラインです。
  198. これは広いルーンラインです。
  199. これは広いルーンラインです。
  200. これは広いルーンラインです。
  201. これは広いルーンラインです。
  202. これは広いルーンラインです。
  203. これは広いルーンラインです。
  204. これは広いルーンラインです。
  205. """
  206. };
  207. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
  208. win.Add (tv);
  209. var top = new Toplevel ();
  210. top.Add (win);
  211. // Don't use Label. It sets AutoSize = true which is not what we're testing here.
  212. var view = new View { Text = "ワイドルーン。", Height = Dim.Fill (), Width = Dim.Fill () };
  213. // Don't have unit tests use things that aren't absolutely critical for the test, like Dialog
  214. var dg = new Window { X = 2, Y = 2, Width = 14, Height = 3 };
  215. dg.Add (view);
  216. RunState rsTop = Application.Begin (top);
  217. RunState rsDiag = Application.Begin (dg);
  218. ((FakeDriver)Application.Driver).SetBufferSize (30, 10);
  219. const string expectedOutput = """
  220. ┌────────────────────────────┐
  221. │これは広いルーンラインです。│
  222. │�┌────────────┐�ラインです。│
  223. │�│ワイドルーン│�ラインです。│
  224. │�└────────────┘�ラインです。│
  225. │これは広いルーンラインです。│
  226. │これは広いルーンラインです。│
  227. │これは広いルーンラインです。│
  228. │これは広いルーンラインです。│
  229. └────────────────────────────┘
  230. """;
  231. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expectedOutput, output);
  232. Assert.Equal (new Rectangle (0, 0, 30, 10), pos);
  233. Application.End (rsDiag);
  234. Application.End (rsTop);
  235. }
  236. [Fact]
  237. [AutoInitShutdown]
  238. [Trait ("Category", "Output")]
  239. public void Colors_On_TextAlignment_Right_And_Bottom ()
  240. {
  241. var viewRight = new View
  242. {
  243. Text = "Test",
  244. Width = 6,
  245. Height = 1,
  246. TextAlignment = TextAlignment.Right,
  247. ColorScheme = Colors.ColorSchemes ["Base"]
  248. };
  249. var viewBottom = new View
  250. {
  251. Text = "Test",
  252. TextDirection = TextDirection.TopBottom_LeftRight,
  253. Y = 1,
  254. Width = 1,
  255. Height = 6,
  256. VerticalTextAlignment = VerticalTextAlignment.Bottom,
  257. ColorScheme = Colors.ColorSchemes ["Base"]
  258. };
  259. Toplevel top = new ();
  260. top.Add (viewRight, viewBottom);
  261. Application.Begin (top);
  262. ((FakeDriver)Application.Driver).SetBufferSize (7, 7);
  263. TestHelpers.AssertDriverContentsWithFrameAre (
  264. """
  265. Test
  266. T
  267. e
  268. s
  269. t
  270. """,
  271. output
  272. );
  273. TestHelpers.AssertDriverAttributesAre (
  274. """
  275. 000000
  276. 0
  277. 0
  278. 0
  279. 0
  280. 0
  281. 0
  282. """,
  283. Application.Driver,
  284. Colors.ColorSchemes ["Base"].Normal
  285. );
  286. }
  287. [Fact]
  288. [SetupFakeDriver]
  289. public void Draw_Minimum_Full_Border_With_Empty_Viewport ()
  290. {
  291. var view = new View { Width = 2, Height = 2, BorderStyle = LineStyle.Single };
  292. view.BeginInit ();
  293. view.EndInit ();
  294. view.SetRelativeLayout (Application.Driver.Screen.Size);
  295. Assert.Equal (new (0, 0, 2, 2), view.Frame);
  296. Assert.Equal (Rectangle.Empty, view.Viewport);
  297. view.Draw ();
  298. TestHelpers.AssertDriverContentsWithFrameAre (
  299. """
  300. ┌┐
  301. └┘
  302. """,
  303. output
  304. );
  305. }
  306. [Fact]
  307. [SetupFakeDriver]
  308. public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Bottom ()
  309. {
  310. var view = new View { Width = 2, Height = 1, BorderStyle = LineStyle.Single };
  311. view.Border.Thickness = new Thickness (1, 1, 1, 0);
  312. view.BeginInit ();
  313. view.EndInit ();
  314. view.SetRelativeLayout (Application.Driver.Screen.Size);
  315. Assert.Equal (new (0, 0, 2, 1), view.Frame);
  316. Assert.Equal (Rectangle.Empty, view.Viewport);
  317. view.Draw ();
  318. TestHelpers.AssertDriverContentsWithFrameAre (string.Empty, output);
  319. }
  320. [Fact]
  321. [SetupFakeDriver]
  322. public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Left ()
  323. {
  324. var view = new View { Width = 1, Height = 2, BorderStyle = LineStyle.Single };
  325. view.Border.Thickness = new Thickness (0, 1, 1, 1);
  326. view.BeginInit ();
  327. view.EndInit ();
  328. view.SetRelativeLayout (Application.Driver.Screen.Size);
  329. Assert.Equal (new (0, 0, 1, 2), view.Frame);
  330. Assert.Equal (Rectangle.Empty, view.Viewport);
  331. view.Draw ();
  332. TestHelpers.AssertDriverContentsWithFrameAre (
  333. """
  334. """,
  335. output
  336. );
  337. }
  338. [Fact]
  339. [SetupFakeDriver]
  340. public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Right ()
  341. {
  342. var view = new View { Width = 1, Height = 2, BorderStyle = LineStyle.Single };
  343. view.Border.Thickness = new Thickness (1, 1, 0, 1);
  344. view.BeginInit ();
  345. view.EndInit ();
  346. view.SetRelativeLayout (Application.Driver.Screen.Size);
  347. Assert.Equal (new (0, 0, 1, 2), view.Frame);
  348. Assert.Equal (Rectangle.Empty, view.Viewport);
  349. view.Draw ();
  350. TestHelpers.AssertDriverContentsWithFrameAre (
  351. """
  352. """,
  353. output
  354. );
  355. }
  356. [Fact]
  357. [SetupFakeDriver]
  358. public void Draw_Minimum_Full_Border_With_Empty_Viewport_Without_Top ()
  359. {
  360. var view = new View { Width = 2, Height = 1, BorderStyle = LineStyle.Single };
  361. view.Border.Thickness = new Thickness (1, 0, 1, 1);
  362. view.BeginInit ();
  363. view.EndInit ();
  364. view.SetRelativeLayout (Application.Driver.Screen.Size);
  365. Assert.Equal (new (0, 0, 2, 1), view.Frame);
  366. Assert.Equal (Rectangle.Empty, view.Viewport);
  367. view.Draw ();
  368. // BUGBUG: Wha? Is this right? Shouldn't it be "└┘"???
  369. TestHelpers.AssertDriverContentsWithFrameAre (
  370. """
  371. ┌┐
  372. """,
  373. output
  374. );
  375. }
  376. [Fact]
  377. [AutoInitShutdown]
  378. public void Draw_Negative_Viewport_Horizontal_With_New_Lines ()
  379. {
  380. var subView = new View
  381. {
  382. Id = "subView",
  383. X = 1,
  384. Width = 1,
  385. Height = 7,
  386. Text = """
  387. s
  388. u
  389. b
  390. V
  391. i
  392. e
  393. w
  394. """
  395. };
  396. var view = new View
  397. {
  398. Id = "view", Width = 2, Height = 20, Text = """
  399. 0
  400. 1
  401. 2
  402. 3
  403. 4
  404. 5
  405. 6
  406. 7
  407. 8
  408. 9
  409. 0
  410. 1
  411. 2
  412. 3
  413. 4
  414. 5
  415. 6
  416. 7
  417. 8
  418. 9
  419. """
  420. };
  421. view.Add (subView);
  422. var content = new View { Id = "content", Width = 20, Height = 20 };
  423. content.Add (view);
  424. var container = new View
  425. {
  426. Id = "container",
  427. X = 1,
  428. Y = 1,
  429. Width = 5,
  430. Height = 5
  431. };
  432. container.Add (content);
  433. Toplevel top = new ();
  434. top.Add (container);
  435. Application.Driver.Clip = container.Frame;
  436. Application.Begin (top);
  437. TestHelpers.AssertDriverContentsWithFrameAre (
  438. """
  439. 0s
  440. 1u
  441. 2b
  442. 3V
  443. 4i
  444. """,
  445. output
  446. );
  447. content.X = -1;
  448. Application.Refresh ();
  449. TestHelpers.AssertDriverContentsWithFrameAre (
  450. """
  451. s
  452. u
  453. b
  454. V
  455. i
  456. """,
  457. output
  458. );
  459. content.X = -2;
  460. Application.Refresh ();
  461. TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
  462. content.X = 0;
  463. content.Y = -1;
  464. Application.Refresh ();
  465. TestHelpers.AssertDriverContentsWithFrameAre (
  466. """
  467. 1u
  468. 2b
  469. 3V
  470. 4i
  471. 5e
  472. """,
  473. output
  474. );
  475. content.Y = -6;
  476. Application.Refresh ();
  477. TestHelpers.AssertDriverContentsWithFrameAre (
  478. """
  479. 6w
  480. 7
  481. 8
  482. 9
  483. 0
  484. """,
  485. output
  486. );
  487. content.Y = -19;
  488. Application.Refresh ();
  489. TestHelpers.AssertDriverContentsWithFrameAre (
  490. """
  491. 9
  492. """,
  493. output
  494. );
  495. content.Y = -20;
  496. Application.Refresh ();
  497. TestHelpers.AssertDriverContentsWithFrameAre ("", output);
  498. content.X = -2;
  499. content.Y = 0;
  500. Application.Refresh ();
  501. TestHelpers.AssertDriverContentsWithFrameAre ("", output);
  502. }
  503. [Fact]
  504. [AutoInitShutdown]
  505. public void Draw_Negative_Viewport_Horizontal_Without_New_Lines ()
  506. {
  507. // BUGBUG: This previously assumed the default height of a View was 1.
  508. var subView = new View
  509. {
  510. Id = "subView",
  511. Y = 1,
  512. Width = 7,
  513. Height = 1,
  514. Text = "subView"
  515. };
  516. var view = new View { Id = "view", Width = 20, Height = 2, Text = "01234567890123456789" };
  517. view.Add (subView);
  518. var content = new View { Id = "content", Width = 20, Height = 20 };
  519. content.Add (view);
  520. var container = new View
  521. {
  522. Id = "container",
  523. X = 1,
  524. Y = 1,
  525. Width = 5,
  526. Height = 5
  527. };
  528. container.Add (content);
  529. Toplevel top = new ();
  530. top.Add (container);
  531. // BUGBUG: v2 - it's bogus to reference .Frame before BeginInit. And why is the clip being set anyway???
  532. void Top_LayoutComplete (object sender, LayoutEventArgs e) { Application.Driver.Clip = container.Frame; }
  533. top.LayoutComplete += Top_LayoutComplete;
  534. Application.Begin (top);
  535. TestHelpers.AssertDriverContentsWithFrameAre (
  536. """
  537. 01234
  538. subVi
  539. """,
  540. output
  541. );
  542. content.X = -1;
  543. Application.Refresh ();
  544. TestHelpers.AssertDriverContentsWithFrameAre (
  545. """
  546. 12345
  547. ubVie
  548. """,
  549. output
  550. );
  551. content.Y = -1;
  552. Application.Refresh ();
  553. TestHelpers.AssertDriverContentsWithFrameAre (
  554. """
  555. ubVie
  556. """,
  557. output
  558. );
  559. content.Y = -2;
  560. Application.Refresh ();
  561. TestHelpers.AssertDriverContentsWithFrameAre ("", output);
  562. content.X = -20;
  563. content.Y = 0;
  564. Application.Refresh ();
  565. TestHelpers.AssertDriverContentsWithFrameAre ("", output);
  566. }
  567. [Fact]
  568. [AutoInitShutdown]
  569. public void Draw_Negative_Viewport_Vertical ()
  570. {
  571. var subView = new View
  572. {
  573. Id = "subView",
  574. X = 1,
  575. Width = 1,
  576. Height = 7,
  577. Text = "subView",
  578. TextDirection = TextDirection.TopBottom_LeftRight
  579. };
  580. var view = new View
  581. {
  582. Id = "view",
  583. Width = 2,
  584. Height = 20,
  585. Text = "01234567890123456789",
  586. TextDirection = TextDirection.TopBottom_LeftRight
  587. };
  588. view.Add (subView);
  589. var content = new View { Id = "content", Width = 20, Height = 20 };
  590. content.Add (view);
  591. var container = new View
  592. {
  593. Id = "container",
  594. X = 1,
  595. Y = 1,
  596. Width = 5,
  597. Height = 5
  598. };
  599. container.Add (content);
  600. Toplevel top = new ();
  601. top.Add (container);
  602. Application.Driver.Clip = container.Frame;
  603. Application.Begin (top);
  604. TestHelpers.AssertDriverContentsWithFrameAre (
  605. """
  606. 0s
  607. 1u
  608. 2b
  609. 3V
  610. 4i
  611. """,
  612. output
  613. );
  614. content.X = -1;
  615. Application.Refresh ();
  616. TestHelpers.AssertDriverContentsWithFrameAre (
  617. """
  618. s
  619. u
  620. b
  621. V
  622. i
  623. """,
  624. output
  625. );
  626. content.X = -2;
  627. Application.Refresh ();
  628. TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
  629. content.X = 0;
  630. content.Y = -1;
  631. Application.Refresh ();
  632. TestHelpers.AssertDriverContentsWithFrameAre (
  633. """
  634. 1u
  635. 2b
  636. 3V
  637. 4i
  638. 5e
  639. """,
  640. output
  641. );
  642. content.Y = -6;
  643. Application.Refresh ();
  644. TestHelpers.AssertDriverContentsWithFrameAre (
  645. """
  646. 6w
  647. 7
  648. 8
  649. 9
  650. 0
  651. """,
  652. output
  653. );
  654. content.Y = -19;
  655. Application.Refresh ();
  656. TestHelpers.AssertDriverContentsWithFrameAre (
  657. """
  658. 9
  659. """,
  660. output
  661. );
  662. content.Y = -20;
  663. Application.Refresh ();
  664. TestHelpers.AssertDriverContentsWithFrameAre ("", output);
  665. content.X = -2;
  666. content.Y = 0;
  667. Application.Refresh ();
  668. TestHelpers.AssertDriverContentsWithFrameAre ("", output);
  669. }
  670. [Theory]
  671. [SetupFakeDriver]
  672. [InlineData ("𝔽𝕆𝕆𝔹𝔸R")]
  673. [InlineData ("a𐐀b")]
  674. public void DrawHotString_NonBmp (string expected)
  675. {
  676. var view = new View { Width = 10, Height = 1 };
  677. view.DrawHotString (expected, Attribute.Default, Attribute.Default);
  678. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  679. }
  680. // TODO: The tests below that use Label should use View instead.
  681. [Fact]
  682. [AutoInitShutdown]
  683. public void Non_Bmp_ConsoleWidth_ColumnWidth_Equal_Two ()
  684. {
  685. var us = "\U0001d539";
  686. var r = (Rune)0x1d539;
  687. Assert.Equal ("𝔹", us);
  688. Assert.Equal ("𝔹", r.ToString ());
  689. Assert.Equal (us, r.ToString ());
  690. Assert.Equal (1, us.GetColumns ());
  691. Assert.Equal (1, r.GetColumns ());
  692. var win = new Window { Title = us };
  693. var view = new Label { Text = r.ToString () };
  694. var tf = new TextField { Text = us, Y = 1, Width = 3 };
  695. win.Add (view, tf);
  696. Toplevel top = new ();
  697. top.Add (win);
  698. Application.Begin (top);
  699. ((FakeDriver)Application.Driver).SetBufferSize (10, 4);
  700. var expected = """
  701. ┌┤𝔹├─────┐
  702. │𝔹 │
  703. │𝔹 │
  704. └────────┘
  705. """;
  706. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  707. TestHelpers.AssertDriverContentsAre (expected, output);
  708. Attribute [] expectedColors =
  709. {
  710. // 0
  711. Colors.ColorSchemes ["Base"].Normal,
  712. // 1
  713. Colors.ColorSchemes ["Base"].Focus,
  714. // 2
  715. Colors.ColorSchemes ["Base"].HotNormal
  716. };
  717. TestHelpers.AssertDriverAttributesAre (
  718. """
  719. 0010000000
  720. 0000000000
  721. 0111000000
  722. 0000000000
  723. """,
  724. Application.Driver,
  725. expectedColors
  726. );
  727. }
  728. }