| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- ๏ปฟ#nullable enable
- using System.Text;
- using UnitTests;
- using Xunit.Abstractions;
- namespace ViewBaseTests.Adornments;
- [Collection ("Global Test Setup")]
- public class BorderArrangementTests (ITestOutputHelper output)
- {
- [Fact]
- public void Arrangement_Handles_Wide_Glyphs_Correctly ()
- {
- IApplication app = Application.Create ();
- app.Init ("fake");
- app.Driver?.SetScreenSize (6, 5);
- // Using a replacement char to make sure wide glyphs are handled correctly
- // in the shadow area, to not confusing with a space char.
- app.Driver?.GetOutputBuffer ().SetWideGlyphReplacement (Rune.ReplacementChar);
- Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
- superview.Text = """
- ๐๐๐
- ๐๐๐
- ๐๐๐
- ๐๐๐
- ๐๐๐
- """;
- View view = new ()
- {
- X = 2, Width = 4, Height = 4, BorderStyle = LineStyle.Single,
- Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, CanFocus = true
- };
- superview.Add (view);
- app.Begin (superview);
- Assert.Equal ("Absolute(2)", view.X.ToString ());
- DriverAssert.AssertDriverContentsAre (
- """
- ๐โโโโ
- ๐โ โ
- ๐โ โ
- ๐โโโโ
- ๐๐๐
- """,
- output,
- app.Driver);
- Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.F5.WithCtrl));
- app.LayoutAndDraw ();
- DriverAssert.AssertDriverContentsAre (
- """
- ๐โโโโ
- ๐โ โ
- ๐โ โ
- ๐โโโโ
- ๐๐๐
- """,
- output,
- app.Driver);
- Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
- Assert.Equal ("Absolute(1)", view.X.ToString ());
- app.LayoutAndDraw ();
- DriverAssert.AssertDriverContentsAre (
- """
- ๏ฟฝโโโโ
- ๏ฟฝโ โ
- ๏ฟฝโ โ
- ๏ฟฝโโโโ
- ๐๐๐
- """,
- output,
- app.Driver);
- Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
- Assert.Equal ("Absolute(0)", view.X.ToString ());
- app.LayoutAndDraw ();
- DriverAssert.AssertDriverContentsAre (
- """
- โโโโ๐
- โ โ๐
- โ โ๐
- โโโโ๐
- ๐๐๐
- """,
- output,
- app.Driver);
- }
- [Fact]
- public void Arrangement_With_SubView_In_Border_Handles_Wide_Glyphs_Correctly ()
- {
- IApplication app = Application.Create ();
- app.Init ("fake");
- app.Driver?.SetScreenSize (8, 7);
- // Using a replacement char to make sure wide glyphs are handled correctly
- // in the shadow area, to not confusing with a space char.
- app.Driver?.GetOutputBuffer ().SetWideGlyphReplacement (Rune.ReplacementChar);
- // Don't remove this array even if it seems unused, it is used to map the attributes indexes in the DriverAssert
- // Otherwise the test won't detect issues with attributes not visibly by the naked eye
- Attribute [] attributes =
- [
- new (ColorName16.Blue, ColorName16.BrightBlue, TextStyle.None),
- new (ColorName16.BrightBlue, ColorName16.Blue, TextStyle.None),
- new (ColorName16.Green, ColorName16.BrightGreen, TextStyle.None),
- new (ColorName16.Magenta, ColorName16.BrightMagenta, TextStyle.None),
- new (ColorName16.BrightMagenta, ColorName16.Magenta, TextStyle.None)
- ];
- Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
- superview.SetScheme (new () { Normal = attributes [0], Focus = attributes [1] });
- superview.Text = """
- ๐๐๐๐
- ๐๐๐๐
- ๐๐๐๐
- ๐๐๐๐
- ๐๐๐๐
- ๐๐๐๐
- ๐๐๐๐
- """;
- View view = new () { X = 6, Width = 2, Height = 1, Text = "๐ฆฎ" };
- view.SetScheme (new () { Normal = attributes [2] });
- View view2 = new ()
- {
- X = 2, Width = 6, Height = 6, Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, CanFocus = true
- };
- view2.Border!.Thickness = new (1);
- view2.Border.Add (new View { Height = Dim.Auto (), Width = Dim.Auto (), Text = "Hi" });
- view2.SetScheme (new () { Normal = attributes [3], HotNormal = attributes [4] });
- superview.Add (view, view2);
- app.Begin (superview);
- Assert.Equal ("Absolute(2)", view2.X.ToString ());
- DriverAssert.AssertDriverContentsAre (
- """
- ๐Hi
- ๐
- ๐
- ๐
- ๐
- ๐
- ๐๐๐๐
- """,
- output,
- app.Driver);
- DriverAssert.AssertDriverAttributesAre (
- """
- 11333333
- 11333333
- 11333333
- 11333333
- 11333333
- 11333333
- 11111111
- """,
- output,
- app.Driver,
- attributes);
- Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.F5.WithCtrl));
- app.LayoutAndDraw ();
- DriverAssert.AssertDriverContentsAre (
- """
- ๐โi
- ๐
- ๐
- ๐
- ๐
- ๐ โ
- ๐๐๐๐
- """,
- output,
- app.Driver);
- DriverAssert.AssertDriverAttributesAre (
- """
- 11433333
- 11333333
- 11333333
- 11333333
- 11333333
- 11333333
- 11111111
- """,
- output,
- app.Driver,
- attributes);
- Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
- Assert.Equal ("Absolute(1)", view2.X.ToString ());
- app.LayoutAndDraw ();
- DriverAssert.AssertDriverContentsAre (
- """
- ๏ฟฝโi
- ๏ฟฝ
- ๏ฟฝ
- ๏ฟฝ
- ๏ฟฝ
- ๏ฟฝ โ
- ๐๐๐๐
- """,
- output,
- app.Driver);
- DriverAssert.AssertDriverAttributesAre (
- """
- 14333332
- 13333330
- 13333330
- 13333330
- 13333330
- 13333330
- 11111111
- """,
- output,
- app.Driver,
- attributes);
- Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
- Assert.Equal ("Absolute(0)", view2.X.ToString ());
- app.LayoutAndDraw ();
- DriverAssert.AssertDriverContentsAre (
- """
- โi ๐ฆฎ
- ๐
- ๐
- ๐
- ๐
- โ๐
- ๐๐๐๐
- """,
- output,
- app.Driver);
- DriverAssert.AssertDriverAttributesAre (
- """
- 43333322
- 33333311
- 33333311
- 33333311
- 33333311
- 33333311
- 11111111
- """,
- output,
- app.Driver,
- attributes);
- }
- }
|