Changing from AssertDriverContentsWithPosAre to AssertDriverContentsWithFrameAre to return a Rect.

This commit is contained in:
BDisp
2022-03-11 00:33:22 +00:00
parent 484e98998a
commit d9f52fc2f2
4 changed files with 364 additions and 305 deletions

View File

@@ -269,8 +269,8 @@ namespace Terminal.Gui.Core {
└──────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (72, 21), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (72, 21, 80, 4), pos);
cm.Hide ();
Assert.Equal (new Point (80, 25), cm.Position);
@@ -299,8 +299,8 @@ namespace Terminal.Gui.Core {
└──────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (70, 21), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (70, 21, 78, 4), pos);
cm.Hide ();
Assert.Equal (new Point (70, 25), cm.Position);
@@ -332,8 +332,8 @@ namespace Terminal.Gui.Core {
└──────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (6, 12), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (6, 12, 14, 4), pos);
cm.Hide ();
Assert.Equal (new Point (6, 11), cm.Position);
@@ -363,8 +363,8 @@ namespace Terminal.Gui.Core {
└────
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 1), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 1, 5, 4), pos);
cm.Hide ();
Assert.Equal (new Point (0, 0), cm.Position);
@@ -393,8 +393,8 @@ namespace Terminal.Gui.Core {
│ Two │
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 1), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 1, 8, 3), pos);
cm.Hide ();
Assert.Equal (new Point (0, 0), cm.Position);
@@ -446,8 +446,8 @@ namespace Terminal.Gui.Core {
└──────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 1), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 1, 8, 4), pos);
cm.ForceMinimumPosToZero = false;
cm.Show ();
@@ -460,8 +460,8 @@ namespace Terminal.Gui.Core {
──────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (1, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 0, 7, 3), pos);
}
[Fact, AutoInitShutdown]

View File

