123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- using Xunit.Abstractions;
- namespace Terminal.Gui.DrawingTests;
- public class RulerTests
- {
- private readonly ITestOutputHelper _output;
- public RulerTests (ITestOutputHelper output) { _output = output; }
- [Fact]
- public void Attribute_set ()
- {
- var newAttribute = new Attribute (Color.Red, Color.Green);
- var r = new Ruler ();
- r.Attribute = newAttribute;
- Assert.Equal (newAttribute, r.Attribute);
- }
- [Fact]
- public void Constructor_Defaults ()
- {
- var r = new Ruler ();
- Assert.Equal (0, r.Length);
- Assert.Equal (Orientation.Horizontal, r.Orientation);
- }
- [Fact]
- [AutoInitShutdown]
- public void Draw_Default ()
- {
- ((FakeDriver)Application.Driver!).SetBufferSize (25, 25);
- var r = new Ruler ();
- r.Draw (Point.Empty);
- TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
- }
- [Fact]
- [AutoInitShutdown]
- public void Draw_Horizontal ()
- {
- var len = 15;
- // Add a frame so we can see the ruler
- var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
- var top = new Toplevel ();
- top.Add (f);
- Application.Begin (top);
- ((FakeDriver)Application.Driver!).SetBufferSize (len + 5, 5);
- Assert.Equal (new (0, 0, len + 5, 5), f.Frame);
- var r = new Ruler ();
- Assert.Equal (Orientation.Horizontal, r.Orientation);
- r.Length = len;
- r.Draw (Point.Empty);
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- |123456789|1234────┐
- │ │
- │ │
- │ │
- └──────────────────┘",
- _output
- );
- // Postive offset
- top.SetNeedsDisplay ();
- Application.Refresh ();
- r.Draw (new (1, 1));
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌──────────────────┐
- │|123456789|1234 │
- │ │
- │ │
- └──────────────────┘",
- _output
- );
- // Negative offset
- top.SetNeedsDisplay ();
- Application.Refresh ();
- r.Draw (new (-1, 1));
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌──────────────────┐
- 123456789|1234 │
- │ │
- │ │
- └──────────────────┘",
- _output
- );
- // Clip
- top.SetNeedsDisplay ();
- Application.Refresh ();
- r.Draw (new (10, 1));
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌──────────────────┐
- │ |123456789
- │ │
- │ │
- └──────────────────┘",
- _output
- );
- top.Dispose ();
- }
- [Fact]
- [AutoInitShutdown]
- public void Draw_Horizontal_Start ()
- {
- var len = 15;
- // Add a frame so we can see the ruler
- var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
- var top = new Toplevel ();
- top.Add (f);
- Application.Begin (top);
- ((FakeDriver)Application.Driver!).SetBufferSize (len + 5, 5);
- Assert.Equal (new (0, 0, len + 5, 5), f.Frame);
- var r = new Ruler ();
- Assert.Equal (Orientation.Horizontal, r.Orientation);
- r.Length = len;
- r.Draw (Point.Empty, 1);
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- 123456789|12345────┐
- │ │
- │ │
- │ │
- └──────────────────┘",
- _output
- );
- Application.Refresh (true);
- r.Length = len;
- r.Draw (new (1, 0), 1);
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌123456789|12345───┐
- │ │
- │ │
- │ │
- └──────────────────┘",
- _output
- );
- top.Dispose ();
- }
- [Fact]
- [AutoInitShutdown]
- public void Draw_Vertical ()
- {
- var len = 15;
- // Add a frame so we can see the ruler
- var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
- var top = new Toplevel ();
- top.Add (f);
- Application.Begin (top);
- ((FakeDriver)Application.Driver!).SetBufferSize (5, len + 5);
- Assert.Equal (new (0, 0, 5, len + 5), f.Frame);
- var r = new Ruler ();
- r.Orientation = Orientation.Vertical;
- r.Length = len;
- r.Draw (Point.Empty);
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- -───┐
- 1 │
- 2 │
- 3 │
- 4 │
- 5 │
- 6 │
- 7 │
- 8 │
- 9 │
- - │
- 1 │
- 2 │
- 3 │
- 4 │
- │ │
- │ │
- │ │
- │ │
- └───┘",
- _output
- );
- // Postive offset
- Application.Refresh (true);
- r.Draw (new (1, 1));
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌───┐
- │- │
- │1 │
- │2 │
- │3 │
- │4 │
- │5 │
- │6 │
- │7 │
- │8 │
- │9 │
- │- │
- │1 │
- │2 │
- │3 │
- │4 │
- │ │
- │ │
- │ │
- └───┘",
- _output
- );
- // Negative offset
- Application.Refresh (true);
- r.Draw (new (1, -1));
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌1──┐
- │2 │
- │3 │
- │4 │
- │5 │
- │6 │
- │7 │
- │8 │
- │9 │
- │- │
- │1 │
- │2 │
- │3 │
- │4 │
- │ │
- │ │
- │ │
- │ │
- │ │
- └───┘",
- _output
- );
- // Clip
- Application.Refresh (true);
- r.Draw (new (1, 10));
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌───┐
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │ │
- │- │
- │1 │
- │2 │
- │3 │
- │4 │
- │5 │
- │6 │
- │7 │
- │8 │
- └9──┘",
- _output
- );
- top.Dispose ();
- }
- [Fact]
- [AutoInitShutdown]
- public void Draw_Vertical_Start ()
- {
- var len = 15;
- // Add a frame so we can see the ruler
- var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
- var top = new Toplevel ();
- top.Add (f);
- Application.Begin (top);
- ((FakeDriver)Application.Driver!).SetBufferSize (5, len + 5);
- Assert.Equal (new (0, 0, 5, len + 5), f.Frame);
- var r = new Ruler ();
- r.Orientation = Orientation.Vertical;
- r.Length = len;
- r.Draw (Point.Empty, 1);
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- 1───┐
- 2 │
- 3 │
- 4 │
- 5 │
- 6 │
- 7 │
- 8 │
- 9 │
- - │
- 1 │
- 2 │
- 3 │
- 4 │
- 5 │
- │ │
- │ │
- │ │
- │ │
- └───┘",
- _output
- );
- Application.Refresh (true);
- r.Length = len;
- r.Draw (new (0, 1), 1);
- TestHelpers.AssertDriverContentsWithFrameAre (
- @"
- ┌───┐
- 1 │
- 2 │
- 3 │
- 4 │
- 5 │
- 6 │
- 7 │
- 8 │
- 9 │
- - │
- 1 │
- 2 │
- 3 │
- 4 │
- 5 │
- │ │
- │ │
- │ │
- └───┘",
- _output
- );
- top.Dispose ();
- }
- [Fact]
- public void Length_set ()
- {
- var r = new Ruler ();
- Assert.Equal (0, r.Length);
- r.Length = 42;
- Assert.Equal (42, r.Length);
- }
- [Fact]
- public void Orientation_set ()
- {
- var r = new Ruler ();
- Assert.Equal (Orientation.Horizontal, r.Orientation);
- r.Orientation = Orientation.Vertical;
- Assert.Equal (Orientation.Vertical, r.Orientation);
- }
- }
|