mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Fix duplicate minus in print output.
Co-authored-by: kleonc <9283098+kleonc@users.noreply.github.com>
This commit is contained in:
parent
5f12ada7a4
commit
a9ef3e5804
2 changed files with 37 additions and 1 deletions
|
|
@ -5262,7 +5262,11 @@ String String::sprintf(const Span<Variant> &values, bool *error) const {
|
|||
// Get basic number.
|
||||
String str;
|
||||
if (!as_unsigned) {
|
||||
if (value == INT64_MIN) { // INT64_MIN can't be represented as positive value.
|
||||
str = String::num_int64(value, base, capitalize).trim_prefix("-");
|
||||
} else {
|
||||
str = String::num_int64(Math::abs(value), base, capitalize);
|
||||
}
|
||||
} else {
|
||||
uint64_t uvalue = *((uint64_t *)&value);
|
||||
// In unsigned hex, if the value fits in 32 bits, trim it down to that.
|
||||
|
|
|
|||
|
|
@ -992,6 +992,38 @@ TEST_CASE("[String] sprintf") {
|
|||
REQUIRE(error == false);
|
||||
CHECK(output == String("fish 143 frog"));
|
||||
|
||||
// INT64_MIN
|
||||
format = "fish %d frog";
|
||||
args.clear();
|
||||
args.push_back(INT64_MIN);
|
||||
output = format.sprintf(args, &error);
|
||||
REQUIRE(error == false);
|
||||
CHECK(output == String("fish -9223372036854775808 frog"));
|
||||
|
||||
// INT64_MIN hex (lower)
|
||||
format = "fish %x frog";
|
||||
args.clear();
|
||||
args.push_back(INT64_MIN);
|
||||
output = format.sprintf(args, &error);
|
||||
REQUIRE(error == false);
|
||||
CHECK(output == String("fish -8000000000000000 frog"));
|
||||
|
||||
// INT64_MIN hex (upper)
|
||||
format = "fish %X frog";
|
||||
args.clear();
|
||||
args.push_back(INT64_MIN);
|
||||
output = format.sprintf(args, &error);
|
||||
REQUIRE(error == false);
|
||||
CHECK(output == String("fish -8000000000000000 frog"));
|
||||
|
||||
// INT64_MIN octal
|
||||
format = "fish %o frog";
|
||||
args.clear();
|
||||
args.push_back(INT64_MIN);
|
||||
output = format.sprintf(args, &error);
|
||||
REQUIRE(error == false);
|
||||
CHECK(output == String("fish -1000000000000000000000 frog"));
|
||||
|
||||
///// Reals
|
||||
|
||||
// Real
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue