summaryrefslogtreecommitdiff
path: root/tests/core/string/test_string.h
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2022-05-01 11:04:52 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2022-05-01 12:42:48 +0800
commitad1a8777bdc66ff0fddd7de676e7089c957f3506 (patch)
treef0d3722e0664dd332134a462da0dc87f12cb4caa /tests/core/string/test_string.h
parent4a9e8b560a648f4c1746697b348ebbbb89c5bb0a (diff)
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.h40
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