From 86a45075739888fdaf34ee562843b694d2fd368e Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Sat, 11 Jun 2022 02:44:09 -0700 Subject: [PATCH] more tests --- Terminal.Gui/Windows/Dialog.cs | 47 ++++---- UnitTests/DialogTests.cs | 208 +++++++++++++++++++++++++++------ 2 files changed, 198 insertions(+), 57 deletions(-) diff --git a/Terminal.Gui/Windows/Dialog.cs b/Terminal.Gui/Windows/Dialog.cs index cadefa1c1..80d0aa221 100644 --- a/Terminal.Gui/Windows/Dialog.cs +++ b/Terminal.Gui/Windows/Dialog.cs @@ -109,12 +109,13 @@ namespace Terminal.Gui { LayoutSubviews (); } + // Get the width of all buttons, not including any spacing internal int GetButtonsWidth () { if (buttons.Count == 0) { return 0; } - return buttons.Select (b => b.Bounds.Width).Sum () + buttons.Count - 1; + return buttons.Select (b => b.Bounds.Width).Sum (); } /// /// Determines the horizontal alignment of the Dialog buttons. @@ -148,16 +149,18 @@ namespace Terminal.Gui { void LayoutStartedHandler () { + if (buttons.Count == 0) return; + int shiftLeft = 0; int buttonsWidth = GetButtonsWidth (); switch (ButtonAlignment) { case ButtonAlignments.Center: // Center Buttons - shiftLeft = Math.Max ((Bounds.Width - buttonsWidth) / 2 - 2, 0); + shiftLeft = Math.Max ((Bounds.Width - buttonsWidth - buttons.Count - 2) / 2 + 1, 0); for (int i = buttons.Count - 1; i >= 0; i--) { Button button = buttons [i]; - shiftLeft += button.Frame.Width + 1; + shiftLeft += button.Frame.Width + (i == buttons.Count - 1 ? 0 : 1); button.X = Pos.AnchorEnd (shiftLeft); button.Y = Pos.AnchorEnd (1); } @@ -165,33 +168,31 @@ namespace Terminal.Gui { case ButtonAlignments.Justify: // Justify Buttons - if (buttons.Count == 0) break; - if (buttons.Count == 1) { - buttons [0].X = Pos.Center (); - buttons [0].Y = Pos.AnchorEnd (1); - break; - } + // leftmost and rightmost buttons are hard against edges. The rest are evenly spaced. - var prevButton = buttons [0]; - prevButton.X = 0; - prevButton.Y = Pos.AnchorEnd (1); - if (buttons.Count > 1) { - var shiftRight = (Bounds.Width - buttonsWidth - 1) / (buttons.Count - 1); - for (int i = 1; i < buttons.Count; i++) { - Button button = buttons [i]; - button.X = Pos.Right (prevButton) + shiftRight + 1; - button.Y = Pos.AnchorEnd (1); - prevButton = button; + var spacing = (int)Math.Ceiling ((double)(Bounds.Width - buttonsWidth - 2) / (buttons.Count - 1)); + for (int i = buttons.Count - 1; i >= 0; i--) { + Button button = buttons [i]; + if (i == buttons.Count - 1) { + shiftLeft += button.Frame.Width; + button.X = Pos.AnchorEnd (shiftLeft); + } else { + if (i == 0) { + // first (leftmost) button - always hard flush left + var left = Bounds.Width - 2; + button.X = Pos.AnchorEnd (left); + } else { + shiftLeft += button.Frame.Width + (spacing); + button.X = Pos.AnchorEnd (shiftLeft); + } } + button.Y = Pos.AnchorEnd (1); } - // Force last button to right align (due to rounding) - var shift = buttons [buttons.Count - 1].Bounds.Width ; - buttons [buttons.Count - 1].X = Pos.AnchorEnd (shift); break; case ButtonAlignments.Left: // Left Align Buttons - prevButton = buttons [0]; + var prevButton = buttons [0]; prevButton.X = 0; prevButton.Y = Pos.AnchorEnd (1); for (int i = 1; i < buttons.Count; i++) { diff --git a/UnitTests/DialogTests.cs b/UnitTests/DialogTests.cs index 85ce255e7..1ac792a93 100644 --- a/UnitTests/DialogTests.cs +++ b/UnitTests/DialogTests.cs @@ -19,10 +19,10 @@ namespace Terminal.Gui.Views { this.output = output; } - private void RunButtonTestDialog (string title, int width, Dialog.ButtonAlignments align, params Button [] btns) + private Application.RunState RunButtonTestDialog (string title, int width, Dialog.ButtonAlignments align, params Button [] btns) { var dlg = new Dialog (title, width, 3, btns) { ButtonAlignment = align }; - Application.End (Application.Begin (dlg)); + return Application.Begin (dlg); } [Fact] @@ -41,26 +41,30 @@ namespace Terminal.Gui.Views { d.SetBufferSize (width, 3); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText)); + var runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); // Justify - buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}"; + buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}"; Assert.Equal (width, buttonRow.Length); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText)); GraphViewTests.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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText)); GraphViewTests.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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); } [Fact] @@ -83,26 +87,30 @@ namespace Terminal.Gui.Views { d.SetBufferSize (buttonRow.Length, 3); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text)); + var runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); // Justify buttonRow = $@"{d.VLine}{btn1} {btn2}{d.VLine}"; Assert.Equal (width, buttonRow.Length); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); // Right buttonRow = $@"{d.VLine} {btn1} {btn2}{d.VLine}"; Assert.Equal (width, buttonRow.Length); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); // Left buttonRow = $@"{d.VLine}{btn1} {btn2} {d.VLine}"; Assert.Equal (width, buttonRow.Length); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); } [Fact] @@ -127,26 +135,30 @@ namespace Terminal.Gui.Views { d.SetBufferSize (buttonRow.Length, 3); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text)); + var runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); // Justify buttonRow = $@"{d.VLine}{btn1} {btn2} {btn3}{d.VLine}"; Assert.Equal (width, buttonRow.Length); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); // Right buttonRow = $@"{d.VLine} {btn1} {btn2} {btn3}{d.VLine}"; Assert.Equal (width, buttonRow.Length); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); // Left buttonRow = $@"{d.VLine}{btn1} {btn2} {btn3} {d.VLine}"; Assert.Equal (width, buttonRow.Length); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); } [Fact] @@ -174,26 +186,30 @@ namespace Terminal.Gui.Views { d.SetBufferSize (buttonRow.Length, 3); // Default - Center - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + var runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", 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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); } [Fact] @@ -216,34 +232,38 @@ namespace Terminal.Gui.Views { var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}"; // Note extra spaces to make dialog even wider - // 123456 12345 - var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}"; + // 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 - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + var runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", 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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); } [Fact] @@ -265,34 +285,154 @@ namespace Terminal.Gui.Views { var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}"; // Note extra spaces to make dialog even wider - // 123456 12345 - var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}"; + // 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 - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + var runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", 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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.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); - RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); + runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text)); GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); + } + + [Fact] + [AutoInitShutdown] + public void Zero_Buttons_Works () + { + 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); + + var runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null); + GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + + Application.End (runstate); + } + + [Fact] + [AutoInitShutdown] + public void One_Button_Works () + { + 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); + + var runstate = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText)); + GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); + } + + [Fact] + [AutoInitShutdown] + public void Add_Button_Works () + { + 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 }; + var runstate = Application.Begin (dlg); + var buttonRow = $"{d.VLine} {btn1} {d.VLine}"; + GraphViewTests.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); + GraphViewTests.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}"; + GraphViewTests.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); + GraphViewTests.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}"; + GraphViewTests.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); + GraphViewTests.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}"; + GraphViewTests.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); + GraphViewTests.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output); + Application.End (runstate); } } } \ No newline at end of file