Pos.CombineTests.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Microsoft.VisualStudio.TestPlatform.Utilities;
  2. using Xunit.Abstractions;
  3. using static Terminal.Gui.Dim;
  4. using static Terminal.Gui.Pos;
  5. namespace Terminal.Gui.PosDimTests;
  6. public class PosCombineTests (ITestOutputHelper output)
  7. {
  8. private readonly ITestOutputHelper _output = output;
  9. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  10. // TODO: A new test that calls SetRelativeLayout directly is needed.
  11. [Fact]
  12. public void PosCombine_Referencing_Same_View ()
  13. {
  14. var super = new View { Width = 10, Height = 10, Text = "super" };
  15. var view1 = new View { Width = 2, Height = 2, Text = "view1" };
  16. var view2 = new View { Width = 2, Height = 2, Text = "view2" };
  17. view2.X = Pos.AnchorEnd (0) - (Pos.Right (view2) - Pos.Left (view2));
  18. super.Add (view1, view2);
  19. super.BeginInit ();
  20. super.EndInit ();
  21. Exception exception = Record.Exception (super.LayoutSubviews);
  22. Assert.Null (exception);
  23. Assert.Equal (new (0, 0, 10, 10), super.Frame);
  24. Assert.Equal (new (0, 0, 2, 2), view1.Frame);
  25. Assert.Equal (new (8, 0, 2, 2), view2.Frame);
  26. super.Dispose ();
  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 PosCombine_Will_Throws ()
  33. {
  34. Application.Init (new FakeDriver ());
  35. Toplevel t = new ();
  36. var w = new Window { X = Pos.Left (t) + 2, Y = Pos.Top (t) + 2 };
  37. var f = new FrameView ();
  38. var v1 = new View { X = Pos.Left (w) + 2, Y = Pos.Top (w) + 2 };
  39. var v2 = new View { X = Pos.Left (v1) + 2, Y = Pos.Top (v1) + 2 };
  40. f.Add (v1); // v2 not added
  41. w.Add (f);
  42. t.Add (w);
  43. f.X = Pos.X (v2) - Pos.X (v1);
  44. f.Y = Pos.Y (v2) - Pos.Y (v1);
  45. Assert.Throws<InvalidOperationException> (() => Application.Run (t));
  46. t.Dispose ();
  47. Application.Shutdown ();
  48. v2.Dispose ();
  49. }
  50. }