From 26cf5309cbdce5bd099e54b9edf3fce47c69380b Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 30 Jan 2018 10:45:42 -0500 Subject: [PATCH] Test encoding/decoding immutable tuple objects. --- package.json | 3 ++- test/tests.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a83801f..90e97ea 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "debug": "node ./node_modules/mocha/bin/mocha --debug-brk --reporter spec --full-trace" }, "devDependencies": { - "mocha": "~5.0.0" + "mocha": "~5.0.0", + "immutable-tuple": "^0.4.2" } } diff --git a/test/tests.js b/test/tests.js index e6d014e..78e2d8d 100644 --- a/test/tests.js +++ b/test/tests.js @@ -128,4 +128,29 @@ describe("encoding and decoding", function () { var copy = arson.decode(arson.encode(global)); assert.strictEqual(copy.global, copy); }); + + it("should preserve identity of immutable tuples", function () { + var tuple = require("immutable-tuple").tuple; + + arson.registerType("tuple", { + deconstruct: function (t) { + if (tuple.isTuple(t)) { + return Array.from(t); + } + }, + + reconstruct: function (entries) { + if (entries) { + return tuple.apply(null, entries); + } + } + }); + + var t1 = tuple(1, 2, tuple(3, 4), 5); + var input = ["asdf", t1, true]; + var output = arson.decode(arson.encode(input)); + + assert.notStrictEqual(input, output); + assert.strictEqual(output[1], t1); + }); });