aboutsummaryrefslogtreecommitdiff
path: root/node_modules/structured-clone/test
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/structured-clone/test
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/structured-clone/test')
-rw-r--r--node_modules/structured-clone/test/test.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/node_modules/structured-clone/test/test.js b/node_modules/structured-clone/test/test.js
new file mode 100644
index 000000000..1a201e572
--- /dev/null
+++ b/node_modules/structured-clone/test/test.js
@@ -0,0 +1,100 @@
+var test = require('tape');
+
+test('deep cloning test', function (t) {
+ t.plan(12)
+
+ var clone = require('../')
+
+ var a = { }
+ a.b = a
+ a.c = { $ref: '$' }
+ a.d = new Buffer([0xde, 0xad])
+ a.e = [ a, a.b ]
+ a.f = new Date()
+ a.g = /ab+a/i
+
+ var a = clone(a);
+
+ t.ok(a.b == a);
+ t.ok(a.c.$ref == '$')
+ t.ok(Buffer.isBuffer(a.d))
+ t.ok(a.d[0] == 0xde)
+ t.ok(a.d[1] == 0xad)
+ t.ok(a.d.length == 2);
+ t.ok(Array.isArray(a.e));
+ t.ok(a.e.length == 2);
+ t.ok(a.e[0] == a);
+ t.ok(a.e[1] == a.b);
+ t.ok(a.f instanceof Date);
+ t.ok(a.g instanceof RegExp);
+})
+
+test('serializing test', function (t) {
+ t.plan(14)
+
+ var clone = require('../')
+
+ var a = { }
+ a.b = a
+ a.c = { $ref: '$' }
+ a.d = new Buffer([0xde, 0xad])
+ a.e = [ a, a.b ]
+ a.f = new Date()
+ a.g = /ab+a/i
+
+ var buf = clone.serialize(a);
+ t.ok(buf.length, 'Buffer has length')
+ t.ok(Buffer.isBuffer(buf), 'Buffer has length')
+
+ var a = clone.deserialize(buf);
+
+ t.ok(a.b == a);
+ t.ok(a.c.$ref == '$')
+ t.ok(Buffer.isBuffer(a.d))
+ t.ok(a.d[0] == 0xde)
+ t.ok(a.d[1] == 0xad)
+ t.ok(a.d.length == 2);
+ t.ok(Array.isArray(a.e));
+ t.ok(a.e.length == 2);
+ t.ok(a.e[0] == a);
+ t.ok(a.e[1] == a.b);
+ t.ok(a.f instanceof Date);
+ t.ok(a.g instanceof RegExp);
+})
+
+test('deep copy root object', function (t) {
+ t.plan(3);
+
+ var clone = require('../');
+
+ var buf = clone(new Buffer([0xca, 0xfe, 0xba, 0xbe]));
+ t.ok(Buffer.isBuffer(buf));
+ t.ok(buf.length == 4);
+ t.ok(buf.readUInt32BE(0) == 0xcafebabe);
+});
+
+test('serializing root object', function (t) {
+ t.plan(3);
+
+ var clone = require('../');
+
+ var buf = clone.deserialize(clone.serialize(new Buffer([0xca, 0xfe, 0xba, 0xbe])));
+ t.ok(Buffer.isBuffer(buf));
+ t.ok(buf.length == 4);
+ t.ok(buf.readUInt32BE(0) == 0xcafebabe);
+});
+
+
+test('errors', function (t) {
+ t.plan(4);
+
+ var clone = require('../');
+
+ var err = clone(new Error('boo!'));
+ t.ok(err instanceof Error);
+ t.ok(err.message == 'boo!');
+
+ var err = clone.deserialize(clone.serialize(new Error('boo!')));
+ t.ok(err instanceof Error);
+ t.ok(err.message == 'boo!');
+}); \ No newline at end of file