Dim.ViewTests.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #nullable disable
  2. using static Terminal.Gui.ViewBase.Dim;
  3. namespace ViewBaseTests.Layout;
  4. public class DimViewTests
  5. {
  6. [Fact]
  7. public void DimView_Equal ()
  8. {
  9. var view1 = new View ();
  10. var view2 = new View ();
  11. Dim dim1 = Width (view1);
  12. Dim dim2 = Width (view1);
  13. Assert.Equal (dim1, dim2);
  14. dim2 = Width (view2);
  15. Assert.NotEqual (dim1, dim2);
  16. dim2 = Height (view1);
  17. Assert.NotEqual (dim1, dim2);
  18. }
  19. [Fact]
  20. public void DimView_Calculate_ReturnsCorrectValue ()
  21. {
  22. var view = new View { Width = 10 };
  23. view.Layout ();
  24. var dim = new DimView (view, Dimension.Width);
  25. int 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. public void Dim_Referencing_SuperView_Does_Not_Throw ()
  32. {
  33. var super = new View { Width = 10, Height = 10, Text = "super" };
  34. var view = new View
  35. {
  36. Width = Width (super), // this is allowed
  37. Height = Height (super), // this is allowed
  38. Text = "view"
  39. };
  40. super.Add (view);
  41. super.BeginInit ();
  42. super.EndInit ();
  43. Exception exception = Record.Exception (super.LayoutSubViews);
  44. Assert.Null (exception);
  45. super.Dispose ();
  46. }
  47. }