123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Threading.Tasks;
- using Terminal.Gui;
- using Xunit;
- using System.Globalization;
- using Xunit.Abstractions;
- using NStack;
- namespace Terminal.Gui.Views {
- public class DialogTests {
- readonly ITestOutputHelper output;
- public DialogTests (ITestOutputHelper output)
- {
- this.output = output;
- }
- 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 };
- return (Application.Begin (dlg), dlg);
- }
- [Fact]
- [AutoInitShutdown]
- public void ButtonAlignment_One ()
- {
- var d = ((FakeDriver)Application.Driver);
- Application.RunState runstate = null;
- var title = "1234";
- // E.g "|[ ok ]|"
- 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 - 4)}┐";
- var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
- d.SetBufferSize (width, 3);
- (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
- TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", 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);
- 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);
- 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void ButtonAlignment_Two ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- // E.g "|[ yes ][ no ]|"
- var btn1Text = "yes";
- var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
- var btn2Text = "no";
- var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
- 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);
- 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);
- 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);
- 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void ButtonAlignment_Two_Hidden ()
- {
- Application.RunState runstate = null;
- bool firstIteration = false;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- // E.g "|[ yes ][ no ]|"
- var btn1Text = "yes";
- var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
- var btn2Text = "no";
- var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
- 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);
- Dialog dlg = null;
- Button button1, button2;
- // Default (Center)
- button1 = new Button (btn1Text);
- button2 = new Button (btn2Text);
- (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, button1, button2);
- button1.Visible = false;
- Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
- buttonRow = $@"{d.VLine} {btn2} {d.VLine}";
- TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
- Application.End (runstate);
- // Justify
- Assert.Equal (width, buttonRow.Length);
- button1 = new Button (btn1Text);
- button2 = new Button (btn2Text);
- (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, button1, button2);
- button1.Visible = false;
- Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
- buttonRow = $@"{d.VLine} {btn2}{d.VLine}";
- TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
- Application.End (runstate);
- // Right
- Assert.Equal (width, buttonRow.Length);
- button1 = new Button (btn1Text);
- button2 = new Button (btn2Text);
- (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);
- Application.End (runstate);
- // Left
- Assert.Equal (width, buttonRow.Length);
- button1 = new Button (btn1Text);
- button2 = new Button (btn2Text);
- (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, button1, button2);
- button1.Visible = false;
- Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
- buttonRow = $@"{d.VLine} {btn2} {d.VLine}";
- TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void ButtonAlignment_Three ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- // E.g "|[ yes ][ no ][ maybe ]|"
- var btn1Text = "yes";
- var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
- var btn2Text = "no";
- var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
- var btn3Text = "maybe";
- var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
- 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);
- 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);
- 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);
- 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void ButtonAlignment_Four ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- // E.g "|[ yes ][ no ][ maybe ]|"
- var btn1Text = "yes";
- var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
- var btn2Text = "no";
- var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
- var btn3Text = "maybe";
- var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
- var btn4Text = "never";
- var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}";
- 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);
- 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);
- 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);
- 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void ButtonAlignment_Four_On_Smaller_Width ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- // E.g "|[ yes ][ no ][ maybe ][ never ]|"
- var btn1Text = "yes";
- var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
- var btn2Text = "no";
- var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
- var btn3Text = "maybe";
- var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
- var btn4Text = "never";
- var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}";
- var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
- var width = buttonRow.Length;
- var topRow = "34 ───────────────────────────";
- var bottomRow = "──────────────────────────────";
- d.SetBufferSize (30, 3);
- // 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);
- 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);
- // 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);
- // Left
- 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);
- }
- [Fact]
- [AutoInitShutdown]
- public void ButtonAlignment_Four_Wider ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- // E.g "|[ yes ][ no ][ maybe ]|"
- var btn1Text = "yes";
- var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
- var btn2Text = "no";
- var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
- var btn3Text = "你你你你你"; // This is a wide char
- var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
- // Requires a Nerd Font
- var btn4Text = "\uE36E\uE36F\uE370\uE371\uE372\uE373";
- 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}";
- 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);
- Application.End (runstate);
- // Justify
- 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);
- Application.End (runstate);
- // Right
- 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);
- Application.End (runstate);
- // Left
- 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void ButtonAlignment_Four_WideOdd ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- // E.g "|[ yes ][ no ][ maybe ]|"
- var btn1Text = "really long button 1";
- var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
- var btn2Text = "really long button 2";
- var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
- var btn3Text = "really long button 3";
- var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
- var btn4Text = "really long button 44"; // 44 is intentional to make length different than rest
- 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}";
- 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);
- 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);
- 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);
- 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void Zero_Buttons_Works ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void One_Button_Works ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- 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 - 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void Add_Button_Works ()
- {
- Application.RunState runstate = null;
- var d = ((FakeDriver)Application.Driver);
- var title = "1234";
- var btn1Text = "yes";
- var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
- var btn2Text = "no";
- var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
- // 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}";
- // Default (center)
- var dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Center };
- runstate = Application.Begin (dlg);
- var buttonRow = $"{d.VLine} {btn1} {d.VLine}";
- TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", 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);
- Application.End (runstate);
- // Justify
- dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Justify };
- runstate = Application.Begin (dlg);
- buttonRow = $"{d.VLine} {btn1}{d.VLine}";
- TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", 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);
- Application.End (runstate);
- // Right
- dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Right };
- runstate = Application.Begin (dlg);
- buttonRow = $"{d.VLine}{new String (' ', width - btn1.Length - 2)}{btn1}{d.VLine}";
- TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", 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);
- Application.End (runstate);
- // Left
- dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Left };
- runstate = Application.Begin (dlg);
- buttonRow = $"{d.VLine}{btn1}{new String (' ', width - btn1.Length - 2)}{d.VLine}";
- TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", 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);
- Application.End (runstate);
- }
- [Fact]
- [AutoInitShutdown]
- public void FileDialog_FileSystemWatcher ()
- {
- for (int i = 0; i < 8; i++) {
- var fd = new FileDialog ();
- fd.Ready += () => Application.RequestStop ();
- Application.Run (fd);
- }
- }
- }
- }
|