BoundsTests.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.ViewTests;
  3. /// <summary>
  4. /// Test the <see cref="View.Bounds"/>.
  5. /// DOES NOT TEST Adornment.Bounds methods. Those are in ./Adornment/BoundsTests.cs
  6. /// </summary>
  7. /// <param name="output"></param>
  8. public class BoundsTests (ITestOutputHelper output)
  9. {
  10. private readonly ITestOutputHelper _output = output;
  11. [Theory]
  12. [InlineData (0, 10)]
  13. [InlineData (1, 10)]
  14. [InlineData (-1, 10)]
  15. [InlineData (11, 10)]
  16. public void Get_Bounds_NoSuperView_WithoutAdornments (int x, int expectedW)
  17. {
  18. // We test with only X because Y is equivalent. Height/Width are irrelevant.
  19. // Arrange
  20. var frame = new Rectangle (x, 0, 10, 10);
  21. var view = new View ();
  22. view.Frame = frame;
  23. view.BeginInit();
  24. view.EndInit();
  25. // Act
  26. var bounds = view.Bounds;
  27. // Assert
  28. Assert.Equal(expectedW, bounds.Width);
  29. }
  30. [Theory]
  31. [InlineData (0, 0, 10)]
  32. [InlineData (1, 0, 9)]
  33. [InlineData (-1, 0, 11)]
  34. [InlineData (10, 0, 0)]
  35. [InlineData (11, 0, 0)]
  36. [InlineData (0, 1, 6)]
  37. [InlineData (1, 1, 5)]
  38. [InlineData (-1, 1, 7)]
  39. [InlineData (10, 1, 0)]
  40. [InlineData (11, 1, 0)]
  41. public void Get_Bounds_NestedSuperView_WithAdornments (int frameX, int borderThickness, int expectedW)
  42. {
  43. // We test with only X because Y is equivalent. Height/Width are irrelevant.
  44. // Arrange
  45. var superSuperView = new View ()
  46. {
  47. X = 0,
  48. Y = 0,
  49. Height = 10,
  50. Width = 10,
  51. };
  52. superSuperView.Border.Thickness = new Thickness (borderThickness);
  53. var superView = new View ()
  54. {
  55. X = 0,
  56. Y = 0,
  57. Height = Dim.Fill (),
  58. Width = Dim.Fill ()
  59. };
  60. superView.Border.Thickness = new Thickness (borderThickness);
  61. superSuperView.Add (superView);
  62. var view = new View ()
  63. {
  64. X = frameX,
  65. Y = 0,
  66. Height = Dim.Fill (),
  67. Width = Dim.Fill ()
  68. };
  69. superView.Add (view);
  70. superSuperView.BeginInit ();
  71. superSuperView.EndInit ();
  72. superSuperView.LayoutSubviews ();
  73. // Act
  74. var bounds = view.Bounds;
  75. // Assert
  76. Assert.Equal (expectedW, bounds.Width);
  77. }
  78. [Theory]
  79. [InlineData (0, 0, 10)]
  80. [InlineData (1, 0, 9)]
  81. [InlineData (-1, 0, 11)]
  82. [InlineData (10, 0, 0)]
  83. [InlineData (11, 0, 0)]
  84. [InlineData (0, 1, 4)]
  85. [InlineData (1, 1, 3)]
  86. [InlineData (-1, 1, 5)]
  87. [InlineData (10, 1, 0)]
  88. [InlineData (11, 1, 0)]
  89. public void Get_Bounds_NestedSuperView_WithAdornments_WithBorder (int frameX, int borderThickness, int expectedW)
  90. {
  91. // We test with only X because Y is equivalent. Height/Width are irrelevant.
  92. // Arrange
  93. var superSuperView = new View ()
  94. {
  95. X = 0,
  96. Y = 0,
  97. Height = 10,
  98. Width = 10,
  99. };
  100. superSuperView.Border.Thickness = new Thickness (borderThickness);
  101. var superView = new View ()
  102. {
  103. X = 0,
  104. Y = 0,
  105. Height = Dim.Fill (),
  106. Width = Dim.Fill ()
  107. };
  108. superView.Border.Thickness = new Thickness (borderThickness);
  109. superSuperView.Add (superView);
  110. var view = new View ()
  111. {
  112. X = frameX,
  113. Y = 0,
  114. Height = Dim.Fill (),
  115. Width = Dim.Fill ()
  116. };
  117. view.Border.Thickness = new Thickness (borderThickness);
  118. superView.Add (view);
  119. superSuperView.BeginInit ();
  120. superSuperView.EndInit ();
  121. superSuperView.LayoutSubviews ();
  122. // Act
  123. var bounds = view.Bounds;
  124. // Assert
  125. Assert.Equal (expectedW, bounds.Width);
  126. }
  127. }