RulerTests.cs 3.6 KB

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