summaryrefslogtreecommitdiffstats
path: root/toolkit/jetpack/diffpatcher/test
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
commit37d5300335d81cecbecc99812747a657588c63eb (patch)
tree765efa3b6a56bb715d9813a8697473e120436278 /toolkit/jetpack/diffpatcher/test
parentb2bdac20c02b12f2057b9ef70b0a946113a00e00 (diff)
parent4fb11cd5966461bccc3ed1599b808237be6b0de9 (diff)
downloadUXP-37d5300335d81cecbecc99812747a657588c63eb.tar
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.gz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.lz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.xz
UXP-37d5300335d81cecbecc99812747a657588c63eb.zip
Merge branch 'ext-work'
Diffstat (limited to 'toolkit/jetpack/diffpatcher/test')
-rw-r--r--toolkit/jetpack/diffpatcher/test/common.js3
-rw-r--r--toolkit/jetpack/diffpatcher/test/diff.js59
-rw-r--r--toolkit/jetpack/diffpatcher/test/index.js14
-rw-r--r--toolkit/jetpack/diffpatcher/test/patch.js83
-rw-r--r--toolkit/jetpack/diffpatcher/test/tap.js3
5 files changed, 162 insertions, 0 deletions
diff --git a/toolkit/jetpack/diffpatcher/test/common.js b/toolkit/jetpack/diffpatcher/test/common.js
new file mode 100644
index 000000000..dbc79013c
--- /dev/null
+++ b/toolkit/jetpack/diffpatcher/test/common.js
@@ -0,0 +1,3 @@
+"use strict";
+
+require("test").run(require("./index"))
diff --git a/toolkit/jetpack/diffpatcher/test/diff.js b/toolkit/jetpack/diffpatcher/test/diff.js
new file mode 100644
index 000000000..d1d674005
--- /dev/null
+++ b/toolkit/jetpack/diffpatcher/test/diff.js
@@ -0,0 +1,59 @@
+"use strict";
+
+var diff = require("../diff")
+
+exports["test diff from null"] = function(assert) {
+ var to = { a: 1, b: 2 }
+ assert.equal(diff(null, to), to, "diff null to x returns x")
+ assert.equal(diff(void(0), to), to, "diff undefined to x returns x")
+
+}
+
+exports["test diff to null"] = function(assert) {
+ var from = { a: 1, b: 2 }
+ assert.deepEqual(diff({ a: 1, b: 2 }, null),
+ { a: null, b: null },
+ "diff x null returns x with all properties nullified")
+}
+
+exports["test diff identical"] = function(assert) {
+ assert.deepEqual(diff({}, {}), {}, "diff on empty objects is {}")
+
+ assert.deepEqual(diff({ a: 1, b: 2 }, { a: 1, b: 2 }), {},
+ "if properties match diff is {}")
+
+ assert.deepEqual(diff({ a: 1, b: { c: { d: 3, e: 4 } } },
+ { a: 1, b: { c: { d: 3, e: 4 } } }), {},
+ "diff between identical nested hashes is {}")
+
+}
+
+exports["test diff delete"] = function(assert) {
+ assert.deepEqual(diff({ a: 1, b: 2 }, { b: 2 }), { a: null },
+ "missing property is deleted")
+ assert.deepEqual(diff({ a: 1, b: 2 }, { a: 2 }), { a: 2, b: null },
+ "missing property is deleted another updated")
+ assert.deepEqual(diff({ a: 1, b: 2 }, {}), { a: null, b: null },
+ "missing propertes are deleted")
+ assert.deepEqual(diff({ a: 1, b: { c: { d: 2 } } }, {}),
+ { a: null, b: null },
+ "missing deep propertes are deleted")
+ assert.deepEqual(diff({ a: 1, b: { c: { d: 2 } } }, { b: { c: {} } }),
+ { a: null, b: { c: { d: null } } },
+ "missing nested propertes are deleted")
+}
+
+exports["test add update"] = function(assert) {
+ assert.deepEqual(diff({ a: 1, b: 2 }, { b: 2, c: 3 }), { a: null, c: 3 },
+ "delete and add")
+ assert.deepEqual(diff({ a: 1, b: 2 }, { a: 2, c: 3 }), { a: 2, b: null, c: 3 },
+ "delete and adds")
+ assert.deepEqual(diff({}, { a: 1, b: 2 }), { a: 1, b: 2 },
+ "diff on empty objcet returns equivalen of to")
+ assert.deepEqual(diff({ a: 1, b: { c: { d: 2 } } }, { d: 3 }),
+ { a: null, b: null, d: 3 },
+ "missing deep propertes are deleted")
+ assert.deepEqual(diff({ b: { c: {} }, d: null }, { a: 1, b: { c: { d: 2 } } }),
+ { a: 1, b: { c: { d: 2 } } },
+ "missing nested propertes are deleted")
+}
diff --git a/toolkit/jetpack/diffpatcher/test/index.js b/toolkit/jetpack/diffpatcher/test/index.js
new file mode 100644
index 000000000..c06407e7c
--- /dev/null
+++ b/toolkit/jetpack/diffpatcher/test/index.js
@@ -0,0 +1,14 @@
+"use strict";
+
+var diff = require("../diff")
+var patch = require("../patch")
+
+exports["test diff"] = require("./diff")
+exports["test patch"] = require("./patch")
+
+exports["test patch(a, diff(a, b)) => b"] = function(assert) {
+ var a = { a: { b: 1 }, c: { d: 2 } }
+ var b = { a: { e: 3 }, c: { d: 4 } }
+
+ assert.deepEqual(patch(a, diff(a, b)), b, "patch(a, diff(a, b)) => b")
+}
diff --git a/toolkit/jetpack/diffpatcher/test/patch.js b/toolkit/jetpack/diffpatcher/test/patch.js
new file mode 100644
index 000000000..dc2e38229
--- /dev/null
+++ b/toolkit/jetpack/diffpatcher/test/patch.js
@@ -0,0 +1,83 @@
+"use strict";
+
+var patch = require("../patch")
+
+exports["test patch delete"] = function(assert) {
+ var hash = { a: 1, b: 2 }
+
+ assert.deepEqual(patch(hash, { a: null }), { b: 2 }, "null removes property")
+}
+
+exports["test patch delete with void"] = function(assert) {
+ var hash = { a: 1, b: 2 }
+
+ assert.deepEqual(patch(hash, { a: void(0) }), { b: 2 },
+ "void(0) removes property")
+}
+
+exports["test patch delete missing"] = function(assert) {
+ assert.deepEqual(patch({ a: 1, b: 2 }, { c: null }),
+ { a: 1, b: 2 },
+ "null removes property if exists");
+
+ assert.deepEqual(patch({ a: 1, b: 2 }, { c: void(0) }),
+ { a: 1, b: 2 },
+ "void removes property if exists");
+}
+
+exports["test delete deleted"] = function(assert) {
+ assert.deepEqual(patch({ a: null, b: 2, c: 3, d: void(0)},
+ { a: void(0), b: null, d: null }),
+ {c: 3},
+ "removed all existing and non existing");
+}
+
+exports["test update deleted"] = function(assert) {
+ assert.deepEqual(patch({ a: null, b: void(0), c: 3},
+ { a: { b: 2 } }),
+ { a: { b: 2 }, c: 3 },
+ "replace deleted");
+}
+
+exports["test patch delete with void"] = function(assert) {
+ var hash = { a: 1, b: 2 }
+
+ assert.deepEqual(patch(hash, { a: void(0) }), { b: 2 },
+ "void(0) removes property")
+}
+
+
+exports["test patch addition"] = function(assert) {
+ var hash = { a: 1, b: 2 }
+
+ assert.deepEqual(patch(hash, { c: 3 }), { a: 1, b: 2, c: 3 },
+ "new properties are added")
+}
+
+exports["test patch addition"] = function(assert) {
+ var hash = { a: 1, b: 2 }
+
+ assert.deepEqual(patch(hash, { c: 3 }), { a: 1, b: 2, c: 3 },
+ "new properties are added")
+}
+
+exports["test hash on itself"] = function(assert) {
+ var hash = { a: 1, b: 2 }
+
+ assert.deepEqual(patch(hash, hash), hash,
+ "applying hash to itself returns hash itself")
+}
+
+exports["test patch with empty delta"] = function(assert) {
+ var hash = { a: 1, b: 2 }
+
+ assert.deepEqual(patch(hash, {}), hash,
+ "applying empty delta results in no changes")
+}
+
+exports["test patch nested data"] = function(assert) {
+ assert.deepEqual(patch({ a: { b: 1 }, c: { d: 2 } },
+ { a: { b: null, e: 3 }, c: { d: 4 } }),
+ { a: { e: 3 }, c: { d: 4 } },
+ "nested structures can also be patched")
+}
diff --git a/toolkit/jetpack/diffpatcher/test/tap.js b/toolkit/jetpack/diffpatcher/test/tap.js
new file mode 100644
index 000000000..e550b82f5
--- /dev/null
+++ b/toolkit/jetpack/diffpatcher/test/tap.js
@@ -0,0 +1,3 @@
+"use strict";
+
+require("retape")(require("./index"))