Dim.ViewTests.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Xunit.Abstractions;
  2. using static Terminal.Gui.Dim;
  3. namespace Terminal.Gui.LayoutTests;
  4. public class DimViewTests (ITestOutputHelper output)
  5. {
  6. private readonly ITestOutputHelper _output = output;
  7. [Fact]
  8. public void DimView_Equal ()
  9. {
  10. var view1 = new View ();
  11. var view2 = new View ();
  12. Dim dim1 = Width (view1);
  13. Dim dim2 = Width (view1);
  14. Assert.Equal (dim1, dim2);
  15. dim2 = Width (view2);
  16. Assert.NotEqual (dim1, dim2);
  17. dim2 = Height (view1);
  18. Assert.NotEqual (dim1, dim2);
  19. }
  20. [Fact]
  21. public void DimView_Calculate_ReturnsCorrectValue ()
  22. {
  23. var view = new View { Width = 10 };
  24. var dim = new DimView (view, Dimension.Width);
  25. var result = dim.Calculate (0, 100, null, Dimension.None);
  26. Assert.Equal (10, result);
  27. }
  28. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  29. // TODO: A new test that calls SetRelativeLayout directly is needed.
  30. [Fact]
  31. [TestRespondersDisposed]
  32. public void Dim_Referencing_SuperView_Does_Not_Throw ()
  33. {
  34. var super = new View { Width = 10, Height = 10, Text = "super" };
  35. var view = new View
  36. {
  37. Width = Dim.Width (super), // this is allowed
  38. Height = Dim.Height (super), // this is allowed
  39. Text = "view"
  40. };
  41. super.Add (view);
  42. super.BeginInit ();
  43. super.EndInit ();
  44. Exception exception = Record.Exception (super.LayoutSubviews);
  45. Assert.Null (exception);
  46. super.Dispose ();
  47. }
  48. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  49. // TODO: A new test that calls SetRelativeLayout directly is needed.
  50. [Fact]
  51. [TestRespondersDisposed]
  52. public void Dim_SuperView_Referencing_SubView_Throws ()
  53. {
  54. var super = new View { Width = 10, Height = 10, Text = "super" };
  55. var view2 = new View { Width = 10, Height = 10, Text = "view2" };
  56. var view = new View
  57. {
  58. Width = Dim.Width (view2), // this is not allowed
  59. Height = Dim.Height (view2), // this is not allowed
  60. Text = "view"
  61. };
  62. view.Add (view2);
  63. super.Add (view);
  64. super.BeginInit ();
  65. super.EndInit ();
  66. Assert.Throws<InvalidOperationException> (super.LayoutSubviews);
  67. super.Dispose ();
  68. }
  69. }