Dim.ViewTests.cs 1.6 KB

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