Merge branch 'v2_1785-PosJustify' of tig:tig/Terminal.Gui into v2_1785-PosJustify

This commit is contained in:
Tig
2024-04-21 12:36:05 -06:00
16 changed files with 1199 additions and 300 deletions

View File

@@ -29,12 +29,12 @@ public class ThemeScopeTests
{
Reset ();
Assert.NotEmpty (Themes);
Assert.Equal (Dialog.ButtonAlignments.Center, Dialog.DefaultButtonAlignment);
Assert.Equal (Justification.Centered, Dialog.DefaultButtonAlignment);
Themes ["Default"] ["Dialog.DefaultButtonAlignment"].PropertyValue = Dialog.ButtonAlignments.Right;
Themes ["Default"] ["Dialog.DefaultButtonAlignment"].PropertyValue = Justification.Right;
ThemeManager.Themes! [ThemeManager.SelectedTheme]!.Apply ();
Assert.Equal (Dialog.ButtonAlignments.Right, Dialog.DefaultButtonAlignment);
Assert.Equal (Justification.Right, Dialog.DefaultButtonAlignment);
Reset ();
}

View File

@@ -77,15 +77,15 @@ public class ThemeTests
public void TestSerialize_RoundTrip ()
{
var theme = new ThemeScope ();
theme ["Dialog.DefaultButtonAlignment"].PropertyValue = Dialog.ButtonAlignments.Right;
theme ["Dialog.DefaultButtonAlignment"].PropertyValue = Justification.Right;
string json = JsonSerializer.Serialize (theme, _jsonOptions);
var deserialized = JsonSerializer.Deserialize<ThemeScope> (json, _jsonOptions);
Assert.Equal (
Dialog.ButtonAlignments.Right,
(Dialog.ButtonAlignments)deserialized ["Dialog.DefaultButtonAlignment"].PropertyValue
Justification.Right,
(Justification)deserialized ["Dialog.DefaultButtonAlignment"].PropertyValue
);
Reset ();
}

View File

