Add string methods to json, and fix issue in dstring when the formatter uses temp. Remove unnecessary use of temp allocator in to_format for json.

This commit is contained in:
Christoffer Lerno
2024-08-10 19:13:58 +02:00
parent 05421223be
commit 811cb2b95c
4 changed files with 62 additions and 12 deletions

View File

@@ -24,4 +24,30 @@ fn void! simple_test2()
reader.init(`{"jsonrpc":"2.0","id":null,"method":"initialize"}`);
Object* o = json::parse(&reader)!;
defer o.free();
}
}
fn void! test_string()
{
Object* o = json::parse_string(`{"jsonrpc":"2","id":null,"method":"initialize"}`)!;
defer o.free();
String s = string::tformat("%s", *o);
Object* o2 = json::parse_string(s)!;
defer o2.free();
String s2 = string::tformat("%s", *o2);
assert(s2 == s, "Unexpectedly got %s and not %s", s2, s);
}
fn void! test_temp_string()
{
@pool()
{
Object* o = json::temp_parse_string(`{"jsonrpc":"2","id":null,"method":"initialize"}`)!;
defer o.free();
String s = string::tformat("%s", *o);
Object* o2 = json::temp_parse_string(s)!;
defer o2.free();
String s2 = string::tformat("%s", *o2);
assert(s2 == s, "Unexpectedly got %s and not %s", s2, s);
};
}