Fixes #2469 - Revamp file structure and namespace (#2471)

* initial commit

* All tests pass

* Updated readme

* Revert "All tests pass"

This reverts commit 94ac462350.

* Revert "initial commit"

This reverts commit 36d92cc4e5.

* Moved Terminal.Gui files around

* Nuked .Graphs namespace

* Nuked .Graphs namespace

* Nuked .Trees namespace

* Nuked .Configuration namespace

* Nuked .Configuration namespace

* All tests pass

* tweaked tests

* removed unneeded usings

* re-enabled scrollview tests

* move scrollview test to ScrollViewTests

* Moved view navigation related tests to separate cs file

* Moved view scrollbarview related tests ScrollBarTestse

* Refactored View tests into smaller files

* Refactored driver tests

* Fixed a ton of BUGBUGs
This commit is contained in:
Tig
2023-04-06 10:09:21 -06:00
committed by GitHub
parent ec08c12162
commit 574ed8fec7
187 changed files with 6591 additions and 6541 deletions

View File

@@ -0,0 +1,635 @@
using System;
using System.Reflection.Emit;
using Xunit;
using Xunit.Abstractions;
using Rune = System.Rune;
namespace Terminal.Gui.ViewTests {
public class BorderTests {
readonly ITestOutputHelper output;
public BorderTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact, AutoInitShutdown]
public void Constructor_Defaults ()
{
var b = new Border ();
Assert.Equal (BorderStyle.None, b.BorderStyle);
Assert.False (b.DrawMarginFrame);
Assert.Equal (Thickness.Empty, b.BorderThickness);
Assert.Equal (Color.Black, b.ForgroundColor);
Assert.Equal (Color.Black, b.BackgroundColor);
Assert.Equal (Thickness.Empty, b.PaddingThickness);
Assert.False (b.Effect3D);
Assert.Equal (new Point (1, 1), b.Effect3DOffset);
Assert.Null (b.Effect3DBrush);
}
//[Fact]
//public void BorderStyle_Different_None_Ensures_DrawMarginFrame_To_True ()
//{
// var b = new Border () {
// BorderStyle = BorderStyle.Single,
// DrawMarginFrame = false
// };
// Assert.True (b.DrawMarginFrame);
// b.BorderStyle = BorderStyle.None;
// Assert.True (b.DrawMarginFrame);
// b.DrawMarginFrame = false;
// Assert.False (b.DrawMarginFrame);
//}
//[Fact, AutoInitShutdown]
// public void ActualWidth_ActualHeight ()
// {
// var v = new View (new Rect (5, 10, 60, 20), "", new Border ());
//[Fact]
//public void ToplevelContainer_LayoutStyle_Computed_Constuctor_ ()
//{
// var tc = new Border.ToplevelContainer (new Border ());
// Assert.Equal (LayoutStyle.Computed, tc.LayoutStyle);
//}
//[Fact]
//public void ToplevelContainer_LayoutStyle_Absolute_Constuctor_ ()
//{
// var tc = new Border.ToplevelContainer (new Rect (1, 2, 3, 4), new Border ());
// Assert.Equal (LayoutStyle.Absolute, tc.LayoutStyle);
//}
//[Fact]
//public void GetSumThickness_Test ()
//{
// var b = new Border () {
// BorderThickness = new Thickness (1, 2, 3, 4),
// Padding = new Thickness (4, 3, 2, 1)
// };
// Assert.Equal (new Thickness (5, 5, 5, 5), b.GetSumThickness ());
//}
//[Fact]
//[AutoInitShutdown]
//public void DrawContent_With_Child_Border ()
//{
// var top = Application.Top;
// var driver = (FakeDriver)Application.Driver;
// [Fact]
// [AutoInitShutdown]
// public void DrawContent_With_Child_Border ()
// {
// var top = Application.Top;
// var driver = (FakeDriver)Application.Driver;
// top.LayoutSubviews ();
// label.Redraw (label.Bounds);
// var frame = label.Frame;
// var drawMarginFrame = label.Border.DrawMarginFrame ? 1 : 0;
// var sumThickness = label.Border.GetSumThickness ();
// var padding = label.Border.Padding;
// var effect3DOffset = label.Border.Effect3DOffset;
// var borderStyle = label.Border.BorderStyle;
// // Check the upper BorderThickness
// for (int r = frame.Y - drawMarginFrame - sumThickness.Top;
// r < frame.Y - drawMarginFrame - padding.Top; r++) {
// for (int c = frame.X - drawMarginFrame - sumThickness.Left;
// c < frame.Right + drawMarginFrame + sumThickness.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.Red, color.Background);
// }
// }
// // Check the left BorderThickness
// for (int r = frame.Y - drawMarginFrame - padding.Top;
// r < frame.Bottom + drawMarginFrame + padding.Bottom; r++) {
// for (int c = frame.X - drawMarginFrame - sumThickness.Left;
// c < frame.X - drawMarginFrame - padding.Left; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.Red, color.Background);
// }
// }
// // Check the right BorderThickness
// for (int r = frame.Y - drawMarginFrame - padding.Top;
// r < frame.Bottom + drawMarginFrame + padding.Bottom; r++) {
// for (int c = frame.Right + drawMarginFrame + padding.Right;
// c < frame.Right + drawMarginFrame - sumThickness.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.Red, color.Background);
// }
// }
// // Check the lower BorderThickness
// for (int r = frame.Bottom + drawMarginFrame + padding.Bottom;
// r < frame.Bottom + drawMarginFrame + sumThickness.Bottom; r++) {
// for (int c = frame.X - drawMarginFrame - sumThickness.Left;
// c < frame.Right + drawMarginFrame + sumThickness.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.Red, color.Background);
// }
// }
// // Check the upper Padding
// for (int r = frame.Y - drawMarginFrame - padding.Top;
// r < frame.Y - drawMarginFrame; r++) {
// for (int c = frame.X - drawMarginFrame - padding.Left;
// c < frame.Right + drawMarginFrame + padding.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.BrightGreen, color.Background);
// }
// }
// // Check the left Padding
// for (int r = frame.Y - drawMarginFrame;
// r < frame.Bottom + drawMarginFrame; r++) {
// for (int c = frame.X - drawMarginFrame - padding.Left;
// c < frame.X - drawMarginFrame; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.BrightGreen, color.Background);
// }
// }
// // Check the right Padding
// for (int r = frame.Y - drawMarginFrame;
// r < frame.Bottom + drawMarginFrame; r++) {
// for (int c = frame.Right + drawMarginFrame;
// c < frame.Right + drawMarginFrame - padding.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.BrightGreen, color.Background);
// }
// }
// // Check the lower Padding
// for (int r = frame.Bottom + drawMarginFrame;
// r < frame.Bottom + drawMarginFrame + padding.Bottom; r++) {
// for (int c = frame.X - drawMarginFrame - padding.Left;
// c < frame.Right + drawMarginFrame + padding.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.BrightGreen, color.Background);
// }
// }
// Rune hLine = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.HLine : (borderStyle == BorderStyle.Double ? driver.HDLine : ' ')) : ' ';
// Rune vLine = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.VLine : (borderStyle == BorderStyle.Double ? driver.VDLine : ' ')) : ' ';
// Rune uRCorner = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.URCorner : (borderStyle == BorderStyle.Double ? driver.URDCorner : ' ')) : ' ';
// Rune uLCorner = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.ULCorner : (borderStyle == BorderStyle.Double ? driver.ULDCorner : ' ')) : ' ';
// Rune lLCorner = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.LLCorner : (borderStyle == BorderStyle.Double ? driver.LLDCorner : ' ')) : ' ';
// Rune lRCorner = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.LRCorner : (borderStyle == BorderStyle.Double ? driver.LRDCorner : ' ')) : ' ';
// var text = "";
// // Check the MarginFrame
// for (int r = frame.Y - drawMarginFrame;
// r < frame.Bottom + drawMarginFrame; r++) {
// for (int c = frame.X - drawMarginFrame;
// c <= frame.Right + drawMarginFrame - 1; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// var rune = (Rune)driver.Contents [r, c, 0];
// Assert.Equal (Color.Black, color.Background);
// if (c == frame.X - drawMarginFrame && r == frame.Y - drawMarginFrame) {
// Assert.Equal (uLCorner, rune);
// } else if (c == frame.Right && r == frame.Y - drawMarginFrame) {
// Assert.Equal (uRCorner, rune);
// } else if (c == frame.X - drawMarginFrame && r == frame.Bottom) {
// Assert.Equal (lLCorner, rune);
// } else if (c == frame.Right && r == frame.Bottom) {
// Assert.Equal (lRCorner, rune);
// } else if (c >= frame.X && (r == frame.Y - drawMarginFrame
// || r == frame.Bottom)) {
// Assert.Equal (hLine, rune);
// } else if ((c == frame.X - drawMarginFrame || c == frame.Right)
// && r >= frame.Y && r <= frame.Bottom - drawMarginFrame) {
// Assert.Equal (vLine, rune);
// } else {
// text += rune.ToString ();
// }
// }
// }
// Assert.Equal ("This is a test", text.Trim ());
// var color = (Attribute)driver.Contents [r, c, 1];
// var rune = (Rune)driver.Contents [r, c, 0];
// if (r == frame.Y - drawMarginFrame || r == frame.Bottom + drawMarginFrame - 1
// || c == frame.X - drawMarginFrame || c == frame.Right + drawMarginFrame - 1) {
// Assert.Equal (Color.BrightGreen, color.Background);
// } else {
// Assert.Equal (Color.Black, color.Background);
// }
// if (c == frame.X - drawMarginFrame && r == frame.Y - drawMarginFrame) {
// Assert.Equal (uLCorner, rune);
// } else if (c == frame.Right && r == frame.Y - drawMarginFrame) {
// Assert.Equal (uRCorner, rune);
// } else if (c == frame.X - drawMarginFrame && r == frame.Bottom) {
// Assert.Equal (lLCorner, rune);
// } else if (c == frame.Right && r == frame.Bottom) {
// Assert.Equal (lRCorner, rune);
// } else if (c >= frame.X && (r == frame.Y - drawMarginFrame
// || r == frame.Bottom)) {
// Assert.Equal (hLine, rune);
// } else if ((c == frame.X - drawMarginFrame || c == frame.Right)
// && r >= frame.Y && r <= frame.Bottom - drawMarginFrame) {
// Assert.Equal (vLine, rune);
// } else {
// text += rune.ToString ();
// }
// }
// }
// Assert.Equal ("This is a test", text.Trim ());
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.DarkGray, color.Background);
// }
// }
// // Check the left Effect3D
// for (int r = frame.Y - drawMarginFrame - sumThickness.Top + effect3DOffset.Y;
// r < frame.Bottom + drawMarginFrame + sumThickness.Bottom + effect3DOffset.Y; r++) {
// for (int c = frame.X - drawMarginFrame - sumThickness.Left + effect3DOffset.X;
// c < frame.X - drawMarginFrame - sumThickness.Left; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.DarkGray, color.Background);
// }
// }
// // Check the right Effect3D
// for (int r = frame.Y - drawMarginFrame - sumThickness.Top + effect3DOffset.Y;
// r < frame.Bottom + drawMarginFrame + sumThickness.Bottom + effect3DOffset.Y; r++) {
// for (int c = frame.Right + drawMarginFrame + sumThickness.Right;
// c < frame.Right + drawMarginFrame + sumThickness.Right + effect3DOffset.X; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.DarkGray, color.Background);
// }
// }
// // Check the lower Effect3D
// for (int r = frame.Bottom + drawMarginFrame + sumThickness.Bottom;
// r < frame.Bottom + drawMarginFrame + sumThickness.Bottom + effect3DOffset.Y; r++) {
// for (int c = frame.X - drawMarginFrame - sumThickness.Left + effect3DOffset.X;
// c < frame.Right + drawMarginFrame + sumThickness.Right + effect3DOffset.X; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.DarkGray, color.Background);
// }
// }
// // Check the Child frame
// for (int r = frame.Y; r < frame.Y + frame.Height; r++) {
// for (int c = frame.X; c < frame.X + frame.Width; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.BrightGreen, color.Foreground);
// Assert.Equal (Color.Black, color.Background);
// }
// }
//}
//[Fact]
//[AutoInitShutdown]
//public void DrawContent_With_Parent_Border ()
//{
// var top = Application.Top;
// var driver = (FakeDriver)Application.Driver;
// [Fact]
// [AutoInitShutdown]
// public void DrawContent_With_Parent_Border ()
// {
// var top = Application.Top;
// var driver = (FakeDriver)Application.Driver;
// top.LayoutSubviews ();
// frameView.Redraw (frameView.Bounds);
// var frame = frameView.Frame;
// var drawMarginFrame = frameView.Border.DrawMarginFrame ? 1 : 0;
// var borderThickness = frameView.Border.BorderThickness;
// var padding = frameView.Border.Padding;
// var effect3DOffset = frameView.Border.Effect3DOffset;
// var borderStyle = frameView.Border.BorderStyle;
// // Check the upper BorderThickness
// for (int r = frame.Y;
// r < Math.Min (frame.Y + borderThickness.Top, frame.Bottom); r++) {
// for (int c = frame.X;
// c < frame.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.Red, color.Background);
// }
// }
// // Check the left BorderThickness
// for (int r = Math.Min (frame.Y + borderThickness.Top, frame.Bottom);
// r < frame.Bottom - borderThickness.Bottom; r++) {
// for (int c = frame.X;
// c < Math.Min (frame.X + borderThickness.Left, frame.Right); c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.Red, color.Background);
// }
// }
// // Check the right BorderThickness
// for (int r = Math.Min (frame.Y + borderThickness.Top, frame.Bottom);
// r < frame.Bottom - borderThickness.Bottom; r++) {
// for (int c = Math.Max (frame.Right - borderThickness.Right, frame.X);
// c < frame.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.Red, color.Background);
// }
// }
// // Check the lower BorderThickness
// for (int r = Math.Max (frame.Bottom - borderThickness.Bottom, frame.Y);
// r < frame.Bottom; r++) {
// for (int c = frame.X;
// c < frame.Right; c++) {
// var color = (Attribute)driver.Contents [r, c, 1];
// Assert.Equal (Color.Red, color.Background);
// }
// }
// //TODO: Re-do padding tests
// //// Check the upper Padding
// //for (int r = frame.Y + borderThickness.Top;
// // r < Math.Min (frame.Y + sumThickness.Top, frame.Bottom - borderThickness.Bottom); r++) {
// // for (int c = frame.X + borderThickness.Left;
// // c < frame.Right - borderThickness.Right; c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.BrightGreen, color.Background);
// // }
// //}
// //// Check the left Padding
// //for (int r = frame.Y + sumThickness.Top;
// // r < frame.Bottom - sumThickness.Bottom; r++) {
// // for (int c = frame.X + borderThickness.Left;
// // c < Math.Min (frame.X + sumThickness.Left, frame.Right - borderThickness.Right); c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.BrightGreen, color.Background);
// // }
// //}
// //// Check the right Padding
// //// Draw the right Padding
// //for (int r = frame.Y + sumThickness.Top;
// // r < frame.Bottom - sumThickness.Bottom; r++) {
// // for (int c = Math.Max (frame.Right - sumThickness.Right, frame.X + sumThickness.Left);
// // c < Math.Max (frame.Right - borderThickness.Right, frame.X + sumThickness.Left); c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.BrightGreen, color.Background);
// // }
// //}
// //// Check the lower Padding
// //for (int r = Math.Max (frame.Bottom - sumThickness.Bottom, frame.Y + borderThickness.Top);
// // r < frame.Bottom - borderThickness.Bottom; r++) {
// // for (int c = frame.X + borderThickness.Left;
// // c < frame.Right - borderThickness.Right; c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.BrightGreen, color.Background);
// // }
// //}
// Rune hLine = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.HLine : (borderStyle == BorderStyle.Double ? driver.HDLine : ' ')) : ' ';
// Rune vLine = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.VLine : (borderStyle == BorderStyle.Double ? driver.VDLine : ' ')) : ' ';
// Rune uRCorner = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.URCorner : (borderStyle == BorderStyle.Double ? driver.URDCorner : ' ')) : ' ';
// Rune uLCorner = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.ULCorner : (borderStyle == BorderStyle.Double ? driver.ULDCorner : ' ')) : ' ';
// Rune lLCorner = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.LLCorner : (borderStyle == BorderStyle.Double ? driver.LLDCorner : ' ')) : ' ';
// Rune lRCorner = drawMarginFrame > 0 ? (borderStyle == BorderStyle.Single
// ? driver.LRCorner : (borderStyle == BorderStyle.Double ? driver.LRDCorner : ' ')) : ' ';
// // TODO: redo margin tests
// //var text = "";
// //// Check the MarginFrame
// //for (int r = frame.Y + sumThickness.Top;
// // r < frame.Bottom - sumThickness.Bottom; r++) {
// // for (int c = frame.X + sumThickness.Left;
// // c <= frame.Right - sumThickness.Right - 1; c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // var rune = (Rune)driver.Contents [r, c, 0];
// // Assert.Equal (Color.Black, color.Background);
// // if (c == frame.X + sumThickness.Left && r == frame.Y + sumThickness.Top) {
// // Assert.Equal (uLCorner, rune);
// // } else if (c == frame.Right - drawMarginFrame - sumThickness.Right
// // && r == frame.Y + sumThickness.Top) {
// // Assert.Equal (uRCorner, rune);
// // } else if (c == frame.X + sumThickness.Left
// // && r == frame.Bottom - drawMarginFrame - sumThickness.Bottom) {
// // Assert.Equal (lLCorner, rune);
// // } else if (c == frame.Right - drawMarginFrame - sumThickness.Right
// // && r == frame.Bottom - drawMarginFrame - sumThickness.Bottom) {
// // Assert.Equal (lRCorner, rune);
// // } else if (c > frame.X + sumThickness.Left
// // && (r == frame.Y + sumThickness.Top
// // || r == frame.Bottom - drawMarginFrame - sumThickness.Bottom)) {
// // Assert.Equal (hLine, rune);
// // } else if ((c == frame.X + sumThickness.Left
// // || c == frame.Right - drawMarginFrame - sumThickness.Right)
// // && r >= frame.Y + drawMarginFrame + sumThickness.Top) {
// // Assert.Equal (vLine, rune);
// // } else {
// // text += rune.ToString ();
// // }
// // }
// //}
// //Assert.Equal ("This is a test", text.Trim ());
// var color = (Attribute)driver.Contents [r, c, 1];
// var rune = (Rune)driver.Contents [r, c, 0];
// Assert.Equal (Color.Black, color.Background);
// if (c == frame.X + sumThickness.Left && r == frame.Y + sumThickness.Top) {
// Assert.Equal (uLCorner, rune);
// } else if (c == frame.Right - drawMarginFrame - sumThickness.Right
// && r == frame.Y + sumThickness.Top) {
// Assert.Equal (uRCorner, rune);
// } else if (c == frame.X + sumThickness.Left
// && r == frame.Bottom - drawMarginFrame - sumThickness.Bottom) {
// Assert.Equal (lLCorner, rune);
// } else if (c == frame.Right - drawMarginFrame - sumThickness.Right
// && r == frame.Bottom - drawMarginFrame - sumThickness.Bottom) {
// Assert.Equal (lRCorner, rune);
// } else if (c > frame.X + sumThickness.Left
// && (r == frame.Y + sumThickness.Top
// || r == frame.Bottom - drawMarginFrame - sumThickness.Bottom)) {
// Assert.Equal (hLine, rune);
// } else if ((c == frame.X + sumThickness.Left
// || c == frame.Right - drawMarginFrame - sumThickness.Right)
// && r >= frame.Y + drawMarginFrame + sumThickness.Top) {
// Assert.Equal (vLine, rune);
// } else {
// text += rune.ToString ();
// }
// }
// }
// Assert.Equal ("This is a test", text.Trim ());
// // Check the upper Effect3D
// for (int r = frame.Y + effect3DOffset.Y;
// r < frame.Y; r++) {
// for (int c = frame.X + effect3DOffset.X;
// c < frame.Right + effect3DOffset.X; c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.DarkGray, color.Background);
// // }
// //}
// //// Check the left Effect3D
// //for (int r = frame.Y + effect3DOffset.Y;
// // r < frame.Bottom + effect3DOffset.Y; r++) {
// // for (int c = frame.X + effect3DOffset.X;
// // c < frame.X; c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.DarkGray, color.Background);
// // }
// //}
// //// Check the right Effect3D
// //for (int r = frame.Y + effect3DOffset.Y;
// // r < frame.Bottom + effect3DOffset.Y; r++) {
// // for (int c = frame.Right;
// // c < frame.Right + effect3DOffset.X; c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.DarkGray, color.Background);
// // }
// //}
// //// Check the lower Effect3D
// //for (int r = frame.Bottom;
// // r < frame.Bottom + effect3DOffset.Y; r++) {
// // for (int c = frame.X + effect3DOffset.X;
// // c < frame.Right + effect3DOffset.X; c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.DarkGray, color.Background);
// // }
// //}
// //// Check the Child frame
// //for (int r = frame.Y + drawMarginFrame + sumThickness.Top;
// // r < frame.Bottom - drawMarginFrame - sumThickness.Bottom; r++) {
// // for (int c = frame.X + drawMarginFrame + sumThickness.Left;
// // c < frame.Right - drawMarginFrame - sumThickness.Right; c++) {
// // var color = (Attribute)driver.Contents [r, c, 1];
// // Assert.Equal (Color.BrightGreen, color.Foreground);
// // Assert.Equal (Color.Black, color.Background);
// // }
// //}
//}
[Fact, AutoInitShutdown]
public void BorderOnControlWithNoChildren ()
{
var label = new TextField ("Loading...") {
Border = new Border () {
BorderStyle = BorderStyle.Single,
DrawMarginFrame = true,
PaddingThickness = new Thickness (1),
ForgroundColor = Color.White
}
};
Application.Top.Add (label);
Assert.Null (Record.Exception (() => label.Redraw (label.Bounds)));
}
// [Fact, AutoInitShutdown]
// public void BorderStyle_And_DrawMarginFrame_Gets_Sets ()
// {
// var lblTop = new Label ("At 0,0");
// var lblFrame = new Label ("Centered") { X = Pos.Center (), Y = Pos.Center () };
// var frame = new FrameView () { Y = 1, Width = 20, Height = 3 };
// var lblFill = new Label () { Width = Dim.Fill(),Height = Dim.Fill(), Visible = false };
// var fillText = new System.Text.StringBuilder ();
// for (int i = 0; i < frame.Bounds.Height; i++) {
// if (i > 0) {
// fillText.AppendLine ("");
// }
// for (int j = 0; j < frame.Bounds.Width; j++) {
// fillText.Append ("█");
// }
// }
// lblFill.Text = fillText.ToString ();
// frame.Add (lblFill, lblFrame);
// var lblBottom = new Label ("At 0,4") { Y = 4 };
// Application.Top.Add (lblTop, frame, lblBottom);
// Application.Begin (Application.Top);
// Assert.Equal (BorderStyle.Single, frame.Border.BorderStyle);
// Assert.True (frame.Border.DrawMarginFrame);
// TestHelpers.AssertDriverContentsWithFrameAre (@"
//At 0,0
//┌──────────────────┐
//│ Centered │
//└──────────────────┘
//At 0,4 ", output);
// frame.Border.BorderStyle = BorderStyle.None;
// Application.Refresh ();
// Assert.True (frame.Border.DrawMarginFrame);
// TestHelpers.AssertDriverContentsWithFrameAre (@"
//At 0,0
// Centered
//At 0,4 ", output);
//// frame.Border.DrawMarginFrame = false;
//// lblFill.Visible = true;
//// Application.Refresh ();
//// TestHelpers.AssertDriverContentsWithFrameAre (@"
////At 0,0
////████████████████████
////██████Centered██████
////████████████████████
////At 0,4 ", output);
//}
}
}

