Pos.PercentTests.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Xunit.Abstractions;
  2. using static Terminal.Gui.Pos;
  3. namespace Terminal.Gui.LayoutTests;
  4. public class PosPercentTests (ITestOutputHelper output)
  5. {
  6. private readonly ITestOutputHelper _output = output;
  7. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  8. // TODO: A new test that calls SetRelativeLayout directly is needed.
  9. [Theory]
  10. [InlineData (true)]
  11. [InlineData (false)]
  12. public void PosPercent_PlusOne (bool testHorizontal)
  13. {
  14. var container = new View { Width = 100, Height = 100 };
  15. var view = new View
  16. {
  17. X = testHorizontal ? Percent (50) + Percent (10) + 1 : 1,
  18. Y = testHorizontal ? 1 : Percent (50) + Percent (10) + 1,
  19. Width = 10,
  20. Height = 10
  21. };
  22. container.Add (view);
  23. var top = new Toplevel ();
  24. top.Add (container);
  25. top.LayoutSubviews ();
  26. Assert.Equal (100, container.Frame.Width);
  27. Assert.Equal (100, container.Frame.Height);
  28. if (testHorizontal)
  29. {
  30. Assert.Equal (61, view.Frame.X);
  31. Assert.Equal (1, view.Frame.Y);
  32. }
  33. else
  34. {
  35. Assert.Equal (1, view.Frame.X);
  36. Assert.Equal (61, view.Frame.Y);
  37. }
  38. top.Dispose ();
  39. }
  40. [Fact]
  41. public void PosPercent_SetsValue ()
  42. {
  43. var f = 0;
  44. Pos pos = Percent (f);
  45. Assert.Equal ($"Percent({f})", pos.ToString ());
  46. f = 50;
  47. pos = Percent (f);
  48. Assert.Equal ($"Percent({f})", pos.ToString ());
  49. f = 100;
  50. pos = Percent (f);
  51. Assert.Equal ($"Percent({f})", pos.ToString ());
  52. }
  53. [Fact]
  54. public void PosPercent_ThrowsOnIvalid ()
  55. {
  56. Pos pos = Percent (0);
  57. Assert.Throws<ArgumentException> (() => pos = Percent (-1));
  58. //Assert.Throws<ArgumentException> (() => pos = Pos.Percent (101));
  59. //Assert.Throws<ArgumentException> (() => pos = Pos.Percent (1000001));
  60. }
  61. }