diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /addon-sdk/source/lib/diffpatcher/test/diff.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'addon-sdk/source/lib/diffpatcher/test/diff.js')
-rw-r--r-- | addon-sdk/source/lib/diffpatcher/test/diff.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/addon-sdk/source/lib/diffpatcher/test/diff.js b/addon-sdk/source/lib/diffpatcher/test/diff.js new file mode 100644 index 000000000..d1d674005 --- /dev/null +++ b/addon-sdk/source/lib/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") +} |