diff options
author | 2021-05-15 17:23:55 -0700 | |
---|---|---|
committer | 2021-05-15 17:23:55 -0700 | |
commit | e80f865974df7aae5e2f6abb966b36497da693c6 (patch) | |
tree | e82bcf4860c1fc43de189f13a18e8526a2966f44 /src/json_parser.zig | |
parent | c88625436cf866bdaa68249d10880a2271f611e0 (diff) | |
download | bun-e80f865974df7aae5e2f6abb966b36497da693c6.tar.gz bun-e80f865974df7aae5e2f6abb966b36497da693c6.tar.zst bun-e80f865974df7aae5e2f6abb966b36497da693c6.zip |
lots
Former-commit-id: d8b1d296562a01800248bd1148bc4778225b436e
Diffstat (limited to 'src/json_parser.zig')
-rw-r--r-- | src/json_parser.zig | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/json_parser.zig b/src/json_parser.zig index 120bcb4d7..ee28c2a93 100644 --- a/src/json_parser.zig +++ b/src/json_parser.zig @@ -249,7 +249,7 @@ const js_printer = @import("js_printer.zig"); const renamer = @import("renamer.zig"); const SymbolList = [][]Symbol; -fn expectPrintedJSON(_contents: string, expected: string) void { +fn expectPrintedJSON(_contents: string, expected: string) !void { var contents = alloc.dynamic.alloc(u8, _contents.len + 1) catch unreachable; std.mem.copy(u8, contents, _contents); contents[contents.len - 1] = ';'; @@ -292,20 +292,21 @@ fn expectPrintedJSON(_contents: string, expected: string) void { } test "ParseJSON" { - expectPrintedJSON("true", "true"); - expectPrintedJSON("false", "false"); - expectPrintedJSON("1", "1"); - expectPrintedJSON("10", "10"); - expectPrintedJSON("100", "100"); - expectPrintedJSON("100.1", "100.1"); - expectPrintedJSON("19.1", "19.1"); - expectPrintedJSON("19.12", "19.12"); - expectPrintedJSON("3.4159820837456", "3.4159820837456"); - expectPrintedJSON("-10000.25", "-10000.25"); - expectPrintedJSON("\"hi\"", "\"hi\""); - expectPrintedJSON("{\"hi\": 1, \"hey\": \"200\", \"boom\": {\"yo\": true}}", "({\"hi\": 1, \"hey\": \"200\", \"boom\": {\"yo\": true}})"); - expectPrintedJSON("{\"hi\": \"hey\"}", "({hi: \"hey\"})"); - expectPrintedJSON("{\"hi\": [\"hey\", \"yo\"]}", "({hi:[\"hey\",\"yo\"]})"); + try alloc.setup(std.heap.c_allocator); + try expectPrintedJSON("true", "true"); + try expectPrintedJSON("false", "false"); + try expectPrintedJSON("1", "1"); + try expectPrintedJSON("10", "10"); + try expectPrintedJSON("100", "100"); + try expectPrintedJSON("100.1", "100.1"); + try expectPrintedJSON("19.1", "19.1"); + try expectPrintedJSON("19.12", "19.12"); + try expectPrintedJSON("3.4159820837456", "3.4159820837456"); + try expectPrintedJSON("-10000.25", "-10000.25"); + try expectPrintedJSON("\"hi\"", "\"hi\""); + try expectPrintedJSON("{\"hi\": 1, \"hey\": \"200\", \"boom\": {\"yo\": true}}", "({\"hi\": 1, \"hey\": \"200\", \"boom\": {\"yo\": true}})"); + try expectPrintedJSON("{\"hi\": \"hey\"}", "({hi: \"hey\"})"); + try expectPrintedJSON("{\"hi\": [\"hey\", \"yo\"]}", "({hi:[\"hey\",\"yo\"]})"); // TODO: emoji? } |