RulerTests.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. public void Attribute_set ()
  10. {
  11. var newAttribute = new Attribute (Color.Red, Color.Green);
  12. var r = new Ruler ();
  13. r.Attribute = newAttribute;
  14. Assert.Equal (newAttribute, r.Attribute);
  15. }
  16. [Fact]
  17. public void Constructor_Defaults ()
  18. {
  19. var r = new Ruler ();
  20. Assert.Equal (0, r.Length);
  21. Assert.Equal (Orientation.Horizontal, r.Orientation);
  22. }
  23. [Fact]
  24. [AutoInitShutdown]
  25. public void Draw_Default ()
  26. {
  27. ((FakeDriver)Application.Driver!).SetBufferSize (25, 25);
  28. var r = new Ruler ();
  29. r.Draw (Point.Empty);
  30. DriverAssert.AssertDriverContentsWithFrameAre (@"", _output);
  31. }
  32. [Fact]
  33. [SetupFakeDriver]
  34. public void Draw_Horizontal ()
  35. {
  36. var len = 15;
  37. var r = new Ruler ();
  38. Assert.Equal (Orientation.Horizontal, r.Orientation);
  39. r.Length = len;
  40. r.Draw (Point.Empty);
  41. DriverAssert.AssertDriverContentsWithFrameAre (
  42. @"
  43. |123456789|1234",
  44. _output
  45. );
  46. // Postive offset
  47. r.Draw (new (1, 1));
  48. DriverAssert.AssertDriverContentsAre (
  49. @"
  50. |123456789|1234
  51. |123456789|1234
  52. ",
  53. _output
  54. );
  55. // Negative offset
  56. r.Draw (new (-1, 3));
  57. DriverAssert.AssertDriverContentsAre (
  58. @"
  59. |123456789|1234
  60. |123456789|1234
  61. 123456789|1234
  62. ",
  63. _output
  64. );
  65. }
  66. [Fact]
  67. [SetupFakeDriver]
  68. public void Draw_Vertical ()
  69. {
  70. var len = 15;
  71. var r = new Ruler ();
  72. r.Orientation = Orientation.Vertical;
  73. r.Length = len;
  74. r.Draw (Point.Empty);
  75. DriverAssert.AssertDriverContentsWithFrameAre (
  76. @"
  77. -
  78. 1
  79. 2
  80. 3
  81. 4
  82. 5
  83. 6
  84. 7
  85. 8
  86. 9
  87. -
  88. 1
  89. 2
  90. 3
  91. 4",
  92. _output
  93. );
  94. r.Draw (new (1, 1));
  95. DriverAssert.AssertDriverContentsWithFrameAre (
  96. @"
  97. -
  98. 1-
  99. 21
  100. 32
  101. 43
  102. 54
  103. 65
  104. 76
  105. 87
  106. 98
  107. -9
  108. 1-
  109. 21
  110. 32
  111. 43
  112. 4",
  113. _output
  114. );
  115. // Negative offset
  116. r.Draw (new (2, -1));
  117. DriverAssert.AssertDriverContentsWithFrameAre (
  118. @"
  119. - 1
  120. 1-2
  121. 213
  122. 324
  123. 435
  124. 546
  125. 657
  126. 768
  127. 879
  128. 98-
  129. -91
  130. 1-2
  131. 213
  132. 324
  133. 43
  134. 4 ",
  135. _output
  136. );
  137. }
  138. [Fact]
  139. public void Length_set ()
  140. {
  141. var r = new Ruler ();
  142. Assert.Equal (0, r.Length);
  143. r.Length = 42;
  144. Assert.Equal (42, r.Length);
  145. }
  146. [Fact]
  147. public void Orientation_set ()
  148. {
  149. var r = new Ruler ();
  150. Assert.Equal (Orientation.Horizontal, r.Orientation);
  151. r.Orientation = Orientation.Vertical;
  152. Assert.Equal (Orientation.Vertical, r.Orientation);
  153. }
  154. }