import { encodeJSONAsBinary, decodeJSONFromBinary } from "./binary"; describe("binary JSON serialization", () => { test("a simple JSON structure is encoded correctly", function() { const encoded = encodeJSONAsBinary({ a: [1, 2, "3"] }); const expected = Uint8Array.from([ 123, 34, 97, 34, 58, 91, 49, 44, 50, 44, 34, 51, 34, 93, 125 ]); expect(encoded).toEqual(expected); }); test("a simple JSON structure is decoded correctly", function() { const encoded = Uint8Array.from([ 123, 34, 97, 34, 58, 91, 49, 44, 50, 44, 34, 51, 34, 93, 125 ]); const decoded = decodeJSONFromBinary(encoded); const expected = { a: [1, 2, "3"] }; expect(decoded).toEqual(expected); }); });