diff options
| author | Rémi Verschelde <remi@verschelde.fr> | 2022-05-01 14:20:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-01 14:20:14 +0200 |
| commit | 4c2a614ad41564ab33eb6515b48e0e5b52ea8b81 (patch) | |
| tree | 0f8cb34ea10f387cccc541cb5736d9773f61d5f2 /tests/core/string/test_string.h | |
| parent | 4e06ce7840be00403f28fcd4bb031780cbaffe86 (diff) | |
| parent | ad1a8777bdc66ff0fddd7de676e7089c957f3506 (diff) | |
Merge pull request #60678 from timothyqiu/left-fmt
Fix left aligned integer sign in string formatting
Diffstat (limited to 'tests/core/string/test_string.h')
| -rw-r--r-- | tests/core/string/test_string.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 87016dddf6..58372a0ed6 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -636,6 +636,38 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish -5 frog")); + // Negative int left padded with spaces. + format = "fish %5d frog"; + args.clear(); + args.push_back(-5); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish -5 frog")); + + // Negative int left padded with zeros. + format = "fish %05d frog"; + args.clear(); + args.push_back(-5); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish -0005 frog")); + + // Negative int right padded with spaces. + format = "fish %-5d frog"; + args.clear(); + args.push_back(-5); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish -5 frog")); + + // Negative int right padded with zeros. (0 ignored) + format = "fish %-05d frog"; + args.clear(); + args.push_back(-5); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish -5 frog")); + // Hex (lower) format = "fish %x frog"; args.clear(); @@ -726,6 +758,14 @@ TEST_CASE("[String] sprintf") { REQUIRE(error == false); CHECK(output == String("fish 100 frog")); + // Negative real right padded with zeros. (0 ignored) + format = "fish %-011f frog"; + args.clear(); + args.push_back(-99.99); + output = format.sprintf(args, &error); + REQUIRE(error == false); + CHECK(output == String("fish -99.990000 frog")); + /////// Strings. // String |