AutoSizeFalseTests.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.ViewTests;
  3. /// <summary>Tests of the <see cref="View.Text"/> property with AutoSize set to false.</summary>
  4. public class AutoSizeFalseTests (ITestOutputHelper output)
  5. {
  6. [Fact]
  7. public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
  8. {
  9. var super = new View { Frame = new (0, 0, 30, 80) };
  10. var view = new View { Width = Dim.Fill (), Height = Dim.Fill () };
  11. super.Add (view);
  12. view.Text = "New text\nNew line";
  13. super.LayoutSubviews ();
  14. Rectangle expectedViewBounds = new (0, 0, 30, 80);
  15. Assert.Equal (expectedViewBounds, view.Viewport);
  16. Assert.False (view.IsInitialized);
  17. super.BeginInit ();
  18. super.EndInit ();
  19. Assert.True (view.IsInitialized);
  20. Assert.Equal (expectedViewBounds, view.Viewport);
  21. }
  22. [Fact]
  23. [SetupFakeDriver]
  24. public void AutoSize_False_Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
  25. {
  26. ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
  27. var top = new View { Width = 32, Height = 32 };
  28. var text = $"First line{Environment.NewLine}Second line";
  29. var horizontalView = new View { Width = 20, Height = 1, Text = text };
  30. // Autosize is off, so we have to explicitly set TextFormatter.Size
  31. horizontalView.TextFormatter.Size = new (20, 1);
  32. var verticalView = new View
  33. {
  34. Y = 3,
  35. Height = 20,
  36. Width = 1,
  37. Text = text,
  38. TextDirection = TextDirection.TopBottom_LeftRight
  39. };
  40. // Autosize is off, so we have to explicitly set TextFormatter.Size
  41. verticalView.TextFormatter.Size = new (1, 20);
  42. var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window" };
  43. frame.Add (horizontalView, verticalView);
  44. top.Add (frame);
  45. top.BeginInit ();
  46. top.EndInit ();
  47. Assert.Equal (new (0, 0, 20, 1), horizontalView.Frame);
  48. Assert.Equal (new (0, 3, 1, 20), verticalView.Frame);
  49. top.Draw ();
  50. var expected = @"
  51. ┌──────────────────────────────┐
  52. │First line Second li │
  53. │ │
  54. │ │
  55. │F │
  56. │i │
  57. │r │
  58. │s │
  59. │t │
  60. │ │
  61. │l │
  62. │i │
  63. │n │
  64. │e │
  65. │ │
  66. │S │
  67. │e │
  68. │c │
  69. │o │
  70. │n │
  71. │d │
  72. │ │
  73. │l │
  74. │i │
  75. │ │
  76. │ │
  77. │ │
  78. │ │
  79. │ │
  80. │ │
  81. │ │
  82. └──────────────────────────────┘
  83. ";
  84. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  85. verticalView.Text = $"最初の行{Environment.NewLine}二行目";
  86. Assert.True (verticalView.TextFormatter.NeedsFormat);
  87. // Autosize is off, so we have to explicitly set TextFormatter.Size
  88. // We know these glpyhs are 2 cols wide, so we need to widen the view
  89. verticalView.Width = 2;
  90. verticalView.TextFormatter.Size = new (2, 20);
  91. Assert.True (verticalView.TextFormatter.NeedsFormat);
  92. top.Draw ();
  93. Assert.Equal (new (0, 3, 2, 20), verticalView.Frame);
  94. expected = @"
  95. ┌──────────────────────────────┐
  96. │First line Second li │
  97. │ │
  98. │ │
  99. │最 │
  100. │初 │
  101. │の │
  102. │行 │
  103. │ │
  104. │二 │
  105. │行 │
  106. │目 │
  107. │ │
  108. │ │
  109. │ │
  110. │ │
  111. │ │
  112. │ │
  113. │ │
  114. │ │
  115. │ │
  116. │ │
  117. │ │
  118. │ │
  119. │ │
  120. │ │
  121. │ │
  122. │ │
  123. │ │
  124. │ │
  125. │ │
  126. └──────────────────────────────┘
  127. ";
  128. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  129. }
  130. }