Dim.CombineTests.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Xunit.Abstractions;
  2. using static Terminal.Gui.Dim;
  3. namespace Terminal.Gui.LayoutTests;
  4. public class DimCombineTests (ITestOutputHelper output)
  5. {
  6. private readonly ITestOutputHelper _output = output;
  7. [Fact]
  8. public void DimCombine_Calculate_ReturnsCorrectValue ()
  9. {
  10. var dim1 = new DimAbsolute (10);
  11. var dim2 = new DimAbsolute (20);
  12. var dim = dim1 + dim2;
  13. var result = dim.Calculate (0, 100, null, Dimension.None);
  14. Assert.Equal (30, result);
  15. }
  16. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  17. // TODO: A new test that calls SetRelativeLayout directly is needed.
  18. [Fact]
  19. [TestRespondersDisposed]
  20. public void DimCombine_View_Not_Added_Throws ()
  21. {
  22. var t = new View { Width = 80, Height = 50 };
  23. var super = new View { Width = Dim.Width (t) - 2, Height = Dim.Height (t) - 2 };
  24. t.Add (super);
  25. var sub = new View ();
  26. super.Add (sub);
  27. var v1 = new View { Width = Dim.Width (super) - 2, Height = Dim.Height (super) - 2 };
  28. var v2 = new View { Width = Dim.Width (v1) - 2, Height = Dim.Height (v1) - 2 };
  29. sub.Add (v1);
  30. // v2 not added to sub; should cause exception on Layout since it's referenced by sub.
  31. sub.Width = Dim.Fill () - Dim.Width (v2);
  32. sub.Height = Dim.Fill () - Dim.Height (v2);
  33. t.BeginInit ();
  34. t.EndInit ();
  35. Assert.Throws<InvalidOperationException> (() => t.LayoutSubviews ());
  36. t.Dispose ();
  37. v2.Dispose ();
  38. }
  39. }