Nuked TextFormatter.CalcRect and unit tests

This commit is contained in:
Tig
2024-07-20 11:45:55 -06:00
parent 71e14c8ad1
commit 4bdaef7ad6
2 changed files with 0 additions and 237 deletions

View File

@@ -39,101 +39,6 @@ public class TextFormatterTests
}
};
[Theory]
[InlineData (null)]
[InlineData ("")]
public void CalcRect_Invalid_Returns_Empty (string text)
{
Assert.Equal (Rectangle.Empty, TextFormatter.CalcRect (0, 0, text));
Assert.Equal (new (new (1, 2), Size.Empty), TextFormatter.CalcRect (1, 2, text));
Assert.Equal (new (new (-1, -2), Size.Empty), TextFormatter.CalcRect (-1, -2, text));
}
[Theory]
[InlineData ("line1\nline2", 5, 2)]
[InlineData ("\nline2", 5, 2)]
[InlineData ("\n\n", 0, 3)]
[InlineData ("\n\n\n", 0, 4)]
[InlineData ("line1\nline2\nline3long!", 10, 3)]
[InlineData ("line1\nline2\n\n", 5, 4)]
[InlineData ("line1\r\nline2", 5, 2)]
[InlineData (" ~  s  gui.cs   master ↑10\n", 31, 2)]
[InlineData ("\n ~  s  gui.cs   master ↑10", 31, 2)]
[InlineData (" ~  s  gui.cs   master\n↑10", 27, 2)]
public void CalcRect_MultiLine_Returns_nHigh (string text, int expectedWidth, int expectedLines)
{
Assert.Equal (new (0, 0, expectedWidth, expectedLines), TextFormatter.CalcRect (0, 0, text));
string [] lines = text.Split (text.Contains (Environment.NewLine) ? Environment.NewLine : "\n");
int maxWidth = lines.Max (s => s.GetColumns ());
var lineWider = 0;
for (var i = 0; i < lines.Length; i++)
{
int w = lines [i].GetColumns ();
if (w == maxWidth)
{
lineWider = i;
}
}
Assert.Equal (new (0, 0, maxWidth, expectedLines), TextFormatter.CalcRect (0, 0, text));
Assert.Equal (
new (
0,
0,
lines [lineWider].ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 0)),
expectedLines
),
TextFormatter.CalcRect (0, 0, text)
);
}
[Theory]
[InlineData ("test")]
[InlineData (" ~  s  gui.cs   master ↑10")]
public void CalcRect_SingleLine_Returns_1High (string text)
{
Assert.Equal (new (0, 0, text.GetRuneCount (), 1), TextFormatter.CalcRect (0, 0, text));
Assert.Equal (new (0, 0, text.GetColumns (), 1), TextFormatter.CalcRect (0, 0, text));
}
[Theory]
[InlineData (14, 1, TextDirection.LeftRight_TopBottom)]
[InlineData (1, 14, TextDirection.TopBottom_LeftRight)]
public void CalcRect_With_Combining_Runes (int width, int height, TextDirection textDirection)
{
var text = "Les Mise\u0328\u0301rables";
Assert.Equal (new (0, 0, width, height), TextFormatter.CalcRect (0, 0, text, textDirection));
}
[Theory]
[InlineData ("test", TextDirection.LeftRight_TopBottom)]
[InlineData (" ~  s  gui.cs   master ↑10", TextDirection.LeftRight_TopBottom)]
[InlineData ("Say Hello view4 你", TextDirection.LeftRight_TopBottom)]
[InlineData ("Say Hello view4 你", TextDirection.RightLeft_TopBottom)]
[InlineData ("Say Hello view4 你", TextDirection.LeftRight_BottomTop)]
[InlineData ("Say Hello view4 你", TextDirection.RightLeft_BottomTop)]
public void CalcRect_Horizontal_Width_Correct (string text, TextDirection textDirection)
{
// The width is the number of columns in the text
Assert.Equal (new (text.GetColumns (), 1), TextFormatter.CalcRect (0, 0, text, textDirection).Size);
}
[Theory]
[InlineData ("test", TextDirection.TopBottom_LeftRight)]
[InlineData (" ~  s  gui.cs   master ↑10", TextDirection.TopBottom_LeftRight)]
[InlineData ("Say Hello view4 你", TextDirection.TopBottom_LeftRight)]
[InlineData ("Say Hello view4 你", TextDirection.TopBottom_RightLeft)]
[InlineData ("Say Hello view4 你", TextDirection.BottomTop_LeftRight)]
[InlineData ("Say Hello view4 你", TextDirection.BottomTop_RightLeft)]
public void CalcRect_Vertical_Height_Correct (string text, TextDirection textDirection)
{
// The height is based both the number of lines and the number of wide chars
Assert.Equal (new (1 + text.GetColumns () - text.Length, text.Length), TextFormatter.CalcRect (0, 0, text, textDirection).Size);
}
[Theory]
[InlineData ("")]
[InlineData (null)]