View File

@@ -0,0 +1,174 @@
using NStack;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Xunit;
using Xunit.Abstractions;
//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui.ViewTests {
public class FrameTests {
readonly ITestOutputHelper output;
public FrameTests (ITestOutputHelper output)
{
this.output = output;
}
[Theory, AutoInitShutdown]
[InlineData (0)]
[InlineData (1)]
[InlineData (2)]
[InlineData (3)]
public void BorderFrame_With_Title_Size_Height (int height)
{
var win = new Window ("1234") {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
var rs = Application.Begin (win);
bool firstIteration = false;
((FakeDriver)Application.Driver).SetBufferSize (20, height);
Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
var expected = string.Empty;
switch (height) {
case 0:
//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
expected = @"
";
break;
case 1:
//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
expected = @"
────────────────────";
break;
case 2:
//Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
expected = @"
┌┤1234├────────────┐
└──────────────────┘
";
break;
case 3:
//Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
expected = @"
┌┤1234├────────────┐
│ │
└──────────────────┘
";
break;
}
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Theory, AutoInitShutdown]
[InlineData (0)]
[InlineData (1)]
[InlineData (2)]
[InlineData (3)]
[InlineData (4)]
[InlineData (5)]
[InlineData (6)]
[InlineData (7)]
[InlineData (8)]
[InlineData (9)]
[InlineData (10)]
public void BorderFrame_With_Title_Size_Width (int width)
{
var win = new Window ("1234") {
Width = Dim.Fill (),
Height = Dim.Fill ()
};
var rs = Application.Begin (win);
bool firstIteration = false;
((FakeDriver)Application.Driver).SetBufferSize (width, 3);
Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
var expected = string.Empty;
switch (width) {
case 1:
//Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
expected = @"
│";
break;
case 2:
//Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
expected = @"
┌┐
││
└┘";
break;
case 3:
//Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
expected = @"
┌─┐
│ │
└─┘
";
break;
case 4:
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
expected = @"
┌┤├┐
│ │
└──┘";
break;
case 5:
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
expected = @"
┌┤1├┐
│ │
└───┘";
break;
case 6:
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
expected = @"
┌┤12├┐
│ │
└────┘";
break;
case 7:
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
expected = @"
┌┤123├┐
│ │
└─────┘";
break;
case 8:
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
expected = @"
┌┤1234├┐
│ │
└──────┘";
break;
case 9:
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
expected = @"
┌┤1234├─┐
│ │
└───────┘";
break;
case 10:
//Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
expected = @"
┌┤1234├──┐
│ │
└────────┘";
break;
}
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
}
}

View File

@@ -0,0 +1,181 @@
using System;
using Xunit;
using Xunit.Abstractions;
using NStack;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui.ViewTests {
public class KeyboardTests {
readonly ITestOutputHelper output;
public KeyboardTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void KeyPress_Handled_To_True_Prevents_Changes ()
{
Application.Init (new FakeDriver ());
Console.MockKeyPresses.Push (new ConsoleKeyInfo ('N', ConsoleKey.N, false, false, false));
var top = Application.Top;
var text = new TextField ("");
text.KeyPress += (s, e) => {
e.Handled = true;
Assert.True (e.Handled);
Assert.Equal (Key.N, e.KeyEvent.Key);
};
top.Add (text);
Application.Iteration += () => {
Console.MockKeyPresses.Push (new ConsoleKeyInfo ('N', ConsoleKey.N, false, false, false));
Assert.Equal ("", text.Text);
Application.RequestStop ();
};
Application.Run ();
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
}
[Fact, AutoInitShutdown]
public void KeyDown_And_KeyUp_Events_Must_Called_Before_OnKeyDown_And_OnKeyUp ()
{
var keyDown = false;
var keyPress = false;
var keyUp = false;
var view = new DerivedView ();
view.KeyDown += (s, e) => {
Assert.Equal (Key.a, e.KeyEvent.Key);
Assert.False (keyDown);
Assert.False (view.IsKeyDown);
e.Handled = true;
keyDown = true;
};
view.KeyPress += (s, e) => {
Assert.Equal (Key.a, e.KeyEvent.Key);
Assert.False (keyPress);
Assert.False (view.IsKeyPress);
e.Handled = true;
keyPress = true;
};
view.KeyUp += (s, e) => {
Assert.Equal (Key.a, e.KeyEvent.Key);
Assert.False (keyUp);
Assert.False (view.IsKeyUp);
e.Handled = true;
keyUp = true;
};
Application.Top.Add (view);
Console.MockKeyPresses.Push (new ConsoleKeyInfo ('a', ConsoleKey.A, false, false, false));
Application.Iteration += () => Application.RequestStop ();
Assert.True (view.CanFocus);
Application.Run ();
Application.Shutdown ();
Assert.True (keyDown);
Assert.True (keyPress);
Assert.True (keyUp);
Assert.False (view.IsKeyDown);
Assert.False (view.IsKeyPress);
Assert.False (view.IsKeyUp);
}
public class DerivedView : View {
public DerivedView ()
{
CanFocus = true;
}
public bool IsKeyDown { get; set; }
public bool IsKeyPress { get; set; }
public bool IsKeyUp { get; set; }
public override ustring Text { get; set; }
public override bool OnKeyDown (KeyEvent keyEvent)
{
IsKeyDown = true;
return true;
}
public override bool ProcessKey (KeyEvent keyEvent)
{
IsKeyPress = true;
return true;
}
public override bool OnKeyUp (KeyEvent keyEvent)
{
IsKeyUp = true;
return true;
}
}
[Theory, AutoInitShutdown]
[InlineData (true, false, false)]
[InlineData (true, true, false)]
[InlineData (true, true, true)]
public void KeyDown_And_KeyUp_Events_With_Only_Key_Modifiers (bool shift, bool alt, bool control)
{
var keyDown = false;
var keyPress = false;
var keyUp = false;
var view = new DerivedView ();
view.KeyDown += (s, e) => {
Assert.Equal (-1, e.KeyEvent.KeyValue);
Assert.Equal (shift, e.KeyEvent.IsShift);
Assert.Equal (alt, e.KeyEvent.IsAlt);
Assert.Equal (control, e.KeyEvent.IsCtrl);
Assert.False (keyDown);
Assert.False (view.IsKeyDown);
keyDown = true;
};
view.KeyPress += (s, e) => {
keyPress = true;
};
view.KeyUp += (s, e) => {
Assert.Equal (-1, e.KeyEvent.KeyValue);
Assert.Equal (shift, e.KeyEvent.IsShift);
Assert.Equal (alt, e.KeyEvent.IsAlt);
Assert.Equal (control, e.KeyEvent.IsCtrl);
Assert.False (keyUp);
Assert.False (view.IsKeyUp);
keyUp = true;
};
Application.Top.Add (view);
Console.MockKeyPresses.Push (new ConsoleKeyInfo ('\0', (ConsoleKey)'\0', shift, alt, control));
Application.Iteration += () => Application.RequestStop ();
Assert.True (view.CanFocus);
Application.Run ();
Application.Shutdown ();
Assert.True (keyDown);
Assert.False (keyPress);
Assert.True (keyUp);
Assert.True (view.IsKeyDown);
Assert.False (view.IsKeyPress);
Assert.True (view.IsKeyUp);
}
}
}

View File

@@ -0,0 +1,327 @@
using NStack;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Xunit;
using Xunit.Abstractions;
//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui.ViewTests {
public class AbsoluteLayoutTests {
readonly ITestOutputHelper output;
public AbsoluteLayoutTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void AbsoluteLayout_Constructor ()
{
var frame = new Rect (1, 2, 3, 4);
var v = new View (frame);
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (frame, v.Frame);
Assert.Equal (new Rect(0, 0, frame.Width, frame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
v = new View (frame, "v");
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (frame, v.Frame);
Assert.Equal (new Rect (0, 0, frame.Width, frame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
v = new View (frame.X, frame.Y, "v");
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
// BUGBUG: v2 - I think the default size should be 0,0
Assert.Equal (new Rect(frame.X, frame.Y, 1, 1), v.Frame);
Assert.Equal (new Rect (0, 0, 1, 1), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
}
[Fact]
public void AbsoluteLayout_Change_Frame ()
{
var frame = new Rect (1, 2, 3, 4);
var newFrame = new Rect (1, 2, 30, 40);
var v = new View (frame);
v.Frame = newFrame;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
v = new View (frame.X, frame.Y, "v");
v.Frame = newFrame;
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
newFrame = new Rect (10, 20, 30, 40);
v = new View (frame);
v.Frame = newFrame;
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
v = new View (frame.X, frame.Y, "v");
v.Frame = newFrame;
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Null (v.Height);
Assert.Null (v.Width);
}
[Fact]
public void AbsoluteLayout_Change_Height_or_Width_Absolute ()
{
var frame = new Rect (1, 2, 3, 4);
var newFrame = new Rect (1, 2, 30, 40);
var v = new View (frame);
v.Height = newFrame.Height;
v.Width = newFrame.Width;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Null (v.X);
Assert.Null (v.Y);
Assert.Equal ($"Absolute({newFrame.Height})", v.Height.ToString());
Assert.Equal ($"Absolute({newFrame.Width})", v.Width.ToString ());
}
[Fact]
public void AbsoluteLayout_Change_Height_or_Width_NotAbsolute ()
{
var v = new View (Rect.Empty);
v.Height = Dim.Fill ();
v.Width = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
}
[Fact]
public void AbsoluteLayout_Change_Height_or_Width_Null ()
{
var v = new View (Rect.Empty);
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
}
[Fact]
public void AbsoluteLayout_Change_X_or_Y_Absolute ()
{
var frame = new Rect (1, 2, 3, 4);
var newFrame = new Rect (10, 20, 3, 4);
var v = new View (frame);
v.X = newFrame.X;
v.Y = newFrame.Y;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
Assert.Equal (newFrame, v.Frame);
Assert.Equal (new Rect (0, 0, newFrame.Width, newFrame.Height), v.Bounds); // With Absolute Bounds *is* deterministic before Layout
Assert.Equal ($"Absolute({newFrame.X})", v.X.ToString ());
Assert.Equal ($"Absolute({newFrame.Y})", v.Y.ToString ());
Assert.Null (v.Height);
Assert.Null (v.Width);
}
[Fact]
public void AbsoluteLayout_Change_X_or_Y_NotAbsolute ()
{
var v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
}
[Fact]
public void AbsoluteLayout_Change_X_or_Y_Null ()
{
var v = new View (Rect.Empty);
v.X = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v = new View (Rect.Empty);
v.X = Pos.Center ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
v.X = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v = new View (Rect.Empty);
v.Y = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v = new View (Rect.Empty);
v.Y = Pos.Center ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
v.Y = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
}
[Fact]
public void AbsoluteLayout_Change_X_Y_Height_Width_Absolute ()
{
var v = new View (Rect.Empty);
v.X = 1;
v.Y = 2;
v.Height = 3;
v.Width = 4;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = null;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = 1;
v.Y = null;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = 2;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = null;
v.Height = 3;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = null;
v.Height = null;
v.Width = 4;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
}
[Fact]
public void AbsoluteLayout_Change_X_Y_Height_Width_Null ()
{
var v = new View (Rect.Empty);
v.X = null;
v.Y = null;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
v = new View (Rect.Empty);
v.X = Pos.Center ();
v.Y = Pos.Center ();
v.Width = Dim.Fill ();
v.Height = Dim.Fill ();
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // BUGBUG: v2 - Changing the Height or Width should change the LayoutStyle
// BUGBUG: v2 - If all of X, Y, Width, and Height are null or Absolute(n), isn't that the same as LayoutStyle.Absoulte?
v.X = null;
v.Y = null;
v.Height = null;
v.Width = null;
Assert.True (v.LayoutStyle == LayoutStyle.Absolute); // We never automatically change to Absolute from Computed??
}
[Fact]
public void AbsoluteLayout_Layout ()
{
var superRect = new Rect (0, 0, 100, 100);
var super = new View (superRect, "super");
Assert.True (super.LayoutStyle == LayoutStyle.Absolute);
var v1 = new View () {
X = 0,
Y = 0,
Width = 10,
Height = 10
};
// BUGBUG: v2 - This should be LayoutStyle.Absolute
Assert.True (v1.LayoutStyle == LayoutStyle.Computed);
var v2 = new View () {
X = 10,
Y = 10,
Width = 10,
Height = 10
};
// BUGBUG: v2 - This should be LayoutStyle.Absolute
Assert.True (v1.LayoutStyle == LayoutStyle.Computed);
super.Add (v1, v2);
super.LayoutSubviews ();
Assert.Equal (new Rect (0, 0, 10, 10), v1.Frame);
Assert.Equal (new Rect (10, 10, 10, 10), v2.Frame);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,74 @@
using NStack;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Xunit;
using Xunit.Abstractions;
//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
// Alias Console to MockConsole so we don't accidentally use Console
using Console = Terminal.Gui.FakeConsole;
namespace Terminal.Gui.ViewTests {
public class TitleTests {
readonly ITestOutputHelper output;
public TitleTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void Set_Title_Fires_TitleChanging ()
{
var r = new View ();
Assert.Equal (ustring.Empty, r.Title);
string expectedOld = null;
string expectedDuring = null;
string expectedAfter = null;
bool cancel = false;
r.TitleChanging += (s, args) => {
Assert.Equal (expectedOld, args.OldTitle);
Assert.Equal (expectedDuring, args.NewTitle);
args.Cancel = cancel;
};
expectedOld = string.Empty;
r.Title = expectedDuring = expectedAfter = "title";
Assert.Equal (expectedAfter, r.Title.ToString ());
expectedOld = r.Title.ToString ();
r.Title = expectedDuring = expectedAfter = "a different title";
Assert.Equal (expectedAfter, r.Title.ToString ());
// Now setup cancelling the change and change it back to "title"
cancel = true;
expectedOld = r.Title.ToString ();
r.Title = expectedDuring = "title";
Assert.Equal (expectedAfter, r.Title.ToString ());
r.Dispose ();
}
[Fact]
public void Set_Title_Fires_TitleChanged ()
{
var r = new View ();
Assert.Equal (ustring.Empty, r.Title);
string expectedOld = null;
string expected = null;
r.TitleChanged += (s, args) => {
Assert.Equal (expectedOld, args.OldTitle);
Assert.Equal (r.Title, args.NewTitle);
};
expected = "title";
expectedOld = r.Title.ToString ();
r.Title = expected;
Assert.Equal (expected, r.Title.ToString ());
}
}
}

1550
UnitTests/View/ViewTests.cs Normal file

File diff suppressed because it is too large Load Diff