Dim.ViewTests.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using static Terminal.Gui.Dim;
  2. namespace Terminal.Gui.LayoutTests;
  3. public class DimViewTests
  4. {
  5. [Fact]
  6. public void DimView_Equal ()
  7. {
  8. var view1 = new View ();
  9. var view2 = new View ();
  10. Dim dim1 = Width (view1);
  11. Dim dim2 = Width (view1);
  12. Assert.Equal (dim1, dim2);
  13. dim2 = Width (view2);
  14. Assert.NotEqual (dim1, dim2);
  15. dim2 = Height (view1);
  16. Assert.NotEqual (dim1, dim2);
  17. }
  18. [Fact]
  19. public void DimView_Calculate_ReturnsCorrectValue ()
  20. {
  21. var view = new View { Width = 10 };
  22. view.Layout ();
  23. var dim = new DimView (view, Dimension.Width);
  24. int result = dim.Calculate (0, 100, null, Dimension.None);
  25. Assert.Equal (10, result);
  26. }
  27. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  28. // TODO: A new test that calls SetRelativeLayout directly is needed.
  29. [Fact]
  30. public void Dim_Referencing_SuperView_Does_Not_Throw ()
  31. {
  32. var super = new View { Width = 10, Height = 10, Text = "super" };
  33. var view = new View
  34. {
  35. Width = Width (super), // this is allowed
  36. Height = Height (super), // this is allowed
  37. Text = "view"
  38. };
  39. super.Add (view);
  40. super.BeginInit ();
  41. super.EndInit ();
  42. Exception exception = Record.Exception (super.LayoutSubViews);
  43. Assert.Null (exception);
  44. super.Dispose ();
  45. }
  46. }