RulerTests.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using Terminal.Gui;
  2. using NStack;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Xml.Linq;
  6. using Terminal.Gui.Graphs;
  7. using Xunit;
  8. using Xunit.Abstractions;
  9. //using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
  10. // Alias Console to MockConsole so we don't accidentally use Console
  11. using Console = Terminal.Gui.FakeConsole;
  12. namespace Terminal.Gui.DrawingTests {
  13. public class RulerTests {
  14. readonly ITestOutputHelper output;
  15. public RulerTests (ITestOutputHelper output)
  16. {
  17. this.output = output;
  18. }
  19. [Fact ()]
  20. public void Constructor_Defaults ()
  21. {
  22. var r = new Ruler ();
  23. Assert.Equal (0, r.Length);
  24. Assert.Equal ("0123456789", r.Template);
  25. Assert.Equal (Orientation.Horizontal, r.Orientation);
  26. Assert.Equal (default, r.Attribute);
  27. }
  28. [Fact ()]
  29. public void Orientation_set ()
  30. {
  31. var r = new Ruler ();
  32. Assert.Equal (Orientation.Horizontal, r.Orientation);
  33. r.Orientation = Orientation.Vertical;
  34. Assert.Equal (Orientation.Vertical, r.Orientation);
  35. }
  36. [Fact ()]
  37. public void Length_set ()
  38. {
  39. var r = new Ruler ();
  40. Assert.Equal (0, r.Length);
  41. r.Length = 42;
  42. Assert.Equal (42, r.Length);
  43. }
  44. [Fact ()]
  45. public void Template_set ()
  46. {
  47. var newTemplate = ")!@#$$%^&*(";
  48. var r = new Ruler ();
  49. Assert.Equal ("0123456789", r.Template);
  50. r.Template = newTemplate;
  51. Assert.Equal (newTemplate, r.Template);
  52. }
  53. [Fact ()]
  54. public void Attribute_set ()
  55. {
  56. var newAttribute = new Attribute (Color.Red, Color.Green);
  57. var r = new Ruler ();
  58. Assert.Equal (default, r.Attribute);
  59. r.Attribute = newAttribute;
  60. Assert.Equal (newAttribute, r.Attribute);
  61. }
  62. [Fact (), AutoInitShutdown]
  63. public void Draw_Default ()
  64. {
  65. ((FakeDriver)Application.Driver).SetBufferSize (25, 25);
  66. var r = new Ruler ();
  67. r.Draw (new Point (0, 0));
  68. TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
  69. }
  70. [Fact (), AutoInitShutdown]
  71. public void Draw_Horizontal ()
  72. {
  73. var len = 15;
  74. ((FakeDriver)Application.Driver).SetBufferSize (len + 5, 5);
  75. // Add a frame so we can see the ruler
  76. var f = new FrameView () {
  77. X = 0,
  78. Y = 0,
  79. Width = Dim.Fill (),
  80. Height = Dim.Fill (),
  81. };
  82. Application.Top.Add (f);
  83. Application.Begin (Application.Top);
  84. Assert.Equal (new Rect (0, 0, len + 5, 5), f.Frame);
  85. var r = new Ruler ();
  86. Assert.Equal (Orientation.Horizontal, r.Orientation);
  87. r.Length = len;
  88. r.Draw (new Point(0,0));
  89. TestHelpers.AssertDriverContentsWithFrameAre (@"012345678901234", output);
  90. // Postive offset
  91. ((FakeDriver)Application.Driver).FillRect (new Rect (0, 0, len * 2, len * 2), ' ');
  92. r.Draw (new Point (1, 1));
  93. TestHelpers.AssertDriverContentsWithFrameAre (@"
  94. 012345678901234", output);
  95. }
  96. [Fact (), AutoInitShutdown]
  97. public void Draw_Vertical ()
  98. {
  99. var len = 25;
  100. ((FakeDriver)Application.Driver).SetBufferSize (len * 2, len * 2);
  101. var r = new Ruler ();
  102. r.Orientation = Orientation.Vertical;
  103. Assert.Equal (Orientation.Vertical, r.Orientation);
  104. r.Length = len;
  105. r.Draw (new Point (0, 0));
  106. TestHelpers.AssertDriverContentsWithFrameAre (@"
  107. 0
  108. 1
  109. 2
  110. 3
  111. 4
  112. 5
  113. 6
  114. 7
  115. 8
  116. 9
  117. 0
  118. 1
  119. 2
  120. 3
  121. 4
  122. 5
  123. 6
  124. 7
  125. 8
  126. 9
  127. 0
  128. 1
  129. 2
  130. 3
  131. 4", output);
  132. }
  133. }
  134. }