Resolving merge conflicts.

This commit is contained in:
BDisp
2023-04-04 12:51:14 +01:00
88 changed files with 6422 additions and 5962 deletions

View File

@@ -8,6 +8,7 @@ using Xunit;
using System.Globalization;
using Xunit.Abstractions;
using NStack;
using static Terminal.Gui.Application;
namespace Terminal.Gui.TopLevelTests {
@@ -19,9 +20,35 @@ namespace Terminal.Gui.TopLevelTests {
this.output = output;
}
//[Fact]
//[AutoInitShutdown]
//public void Default_Has_Border ()
//{
// var d = (FakeDriver)Application.Driver;
// d.SetBufferSize (20, 5);
// Application.RunState runstate = null;
// var title = "Title";
// var btnText = "ok";
// var buttonRow = $"{d.VLine}{d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
// var width = buttonRow.Length;
// var topRow = $"┌┤{title} {new string (d.HLine.ToString () [0], width - title.Length - 2)}├┐";
// var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
// var dlg = new Dialog (title, new Button (btnText));
// Application.Begin (dlg);
// TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
// Application.End (runstate);
//}
private (Application.RunState, Dialog) RunButtonTestDialog (string title, int width, Dialog.ButtonAlignments align, params Button [] btns)
{
var dlg = new Dialog (title, width, 3, btns) { ButtonAlignment = align };
var dlg = new Dialog (title, width, 1, btns) {
ButtonAlignment = align,
};
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
return (Application.Begin (dlg), dlg);
}
@@ -35,36 +62,65 @@ namespace Terminal.Gui.TopLevelTests {
var title = "1234";
// E.g "|[ ok ]|"
var btnText = "ok";
var buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
var buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
var width = buttonRow.Length;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (width, 3);
d.SetBufferSize (width, 1);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Wider
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
width = buttonRow.Length;
d.SetBufferSize (width, 1);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -85,34 +141,32 @@ namespace Terminal.Gui.TopLevelTests {
var buttonRow = $@"{d.VLine} {btn1} {btn2} {d.VLine}";
var width = buttonRow.Length;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (buttonRow.Length, 3);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $@"{d.VLine}{btn1} {btn2}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $@"{d.VLine} {btn1} {btn2}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $@"{d.VLine}{btn1} {btn2} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -134,8 +188,6 @@ namespace Terminal.Gui.TopLevelTests {
var buttonRow = $@"{d.VLine} {btn1} {btn2} {d.VLine}";
var width = buttonRow.Length;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (buttonRow.Length, 3);
@@ -149,7 +201,7 @@ namespace Terminal.Gui.TopLevelTests {
button1.Visible = false;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
buttonRow = $@"{d.VLine} {btn2} {d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
@@ -160,7 +212,7 @@ namespace Terminal.Gui.TopLevelTests {
button1.Visible = false;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
buttonRow = $@"{d.VLine} {btn2}{d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
@@ -170,7 +222,7 @@ namespace Terminal.Gui.TopLevelTests {
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, button1, button2);
button1.Visible = false;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
@@ -181,7 +233,7 @@ namespace Terminal.Gui.TopLevelTests {
button1.Visible = false;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
buttonRow = $@"{d.VLine} {btn2} {d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -204,34 +256,32 @@ namespace Terminal.Gui.TopLevelTests {
var buttonRow = $@"{d.VLine} {btn1} {btn2} {btn3} {d.VLine}";
var width = buttonRow.Length;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (buttonRow.Length, 3);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $@"{d.VLine}{btn1} {btn2} {btn3}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $@"{d.VLine} {btn1} {btn2} {btn3}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $@"{d.VLine}{btn1} {btn2} {btn3} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -257,34 +307,32 @@ namespace Terminal.Gui.TopLevelTests {
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
var width = buttonRow.Length;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (buttonRow.Length, 3);
// Default - Center
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -310,37 +358,32 @@ namespace Terminal.Gui.TopLevelTests {
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
var width = buttonRow.Length;
var topRow = "34 ───────────────────────────";
var bottomRow = "──────────────────────────────";
d.SetBufferSize (30, 3);
d.SetBufferSize (30, 1);
// Default - Center
buttonRow = $"yes ] {btn2} {btn3} [ never";
Assert.NotEqual (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"es ] {btn2} {btn3} [ neve";
Assert.NotEqual (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
Application.End (runstate);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
// Right
buttonRow = $" yes ] {btn2} {btn3} [ neve";
Assert.NotEqual (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
Application.End (runstate);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
// Left
buttonRow = $"es ] {btn2} {btn3} [ never ";
buttonRow = $"es ] {btn2} {btn3} [ never";
Assert.NotEqual (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
Application.End (runstate);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
}
[Fact]
@@ -365,37 +408,35 @@ namespace Terminal.Gui.TopLevelTests {
var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}";
// Note extra spaces to make dialog even wider
// 12345 123456
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
// 123456 123456
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
var width = ustring.Make (buttonRow).ConsoleWidth;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (width, 3);
// Default - Center
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4}{d.VLine}";
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, ustring.Make (buttonRow).ConsoleWidth);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4}{d.VLine}";
buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, ustring.Make (buttonRow).ConsoleWidth);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4} {d.VLine}";
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4} {d.VLine}";
Assert.Equal (width, ustring.Make (buttonRow).ConsoleWidth);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -420,37 +461,35 @@ namespace Terminal.Gui.TopLevelTests {
var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}";
// Note extra spaces to make dialog even wider
// 12345 123456
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
// 123456 1234567
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
var width = buttonRow.Length;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (buttonRow.Length, 3);
d.SetBufferSize (buttonRow.Length, 1);
// Default - Center
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4}{d.VLine}";
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4}{d.VLine}";
buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4} {d.VLine}";
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -466,12 +505,10 @@ namespace Terminal.Gui.TopLevelTests {
var buttonRow = $"{d.VLine} {d.VLine}";
var width = buttonRow.Length;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (buttonRow.Length, 3);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -489,12 +526,10 @@ namespace Terminal.Gui.TopLevelTests {
var buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
var width = buttonRow.Length;
var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
d.SetBufferSize (buttonRow.Length, 3);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -514,65 +549,70 @@ namespace Terminal.Gui.TopLevelTests {
// We test with one button first, but do this to get the width right for 2
var width = $@"{d.VLine} {btn1} {btn2} {d.VLine}".Length;
d.SetBufferSize (width, 3);
var topRow = $"{d.ULCorner} {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}{d.URCorner}";
var bottomRow = $"{d.LLCorner}{new string (d.HLine.ToString () [0], width - 2)}{d.LRCorner}";
d.SetBufferSize (width, 1);
// Default (center)
var dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Center };
var dlg = new Dialog (title, width, 1, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Center };
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
runstate = Application.Begin (dlg);
var buttonRow = $"{d.VLine} {btn1} {d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
var buttonRow = $"{d.VLine} {btn1} {d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
// Now add a second button
buttonRow = $"{d.VLine} {btn1} {btn2} {d.VLine}";
dlg.AddButton (new Button (btn2Text));
bool first = false;
Application.RunMainLoopIteration (ref runstate, true, ref first);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Justify };
dlg = new Dialog (title, width, 1, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Justify };
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
runstate = Application.Begin (dlg);
buttonRow = $"{d.VLine} {btn1}{d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
// Now add a second button
buttonRow = $"{d.VLine}{btn1} {btn2}{d.VLine}";
dlg.AddButton (new Button (btn2Text));
first = false;
Application.RunMainLoopIteration (ref runstate, true, ref first);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Right };
dlg = new Dialog (title, width, 1, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Right };
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
runstate = Application.Begin (dlg);
buttonRow = $"{d.VLine}{new string (' ', width - btn1.Length - 2)}{btn1}{d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
// Now add a second button
buttonRow = $"{d.VLine} {btn1} {btn2}{d.VLine}";
dlg.AddButton (new Button (btn2Text));
first = false;
Application.RunMainLoopIteration (ref runstate, true, ref first);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Left };
dlg = new Dialog (title, width, 1, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Left };
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
runstate = Application.Begin (dlg);
buttonRow = $"{d.VLine}{btn1}{new string (' ', width - btn1.Length - 2)}{d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
// Now add a second button
buttonRow = $"{d.VLine}{btn1} {btn2} {d.VLine}";
dlg.AddButton (new Button (btn2Text));
first = false;
Application.RunMainLoopIteration (ref runstate, true, ref first);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
@@ -611,7 +651,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.True (btn1.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
} else if (iterations == 1) {
expected = @"
Hey ─────────────────────────────────────────────────────────────┐
Hey─────────────────────────────────────────────────────────────┐
│ │
│ │
│ │
@@ -637,7 +677,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.True (btn2.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
} else if (iterations == 2) {
TestHelpers.AssertDriverContentsWithFrameAre (@"
Hey ─────────────────────────────────────────────────────────────┐
Hey─────────────────────────────────────────────────────────────┐
│ │
│ │
│ │
@@ -645,7 +685,7 @@ namespace Terminal.Gui.TopLevelTests {
│ │
│ │
│ │
│ ┌ hey ─────────────────────────────────────────┐ │
│ ┌hey─────────────────────────────────────────┐ │
│ │ ya │ │
│ │ │ │
│ │ [◦ ok ◦] │ │
@@ -676,5 +716,75 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Equal (4, iterations);
}
[Fact, AutoInitShutdown]
public void Dialog_In_Window_With_Size_One_Button_Aligns ()
{
((FakeDriver)Application.Driver).SetBufferSize (20, 5);
var win = new Window ();
int iterations = 0;
Application.Iteration += () => {
if (++iterations > 2) {
Application.RequestStop ();
}
};
win.Loaded += (s, a) => {
var dlg = new Dialog ("Test", 18, 3, new Button ("Ok"));
dlg.Loaded += (s, a) => {
Application.Refresh ();
var expected = @"
┌──────────────────┐
│┌┤Test├──────────┐│
││ [ Ok ] ││
│└────────────────┘│
└──────────────────┘";
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
};
Application.Run (dlg);
};
Application.Run (win);
}
// [Theory, AutoInitShutdown]
// [InlineData (5)]
// //[InlineData (6)]
// //[InlineData (7)]
// //[InlineData (8)]
// //[InlineData (9)]
// public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height)
// {
// ((FakeDriver)Application.Driver).SetBufferSize (20, height);
// var win = new Window ();
// Application.Iteration += () => {
// var dlg = new Dialog ("Test", new Button ("Ok"));
// dlg.LayoutComplete += (s, a) => {
// Application.Refresh ();
// // BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)??
// var expected = @"
//┌┌┤Test├─────────┐─┐
//││ │ │
//││ [ Ok ] │ │
//│└───────────────┘ │
//└──────────────────┘";
// _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
// dlg.RequestStop ();
// win.RequestStop ();
// };
// Application.Run (dlg);
// };
// Application.Run (win);
// Application.Shutdown ();
// }
}
}

View File

@@ -32,7 +32,7 @@ namespace Terminal.Gui.TopLevelTests {
Application.Shutdown ();
#if DEBUG_IDISPOSABLE
Assert.Equal (2, Responder.Instances.Count);
Assert.Equal (8, Responder.Instances.Count);
Assert.True (Responder.Instances [0].WasDisposed);
Assert.True (Responder.Instances [1].WasDisposed);
#endif
@@ -49,7 +49,7 @@ namespace Terminal.Gui.TopLevelTests {
Application.Shutdown ();
#if DEBUG_IDISPOSABLE
Assert.Equal (2, Responder.Instances.Count);
Assert.Equal (8, Responder.Instances.Count);
Assert.True (Responder.Instances [0].WasDisposed);
Assert.True (Responder.Instances [1].WasDisposed);
#endif

View File

@@ -31,7 +31,7 @@ namespace Terminal.Gui.TopLevelTests {
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
Title ───────────────────────────────────────┐
Title───────────────────────────────────────┐
│ Message │
│ │
│ │
@@ -73,7 +73,7 @@ namespace Terminal.Gui.TopLevelTests {
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
About UI Catalog ──────────────────────────────────────────┐
About UI Catalog──────────────────────────────────────────┐
│ A comprehensive sample library for │
│ │
│ _______ _ _ _____ _ │
@@ -97,7 +97,7 @@ namespace Terminal.Gui.TopLevelTests {
}
[Fact, AutoInitShutdown]
public void MessageBox_With_A_Lower_Fixed_Size ()
public void MessageBox_With_A_Smaller_Fixed_Size ()
{
var iterations = -1;
Application.Begin (Application.Top);
@@ -112,7 +112,7 @@ namespace Terminal.Gui.TopLevelTests {
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
─────
┤Tit├
│Messa│
│ ge │
│ Ok ◦│
@@ -142,7 +142,7 @@ namespace Terminal.Gui.TopLevelTests {
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
Title ──┐
Title──┐
│ Message │
│ │
│[◦ Ok ◦] │
@@ -172,7 +172,7 @@ namespace Terminal.Gui.TopLevelTests {
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
mywindow ────────────────────────────────────────────────────────────────────┐
mywindow────────────────────────────────────────────────────────────────────┐
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
@@ -225,7 +225,7 @@ namespace Terminal.Gui.TopLevelTests {
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
mywindow ────────────────────────────────────────────────────────────────────┐
mywindow────────────────────────────────────────────────────────────────────┐
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
@@ -268,7 +268,7 @@ namespace Terminal.Gui.TopLevelTests {
iterations++;
if (iterations == 0) {
MessageBox.Query ("mywindow", new string ('f', 2000), 0, null, false, "ok");
MessageBox.Query ("mywindow", new string ('f', 2000), 0, false, "ok");
Application.RequestStop ();
} else if (iterations == 1) {
@@ -301,7 +301,7 @@ ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
for (int i = 0; i < 1000; i++)
sb.Append ("ff ");
MessageBox.Query ("mywindow", sb.ToString (), 0, null, false, "ok");
MessageBox.Query ("mywindow", sb.ToString (), 0, false, "ok");
Application.RequestStop ();
} else if (iterations == 1) {
@@ -334,13 +334,13 @@ ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
iterations++;
if (iterations == 0) {
MessageBox.Query ("mywindow", message, 0, null, wrapMessage, "ok");
MessageBox.Query ("mywindow", message, 0, wrapMessage, "ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
mywindow ────────────────────────────────────┐
mywindow────────────────────────────────────┐
│ │
│ │
│ [◦ ok ◦] │

View File

@@ -34,6 +34,8 @@ namespace Terminal.Gui.TopLevelTests {
public void Create_Toplevel ()
{
var top = Toplevel.Create ();
top.BeginInit ();
top.EndInit ();
Assert.Equal (new Rect (0, 0, Application.Driver.Cols, Application.Driver.Rows), top.Bounds);
}
@@ -484,7 +486,6 @@ namespace Terminal.Gui.TopLevelTests {
Assert.True (win1.IsMdiChild);
Assert.Null (top.Focused);
Assert.Null (top.MostFocused);
Assert.Equal (win1.Subviews [0], win1.Focused);
Assert.Equal (tf1W1, win1.MostFocused);
Assert.True (win1.IsMdiChild);
Assert.Single (Application.MdiChildes);
@@ -497,7 +498,6 @@ namespace Terminal.Gui.TopLevelTests {
Assert.True (win2.IsMdiChild);
Assert.Null (top.Focused);
Assert.Null (top.MostFocused);
Assert.Equal (win2.Subviews [0], win2.Focused);
Assert.Equal (tf1W2, win2.MostFocused);
Assert.Equal (2, Application.MdiChildes.Count);
@@ -681,35 +681,25 @@ namespace Terminal.Gui.TopLevelTests {
[Fact, AutoInitShutdown]
public void Mouse_Drag_On_Top_With_Superview_Null ()
{
var menu = new MenuBar (new MenuBarItem [] {
new MenuBarItem("File", new MenuItem [] {
new MenuItem("New", "", null)
})
});
var sbar = new StatusBar (new StatusItem [] {
new StatusItem(Key.N, "~CTRL-N~ New", null)
});
var win = new Window ("Window");
var win = new Window ();
var top = Application.Top;
top.Add (menu, sbar, win);
top.Add (win);
var iterations = -1;
Application.Iteration = () => {
iterations++;
if (iterations == 0) {
((FakeDriver)Application.Driver).SetBufferSize (40, 15);
MessageBox.Query ("About", "Hello Word", "Ok");
MessageBox.Query ("", "Hello Word", "Ok");
} else if (iterations == 1) TestHelpers.AssertDriverContentsWithFrameAre (@"
File
Window ──────────────────────────────┐
} else if (iterations == 1) {
TestHelpers.AssertDriverContentsWithFrameAre (@"
──────────────────────────────────────┐
│ │
│ │
│ │
┌ About ───────────────┐
│ ┌──────────────────────┐ │
│ │ Hello Word │ │
│ │ │ │
│ │ [◦ Ok ◦] │ │
@@ -717,9 +707,10 @@ namespace Terminal.Gui.TopLevelTests {
│ │
│ │
│ │
│ │
└──────────────────────────────────────┘
CTRL-N New ", output);
else if (iterations == 2) {
", output);
} else if (iterations == 2) {
Assert.Null (Application.MouseGrabView);
// Grab the mouse
ReflectionTools.InvokePrivate (
@@ -736,7 +727,7 @@ namespace Terminal.Gui.TopLevelTests {
} else if (iterations == 3) {
Assert.Equal (Application.Current, Application.MouseGrabView);
// Grab to left
// Drag to left
ReflectionTools.InvokePrivate (
typeof (Application),
"ProcessMouseEvent",
@@ -753,12 +744,12 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Equal (Application.Current, Application.MouseGrabView);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
┌ Window ──────────────────────────────┐
┌──────────────────────────────────────┐
│ │
│ │
│ │
┌ About ───────────────┐
│ ┌──────────────────────┐ │
│ │ Hello Word │ │
│ │ │ │
│ │ [◦ Ok ◦] │ │
@@ -766,13 +757,13 @@ namespace Terminal.Gui.TopLevelTests {
│ │
│ │
│ │
└──────────────────────────────────────┘
CTRL-N New ", output);
│ │
└──────────────────────────────────────┘", output);
Assert.Equal (Application.Current, Application.MouseGrabView);
} else if (iterations == 5) {
Assert.Equal (Application.Current, Application.MouseGrabView);
// Grab to top
// Drag up
ReflectionTools.InvokePrivate (
typeof (Application),
"ProcessMouseEvent",
@@ -789,11 +780,11 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Equal (Application.Current, Application.MouseGrabView);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
┌ Window ──────────────────────────────┐
┌──────────────────────────────────────┐
│ │
│ │
┌ About ───────────────┐
│ ┌──────────────────────┐ │
│ │ Hello Word │ │
│ │ │ │
│ │ [◦ Ok ◦] │ │
@@ -802,8 +793,8 @@ namespace Terminal.Gui.TopLevelTests {
│ │
│ │
│ │
└──────────────────────────────────────┘
CTRL-N New ", output);
│ │
└──────────────────────────────────────┘", output);
Assert.Equal (Application.Current, Application.MouseGrabView);
Assert.Equal (new Rect (7, 4, 24, 5), Application.MouseGrabView.Frame);
@@ -832,27 +823,22 @@ namespace Terminal.Gui.TopLevelTests {
[Fact, AutoInitShutdown]
public void Mouse_Drag_On_Top_With_Superview_Not_Null ()
{
var menu = new MenuBar (new MenuBarItem [] {
new MenuBarItem("File", new MenuItem [] {
new MenuItem("New", "", null)
})
});
var sbar = new StatusBar (new StatusItem [] {
new StatusItem(Key.N, "~CTRL-N~ New", null)
});
var win = new Window ("Window") {
var win = new Window () {
X = 3,
Y = 2,
Width = Dim.Fill (10),
Height = Dim.Fill (5)
};
var top = Application.Top;
top.Add (menu, sbar, win);
top.Add (win);
var iterations = -1;
int movex = 0;
int movey = 0;
var location = new Rect (win.Frame.X, win.Frame.Y, 7, 3);
Application.Iteration = () => {
iterations++;
if (iterations == 0) {
@@ -864,106 +850,77 @@ namespace Terminal.Gui.TopLevelTests {
typeof (Application),
"ProcessMouseEvent",
new MouseEvent () {
X = 4,
Y = 2,
X = win.Frame.X,
Y = win.Frame.Y,
Flags = MouseFlags.Button1Pressed
});
Assert.Equal (win, Application.MouseGrabView);
Assert.Equal (new Rect (3, 2, 7, 3), Application.MouseGrabView.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
┌─────┐
│ │
└─────┘
CTRL-N New", output);
Assert.Equal (location, Application.MouseGrabView.Frame);
} else if (iterations == 1) {
Assert.Equal (win, Application.MouseGrabView);
// Grab to left
// Drag to left
movex = 1;
movey = 0;
ReflectionTools.InvokePrivate (
typeof (Application),
"ProcessMouseEvent",
new MouseEvent () {
X = 5,
Y = 2,
X = win.Frame.X + movex,
Y = win.Frame.Y + movey,
Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
});
Assert.Equal (win, Application.MouseGrabView);
} else if (iterations == 2) {
// we should have moved +1, +0
Assert.Equal (win, Application.MouseGrabView);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
┌────┐
│ │
└────┘
CTRL-N New", output);
Assert.Equal (win, Application.MouseGrabView);
Assert.Equal (new Rect (4, 2, 6, 3), Application.MouseGrabView.Frame);
location.Offset (movex, movey);
Assert.Equal (location, Application.MouseGrabView.Frame);
} else if (iterations == 3) {
Assert.Equal (win, Application.MouseGrabView);
// Grab to top
// Drag up
movex = 0;
movey = -1;
ReflectionTools.InvokePrivate (
typeof (Application),
"ProcessMouseEvent",
new MouseEvent () {
X = 5,
Y = 1,
X = win.Frame.X + movex,
Y = win.Frame.Y + movey,
Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
});
Assert.Equal (win, Application.MouseGrabView);
} else if (iterations == 4) {
// we should have moved +0, -1
Assert.Equal (win, Application.MouseGrabView);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
┌────┐
│ │
│ │
└────┘
CTRL-N New", output);
Assert.Equal (win, Application.MouseGrabView);
Assert.Equal (new Rect (4, 1, 6, 4), Application.MouseGrabView.Frame);
location.Offset (movex, movey);
Assert.Equal (location, Application.MouseGrabView.Frame);
} else if (iterations == 5) {
Assert.Equal (win, Application.MouseGrabView);
// Ungrab the mouse
movex = 0;
movey = 0;
ReflectionTools.InvokePrivate (
typeof (Application),
"ProcessMouseEvent",
new MouseEvent () {
X = 7,
Y = 4,
X = win.Frame.X + movex,
Y = win.Frame.Y + movey,
Flags = MouseFlags.Button1Released
});
Assert.Null (Application.MouseGrabView);
} else if (iterations == 8) Application.RequestStop ();
} else if (iterations == 8) {
Application.RequestStop ();
}
};
Application.Run ();
@@ -1061,13 +1018,14 @@ namespace Terminal.Gui.TopLevelTests {
Assert.False (top.IsLoaded);
Assert.False (subTop.IsLoaded);
Assert.Equal (new Rect (0, 0, 20, 10), view.Frame);
Assert.Equal (new Rect (0, 0, 20, 10), view.NeedDisplay);
// BUGBUG: v2 - SetNeedsDisplay is all goofed up. Disabling test for now
//Assert.Equal (new Rect (0, 0, 20, 10), view._needsDisplay);
view.LayoutStarted += view_LayoutStarted;
void view_LayoutStarted (object sender, LayoutEventArgs e)
{
Assert.Equal (new Rect (0, 0, 20, 10), view.NeedDisplay);
Assert.Equal (new Rect (0, 0, 20, 10), view._needsDisplay);
view.LayoutStarted -= view_LayoutStarted;
}
@@ -1079,12 +1037,12 @@ namespace Terminal.Gui.TopLevelTests {
view.Frame = new Rect (1, 3, 10, 5);
Assert.Equal (new Rect (1, 3, 10, 5), view.Frame);
Assert.Equal (new Rect (0, 0, 10, 5), view.NeedDisplay);
Assert.Equal (new Rect (0, 0, 10, 5), view._needsDisplay);
view.Redraw (view.Bounds);
view.Frame = new Rect (1, 3, 10, 5);
Assert.Equal (new Rect (1, 3, 10, 5), view.Frame);
Assert.Equal (new Rect (0, 0, 10, 5), view.NeedDisplay);
Assert.Equal (new Rect (0, 0, 10, 5), view._needsDisplay);
}
[Fact, AutoInitShutdown]
@@ -1111,7 +1069,7 @@ namespace Terminal.Gui.TopLevelTests {
Window ───────────────────────────┴
Window───────────────────────────┴
│ ░
│ ░
│ ░
@@ -1156,7 +1114,7 @@ namespace Terminal.Gui.TopLevelTests {
Window ────────────────────────░
Window────────────────────────░
│ ░
│ ░
│ ░
@@ -1183,7 +1141,7 @@ namespace Terminal.Gui.TopLevelTests {
TestHelpers.AssertDriverContentsWithFrameAre (@"
Window ────────────────────────────│
Window────────────────────────────│
│ ┴
│ ░
│ ░
@@ -1222,18 +1180,8 @@ namespace Terminal.Gui.TopLevelTests {
[Fact, AutoInitShutdown]
public void Dialog_Bounds_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom ()
{
var menu = new MenuBar (new MenuBarItem [] {
new MenuBarItem("File", new MenuItem [] {
new MenuItem("New", "", null)
})
});
var sb = new StatusBar (new StatusItem [] {
new StatusItem(Key.N, "~CTRL-N~ New", null)
});
var top = Application.Top;
top.Add (menu, sb);
var dialog = new Dialog ("Dialog", 20, 3, new Button ("Ok"));
var dialog = new Dialog ("", 20, 3, new Button ("Ok"));
Application.Begin (top);
((FakeDriver)Application.Driver).SetBufferSize (40, 10);
Application.Begin (dialog);
@@ -1241,16 +1189,10 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Equal (new Rect (0, 0, 40, 10), top.Frame);
Assert.Equal (new Rect (10, 3, 20, 3), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
┌ Dialog ──────────┐
┌──────────────────┐
│ [ Ok ] │
└──────────────────┘
CTRL-N New ", output);
", output);
Assert.Null (Application.MouseGrabView);
@@ -1276,21 +1218,15 @@ namespace Terminal.Gui.TopLevelTests {
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 40, 10), top.Frame);
Assert.Equal (new Rect (0, 1, 20, 3), dialog.Frame);
Assert.Equal (new Rect (0, 0, 20, 3), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
┌ Dialog ──────────┐
┌──────────────────┐
│ [ Ok ] │
└──────────────────┘
CTRL-N New ", output);
", output);
// Changes Top size to same size as Dialog more menu and scroll bar
((FakeDriver)Application.Driver).SetBufferSize (20, 5);
((FakeDriver)Application.Driver).SetBufferSize (20, 3);
ReflectionTools.InvokePrivate (
typeof (Application),
"ProcessMouseEvent",
@@ -1301,17 +1237,16 @@ namespace Terminal.Gui.TopLevelTests {
});
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 20, 5), top.Frame);
Assert.Equal (new Rect (0, 1, 20, 3), dialog.Frame);
Assert.Equal (new Rect (0, 0, 20, 3), top.Frame);
Assert.Equal (new Rect (0, 0, 20, 3), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
┌ Dialog ──────────┐
┌──────────────────┐
│ [ Ok ] │
└──────────────────┘
CTRL-N New ", output);
", output);
// Changes Top size smaller than Dialog size
((FakeDriver)Application.Driver).SetBufferSize (19, 3);
((FakeDriver)Application.Driver).SetBufferSize (19, 2);
ReflectionTools.InvokePrivate (
typeof (Application),
"ProcessMouseEvent",
@@ -1322,29 +1257,27 @@ namespace Terminal.Gui.TopLevelTests {
});
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 19, 3), top.Frame);
Assert.Equal (new Rect (-1, 1, 20, 3), dialog.Frame);
Assert.Equal (new Rect (0, 0, 19, 2), top.Frame);
Assert.Equal (new Rect (-1, 0, 20, 3), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
Dialog ──────────┐
[ Ok ] │", output);
──────────────────┐
[ Ok ] │
", output);
ReflectionTools.InvokePrivate (
typeof (Application),
"ProcessMouseEvent",
new MouseEvent () {
X = 18,
Y = 3,
Y = 1,
Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
});
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 19, 3), top.Frame);
Assert.Equal (new Rect (18, 2, 20, 3), dialog.Frame);
Assert.Equal (new Rect (0, 0, 19, 2), top.Frame);
Assert.Equal (new Rect (18, 1, 20, 3), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
CTRL-N New ┌", output);
┌", output);
// On a real app we can't go beyond the SuperView bounds
ReflectionTools.InvokePrivate (
@@ -1352,17 +1285,14 @@ namespace Terminal.Gui.TopLevelTests {
"ProcessMouseEvent",
new MouseEvent () {
X = 19,
Y = 4,
Y = 2,
Flags = MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition
});
Application.Refresh ();
Assert.Equal (new Rect (0, 0, 19, 3), top.Frame);
Assert.Equal (new Rect (0, 0, 19, 2), top.Frame);
Assert.Equal (new Rect (19, 2, 20, 3), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
File
CTRL-N New", output);
TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
}
[Fact, AutoInitShutdown]
@@ -1386,7 +1316,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Null (Application.MouseGrabView);
Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
Single smaller Dialog ─────┐
Single smaller Dialog─────┐
│ How should I've to react. │
│Cleaning all chunk trails or│
│ setting the 'Cols' and │
@@ -1412,7 +1342,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
Single smaller Dialog ─────┐
Single smaller Dialog─────┐
│ How should I've to react. │
│Cleaning all chunk trails or│
│ setting the 'Cols' and │
@@ -1437,7 +1367,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Equal (dialog, Application.MouseGrabView);
Assert.Equal (new Rect (20, 10, 30, 10), dialog.Frame);
TestHelpers.AssertDriverContentsWithFrameAre (@"
Single smaller Dialog ─────┐
Single smaller Dialog─────┐
│ How should I've to react. │
│Cleaning all chunk trails or│
│ setting the 'Cols' and │

View File

@@ -17,6 +17,8 @@ namespace Terminal.Gui.TopLevelTests {
this.output = output;
}
// BUGBUG: v2 - move Title related tests from here to `ViewTests.cs` or to a new `TitleTests.cs`
[Fact]
public void New_Initializes ()
{
@@ -38,7 +40,6 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Null (r.Y);
Assert.False (r.IsCurrentTop);
Assert.Empty (r.Id);
Assert.NotEmpty (r.Subviews);
Assert.False (r.WantContinuousButtonPressed);
Assert.False (r.WantMousePositionReports);
Assert.Null (r.SuperView);
@@ -50,7 +51,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.NotNull (r);
Assert.Equal ("title", r.Title);
Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
Assert.Equal ("Window()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
Assert.Equal ("Window(title)({X=0,Y=0,Width=0,Height=0})", r.ToString ());
Assert.True (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rect (0, 0, 0, 0), r.Bounds);
@@ -62,8 +63,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Null (r.X); // All view Pos are initialized now in the IsAdded setter,
Assert.Null (r.Y); // avoiding Pos errors.
Assert.False (r.IsCurrentTop);
Assert.Empty (r.Id);
Assert.NotEmpty (r.Subviews);
Assert.Equal (r.Title, r.Id);
Assert.False (r.WantContinuousButtonPressed);
Assert.False (r.WantMousePositionReports);
Assert.Null (r.SuperView);
@@ -75,7 +75,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Equal ("title", r.Title);
Assert.NotNull (r);
Assert.Equal (LayoutStyle.Absolute, r.LayoutStyle);
Assert.Equal ("Window()({X=1,Y=2,Width=3,Height=4})", r.ToString ());
Assert.Equal ("Window(title)({X=1,Y=2,Width=3,Height=4})", r.ToString ());
Assert.True (r.CanFocus);
Assert.False (r.HasFocus);
Assert.Equal (new Rect (0, 0, 3, 4), r.Bounds);
@@ -87,8 +87,7 @@ namespace Terminal.Gui.TopLevelTests {
Assert.Null (r.X);
Assert.Null (r.Y);
Assert.False (r.IsCurrentTop);
Assert.Empty (r.Id);
Assert.NotEmpty (r.Subviews);
Assert.Equal (r.Title, r.Id);
Assert.False (r.WantContinuousButtonPressed);
Assert.False (r.WantMousePositionReports);
Assert.Null (r.SuperView);
@@ -147,12 +146,6 @@ namespace Terminal.Gui.TopLevelTests {
expectedOld = r.Title.ToString ();
r.Title = expected;
Assert.Equal (expected, r.Title.ToString ());
expected = "another title";
expectedOld = r.Title.ToString ();
r.Title = expected;
Assert.Equal (expected, r.Title.ToString ());
r.Dispose ();
}
[Fact, AutoInitShutdown]
@@ -189,7 +182,7 @@ namespace Terminal.Gui.TopLevelTests {
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌──────────────────┐
│ File Edit │
│┌ Frame View ────┐│
│┌Frame View────┐│
││ ││
││ ││
││ ││
@@ -203,7 +196,7 @@ namespace Terminal.Gui.TopLevelTests {
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌──────────────────────────────────────┐
│ File Edit │
│┌ Frame View ────────────────────────┐│
│┌Frame View────────────────────────┐│
││ ││
││ ││
││ ││
@@ -227,7 +220,7 @@ namespace Terminal.Gui.TopLevelTests {
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌──────────────────┐
│ File Edit │
│┌ Frame View ────┐│
│┌Frame View────┐│
││ ││
││ ││
││ ││

View File

@@ -8,6 +8,7 @@ using Xunit;
using System.Globalization;
using Xunit.Abstractions;
using NStack;
using static Terminal.Gui.Application;
namespace Terminal.Gui.TopLevelTests {
@@ -118,7 +119,7 @@ namespace Terminal.Gui.TopLevelTests {
var btnNextText = "Finish";
var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
var topRow = $"{d.ULDCorner} {title}{stepTitle} {new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
var topRow = $"{d.ULDCorner}{title}{stepTitle}{new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
var row2 = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
var row3 = row2;
var separatorRow = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
@@ -126,8 +127,9 @@ namespace Terminal.Gui.TopLevelTests {
var bottomRow = $"{d.LLDCorner}{new string (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
var wizard = new Wizard (title) { Width = width, Height = height };
Application.End (Application.Begin (wizard));
var runstate = Application.Begin (wizard);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{row2}\n{row3}\n{separatorRow}\n{buttonRow}\n{bottomRow}", output);
Application.End (runstate);
}
[Fact, AutoInitShutdown]
@@ -149,7 +151,7 @@ namespace Terminal.Gui.TopLevelTests {
var btnNextText = "Finish"; // "Next";
var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
var topRow = $"{d.ULDCorner} {title} - {stepTitle} {new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 7)}{d.URDCorner}";
var topRow = $"{d.ULDCorner}{title} - {stepTitle}{new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 7)}{d.URDCorner}";
var row2 = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
var row3 = row2;
var row4 = row3;
@@ -219,7 +221,7 @@ namespace Terminal.Gui.TopLevelTests {
var btnNextText = "Finish";
var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
var topRow = $"{d.ULDCorner} {title}{stepTitle} {new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
var topRow = $"{d.ULDCorner}{title}{stepTitle}{new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
var separatorRow = $"{d.VDLine}{new string (d.HLine.ToString () [0], width - 2)}{d.VDLine}";
// Once this is fixed, revert to commented out line: https://github.com/gui-cs/Terminal.Gui/issues/1791