using System.Globalization; using System.Text; using Xunit.Abstractions; // Alias Console to MockConsole so we don't accidentally use Console using Console = Terminal.Gui.FakeConsole; namespace Terminal.Gui.ViewTests; public class DimTests { private readonly ITestOutputHelper _output; public DimTests (ITestOutputHelper output) { _output = output; Console.OutputEncoding = Encoding.Default; // Change current culture var culture = CultureInfo.CreateSpecificCulture ("en-US"); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved // A new test that does not depend on Application is needed. [Fact] [AutoInitShutdown] public void Dim_Add_Operator () { Toplevel top = Application.Top; var view = new View { X = 0, Y = 0, Width = 20, Height = 0 }; var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 }; var count = 0; field.KeyDown += (s, k) => { if (k.KeyCode == KeyCode.Enter) { field.Text = $"Label {count}"; var label = new Label { X = 0, Y = view.Bounds.Height, /*Width = 20,*/ Text = field.Text }; view.Add (label); Assert.Equal ($"Label {count}", label.Text); Assert.Equal ($"Absolute({count})", label.Y.ToString ()); Assert.Equal ($"Absolute({count})", view.Height.ToString ()); view.Height += 1; count++; Assert.Equal ($"Absolute({count})", view.Height.ToString ()); } }; Application.Iteration += (s, a) => { while (count < 20) { field.NewKeyDownEvent (Key.Enter); } Application.RequestStop (); }; var win = new Window (); win.Add (view); win.Add (field); top.Add (win); Application.Run (top); Assert.Equal (20, count); } // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved // TODO: A new test that calls SetRelativeLayout directly is needed. [Fact] [TestRespondersDisposed] public void Dim_Referencing_SuperView_Does_Not_Throw () { var super = new View { Width = 10, Height = 10, Text = "super" }; var view = new View { Width = Dim.Width (super), // this is allowed Height = Dim.Height (super), // this is allowed Text = "view" }; super.Add (view); super.BeginInit (); super.EndInit (); Exception exception = Record.Exception (super.LayoutSubviews); Assert.Null (exception); super.Dispose (); } // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved // TODO: A new test that calls SetRelativeLayout directly is needed. [Fact] [AutoInitShutdown] public void Dim_Subtract_Operator () { Toplevel top = Application.Top; var view = new View { X = 0, Y = 0, Width = 20, Height = 0 }; var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 }; var count = 20; List