mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
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:
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user