Improve string formatting for %f and %v for inf and nan

This commit is contained in:
Marcus Elg
2022-08-24 15:41:31 +02:00
parent 6e390fa9ab
commit b21460981d
2 changed files with 28 additions and 4 deletions

View File

@@ -745,6 +745,14 @@ TEST_CASE("[String] sprintf") {
REQUIRE(error == false);
CHECK(output == String("fish 99.990000 frog"));
// Real (infinity) left-padded
format = "fish %11f frog";
args.clear();
args.push_back(INFINITY);
output = format.sprintf(args, &error);
REQUIRE(error == false);
CHECK(output == String("fish inf frog"));
// Real right-padded.
format = "fish %-11f frog";
args.clear();
@@ -845,6 +853,14 @@ TEST_CASE("[String] sprintf") {
REQUIRE(error == false);
CHECK(output == String("fish ( 19.990000, 1.000000, -2.050000) frog"));
// Vector left-padded with inf/nan
format = "fish %11v frog";
args.clear();
args.push_back(Variant(Vector2(INFINITY, NAN)));
output = format.sprintf(args, &error);
REQUIRE(error == false);
CHECK(output == String("fish ( inf, nan) frog"));
// Vector right-padded.
format = "fish %-11v frog";
args.clear();