import assert from "node:assert/strict"; import test from "node:test"; import { parseValue } from "../src/values"; import { REF } from "./fixtures"; test("natural JSON preserves i64s, string whitespace, markers, and all value variants", () => { assert.deepEqual( parseValue( `{"items":[null,true,-9223372036854775808,9223372036854775807,"two spaces",{"$actor":"@${REF}"}]}`, ), { type: "record", data: { items: { type: "list", data: [ { type: "null" }, { type: "bool", data: true }, { type: "integer", data: -9223372036854775808n }, { type: "integer", data: 9223372036854775807n }, { type: "string", data: "two spaces" }, { type: "actor_ref", data: REF }, ], }, }, }, ); assert.deepEqual(parseValue(`"${REF}"`), { type: "string", data: REF }); assert.deepEqual(parseValue('{"$record":{"$actor":"literal"}}'), { type: "record", data: { $actor: { type: "string", data: "literal" } }, }); assert.deepEqual(parseValue('{"__proto__":null}'), { type: "record", data: Object.fromEntries([["__proto__", { type: "null" }]]), }); }); test("invalid inputs and depth/node/byte overflow fail explicitly", () => { for (const source of [ "", "undefined", "1.5", "1e2", "9223372036854775808", "-9223372036854775809", '{"$actor":"binding"}', '{"$actor":1}', '{"$record":[]}', '{"$record":null}', "[".repeat(33) + "null" + "]".repeat(33), JSON.stringify(Array(4096).fill(null)), JSON.stringify("x".repeat(1024 * 1024)), ]) assert.throws(() => parseValue(source)); assert.doesNotThrow(() => parseValue("[".repeat(32) + "null" + "]".repeat(32))); assert.doesNotThrow(() => parseValue(JSON.stringify(Array(4095).fill(null)))); });