using System.Globalization; using System.Text; using Xunit.Abstractions; using static Terminal.Gui.Dim; namespace Terminal.Gui.LayoutTests; 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; } [Fact] public void DimAbsolute_Calculate_ReturnsCorrectValue () { var dim = new DimAbsolute (10); int result = dim.Calculate (0, 100, null, Dimension.None); Assert.Equal (10, result); } // 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 = new (); 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.Viewport.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); top.Dispose (); 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] [AutoInitShutdown] public void Dim_Subtract_Operator () { Toplevel top = new (); 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