LineTests.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. using UnitTests;
  2. namespace UnitTests_Parallelizable.ViewsTests;
  3. public class LineTests : FakeDriverBase
  4. {
  5. [Fact]
  6. public void Line_DefaultConstructor_Horizontal ()
  7. {
  8. var line = new Line ();
  9. Assert.Equal (Orientation.Horizontal, line.Orientation);
  10. Assert.Equal (Dim.Fill (), line.Width);
  11. Assert.Equal (LineStyle.Single, line.Style);
  12. Assert.True (line.SuperViewRendersLineCanvas);
  13. Assert.False (line.CanFocus);
  14. line.Layout ();
  15. Assert.Equal (1, line.Frame.Height);
  16. }
  17. [Fact]
  18. public void Line_Horizontal_FillsWidth ()
  19. {
  20. var line = new Line { Orientation = Orientation.Horizontal };
  21. var container = new View { Width = 50, Height = 10 };
  22. container.Add (line);
  23. container.Layout ();
  24. Assert.Equal (50, line.Frame.Width);
  25. Assert.Equal (1, line.Frame.Height);
  26. }
  27. [Fact]
  28. public void Line_Vertical_FillsHeight ()
  29. {
  30. var line = new Line { Orientation = Orientation.Vertical };
  31. var container = new View { Width = 50, Height = 10 };
  32. container.Add (line);
  33. container.Layout ();
  34. Assert.Equal (1, line.Frame.Width);
  35. Assert.Equal (10, line.Frame.Height);
  36. }
  37. [Fact]
  38. public void Line_ChangeOrientation_UpdatesDimensions ()
  39. {
  40. var line = new Line { Orientation = Orientation.Horizontal };
  41. var container = new View { Width = 50, Height = 20 };
  42. container.Add (line);
  43. container.Layout ();
  44. Assert.Equal (50, line.Frame.Width);
  45. Assert.Equal (1, line.Frame.Height);
  46. // Change to vertical
  47. line.Orientation = Orientation.Vertical;
  48. container.Layout ();
  49. Assert.Equal (1, line.Frame.Width);
  50. Assert.Equal (20, line.Frame.Height);
  51. }
  52. [Fact]
  53. public void Line_Style_CanBeSet ()
  54. {
  55. var line = new Line { Style = LineStyle.Double };
  56. Assert.Equal (LineStyle.Double, line.Style);
  57. }
  58. [Theory]
  59. [InlineData (LineStyle.Single)]
  60. [InlineData (LineStyle.Double)]
  61. [InlineData (LineStyle.Heavy)]
  62. [InlineData (LineStyle.Rounded)]
  63. [InlineData (LineStyle.Dashed)]
  64. [InlineData (LineStyle.Dotted)]
  65. public void Line_SupportsDifferentLineStyles (LineStyle style)
  66. {
  67. var line = new Line { Style = style };
  68. Assert.Equal (style, line.Style);
  69. }
  70. [Fact]
  71. public void Line_DrawsCalled_Successfully ()
  72. {
  73. var app = new Window () { Driver = CreateFakeDriver () };
  74. var line = new Line { Y = 1, Width = 10 };
  75. app.Add (line);
  76. app.BeginInit ();
  77. app.EndInit ();
  78. app.Layout ();
  79. // Just verify the line can be drawn without errors
  80. Exception exception = Record.Exception (() => app.Draw ());
  81. Assert.Null (exception);
  82. }
  83. [Fact]
  84. public void Line_WithBorder_DrawsSuccessfully ()
  85. {
  86. var app = new Window { Driver = CreateFakeDriver (), Width = 20, Height = 10, BorderStyle = LineStyle.Single };
  87. // Add a line that intersects with the window border
  88. var line = new Line { X = 5, Y = 0, Height = Dim.Fill (), Orientation = Orientation.Vertical };
  89. app.Add (line);
  90. app.BeginInit ();
  91. app.EndInit ();
  92. app.Layout ();
  93. // Just verify the line and border can be drawn together without errors
  94. Exception exception = Record.Exception (() => app.Draw ());
  95. Assert.Null (exception);
  96. }
  97. [Fact]
  98. public void Line_MultipleIntersecting_DrawsSuccessfully ()
  99. {
  100. var app = new Window { Driver = CreateFakeDriver (), Width = 30, Height = 15 };
  101. // Create intersecting lines
  102. var hLine = new Line { X = 5, Y = 5, Width = 15, Style = LineStyle.Single };
  103. var vLine = new Line
  104. {
  105. X = 12, Y = 2, Height = 8, Orientation = Orientation.Vertical, Style = LineStyle.Single
  106. };
  107. app.Add (hLine, vLine);
  108. app.BeginInit ();
  109. app.EndInit ();
  110. app.Layout ();
  111. // Just verify multiple intersecting lines can be drawn without errors
  112. Exception exception = Record.Exception (() => app.Draw ());
  113. Assert.Null (exception);
  114. }
  115. [Fact]
  116. public void Line_ExplicitWidthAndHeight_RespectValues ()
  117. {
  118. var line = new Line { Width = 10, Height = 1 };
  119. var container = new View { Width = 50, Height = 20 };
  120. container.Add (line);
  121. container.Layout ();
  122. Assert.Equal (10, line.Frame.Width);
  123. Assert.Equal (1, line.Frame.Height);
  124. }
  125. [Fact]
  126. public void Line_VerticalWithExplicitHeight_RespectValues ()
  127. {
  128. var line = new Line { Orientation = Orientation.Vertical };
  129. // Set height AFTER orientation to avoid it being reset
  130. line.Width = 1;
  131. line.Height = 8;
  132. var container = new View { Width = 50, Height = 20 };
  133. container.Add (line);
  134. container.Layout ();
  135. Assert.Equal (1, line.Frame.Width);
  136. Assert.Equal (8, line.Frame.Height);
  137. }
  138. [Fact]
  139. public void Line_SuperViewRendersLineCanvas_IsTrue ()
  140. {
  141. var line = new Line ();
  142. Assert.True (line.SuperViewRendersLineCanvas);
  143. }
  144. [Fact]
  145. public void Line_CannotFocus ()
  146. {
  147. var line = new Line ();
  148. Assert.False (line.CanFocus);
  149. }
  150. [Fact]
  151. public void Line_ImplementsIOrientation ()
  152. {
  153. var line = new Line ();
  154. Assert.IsAssignableFrom<IOrientation> (line);
  155. }
  156. [Fact]
  157. public void Line_Length_Get_ReturnsCorrectDimension ()
  158. {
  159. var line = new Line { Width = 20, Height = 1 };
  160. // For horizontal, Length should be Width
  161. line.Orientation = Orientation.Horizontal;
  162. Assert.Equal (line.Width, line.Length);
  163. Assert.Equal (1, line.Height.GetAnchor (0));
  164. // For vertical, Length should be Height
  165. line.Orientation = Orientation.Vertical;
  166. Assert.Equal (line.Height, line.Length);
  167. Assert.Equal (1, line.Width.GetAnchor (0));
  168. }
  169. [Fact]
  170. public void Line_OrientationChange_SwapsDimensions ()
  171. {
  172. var line = new Line ();
  173. var container = new View { Width = 50, Height = 20 };
  174. container.Add (line);
  175. // Start horizontal with custom dimensions
  176. line.Orientation = Orientation.Horizontal;
  177. line.Width = 30;
  178. line.Height = 1;
  179. container.Layout ();
  180. Assert.Equal (30, line.Frame.Width);
  181. Assert.Equal (1, line.Frame.Height);
  182. // Change to vertical - dimensions should swap
  183. line.Orientation = Orientation.Vertical;
  184. container.Layout ();
  185. Assert.Equal (1, line.Frame.Width);
  186. Assert.Equal (30, line.Frame.Height); // Width became Height
  187. }
  188. [Fact]
  189. public void Line_Dimensions_WorkSameAsInitializers ()
  190. {
  191. // Object initializers work same as sequential assignment
  192. // Test: new Line { Width = 15, Orientation = Orientation.Horizontal }
  193. // Expected: Width=15, Height=1
  194. Line line = new () { Width = 15, Orientation = Orientation.Horizontal };
  195. Assert.Equal (15, line.Width.GetAnchor (0));
  196. Assert.Equal (1, line.Height.GetAnchor (0));
  197. Assert.Equal (line.Length, line.Width); // Length should be Width for horizontal
  198. line = new ();
  199. line.Width = 15;
  200. line.Orientation = Orientation.Horizontal;
  201. Assert.Equal (15, line.Width.GetAnchor (0));
  202. Assert.Equal (1, line.Height.GetAnchor (0));
  203. Assert.Equal (line.Length, line.Width); // Length should be Width for horizontal
  204. // Test: new Line { Height = 9, Orientation = Orientation.Vertical }
  205. // Expected: Width=1, Height=9
  206. line = new () { Height = 9, Orientation = Orientation.Vertical };
  207. Assert.Equal (1, line.Width.GetAnchor (0));
  208. Assert.Equal (9, line.Height.GetAnchor (0));
  209. Assert.Equal (line.Length, line.Height); // Length should be Height for vertical
  210. line = new ();
  211. line.Height = 9;
  212. line.Orientation = Orientation.Vertical;
  213. Assert.Equal (1, line.Width.GetAnchor (0));
  214. Assert.Equal (9, line.Height.GetAnchor (0));
  215. Assert.Equal (line.Length, line.Height); // Length should be Height for vertical
  216. }
  217. }