fix int formatting in std::collections::object

This commit is contained in:
Denis Palashevskii
2024-10-05 13:17:18 +04:00
committed by Christoffer Lerno
parent 2ef1465244
commit 217151be8d
2 changed files with 19 additions and 1 deletions

View File

@@ -63,7 +63,7 @@ fn usz! Object.to_format(&self, Formatter* formatter) @dynamic
switch (self.type.kindof)
{
case SIGNED_INT:
return formatter.printf("%d", self.i)!;
return formatter.printf("%d", (int128)self.i)!;
case UNSIGNED_INT:
return formatter.printf("%d", (uint128)self.i)!;
case FLOAT:

View File

@@ -21,3 +21,21 @@ fn void test_general()
root.set("yyy", true);
assert(root.get_bool("yyy") ?? false);
}
fn void test_to_format_int()
{
{
Object* int_object = object::new_int(16, allocator::heap());
defer int_object.free();
String s = string::new_format("%s", int_object);
defer free(s);
assert(s == "16");
}
{
Object* int_object = object::new_int(-16, allocator::heap());
defer int_object.free();
String s = string::new_format("%s", int_object);
defer free(s);
assert(s == "-16");
}
}