123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using Xunit.Abstractions;
- namespace Terminal.Gui.ViewTests;
- /// <summary>Tests of the <see cref="View.Text"/> property with AutoSize set to false.</summary>
- public class AutoSizeFalseTests (ITestOutputHelper output)
- {
- [Fact]
- public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
- {
- var super = new View { Frame = new (0, 0, 30, 80) };
- var view = new View { Width = Dim.Fill (), Height = Dim.Fill () };
- super.Add (view);
- view.Text = "New text\nNew line";
- super.LayoutSubviews ();
- Rectangle expectedViewBounds = new (0, 0, 30, 80);
- Assert.Equal (expectedViewBounds, view.Viewport);
- Assert.False (view.IsInitialized);
- super.BeginInit ();
- super.EndInit ();
- Assert.True (view.IsInitialized);
- Assert.Equal (expectedViewBounds, view.Viewport);
- }
-
- [Fact]
- [SetupFakeDriver]
- public void AutoSize_False_Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
- {
- ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
- var top = new View { Width = 32, Height = 32 };
- var text = $"First line{Environment.NewLine}Second line";
- var horizontalView = new View { Width = 20, Height = 1, Text = text };
- // Autosize is off, so we have to explicitly set TextFormatter.Size
- horizontalView.TextFormatter.Size = new (20, 1);
- var verticalView = new View
- {
- Y = 3,
- Height = 20,
- Width = 1,
- Text = text,
- TextDirection = TextDirection.TopBottom_LeftRight
- };
- // Autosize is off, so we have to explicitly set TextFormatter.Size
- verticalView.TextFormatter.Size = new (1, 20);
- var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window" };
- frame.Add (horizontalView, verticalView);
- top.Add (frame);
- top.BeginInit ();
- top.EndInit ();
- Assert.Equal (new (0, 0, 20, 1), horizontalView.Frame);
- Assert.Equal (new (0, 3, 1, 20), verticalView.Frame);
- top.Draw ();
- var expected = @"
- ┌──────────────────────────────┐
- │First line Second li │
- │ │
- │ │
- │F │
- │i │
- │r │
- │s │
- │t │
- │ │
- │l │
- │i │
- │n │
- │e │
- │ │
- │S │
- │e │
- │c │
- │o │
- │n │
- │d │
- │ │
- │l │
- │i │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └──────────────────────────────┘
- ";
- Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
- verticalView.Text = $"最初の行{Environment.NewLine}二行目";
- Assert.True (verticalView.TextFormatter.NeedsFormat);
- // Autosize is off, so we have to explicitly set TextFormatter.Size
- // We know these glpyhs are 2 cols wide, so we need to widen the view
- verticalView.Width = 2;
- verticalView.TextFormatter.Size = new (2, 20);
- Assert.True (verticalView.TextFormatter.NeedsFormat);
- top.Draw ();
- Assert.Equal (new (0, 3, 2, 20), verticalView.Frame);
- expected = @"
- ┌──────────────────────────────┐
- │First line Second li │
- │ │
- │ │
- │最 │
- │初 │
- │の │
- │行 │
- │ │
- │二 │
- │行 │
- │目 │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- └──────────────────────────────┘
- ";
- pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
- }
- }
|