@@ -32,8 +32,8 @@ public class DialogTests
Title = title,
Width = width,
Height = 1,
ButtonAlignment = Dialog.ButtonAlignments.Center,
Buttons = [new () { Text = btn1Text }]
ButtonAlignment = Justification.Centered,
Buttons = [new Button { Text = btn1Text }]
};
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
@@ -57,8 +57,8 @@ public class DialogTests
Title = title,
Width = width,
Height = 1,
ButtonAlignment = Dialog.ButtonAlignments.Justify,
Buttons = [new () { Text = btn1Text }]
ButtonAlignment = Justification.Justified,
Buttons = [new Button { Text = btn1Text }]
};
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
@@ -82,8 +82,8 @@ public class DialogTests
Title = title,
Width = width,
Height = 1,
ButtonAlignment = Dialog.ButtonAlignments.Right,
Buttons = [new () { Text = btn1Text }]
ButtonAlignment = Justification.Right,
Buttons = [new Button { Text = btn1Text }]
};
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
@@ -107,8 +107,8 @@ public class DialogTests
Title = title,
Width = width,
Height = 1,
ButtonAlignment = Dialog.ButtonAlignments.Left,
Buttons = [new () { Text = btn1Text }]
ButtonAlignment = Justification.Left,
Buttons = [new Button { Text = btn1Text }]
};
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
@@ -153,14 +153,14 @@ public class DialogTests
// Default - Center
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Centered,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -170,14 +170,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Justify,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Justified,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -187,14 +187,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -204,14 +204,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -248,7 +248,7 @@ public class DialogTests
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
Justification.Centered,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
@@ -264,14 +264,14 @@ public class DialogTests
$"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} yes {CM.Glyphs.LeftBracket} no {CM.Glyphs.LeftBracket} maybe {CM.Glyphs.LeftBracket} never {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Justify,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Justified,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -280,14 +280,14 @@ public class DialogTests
buttonRow = $"{CM.Glyphs.VLine}{CM.Glyphs.RightBracket} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -296,14 +296,14 @@ public class DialogTests
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {CM.Glyphs.LeftBracket} n{CM.Glyphs.VLine}";
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -337,14 +337,14 @@ public class DialogTests
// Default - Center
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Centered,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -354,14 +354,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Justify,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Justified,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -371,14 +371,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -388,14 +388,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -431,14 +431,14 @@ public class DialogTests
// Default - Center
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Centered,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -448,14 +448,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.GetColumns ());
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Justify,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Justified,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -465,14 +465,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.GetColumns ());
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -482,14 +482,14 @@ public class DialogTests
Assert.Equal (width, buttonRow.GetColumns ());
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
title,
width,
Justification.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text },
new Button { Text = btn4Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -514,11 +514,11 @@ public class DialogTests
d.SetBufferSize (width, 1);
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
new Button { Text = btnText }
);
title,
width,
Justification.Centered,
new Button { Text = btnText }
);
// Center
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
@@ -531,11 +531,11 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Justify,
new Button { Text = btnText }
);
title,
width,
Justification.Justified,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -546,11 +546,11 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Right,
new Button { Text = btnText }
);
title,
width,
Justification.Right,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -561,11 +561,11 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Left,
new Button { Text = btnText }
);
title,
width,
Justification.Left,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -578,11 +578,11 @@ public class DialogTests
d.SetBufferSize (width, 1);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
new Button { Text = btnText }
);
title,
width,
Justification.Centered,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -593,11 +593,11 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Justify,
new Button { Text = btnText }
);
title,
width,
Justification.Justified,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -608,11 +608,11 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Right,
new Button { Text = btnText }
);
title,
width,
Justification.Right,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -623,11 +623,11 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Left,
new Button { Text = btnText }
);
title,
width,
Justification.Left,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -657,13 +657,13 @@ public class DialogTests
d.SetBufferSize (buttonRow.Length, 3);
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text }
);
title,
width,
Justification.Centered,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -673,13 +673,13 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Justify,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text }
);
title,
width,
Justification.Justified,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -689,13 +689,13 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text }
);
title,
width,
Justification.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -705,13 +705,13 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text }
);
title,
width,
Justification.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text },
new Button { Text = btn3Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -739,12 +739,12 @@ public class DialogTests
d.SetBufferSize (buttonRow.Length, 3);
(runstate, Dialog dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
new Button { Text = btn1Text },
new Button { Text = btn2Text }
);
title,
width,
Justification.Centered,
new Button { Text = btn1Text },
new Button { Text = btn2Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -754,12 +754,12 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Justify,
new Button { Text = btn1Text },
new Button { Text = btn2Text }
);
title,
width,
Justification.Justified,
new Button { Text = btn1Text },
new Button { Text = btn2Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -769,12 +769,12 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text }
);
title,
width,
Justification.Right,
new Button { Text = btn1Text },
new Button { Text = btn2Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -784,12 +784,12 @@ public class DialogTests
Assert.Equal (width, buttonRow.Length);
(runstate, dlg) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text }
);
title,
width,
Justification.Left,
new Button { Text = btn1Text },
new Button { Text = btn2Text }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
dlg.Dispose ();
@@ -821,9 +821,9 @@ public class DialogTests
Button button1, button2;
// Default (Center)
button1 = new () { Text = btn1Text };
button2 = new () { Text = btn2Text };
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, button1, button2);
button1 = new Button { Text = btn1Text };
button2 = new Button { Text = btn2Text };
(runstate, dlg) = RunButtonTestDialog (title, width, Justification.Centered, button1, button2);
button1.Visible = false;
RunIteration (ref runstate, ref firstIteration);
buttonRow = $@"{CM.Glyphs.VLine} {btn2} {CM.Glyphs.VLine}";
@@ -833,9 +833,9 @@ public class DialogTests
// Justify
Assert.Equal (width, buttonRow.Length);
button1 = new () { Text = btn1Text };
button2 = new () { Text = btn2Text };
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, button1, button2);
button1 = new Button { Text = btn1Text };
button2 = new Button { Text = btn2Text };
(runstate, dlg) = RunButtonTestDialog (title, width, Justification.Justified, button1, button2);
button1.Visible = false;
RunIteration (ref runstate, ref firstIteration);
buttonRow = $@"{CM.Glyphs.VLine} {btn2}{CM.Glyphs.VLine}";
@@ -845,9 +845,9 @@ public class DialogTests
// Right
Assert.Equal (width, buttonRow.Length);
button1 = new () { Text = btn1Text };
button2 = new () { Text = btn2Text };
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, button1, button2);
button1 = new Button { Text = btn1Text };
button2 = new Button { Text = btn2Text };
(runstate, dlg) = RunButtonTestDialog (title, width, Justification.Right, button1, button2);
button1.Visible = false;
RunIteration (ref runstate, ref firstIteration);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
@@ -856,9 +856,9 @@ public class DialogTests
// Left
Assert.Equal (width, buttonRow.Length);
button1 = new () { Text = btn1Text };
button2 = new () { Text = btn2Text };
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, button1, button2);
button1 = new Button { Text = btn1Text };
button2 = new Button { Text = btn2Text };
(runstate, dlg) = RunButtonTestDialog (title, width, Justification.Left, button1, button2);
button1.Visible = false;
RunIteration (ref runstate, ref firstIteration);
buttonRow = $@"{CM.Glyphs.VLine} {btn2} {CM.Glyphs.VLine}";
@@ -1281,7 +1281,7 @@ public class DialogTests
(runstate, Dialog _) = RunButtonTestDialog (
title,
width,
Dialog.ButtonAlignments.Center,
Justification.Centered,
new Button { Text = btnText }
);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
@@ -1334,7 +1334,7 @@ public class DialogTests
int width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 3);
(runstate, Dialog dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null);
(runstate, Dialog dlg) = RunButtonTestDialog (title, width, Justification.Centered, null);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
End (runstate);
@@ -1344,7 +1344,7 @@ public class DialogTests
private (RunState, Dialog) RunButtonTestDialog (
string title,
int width,
Dialog.ButtonAlignments align,
Justification align,
params Button [] btns
)
{

View File

@@ -0,0 +1,414 @@
using System.Text;
using Xunit.Abstractions;
namespace Terminal.Gui.DrawingTests;
public class JustifierTests (ITestOutputHelper output)
{
private readonly ITestOutputHelper _output = output;
public static IEnumerable<object []> JustificationEnumValues ()
{
foreach (object number in Enum.GetValues (typeof (Justification)))
{
yield return new [] { number };
}
}
[Theory]
[MemberData (nameof (JustificationEnumValues))]
public void NoItems_Works (Justification justification)
{
int [] sizes = { };
int [] positions = new Justifier ().Justify (sizes, justification, 100);
Assert.Equal (new int [] { }, positions);
}
//[Theory]
//[MemberData (nameof (JustificationEnumValues))]
//public void Items_Width_Cannot_Exceed_TotalSize (Justification justification)
//{
// int [] sizes = { 1000, 2000, 3000 };
// Assert.Throws<ArgumentException> (() => new Justifier ().Justify (sizes, justification, 100));
//}
[Theory]
[MemberData (nameof (JustificationEnumValues))]
public void Negative_Widths_Not_Allowed (Justification justification)
{
Assert.Throws<ArgumentException> (() => new Justifier ().Justify (new [] { -10, 20, 30 }, justification, 100));
Assert.Throws<ArgumentException> (() => new Justifier ().Justify (new [] { 10, -20, 30 }, justification, 100));
Assert.Throws<ArgumentException> (() => new Justifier ().Justify (new [] { 10, 20, -30 }, justification, 100));
}
[Theory]
[InlineData (Justification.Left, new [] { 0 }, 1, new [] { 0 })]
[InlineData (Justification.Left, new [] { 0, 0 }, 1, new [] { 0, 1 })]
[InlineData (Justification.Left, new [] { 0, 0, 0 }, 1, new [] { 0, 1, 1 })]
[InlineData (Justification.Left, new [] { 1 }, 1, new [] { 0 })]
[InlineData (Justification.Left, new [] { 1 }, 2, new [] { 0 })]
[InlineData (Justification.Left, new [] { 1 }, 3, new [] { 0 })]
[InlineData (Justification.Left, new [] { 1, 1 }, 2, new [] { 0, 1 })]
[InlineData (Justification.Left, new [] { 1, 1 }, 3, new [] { 0, 2 })]
[InlineData (Justification.Left, new [] { 1, 1 }, 4, new [] { 0, 2 })]
[InlineData (Justification.Left, new [] { 1, 1, 1 }, 3, new [] { 0, 1, 2 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 7, new [] { 0, 2, 4 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 10, new [] { 0, 2, 5 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 11, new [] { 0, 2, 5 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 12, new [] { 0, 2, 5 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 13, new [] { 0, 2, 5 })]
[InlineData (Justification.Left, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.Left, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 2, 4, 7 })]
[InlineData (Justification.Left, new [] { 33, 33, 33 }, 100, new [] { 0, 34, 67 })]
[InlineData (Justification.Left, new [] { 10 }, 101, new [] { 0 })]
[InlineData (Justification.Left, new [] { 10, 20 }, 101, new [] { 0, 11 })]
[InlineData (Justification.Left, new [] { 10, 20, 30 }, 100, new [] { 0, 11, 32 })]
[InlineData (Justification.Left, new [] { 10, 20, 30 }, 101, new [] { 0, 11, 32 })]
[InlineData (Justification.Left, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 11, 31, 61 })]
[InlineData (Justification.Left, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 11, 31, 61, 101 })]
[InlineData (Justification.Right, new [] { 0 }, 1, new [] { 1 })]
[InlineData (Justification.Right, new [] { 0, 0 }, 1, new [] { 0, 1 })]
[InlineData (Justification.Right, new [] { 0, 0, 0 }, 1, new [] { 0, 1, 1 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 7, new [] { 0, 2, 4 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 10, new [] { 2, 4, 7 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 11, new [] { 3, 5, 8 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 12, new [] { 4, 6, 9 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 13, new [] { 5, 7, 10 })]
[InlineData (Justification.Right, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.Right, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 2, 4, 7 })]
[InlineData (Justification.Right, new [] { 10, 20, 30 }, 100, new [] { 38, 49, 70 })]
[InlineData (Justification.Right, new [] { 33, 33, 33 }, 100, new [] { 0, 34, 67 })]
[InlineData (Justification.Right, new [] { 10 }, 101, new [] { 91 })]
[InlineData (Justification.Right, new [] { 10, 20 }, 101, new [] { 70, 81 })]
[InlineData (Justification.Right, new [] { 10, 20, 30 }, 101, new [] { 39, 50, 71 })]
[InlineData (Justification.Right, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 11, 31, 61 })]
[InlineData (Justification.Right, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 11, 31, 61, 101 })]
[InlineData (Justification.Centered, new [] { 0 }, 1, new [] { 0 })]
[InlineData (Justification.Centered, new [] { 0, 0 }, 1, new [] { 0, 1 })]
[InlineData (Justification.Centered, new [] { 0, 0, 0 }, 1, new [] { 0, 1, 1 })]
[InlineData (Justification.Centered, new [] { 1 }, 1, new [] { 0 })]
[InlineData (Justification.Centered, new [] { 1 }, 2, new [] { 0 })]
[InlineData (Justification.Centered, new [] { 1 }, 3, new [] { 1 })]
[InlineData (Justification.Centered, new [] { 1, 1 }, 2, new [] { 0, 1 })]
[InlineData (Justification.Centered, new [] { 1, 1 }, 3, new [] { 0, 2 })]
[InlineData (Justification.Centered, new [] { 1, 1 }, 4, new [] { 0, 2 })]
[InlineData (Justification.Centered, new [] { 1, 1, 1 }, 3, new [] { 0, 1, 2 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3 }, 7, new [] { 0, 2, 4 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3 }, 10, new [] { 1, 3, 6 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3 }, 11, new [] { 1, 3, 6 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 2, 4, 7 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 9, new [] { 0, 3, 6 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 10, new [] { 0, 4, 7 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 11, new [] { 0, 4, 8 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 12, new [] { 0, 4, 8 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 13, new [] { 1, 5, 9 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 100, new [] { 0, 34, 67 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 101, new [] { 0, 34, 68 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 102, new [] { 0, 34, 68 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 103, new [] { 1, 35, 69 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 104, new [] { 1, 35, 69 })]
[InlineData (Justification.Centered, new [] { 10 }, 101, new [] { 45 })]
[InlineData (Justification.Centered, new [] { 10, 20 }, 101, new [] { 35, 46 })]
[InlineData (Justification.Centered, new [] { 10, 20, 30 }, 100, new [] { 19, 30, 51 })]
[InlineData (Justification.Centered, new [] { 10, 20, 30 }, 101, new [] { 19, 30, 51 })]
[InlineData (Justification.Centered, new [] { 10, 20, 30, 40 }, 100, new [] { 0, 10, 30, 60 })]
[InlineData (Justification.Centered, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 11, 31, 61 })]
[InlineData (Justification.Centered, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 11, 31, 61, 101 })]
[InlineData (Justification.Centered, new [] { 3, 4, 5, 6 }, 25, new [] { 2, 6, 11, 17 })]
[InlineData (Justification.Justified, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 11, 31, 61, 101 })]
[InlineData (Justification.Justified, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 11, 31, 61 })]
[InlineData (Justification.Justified, new [] { 10, 20, 30 }, 100, new [] { 0, 30, 70 })]
[InlineData (Justification.Justified, new [] { 10, 20, 30 }, 101, new [] { 0, 31, 71 })]
[InlineData (Justification.Justified, new [] { 33, 33, 33 }, 100, new [] { 0, 34, 67 })]
[InlineData (Justification.Justified, new [] { 11, 17, 23 }, 100, new [] { 0, 36, 77 })]
[InlineData (Justification.Justified, new [] { 1, 2, 3 }, 11, new [] { 0, 4, 8 })]
[InlineData (Justification.Justified, new [] { 10, 20 }, 101, new [] { 0, 81 })]
[InlineData (Justification.Justified, new [] { 10 }, 101, new [] { 0 })]
[InlineData (Justification.Justified, new [] { 3, 3, 3 }, 21, new [] { 0, 9, 18 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5 }, 21, new [] { 0, 8, 16 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5, 6 }, 18, new [] { 0, 3, 7, 12 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5, 6 }, 19, new [] { 0, 4, 8, 13 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5, 6 }, 20, new [] { 0, 4, 9, 14 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5, 6 }, 21, new [] { 0, 4, 9, 15 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 22, new [] { 0, 8, 14, 19 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 23, new [] { 0, 8, 15, 20 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 24, new [] { 0, 8, 15, 21 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 25, new [] { 0, 9, 16, 22 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 26, new [] { 0, 9, 17, 23 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 31, new [] { 0, 11, 20, 28 })]
[InlineData (Justification.LastRightRestLeft, new [] { 0 }, 1, new [] { 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 0, 0 }, 1, new [] { 0, 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 0, 0, 0 }, 1, new [] { 0, 1, 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1 }, 1, new [] { 0 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1 }, 2, new [] { 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1 }, 3, new [] { 2 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 1 }, 2, new [] { 0, 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 1 }, 3, new [] { 0, 2 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 1 }, 4, new [] { 0, 3 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 1, 1 }, 3, new [] { 0, 1, 2 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 7, new [] { 0, 2, 4 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 8, new [] { 0, 2, 5 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 9, new [] { 0, 2, 6 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 10, new [] { 0, 2, 7 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 11, new [] { 0, 2, 8 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 2, 4, 7 })]
[InlineData (Justification.LastRightRestLeft, new [] { 3, 3, 3 }, 21, new [] { 0, 4, 18 })]
[InlineData (Justification.LastRightRestLeft, new [] { 3, 4, 5 }, 21, new [] { 0, 4, 16 })]
[InlineData (Justification.LastRightRestLeft, new [] { 33, 33, 33 }, 100, new [] { 0, 34, 67 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10 }, 101, new [] { 91 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20 }, 101, new [] { 0, 81 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20, 30 }, 100, new [] { 0, 11, 70 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20, 30 }, 101, new [] { 0, 11, 71 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 11, 31, 61 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 11, 31, 61, 101 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 0 }, 1, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 0, 0 }, 1, new [] { 0, 1 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 0, 0, 0 }, 1, new [] { 0, 0, 1 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1 }, 1, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1 }, 2, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1 }, 3, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 1 }, 2, new [] { 0, 1 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 1 }, 3, new [] { 0, 2 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 1 }, 4, new [] { 0, 3 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 1, 1 }, 3, new [] { 0, 1, 2 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 7, new [] { 0, 1, 4 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 8, new [] { 0, 2, 5 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 9, new [] { 0, 3, 6 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 10, new [] { 0, 4, 7 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 11, new [] { 0, 5, 8 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 1, 3, 7 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3, 4 }, 12, new [] { 0, 1, 4, 8 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 3, 3, 3 }, 21, new [] { 0, 14, 18 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 3, 4, 5 }, 21, new [] { 0, 11, 16 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 33, 33, 33 }, 100, new [] { 0, 33, 67 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10 }, 101, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20 }, 101, new [] { 0, 81 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20, 30 }, 100, new [] { 0, 49, 70 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20, 30 }, 101, new [] { 0, 50, 71 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 10, 30, 61 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 10, 30, 60, 101 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 3, 3, 3 }, 21, new [] { 0, 14, 18 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 3, 4, 5 }, 21, new [] { 0, 11, 16 })]
public void TestJustifications_PutSpaceBetweenItems (Justification justification, int [] sizes, int totalSize, int [] expected)
{
int [] positions = new Justifier { PutSpaceBetweenItems = true }.Justify (sizes, justification, totalSize);
AssertJustification (justification, sizes, totalSize, positions, expected);
}
[Theory]
[InlineData (Justification.Left, new [] { 0 }, 1, new [] { 0 })]
[InlineData (Justification.Left, new [] { 0, 0 }, 1, new [] { 0, 0 })]
[InlineData (Justification.Left, new [] { 0, 0, 0 }, 1, new [] { 0, 0, 0 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 7, new [] { 0, 1, 3 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 10, new [] { 0, 1, 3 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 11, new [] { 0, 1, 3 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 12, new [] { 0, 1, 3 })]
[InlineData (Justification.Left, new [] { 1, 2, 3 }, 13, new [] { 0, 1, 3 })]
[InlineData (Justification.Left, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.Left, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.Left, new [] { 10, 20, 30 }, 100, new [] { 0, 10, 30 })]
[InlineData (Justification.Left, new [] { 33, 33, 33 }, 100, new [] { 0, 33, 66 })]
[InlineData (Justification.Left, new [] { 10 }, 101, new [] { 0 })]
[InlineData (Justification.Left, new [] { 10, 20 }, 101, new [] { 0, 10 })]
[InlineData (Justification.Left, new [] { 10, 20, 30 }, 101, new [] { 0, 10, 30 })]
[InlineData (Justification.Left, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 10, 30, 60 })]
[InlineData (Justification.Left, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 10, 30, 60, 100 })]
[InlineData (Justification.Right, new [] { 0 }, 1, new [] { 1 })]
[InlineData (Justification.Right, new [] { 0, 0 }, 1, new [] { 1, 1 })]
[InlineData (Justification.Right, new [] { 0, 0, 0 }, 1, new [] { 1, 1, 1 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 7, new [] { 1, 2, 4 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 10, new [] { 4, 5, 7 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 11, new [] { 5, 6, 8 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 12, new [] { 6, 7, 9 })]
[InlineData (Justification.Right, new [] { 1, 2, 3 }, 13, new [] { 7, 8, 10 })]
[InlineData (Justification.Right, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.Right, new [] { 1, 2, 3, 4 }, 11, new [] { 1, 2, 4, 7 })]
[InlineData (Justification.Right, new [] { 10, 20, 30 }, 100, new [] { 40, 50, 70 })]
[InlineData (Justification.Right, new [] { 33, 33, 33 }, 100, new [] { 1, 34, 67 })]
[InlineData (Justification.Right, new [] { 10 }, 101, new [] { 91 })]
[InlineData (Justification.Right, new [] { 10, 20 }, 101, new [] { 71, 81 })]
[InlineData (Justification.Right, new [] { 10, 20, 30 }, 101, new [] { 41, 51, 71 })]
[InlineData (Justification.Right, new [] { 10, 20, 30, 40 }, 101, new [] { 1, 11, 31, 61 })]
[InlineData (Justification.Right, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 1, 11, 31, 61, 101 })]
[InlineData (Justification.Centered, new [] { 1 }, 1, new [] { 0 })]
[InlineData (Justification.Centered, new [] { 1 }, 2, new [] { 0 })]
[InlineData (Justification.Centered, new [] { 1 }, 3, new [] { 1 })]
[InlineData (Justification.Centered, new [] { 1, 1 }, 2, new [] { 0, 1 })]
[InlineData (Justification.Centered, new [] { 1, 1 }, 3, new [] { 0, 1 })]
[InlineData (Justification.Centered, new [] { 1, 1 }, 4, new [] { 1, 2 })]
[InlineData (Justification.Centered, new [] { 1, 1, 1 }, 3, new [] { 0, 1, 2 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3 }, 7, new [] { 0, 1, 3 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3 }, 10, new [] { 2, 3, 5 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3 }, 11, new [] { 2, 3, 5 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.Centered, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 9, new [] { 0, 3, 6 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 10, new [] { 0, 3, 6 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 11, new [] { 1, 4, 7 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 12, new [] { 1, 4, 7 })]
[InlineData (Justification.Centered, new [] { 3, 3, 3 }, 13, new [] { 2, 5, 8 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 100, new [] { 0, 33, 66 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 101, new [] { 1, 34, 67 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 102, new [] { 1, 34, 67 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 103, new [] { 2, 35, 68 })]
[InlineData (Justification.Centered, new [] { 33, 33, 33 }, 104, new [] { 2, 35, 68 })]
[InlineData (Justification.Centered, new [] { 3, 4, 5, 6 }, 25, new [] { 3, 6, 10, 15 })]
[InlineData (Justification.Justified, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 11, 31, 61, 101 })]
[InlineData (Justification.Justified, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 11, 31, 61 })]
[InlineData (Justification.Justified, new [] { 10, 20, 30 }, 100, new [] { 0, 30, 70 })]
[InlineData (Justification.Justified, new [] { 10, 20, 30 }, 101, new [] { 0, 31, 71 })]
[InlineData (Justification.Justified, new [] { 33, 33, 33 }, 100, new [] { 0, 34, 67 })]
[InlineData (Justification.Justified, new [] { 11, 17, 23 }, 100, new [] { 0, 36, 77 })]
[InlineData (Justification.Justified, new [] { 1, 2, 3 }, 11, new [] { 0, 4, 8 })]
[InlineData (Justification.Justified, new [] { 10, 20 }, 101, new [] { 0, 81 })]
[InlineData (Justification.Justified, new [] { 10 }, 101, new [] { 0 })]
[InlineData (Justification.Justified, new [] { 3, 3, 3 }, 21, new [] { 0, 9, 18 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5 }, 21, new [] { 0, 8, 16 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5, 6 }, 18, new [] { 0, 3, 7, 12 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5, 6 }, 19, new [] { 0, 4, 8, 13 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5, 6 }, 20, new [] { 0, 4, 9, 14 })]
[InlineData (Justification.Justified, new [] { 3, 4, 5, 6 }, 21, new [] { 0, 4, 9, 15 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 22, new [] { 0, 8, 14, 19 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 23, new [] { 0, 8, 15, 20 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 24, new [] { 0, 8, 15, 21 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 25, new [] { 0, 9, 16, 22 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 26, new [] { 0, 9, 17, 23 })]
[InlineData (Justification.Justified, new [] { 6, 5, 4, 3 }, 31, new [] { 0, 11, 20, 28 })]
[InlineData (Justification.LastRightRestLeft, new [] { 0 }, 1, new [] { 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 0, 0 }, 1, new [] { 0, 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 0, 0, 0 }, 1, new [] { 0, 0, 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1 }, 1, new [] { 0 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1 }, 2, new [] { 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1 }, 3, new [] { 2 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 1 }, 2, new [] { 0, 1 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 1 }, 3, new [] { 0, 2 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 1 }, 4, new [] { 0, 3 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 1, 1 }, 3, new [] { 0, 1, 2 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 7, new [] { 0, 1, 4 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 8, new [] { 0, 1, 5 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 9, new [] { 0, 1, 6 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 10, new [] { 0, 1, 7 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3 }, 11, new [] { 0, 1, 8 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 1, 3, 7 })]
[InlineData (Justification.LastRightRestLeft, new [] { 1, 2, 3, 4 }, 12, new [] { 0, 1, 3, 8 })]
[InlineData (Justification.LastRightRestLeft, new [] { 3, 3, 3 }, 21, new [] { 0, 3, 18 })]
[InlineData (Justification.LastRightRestLeft, new [] { 3, 4, 5 }, 21, new [] { 0, 3, 16 })]
[InlineData (Justification.LastRightRestLeft, new [] { 33, 33, 33 }, 100, new [] { 0, 33, 67 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10 }, 101, new [] { 91 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20 }, 101, new [] { 0, 81 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20, 30 }, 100, new [] { 0, 10, 70 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20, 30 }, 101, new [] { 0, 10, 71 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 10, 30, 61 })]
[InlineData (Justification.LastRightRestLeft, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 10, 30, 60, 101 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 0 }, 1, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 0, 0 }, 1, new [] { 0, 1 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 0, 0, 0 }, 1, new [] { 0, 1, 1 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1 }, 1, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1 }, 2, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1 }, 3, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 1 }, 2, new [] { 0, 1 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 1 }, 3, new [] { 0, 2 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 1 }, 4, new [] { 0, 3 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 1, 1 }, 3, new [] { 0, 1, 2 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 6, new [] { 0, 1, 3 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 7, new [] { 0, 2, 4 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 8, new [] { 0, 3, 5 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 9, new [] { 0, 4, 6 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 10, new [] { 0, 5, 7 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3 }, 11, new [] { 0, 6, 8 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 2, 4, 7 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 1, 2, 3, 4 }, 12, new [] { 0, 3, 5, 8 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 3, 3, 3 }, 21, new [] { 0, 15, 18 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 3, 4, 5 }, 21, new [] { 0, 12, 16 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 33, 33, 33 }, 100, new [] { 0, 34, 67 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10 }, 101, new [] { 0 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20 }, 101, new [] { 0, 81 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20, 30 }, 100, new [] { 0, 50, 70 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20, 30 }, 101, new [] { 0, 51, 71 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20, 30, 40 }, 101, new [] { 0, 11, 31, 61 })]
[InlineData (Justification.FirstLeftRestRight, new [] { 10, 20, 30, 40, 50 }, 151, new [] { 0, 11, 31, 61, 101 })]
public void TestJustifications_NoSpaceBetweenItems (Justification justification, int [] sizes, int totalSize, int [] expected)
{
int [] positions = new Justifier { PutSpaceBetweenItems = false }.Justify (sizes, justification, totalSize);
AssertJustification (justification, sizes, totalSize, positions, expected);
}
public void AssertJustification (Justification justification, int [] sizes, int totalSize, int [] positions, int [] expected)
{
try
{
_output.WriteLine ($"Testing: {RenderJustification (justification, sizes, totalSize, expected)}");
}
catch (Exception e)
{
_output.WriteLine ($"Exception rendering expected: {e.Message}");
_output.WriteLine ($"Actual: {RenderJustification (justification, sizes, totalSize, positions)}");
}
if (!expected.SequenceEqual (positions))
{
_output.WriteLine ($"Expected: {RenderJustification (justification, sizes, totalSize, expected)}");
_output.WriteLine ($"Actual: {RenderJustification (justification, sizes, totalSize, positions)}");
Assert.Fail (" Expected and actual do not match");
}
}
public string RenderJustification (Justification justification, int [] sizes, int totalSize, int [] positions)
{
var output = new StringBuilder ();
output.AppendLine ($"Justification: {justification}, Positions: {string.Join (", ", positions)}, TotalSize: {totalSize}");
for (var i = 0; i <= totalSize / 10; i++)
{
output.Append (i.ToString ().PadRight (9) + " ");
}
output.AppendLine ();
for (var i = 0; i < totalSize; i++)
{
output.Append (i % 10);
}
output.AppendLine ();
var items = new char [totalSize];
for (var position = 0; position < positions.Length; position++)
{
// try
{
for (var j = 0; j < sizes [position] && positions [position] + j < totalSize; j++)
{
items [positions [position] + j] = (position + 1).ToString () [0];
}
}
//catch (Exception e)
//{
// output.AppendLine ($"{e.Message} - position = {position}, positions[{position}]: {positions [position]}, sizes[{position}]: {sizes [position]}, totalSize: {totalSize}");
// output.Append (new string (items).Replace ('\0', ' '));
// Assert.Fail (e.Message + output.ToString ());
//}
}
output.Append (new string (items).Replace ('\0', ' '));
return output.ToString ();
}
}