RulerTests.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.DrawingTests;
  4. public class RulerTests
  5. {
  6. private readonly ITestOutputHelper _output;
  7. public RulerTests (ITestOutputHelper output) { _output = output; }
  8. [Fact]
  9. [AutoInitShutdown]
  10. public void Draw_Default ()
  11. {
  12. AutoInitShutdownAttribute.FakeResize(new Size(25, 25));
  13. var r = new Ruler ();
  14. r.Draw (Point.Empty);
  15. DriverAssert.AssertDriverContentsWithFrameAre (@"", _output);
  16. }
  17. [Fact]
  18. [SetupFakeDriver]
  19. public void Draw_Horizontal ()
  20. {
  21. var len = 15;
  22. var r = new Ruler ();
  23. Assert.Equal (Orientation.Horizontal, r.Orientation);
  24. r.Length = len;
  25. r.Draw (Point.Empty);
  26. DriverAssert.AssertDriverContentsWithFrameAre (
  27. @"
  28. |123456789|1234",
  29. _output
  30. );
  31. // Postive offset
  32. r.Draw (new (1, 1));
  33. DriverAssert.AssertDriverContentsAre (
  34. @"
  35. |123456789|1234
  36. |123456789|1234
  37. ",
  38. _output
  39. );
  40. // Negative offset
  41. r.Draw (new (-1, 3));
  42. DriverAssert.AssertDriverContentsAre (
  43. @"
  44. |123456789|1234
  45. |123456789|1234
  46. 123456789|1234
  47. ",
  48. _output
  49. );
  50. }
  51. [Fact]
  52. [SetupFakeDriver]
  53. public void Draw_Vertical ()
  54. {
  55. var len = 15;
  56. var r = new Ruler ();
  57. r.Orientation = Orientation.Vertical;
  58. r.Length = len;
  59. r.Draw (Point.Empty);
  60. DriverAssert.AssertDriverContentsWithFrameAre (
  61. @"
  62. -
  63. 1
  64. 2
  65. 3
  66. 4
  67. 5
  68. 6
  69. 7
  70. 8
  71. 9
  72. -
  73. 1
  74. 2
  75. 3
  76. 4",
  77. _output
  78. );
  79. r.Draw (new (1, 1));
  80. DriverAssert.AssertDriverContentsWithFrameAre (
  81. @"
  82. -
  83. 1-
  84. 21
  85. 32
  86. 43
  87. 54
  88. 65
  89. 76
  90. 87
  91. 98
  92. -9
  93. 1-
  94. 21
  95. 32
  96. 43
  97. 4",
  98. _output
  99. );
  100. // Negative offset
  101. r.Draw (new (2, -1));
  102. DriverAssert.AssertDriverContentsWithFrameAre (
  103. @"
  104. - 1
  105. 1-2
  106. 213
  107. 324
  108. 435
  109. 546
  110. 657
  111. 768
  112. 879
  113. 98-
  114. -91
  115. 1-2
  116. 213
  117. 324
  118. 43
  119. 4 ",
  120. _output
  121. );
  122. }
  123. }