Pos.PercentTests.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.LayoutTests;
  6. public class PosPercentTests (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. [Theory]
  12. [AutoInitShutdown]
  13. [InlineData (true)]
  14. [InlineData (false)]
  15. public void PosPercent_PlusOne (bool testHorizontal)
  16. {
  17. var container = new View { Width = 100, Height = 100 };
  18. var view = new View
  19. {
  20. X = testHorizontal ? Pos.Percent (50) + Pos.Percent (10) + 1 : 1,
  21. Y = testHorizontal ? 1 : Pos.Percent (50) + Pos.Percent (10) + 1,
  22. Width = 10,
  23. Height = 10
  24. };
  25. container.Add (view);
  26. var top = new Toplevel ();
  27. top.Add (container);
  28. top.LayoutSubviews ();
  29. Assert.Equal (100, container.Frame.Width);
  30. Assert.Equal (100, container.Frame.Height);
  31. if (testHorizontal)
  32. {
  33. Assert.Equal (61, view.Frame.X);
  34. Assert.Equal (1, view.Frame.Y);
  35. }
  36. else
  37. {
  38. Assert.Equal (1, view.Frame.X);
  39. Assert.Equal (61, view.Frame.Y);
  40. }
  41. }
  42. [Fact]
  43. public void PosPercent_SetsValue ()
  44. {
  45. int f = 0;
  46. Pos pos = Pos.Percent (f);
  47. Assert.Equal ($"Percent({f})", pos.ToString ());
  48. f = 50;
  49. pos = Pos.Percent (f);
  50. Assert.Equal ($"Percent({f})", pos.ToString ());
  51. f = 100;
  52. pos = Pos.Percent (f);
  53. Assert.Equal ($"Percent({f})", pos.ToString ());
  54. }
  55. [Fact]
  56. public void PosPercent_ThrowsOnIvalid ()
  57. {
  58. Pos pos = Pos.Percent (0);
  59. Assert.Throws<ArgumentException> (() => pos = Pos.Percent (-1));
  60. //Assert.Throws<ArgumentException> (() => pos = Pos.Percent (101));
  61. //Assert.Throws<ArgumentException> (() => pos = Pos.Percent (1000001));
  62. }
  63. }