@@ -11,40 +11,40 @@ using System.Text.RegularExpressions;
using Xunit.Abstractions;
namespace Terminal.Gui.Views {
#region Helper Classes
class FakeHAxis : HorizontalAxis {
public List<Point> DrawAxisLinePoints = new List<Point> ();
public List<int> LabelPoints = new List<int>();
public List<int> LabelPoints = new List<int> ();
protected override void DrawAxisLine (GraphView graph, int x, int y)
{
base.DrawAxisLine (graph, x, y);
DrawAxisLinePoints.Add (new Point(x, y));
DrawAxisLinePoints.Add (new Point (x, y));
}
public override void DrawAxisLabel (GraphView graph, int screenPosition, string text)
{
base.DrawAxisLabel (graph, screenPosition, text);
LabelPoints.Add(screenPosition);
LabelPoints.Add (screenPosition);
}
}
class FakeVAxis : VerticalAxis {
public List<Point> DrawAxisLinePoints = new List<Point> ();
public List<int> LabelPoints = new List<int>();
public List<int> LabelPoints = new List<int> ();
protected override void DrawAxisLine (GraphView graph, int x, int y)
{
base.DrawAxisLine (graph, x, y);
DrawAxisLinePoints.Add (new Point(x, y));
DrawAxisLinePoints.Add (new Point (x, y));
}
public override void DrawAxisLabel (GraphView graph, int screenPosition, string text)
{
base.DrawAxisLabel (graph, screenPosition, text);
LabelPoints.Add(screenPosition);
LabelPoints.Add (screenPosition);
}
}
#endregion
@@ -96,49 +96,6 @@ namespace Terminal.Gui.Views {
var actualLook = sb.ToString ();
if (!string.Equals (expectedLook, actualLook)) {
// ignore trailing whitespace on each line
var trailingWhitespace = new Regex (@"\s+$",RegexOptions.Multiline);
// get rid of trailing whitespace on each line (and leading/trailing whitespace of start/end of full string)
expectedLook = trailingWhitespace.Replace(expectedLook,"").Trim();
actualLook = trailingWhitespace.Replace (actualLook, "").Trim ();
// standardise line endings for the comparison
expectedLook = expectedLook.Replace ("\r\n", "\n");
actualLook = actualLook.Replace ("\r\n", "\n");
output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);
Assert.Equal (expectedLook, actualLook);
}
}
public static Point AssertDriverContentsWithPosAre (string expectedLook, ITestOutputHelper output)
{
var sb = new StringBuilder ();
var driver = ((FakeDriver)Application.Driver);
var x = -1;
var y = -1;
var contents = driver.Contents;
for (int r = 0; r < driver.Rows; r++) {
for (int c = 0; c < driver.Cols; c++) {
var rune = (char)contents [r, c, 0];
if (x == -1 && rune != ' ') {
x = c;
y = r;
}
sb.Append (rune);
}
sb.AppendLine ();
}
var actualLook = sb.ToString ();
if (!string.Equals (expectedLook, actualLook)) {
// ignore trailing whitespace on each line
@@ -157,7 +114,95 @@ namespace Terminal.Gui.Views {
Assert.Equal (expectedLook, actualLook);
}
return new Point (x, y);
}
public static Rect AssertDriverContentsWithFrameAre (string expectedLook, ITestOutputHelper output)
{
var lines = new List<List<char>> ();
var sb = new StringBuilder ();
var driver = ((FakeDriver)Application.Driver);
var x = -1;
var y = -1;
int w = -1;
int h = -1;
var contents = driver.Contents;
for (int r = 0; r < driver.Rows; r++) {
var runes = new List<char> ();
for (int c = 0; c < driver.Cols; c++) {
var rune = (char)contents [r, c, 0];
if (rune != ' ') {
if (x == -1) {
x = c;
y = r;
for (int i = 0; i < c; i++) {
runes.InsertRange (i, new List<char> () { ' ' });
}
}
if (c > w) {
w = c;
}
h = r - y;
}
if (x > -1) {
runes.Add (rune);
}
}
if (runes.Count > 0) {
lines.Add (runes);
}
}
// Remove unnecessary empty lines
for (int r = lines.Count - 1; r > h; r--) {
lines.RemoveAt (r);
}
// Remove trailing whitespace on each line
for (int r = 0; r < lines.Count; r++) {
List<char> row = lines [r];
for (int c = row.Count - 1; c >= 0; c--) {
if (row [c] != ' ') {
break;
}
row.RemoveAt (c);
}
if (row.Count == 0) {
lines.Remove (row);
}
}
// Convert char list to string
for (int r = 0; r < lines.Count; r++) {
var line = new string (lines [r].ToArray ());
if (r == lines.Count - 1) {
sb.Append (line);
} else {
sb.AppendLine (line);
}
}
var actualLook = sb.ToString ();
if (!string.Equals (expectedLook, actualLook)) {
// Remove the first empty line from the expectedLook
expectedLook = string.Join (Environment.NewLine, expectedLook
.Split (Environment.NewLine.ToCharArray ())
.Skip (1)
.ToArray ()).TrimEnd ();
// standardise line endings for the comparison
expectedLook = expectedLook.Replace ("\r\n", "\n");
actualLook = actualLook.Replace ("\r\n", "\n");
output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);
Assert.Equal (expectedLook, actualLook);
}
return new Rect (x, y, w > -1 ? w + 1 : 0, h > -1 ? h + 1 : 0);
}
#pragma warning disable xUnit1013 // Public method should be marked as test
@@ -168,11 +213,11 @@ namespace Terminal.Gui.Views {
/// </summary>
/// <param name="expectedLook">Numbers between 0 and 9 for each row/col of the console. Must be valid indexes of <paramref name="expectedColors"/></param>
/// <param name="expectedColors"></param>
public static void AssertDriverColorsAre (string expectedLook, Attribute[] expectedColors)
public static void AssertDriverColorsAre (string expectedLook, Attribute [] expectedColors)
{
#pragma warning restore xUnit1013 // Public method should be marked as test
if(expectedColors.Length > 10) {
if (expectedColors.Length > 10) {
throw new ArgumentException ("This method only works for UIs that use at most 10 colors");
}
@@ -182,7 +227,7 @@ namespace Terminal.Gui.Views {
var contents = driver.Contents;
int r = 0;
foreach(var line in expectedLook.Split ('\n').Select(l=>l.Trim())) {
foreach (var line in expectedLook.Split ('\n').Select (l => l.Trim ())) {
for (int c = 0; c < line.Length; c++) {
@@ -195,10 +240,10 @@ namespace Terminal.Gui.Views {
throw new ArgumentException ($"Bad value for expectedColors, {match.Count} Attributes had the same Value");
}
var colorUsed = Array.IndexOf(expectedColors,match[0]).ToString()[0];
var colorUsed = Array.IndexOf (expectedColors, match [0]).ToString () [0];
var userExpected = line [c];
if( colorUsed != userExpected) {
if (colorUsed != userExpected) {
throw new Exception ($"Colors used did not match expected at row {r} and col {c}. Color index used was {colorUsed} but test expected {userExpected} (these are indexes into the expectedColors array)");
}
}
@@ -434,7 +479,7 @@ namespace Terminal.Gui.Views {
/// is mutable a sensible place to check this is in redraw.
/// </summary>
[Fact]
public void CellSizeZero()
public void CellSizeZero ()
{
InitFakeDriver ();
@@ -442,8 +487,8 @@ namespace Terminal.Gui.Views {
gv.ColorScheme = new ColorScheme ();
gv.Bounds = new Rect (0, 0, 50, 30);
gv.Series.Add (new ScatterSeries () { Points = new List<PointF> { new PointF (1, 1) } });
gv.CellSize= new PointF(0,5);
var ex = Assert.Throws<Exception>(()=>gv.Redraw (gv.Bounds));
gv.CellSize = new PointF (0, 5);
var ex = Assert.Throws<Exception> (() => gv.Redraw (gv.Bounds));
Assert.Equal ("CellSize cannot be 0", ex.Message);
@@ -451,7 +496,7 @@ namespace Terminal.Gui.Views {
Application.Shutdown ();
}
/// <summary>
/// Tests that each point in the screen space maps to a rectangle of
@@ -488,7 +533,7 @@ namespace Terminal.Gui.Views {
Assert.Equal (x, p.X);
Assert.Equal (y, p.Y);
p = gv.GraphSpaceToScreen (new PointF (graphSpace.Right - epsilon , graphSpace.Top + epsilon));
p = gv.GraphSpaceToScreen (new PointF (graphSpace.Right - epsilon, graphSpace.Top + epsilon));
Assert.Equal (x, p.X);
Assert.Equal (y, p.Y);
@@ -613,33 +658,35 @@ namespace Terminal.Gui.Views {
}
}
public class MultiBarSeriesTests{
public class MultiBarSeriesTests {
readonly ITestOutputHelper output;
public MultiBarSeriesTests(ITestOutputHelper output)
public MultiBarSeriesTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void MultiBarSeries_BarSpacing(){
public void MultiBarSeries_BarSpacing ()
{
// Creates clusters of 5 adjacent bars with 2 spaces between clusters
var series = new MultiBarSeries(5,7,1);
var series = new MultiBarSeries (5, 7, 1);
Assert.Equal(5,series.SubSeries.Count);
Assert.Equal (5, series.SubSeries.Count);
Assert.Equal(0,series.SubSeries.ElementAt(0).Offset);
Assert.Equal(1,series.SubSeries.ElementAt(1).Offset);
Assert.Equal(2,series.SubSeries.ElementAt(2).Offset);
Assert.Equal(3,series.SubSeries.ElementAt(3).Offset);
Assert.Equal(4,series.SubSeries.ElementAt(4).Offset);
Assert.Equal (0, series.SubSeries.ElementAt (0).Offset);
Assert.Equal (1, series.SubSeries.ElementAt (1).Offset);
Assert.Equal (2, series.SubSeries.ElementAt (2).Offset);
Assert.Equal (3, series.SubSeries.ElementAt (3).Offset);
Assert.Equal (4, series.SubSeries.ElementAt (4).Offset);
}
[Fact]
public void MultiBarSeriesColors_WrongNumber(){
public void MultiBarSeriesColors_WrongNumber ()
{
var fake = new FakeDriver ();
@@ -648,8 +695,8 @@ namespace Terminal.Gui.Views {
};
// user passes 1 color only but asks for 5 bars
var ex = Assert.Throws<ArgumentException>(()=>new MultiBarSeries(5,7,1,colors));
Assert.Equal("Number of colors must match the number of bars (Parameter 'numberOfBarsPerCategory')",ex.Message);
var ex = Assert.Throws<ArgumentException> (() => new MultiBarSeries (5, 7, 1, colors));
Assert.Equal ("Number of colors must match the number of bars (Parameter 'numberOfBarsPerCategory')", ex.Message);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -657,7 +704,8 @@ namespace Terminal.Gui.Views {
[Fact]
public void MultiBarSeriesColors_RightNumber(){
public void MultiBarSeriesColors_RightNumber ()
{
var fake = new FakeDriver ();
@@ -668,11 +716,11 @@ namespace Terminal.Gui.Views {
};
// user passes 3 colors and asks for 3 bars
var series = new MultiBarSeries(3,7,1,colors);
var series = new MultiBarSeries (3, 7, 1, colors);
Assert.Equal(series.SubSeries.ElementAt(0).OverrideBarColor,colors[0]);
Assert.Equal(series.SubSeries.ElementAt(1).OverrideBarColor,colors[1]);
Assert.Equal(series.SubSeries.ElementAt(2).OverrideBarColor,colors[2]);
Assert.Equal (series.SubSeries.ElementAt (0).OverrideBarColor, colors [0]);
Assert.Equal (series.SubSeries.ElementAt (1).OverrideBarColor, colors [1]);
Assert.Equal (series.SubSeries.ElementAt (2).OverrideBarColor, colors [2]);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -680,20 +728,22 @@ namespace Terminal.Gui.Views {
[Fact]
public void MultiBarSeriesAddValues_WrongNumber(){
public void MultiBarSeriesAddValues_WrongNumber ()
{
// user asks for 3 bars per category
var series = new MultiBarSeries(3,7,1);
var series = new MultiBarSeries (3, 7, 1);
var ex = Assert.Throws<ArgumentException>(()=>series.AddBars("Cars",'#',1));
var ex = Assert.Throws<ArgumentException> (() => series.AddBars ("Cars", '#', 1));
Assert.Equal("Number of values must match the number of bars per category (Parameter 'values')",ex.Message);
Assert.Equal ("Number of values must match the number of bars per category (Parameter 'values')", ex.Message);
}
[Fact]
public void TestRendering_MultibarSeries(){
public void TestRendering_MultibarSeries ()
{
GraphViewTests.InitFakeDriver ();
@@ -703,14 +753,14 @@ namespace Terminal.Gui.Views {
// y axis goes from 0.1 to 1 across 10 console rows
// x axis goes from 0 to 20 across 20 console columns
gv.Bounds = new Rect (0, 0, 20, 10);
gv.CellSize = new PointF(1f,0.1f);
gv.CellSize = new PointF (1f, 0.1f);
gv.MarginBottom = 1;
gv.MarginLeft = 1;
var multibarSeries = new MultiBarSeries (2,4,1);
var multibarSeries = new MultiBarSeries (2, 4, 1);
//nudge them left to avoid float rounding errors at the boundaries of cells
foreach(var sub in multibarSeries.SubSeries) {
foreach (var sub in multibarSeries.SubSeries) {
sub.Offset -= 0.001f;
}
@@ -720,28 +770,28 @@ namespace Terminal.Gui.Views {
// don't show axis labels that means any labels
// that appaer are explicitly from the bars
gv.AxisX = fakeXAxis = new FakeHAxis(){Increment=0};
gv.AxisY = new FakeVAxis(){Increment=0};
gv.AxisX = fakeXAxis = new FakeHAxis () { Increment = 0 };
gv.AxisY = new FakeVAxis () { Increment = 0 };
gv.Redraw(gv.Bounds);
gv.Redraw (gv.Bounds);
// Since bar series has no bars yet no labels should be displayed
Assert.Empty(fakeXAxis.LabelPoints);
Assert.Empty (fakeXAxis.LabelPoints);
multibarSeries.AddBars("hey",'M',0.5001f, 0.5001f);
fakeXAxis.LabelPoints.Clear();
gv.Redraw(gv.Bounds);
Assert.Equal(4,fakeXAxis.LabelPoints.Single());
multibarSeries.AddBars ("hey", 'M', 0.5001f, 0.5001f);
fakeXAxis.LabelPoints.Clear ();
gv.Redraw (gv.Bounds);
multibarSeries.AddBars("there",'M',0.24999f,0.74999f);
multibarSeries.AddBars("bob",'M',1,2);
fakeXAxis.LabelPoints.Clear();
gv.Redraw(gv.Bounds);
Assert.Equal (4, fakeXAxis.LabelPoints.Single ());
Assert.Equal(3,fakeXAxis.LabelPoints.Count);
Assert.Equal(4,fakeXAxis.LabelPoints[0]);
Assert.Equal(8,fakeXAxis.LabelPoints[1]);
multibarSeries.AddBars ("there", 'M', 0.24999f, 0.74999f);
multibarSeries.AddBars ("bob", 'M', 1, 2);
fakeXAxis.LabelPoints.Clear ();
gv.Redraw (gv.Bounds);
Assert.Equal (3, fakeXAxis.LabelPoints.Count);
Assert.Equal (4, fakeXAxis.LabelPoints [0]);
Assert.Equal (8, fakeXAxis.LabelPoints [1]);
Assert.Equal (12, fakeXAxis.LabelPoints [2]);
string looksLike =
@@ -763,7 +813,7 @@ namespace Terminal.Gui.Views {
}
}
public class BarSeriesTests{
public class BarSeriesTests {
private GraphView GetGraph (out FakeBarSeries series, out FakeHAxis axisX, out FakeVAxis axisY)
@@ -776,46 +826,47 @@ namespace Terminal.Gui.Views {
// y axis goes from 0.1 to 1 across 10 console rows
// x axis goes from 0 to 10 across 20 console columns
gv.Bounds = new Rect (0, 0, 20, 10);
gv.CellSize = new PointF(0.5f,0.1f);
gv.CellSize = new PointF (0.5f, 0.1f);
gv.Series.Add (series = new FakeBarSeries ());
// don't show axis labels that means any labels
// that appaer are explicitly from the bars
gv.AxisX = axisX = new FakeHAxis(){Increment=0};
gv.AxisY = axisY = new FakeVAxis(){Increment=0};
gv.AxisX = axisX = new FakeHAxis () { Increment = 0 };
gv.AxisY = axisY = new FakeVAxis () { Increment = 0 };
return gv;
}
[Fact]
public void TestZeroHeightBar_WithName(){
public void TestZeroHeightBar_WithName ()
{
var graph = GetGraph(out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
graph.Redraw(graph.Bounds);
var graph = GetGraph (out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
graph.Redraw (graph.Bounds);
// no bars
Assert.Empty(barSeries.BarScreenStarts);
Assert.Empty(axisX.LabelPoints);
Assert.Empty(axisY.LabelPoints);
Assert.Empty (barSeries.BarScreenStarts);
Assert.Empty (axisX.LabelPoints);
Assert.Empty (axisY.LabelPoints);
// bar of height 0
barSeries.Bars.Add(new BarSeries.Bar("hi",new GraphCellToRender('.'),0));
barSeries.Bars.Add (new BarSeries.Bar ("hi", new GraphCellToRender ('.'), 0));
barSeries.Orientation = Orientation.Vertical;
// redraw graph
graph.Redraw(graph.Bounds);
graph.Redraw (graph.Bounds);
// bar should not be drawn
Assert.Empty(barSeries.BarScreenStarts);
Assert.Empty (barSeries.BarScreenStarts);
Assert.NotEmpty(axisX.LabelPoints);
Assert.Empty(axisY.LabelPoints);
Assert.NotEmpty (axisX.LabelPoints);
Assert.Empty (axisY.LabelPoints);
// but bar name should be
// Screen position x=2 because bars are drawn every 1f of
// graph space and CellSize.X is 0.5f
Assert.Contains(2, axisX.LabelPoints);
Assert.Contains (2, axisX.LabelPoints);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -823,71 +874,73 @@ namespace Terminal.Gui.Views {
[Fact]
public void TestTwoTallBars_WithOffset(){
public void TestTwoTallBars_WithOffset ()
{
var graph = GetGraph(out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
graph.Redraw(graph.Bounds);
var graph = GetGraph (out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
graph.Redraw (graph.Bounds);
// no bars
Assert.Empty(barSeries.BarScreenStarts);
Assert.Empty(axisX.LabelPoints);
Assert.Empty(axisY.LabelPoints);
Assert.Empty (barSeries.BarScreenStarts);
Assert.Empty (axisX.LabelPoints);
Assert.Empty (axisY.LabelPoints);
// 0.5 units of graph fit every screen cell
// so 1 unit of graph space is 2 screen columns
graph.CellSize = new PointF(0.5f,0.1f);
graph.CellSize = new PointF (0.5f, 0.1f);
// Start bar 1 screen unit along
barSeries.Offset = 0.5f;
barSeries.BarEvery = 1f;
barSeries.Bars.Add(
new BarSeries.Bar("hi1",new GraphCellToRender('.'),100));
barSeries.Bars.Add(
new BarSeries.Bar("hi2",new GraphCellToRender('.'),100));
barSeries.Bars.Add (
new BarSeries.Bar ("hi1", new GraphCellToRender ('.'), 100));
barSeries.Bars.Add (
new BarSeries.Bar ("hi2", new GraphCellToRender ('.'), 100));
barSeries.Orientation = Orientation.Vertical;
// redraw graph
graph.Redraw(graph.Bounds);
graph.Redraw (graph.Bounds);
// bar should be drawn at BarEvery 1f + offset 0.5f = 3 screen units
Assert.Equal(3,barSeries.BarScreenStarts[0].X);
Assert.Equal(3,barSeries.BarScreenEnds[0].X);
Assert.Equal (3, barSeries.BarScreenStarts [0].X);
Assert.Equal (3, barSeries.BarScreenEnds [0].X);
// second bar should be BarEveryx2 = 2f + offset 0.5f = 5 screen units
Assert.Equal(5,barSeries.BarScreenStarts[1].X);
Assert.Equal(5,barSeries.BarScreenEnds[1].X);
Assert.Equal (5, barSeries.BarScreenStarts [1].X);
Assert.Equal (5, barSeries.BarScreenEnds [1].X);
// both bars should have labels
Assert.Equal(2,axisX.LabelPoints.Count);
Assert.Contains(3, axisX.LabelPoints);
Assert.Contains(5, axisX.LabelPoints);
Assert.Equal (2, axisX.LabelPoints.Count);
Assert.Contains (3, axisX.LabelPoints);
Assert.Contains (5, axisX.LabelPoints);
// bars are very tall but should not draw up off top of screen
Assert.Equal(9,barSeries.BarScreenStarts[0].Y);
Assert.Equal(0,barSeries.BarScreenEnds[0].Y);
Assert.Equal(9,barSeries.BarScreenStarts[1].Y);
Assert.Equal(0,barSeries.BarScreenEnds[1].Y);
Assert.Equal (9, barSeries.BarScreenStarts [0].Y);
Assert.Equal (0, barSeries.BarScreenEnds [0].Y);
Assert.Equal (9, barSeries.BarScreenStarts [1].Y);
Assert.Equal (0, barSeries.BarScreenEnds [1].Y);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
}
[Fact]
public void TestOneLongOneShortHorizontalBars_WithOffset(){
public void TestOneLongOneShortHorizontalBars_WithOffset ()
{
var graph = GetGraph(out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
graph.Redraw(graph.Bounds);
var graph = GetGraph (out FakeBarSeries barSeries, out FakeHAxis axisX, out FakeVAxis axisY);
graph.Redraw (graph.Bounds);
// no bars
Assert.Empty(barSeries.BarScreenStarts);
Assert.Empty(axisX.LabelPoints);
Assert.Empty(axisY.LabelPoints);
Assert.Empty (barSeries.BarScreenStarts);
Assert.Empty (axisX.LabelPoints);
Assert.Empty (axisY.LabelPoints);
// 0.1 units of graph y fit every screen row
// so 1 unit of graph y space is 10 screen rows
graph.CellSize = new PointF(0.5f,0.1f);
graph.CellSize = new PointF (0.5f, 0.1f);
// Start bar 3 screen units up (y = height-3)
barSeries.Offset = 0.25f;
@@ -896,64 +949,64 @@ namespace Terminal.Gui.Views {
barSeries.Orientation = Orientation.Horizontal;
// 1 bar that is very wide (100 graph units horizontally = screen pos 50 but bounded by screen)
barSeries.Bars.Add(
new BarSeries.Bar("hi1",new GraphCellToRender('.'),100));
barSeries.Bars.Add (
new BarSeries.Bar ("hi1", new GraphCellToRender ('.'), 100));
// 1 bar that is shorter
barSeries.Bars.Add(
new BarSeries.Bar("hi2",new GraphCellToRender('.'),5));
barSeries.Bars.Add (
new BarSeries.Bar ("hi2", new GraphCellToRender ('.'), 5));
// redraw graph
graph.Redraw(graph.Bounds);
graph.Redraw (graph.Bounds);
// since bars are horizontal all have the same X start cordinates
Assert.Equal(0,barSeries.BarScreenStarts[0].X);
Assert.Equal(0,barSeries.BarScreenStarts[1].X);
Assert.Equal (0, barSeries.BarScreenStarts [0].X);
Assert.Equal (0, barSeries.BarScreenStarts [1].X);
// bar goes all the way to the end so bumps up against right screen boundary
// width of graph is 20
Assert.Equal(19,barSeries.BarScreenEnds[0].X);
Assert.Equal (19, barSeries.BarScreenEnds [0].X);
// shorter bar is 5 graph units wide which is 10 screen units
Assert.Equal(10,barSeries.BarScreenEnds[1].X);
Assert.Equal (10, barSeries.BarScreenEnds [1].X);
// first bar should be offset 6 screen units (0.25f + 0.3f graph units)
// since height of control is 10 then first bar should be at screen row 4 (10-6)
Assert.Equal(4,barSeries.BarScreenStarts[0].Y);
Assert.Equal (4, barSeries.BarScreenStarts [0].Y);
// second bar should be offset 9 screen units (0.25f + 0.6f graph units)
// since height of control is 10 then second bar should be at screen row 1 (10-9)
Assert.Equal(1,barSeries.BarScreenStarts[1].Y);
Assert.Equal (1, barSeries.BarScreenStarts [1].Y);
// both bars should have labels but on the y axis
Assert.Equal(2,axisY.LabelPoints.Count);
Assert.Empty(axisX.LabelPoints);
Assert.Equal (2, axisY.LabelPoints.Count);
Assert.Empty (axisX.LabelPoints);
// labels should align with the bars (same screen y axis point)
Assert.Contains(4, axisY.LabelPoints);
Assert.Contains(1, axisY.LabelPoints);
Assert.Contains (4, axisY.LabelPoints);
Assert.Contains (1, axisY.LabelPoints);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
}
private class FakeBarSeries : BarSeries{
private class FakeBarSeries : BarSeries {
public GraphCellToRender FinalColor { get; private set; }
public List<Point> BarScreenStarts { get; private set; } = new List<Point>();
public List<Point> BarScreenEnds { get; private set; } = new List<Point>();
public List<Point> BarScreenStarts { get; private set; } = new List<Point> ();
public List<Point> BarScreenEnds { get; private set; } = new List<Point> ();
protected override GraphCellToRender AdjustColor (GraphCellToRender graphCellToRender)
{
return FinalColor = base.AdjustColor (graphCellToRender);
return FinalColor = base.AdjustColor (graphCellToRender);
}
protected override void DrawBarLine (GraphView graph, Point start, Point end, Bar beingDrawn)
{
base.DrawBarLine (graph, start, end, beingDrawn);
BarScreenStarts.Add(start);
BarScreenEnds.Add(end);
BarScreenStarts.Add (start);
BarScreenEnds.Add (end);
}
}
@@ -965,11 +1018,11 @@ namespace Terminal.Gui.Views {
private GraphView GetGraph (out FakeHAxis axis)
{
return GetGraph(out axis, out _);
return GetGraph (out axis, out _);
}
private GraphView GetGraph (out FakeVAxis axis)
{
return GetGraph(out _, out axis);
return GetGraph (out _, out axis);
}
private GraphView GetGraph (out FakeHAxis axisX, out FakeVAxis axisY)
{
@@ -1003,15 +1056,15 @@ namespace Terminal.Gui.Views {
gv.Redraw (gv.Bounds);
Assert.DoesNotContain (new Point (-1, 29), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 29),axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 29), axis.DrawAxisLinePoints);
Assert.Contains (new Point (1, 29), axis.DrawAxisLinePoints);
Assert.Contains (new Point (48, 29), axis.DrawAxisLinePoints);
Assert.Contains (new Point (49, 29), axis.DrawAxisLinePoints);
Assert.DoesNotContain (new Point (50, 29), axis.DrawAxisLinePoints);
Assert.InRange(axis.LabelPoints.Max(),0,49);
Assert.InRange(axis.LabelPoints.Min(),0,49);
Assert.InRange (axis.LabelPoints.Max (), 0, 49);
Assert.InRange (axis.LabelPoints.Min (), 0, 49);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -1033,8 +1086,8 @@ namespace Terminal.Gui.Views {
Assert.Contains (new Point (49, 19), axis.DrawAxisLinePoints);
Assert.DoesNotContain (new Point (50, 19), axis.DrawAxisLinePoints);
Assert.InRange(axis.LabelPoints.Max(),0,49);
Assert.InRange(axis.LabelPoints.Min(),0,49);
Assert.InRange (axis.LabelPoints.Max (), 0, 49);
Assert.InRange (axis.LabelPoints.Min (), 0, 49);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -1057,8 +1110,8 @@ namespace Terminal.Gui.Views {
Assert.DoesNotContain (new Point (50, 29), axis.DrawAxisLinePoints);
// Axis lables should not be drawn in the margin
Assert.InRange(axis.LabelPoints.Max(),5,49);
Assert.InRange(axis.LabelPoints.Min(),5,49);
Assert.InRange (axis.LabelPoints.Max (), 5, 49);
Assert.InRange (axis.LabelPoints.Min (), 5, 49);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -1081,15 +1134,15 @@ namespace Terminal.Gui.Views {
gv.Redraw (gv.Bounds);
Assert.DoesNotContain (new Point (0, -1), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 1),axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 1), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 2), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 28), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 29), axis.DrawAxisLinePoints);
Assert.DoesNotContain (new Point (0, 30), axis.DrawAxisLinePoints);
Assert.InRange(axis.LabelPoints.Max(),0,29);
Assert.InRange(axis.LabelPoints.Min(),0,29);
Assert.InRange (axis.LabelPoints.Max (), 0, 29);
Assert.InRange (axis.LabelPoints.Min (), 0, 29);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -1104,16 +1157,16 @@ namespace Terminal.Gui.Views {
gv.Redraw (gv.Bounds);
Assert.DoesNotContain (new Point (0, -1), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 1),axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 1), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 2), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 18), axis.DrawAxisLinePoints);
Assert.Contains (new Point (0, 19), axis.DrawAxisLinePoints);
Assert.DoesNotContain (new Point (0, 20), axis.DrawAxisLinePoints);
// Labels should not be drawn into the axis
Assert.InRange(axis.LabelPoints.Max(),0,19);
Assert.InRange(axis.LabelPoints.Min(),0,19);
Assert.InRange (axis.LabelPoints.Max (), 0, 19);
Assert.InRange (axis.LabelPoints.Min (), 0, 19);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -1128,15 +1181,15 @@ namespace Terminal.Gui.Views {
gv.Redraw (gv.Bounds);
Assert.DoesNotContain (new Point (5, -1), axis.DrawAxisLinePoints);
Assert.Contains (new Point (5, 1),axis.DrawAxisLinePoints);
Assert.Contains (new Point (5, 1), axis.DrawAxisLinePoints);
Assert.Contains (new Point (5, 2), axis.DrawAxisLinePoints);
Assert.Contains (new Point (5, 28), axis.DrawAxisLinePoints);
Assert.Contains (new Point (5, 29), axis.DrawAxisLinePoints);
Assert.DoesNotContain (new Point (5, 30), axis.DrawAxisLinePoints);
Assert.InRange(axis.LabelPoints.Max(),0,29);
Assert.InRange(axis.LabelPoints.Min(),0,29);
Assert.InRange (axis.LabelPoints.Max (), 0, 29);
Assert.InRange (axis.LabelPoints.Min (), 0, 29);
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
@@ -1148,13 +1201,13 @@ namespace Terminal.Gui.Views {
public class TextAnnotationTests {
readonly ITestOutputHelper output;
public TextAnnotationTests(ITestOutputHelper output)
public TextAnnotationTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void TestTextAnnotation_ScreenUnits()
public void TestTextAnnotation_ScreenUnits ()
{
var gv = GraphViewTests.GetGraph ();
@@ -1177,8 +1230,8 @@ namespace Terminal.Gui.Views {
// user scrolls up one unit of graph space
gv.ScrollOffset = new PointF (0, 1f);
gv.Redraw (gv.Bounds);
gv.Redraw (gv.Bounds);
// we expect no change in the location of the annotation (only the axis label changes)
// this is because screen units are constant and do not change as the viewport into
// graph space scrolls to different areas of the graph
@@ -1301,7 +1354,7 @@ namespace Terminal.Gui.Views {
}
[Theory]
[InlineData(null)]
[InlineData (null)]
[InlineData (" ")]
[InlineData ("\t\t")]
public void TestTextAnnotation_EmptyText (string whitespace)
@@ -1316,7 +1369,7 @@ namespace Terminal.Gui.Views {
// add a point a bit further along the graph so if the whitespace were rendered
// the test would pick it up (AssertDriverContentsAre ignores trailing whitespace on lines)
var points = new ScatterSeries ();
points.Points.Add(new PointF(7, 2));
points.Points.Add (new PointF (7, 2));
gv.Series.Add (points);
gv.Redraw (gv.Bounds);
@@ -1340,7 +1393,7 @@ namespace Terminal.Gui.Views {
public class LegendTests {
readonly ITestOutputHelper output;
public LegendTests(ITestOutputHelper output)
public LegendTests (ITestOutputHelper output)
{
this.output = output;
}
@@ -1349,7 +1402,7 @@ namespace Terminal.Gui.Views {
public void LegendNormalUsage_WithBorder ()
{
var gv = GraphViewTests.GetGraph ();
var legend = new LegendAnnotation(new Rect(2,0,5,3));
var legend = new LegendAnnotation (new Rect (2, 0, 5, 3));
legend.AddEntry (new GraphCellToRender ('A'), "Ant");
legend.AddEntry (new GraphCellToRender ('B'), "Bat");
@@ -1404,13 +1457,13 @@ namespace Terminal.Gui.Views {
public class PathAnnotationTests {
readonly ITestOutputHelper output;
public PathAnnotationTests( ITestOutputHelper output)
public PathAnnotationTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void PathAnnotation_Box()
public void PathAnnotation_Box ()
{
var gv = GraphViewTests.GetGraph ();
@@ -1480,9 +1533,9 @@ namespace Terminal.Gui.Views {
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
}
[Fact]
public void XAxisLabels_With_MarginLeft()
public void XAxisLabels_With_MarginLeft ()
{
GraphViewTests.InitFakeDriver ();
var gv = new GraphView {
@@ -1499,7 +1552,7 @@ namespace Terminal.Gui.Views {
});
// reserve 3 cells of the left for the margin
gv.MarginLeft = 3;
gv.MarginLeft = 3;
gv.MarginBottom = 1;
gv.Redraw (gv.Bounds);
@@ -1515,7 +1568,7 @@ namespace Terminal.Gui.Views {
0 5
";
GraphViewTests.AssertDriverContentsAre (expected, output);
GraphViewTests.AssertDriverContentsAre (expected, output);
// Shutdown must be called to safely clean up Application if Init has been called
@@ -1599,7 +1652,7 @@ namespace Terminal.Gui.Views {
0┼┬┬┬┬┬┬┬┬
0 5";
GraphViewTests.AssertDriverContentsAre (expected,output);
GraphViewTests.AssertDriverContentsAre (expected, output);
// Shutdown must be called to safely clean up Application if Init has been called
@@ -1657,11 +1710,11 @@ namespace Terminal.Gui.Views {
}
}
public class AxisIncrementToRenderTests {
public class AxisIncrementToRenderTests {
[Fact]
public void AxisIncrementToRenderTests_Constructor ()
{
var render = new AxisIncrementToRender (Orientation.Horizontal,1,6.6f);
var render = new AxisIncrementToRender (Orientation.Horizontal, 1, 6.6f);
Assert.Equal (Orientation.Horizontal, render.Orientation);
Assert.Equal (1, render.ScreenLocation);

View File

@@ -512,8 +512,8 @@ Edit
└──────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 1), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 1, 8, 4), pos);
}
[Fact, AutoInitShutdown]
@@ -541,8 +541,8 @@ Edit
──────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 7, 4), pos);
menu.CloseAllMenus ();
menu.Frame = new Rect (-1, -2, menu.Frame.Width, menu.Frame.Height);
@@ -555,8 +555,8 @@ Edit
──────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (1, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (1, 0, 7, 3), pos);
menu.CloseAllMenus ();
menu.Frame = new Rect (0, 0, menu.Frame.Width, menu.Frame.Height);
@@ -566,13 +566,13 @@ Edit
expected = @"
┌──────
│ One
│ Two
│ One
│ Two
└──────
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 1), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 1, 7, 4), pos);
menu.CloseAllMenus ();
menu.Frame = new Rect (0, 0, menu.Frame.Width, menu.Frame.Height);
@@ -582,12 +582,12 @@ Edit
expected = @"
┌──────
│ One
│ Two
│ One
│ Two
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 1), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 1, 7, 3), pos);
}
[Fact, AutoInitShutdown]
@@ -614,8 +614,8 @@ Edit
Numbers
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 9, 1), pos);
Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, null)));
Application.Top.Redraw (Application.Top.Bounds);
@@ -628,8 +628,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 10, 6), pos);
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, null)));
Application.Top.Redraw (Application.Top.Bounds);
@@ -643,8 +643,8 @@ Edit
└─────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 25, 7), pos);
Assert.True (Application.Top.Subviews [2].ProcessKey (new KeyEvent (Key.CursorLeft, null)));
Application.Top.Redraw (Application.Top.Bounds);
@@ -657,8 +657,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 10, 6), pos);
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.Esc, null)));
Application.Top.Redraw (Application.Top.Bounds);
@@ -666,8 +666,8 @@ Edit
Numbers
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 9, 1), pos);
}
[Fact, AutoInitShutdown]
@@ -694,8 +694,8 @@ Edit
Numbers
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 9, 1), pos);
Assert.True (menu.MouseEvent (new MouseEvent () {
X = 1,
@@ -713,8 +713,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 10, 6), pos);
Assert.False (menu.MouseEvent (new MouseEvent () {
X = 1,
@@ -733,8 +733,8 @@ Edit
└─────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 25, 7), pos);
Assert.False (menu.MouseEvent (new MouseEvent () {
X = 1,
@@ -752,8 +752,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 10, 6), pos);
Assert.False (menu.MouseEvent (new MouseEvent () {
X = 70,
@@ -766,8 +766,8 @@ Edit
Numbers
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 9, 1), pos);
}
[Fact, AutoInitShutdown]
@@ -796,8 +796,8 @@ Edit
Numbers
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 9, 1), pos);
Assert.True (menu.ProcessHotKey (new KeyEvent (Key.F9, null)));
Application.Top.Redraw (Application.Top.Bounds);
@@ -810,8 +810,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 10, 6), pos);
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.CursorDown, null)));
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.Enter, null)));
@@ -826,8 +826,8 @@ Edit
└─────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 15, 7), pos);
Assert.True (Application.Top.Subviews [2].ProcessKey (new KeyEvent (Key.Enter, null)));
Application.Top.Redraw (Application.Top.Bounds);
@@ -840,8 +840,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 10, 6), pos);
Assert.True (Application.Top.Subviews [1].ProcessKey (new KeyEvent (Key.Esc, null)));
Application.Top.Redraw (Application.Top.Bounds);
@@ -849,8 +849,8 @@ Edit
Numbers
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 9, 1), pos);
}
[Fact, AutoInitShutdown]
@@ -879,8 +879,8 @@ Edit
Numbers
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 9, 1), pos);
Assert.True (menu.MouseEvent (new MouseEvent () {
X = 1,
@@ -898,8 +898,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 10, 6), pos);
Assert.False (menu.MouseEvent (new MouseEvent () {
X = 1,
@@ -918,8 +918,8 @@ Edit
└─────────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 15, 7), pos);
Assert.False (menu.MouseEvent (new MouseEvent () {
X = 1,
@@ -937,8 +937,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 10, 6), pos);
Assert.False (menu.MouseEvent (new MouseEvent () {
X = 70,
@@ -951,12 +951,12 @@ Edit
Numbers
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 9, 1), pos);
}
[Fact, AutoInitShutdown]
public void HotKey_MenuBar_OnKeyDown_OnKeyUp_ProcessKey ()
public void HotKey_MenuBar_OnKeyDown_OnKeyUp_ProcessHotKey_ProcessKey ()
{
var newAction = false;
var copyAction = false;
@@ -983,16 +983,22 @@ Edit
File Edit
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 13, 1), pos);
Assert.True (menu.ProcessKey (new (Key.N, null)));
Application.MainLoop.MainIteration ();
Assert.True (newAction);
Assert.False (menu.OnKeyDown (new (Key.AltMask, new KeyModifiers () { Alt = true })));
Assert.True (menu.OnKeyUp (new (Key.AltMask, new KeyModifiers () { Alt = true })));
Assert.True (menu.ProcessHotKey (new (Key.AltMask, new KeyModifiers () { Alt = true })));
Assert.True (menu.IsMenuOpen);
Application.Top.Redraw (Application.Top.Bounds);
expected = @"
File Edit
";
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 13, 1), pos);
Assert.True (menu.ProcessKey (new (Key.CursorRight, null)));
Assert.True (menu.ProcessKey (new (Key.C, null)));
@@ -1030,8 +1036,8 @@ Edit
└───────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 13, 4), pos);
Assert.True (Application.Top.Subviews [1].ProcessKey (new (Key.N, null)));
Application.MainLoop.MainIteration ();
@@ -1047,8 +1053,8 @@ Edit
└────────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (2, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (2, 0, 17, 4), pos);
Assert.True (Application.Top.Subviews [1].ProcessKey (new (Key.C, null)));
Application.MainLoop.MainIteration ();

View File

@@ -1876,8 +1876,8 @@ namespace Terminal.Gui.Core {
└──────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 8, 4), pos);
}
[Fact, AutoInitShutdown]
@@ -1900,8 +1900,8 @@ namespace Terminal.Gui.Core {
──────┘
";
var pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 0), pos);
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 7, 4), pos);
view.Frame = new Rect (-1, -1, 8, 4);
Application.Refresh ();
@@ -1912,33 +1912,33 @@ namespace Terminal.Gui.Core {
──────┘
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (6, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (6, 0, 7, 3), pos);
view.Frame = new Rect (0, 0, 8, 4);
((FakeDriver)Application.Driver).SetBufferSize (7, 4);
expected = @"
┌──────
└──────
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 7, 4), pos);
view.Frame = new Rect (0, 0, 8, 4);
((FakeDriver)Application.Driver).SetBufferSize (7, 3);
expected = @"
┌──────
";
pos = GraphViewTests.AssertDriverContentsWithPosAre (expected, output);
Assert.Equal (new Point (0, 0), pos);
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 7, 3), pos);
}
}
}