1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-13 13:31:48 +00:00

Fix left aligned integer sign in string formatting

(cherry picked from commit 767134fd8d)
This commit is contained in:
Haoyu Qiu
2022-05-01 11:17:01 +08:00
committed by Rémi Verschelde
parent 698dc5cae8
commit a3f91b9fdc
2 changed files with 63 additions and 15 deletions

View File

@@ -555,6 +555,42 @@ bool test_28() {
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
state = state && success;
// Negative int left padded with spaces.
format = "fish %5d frog";
args.clear();
args.push_back(-5);
output = format.sprintf(args, &error);
success = (output == String("fish -5 frog") && !error);
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
state = state && success;
// Negative int left padded with zeros.
format = "fish %05d frog";
args.clear();
args.push_back(-5);
output = format.sprintf(args, &error);
success = (output == String("fish -0005 frog") && !error);
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
state = state && success;
// Negative int right padded with spaces.
format = "fish %-5d frog";
args.clear();
args.push_back(-5);
output = format.sprintf(args, &error);
success = (output == String("fish -5 frog") && !error);
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
state = state && success;
// Negative int right padded with zeros. (0 ignored)
format = "fish %-05d frog";
args.clear();
args.push_back(-5);
output = format.sprintf(args, &error);
success = (output == String("fish -5 frog") && !error);
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
state = state && success;
// Hex (lower)
format = "fish %x frog";
args.clear();
@@ -656,6 +692,15 @@ bool test_28() {
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
state = state && success;
// Negative real right padded with zeros. (0 ignored)
format = "fish %-011f frog";
args.clear();
args.push_back(-99.99);
output = format.sprintf(args, &error);
success = (output == String("fish -99.990000 frog") && !error);
OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL");
state = state && success;
/////// Strings.
// String