Skip to content

Commit

Permalink
Test encoding/decoding immutable tuple objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jan 30, 2018
1 parent b40bb51 commit 26cf530
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
25 changes: 25 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 26cf530

Please sign in to comment.