michael@0: "use strict"; michael@0: michael@0: var patch = require("../patch") michael@0: michael@0: exports["test patch delete"] = function(assert) { michael@0: var hash = { a: 1, b: 2 } michael@0: michael@0: assert.deepEqual(patch(hash, { a: null }), { b: 2 }, "null removes property") michael@0: } michael@0: michael@0: exports["test patch delete with void"] = function(assert) { michael@0: var hash = { a: 1, b: 2 } michael@0: michael@0: assert.deepEqual(patch(hash, { a: void(0) }), { b: 2 }, michael@0: "void(0) removes property") michael@0: } michael@0: michael@0: exports["test patch delete missing"] = function(assert) { michael@0: assert.deepEqual(patch({ a: 1, b: 2 }, { c: null }), michael@0: { a: 1, b: 2 }, michael@0: "null removes property if exists"); michael@0: michael@0: assert.deepEqual(patch({ a: 1, b: 2 }, { c: void(0) }), michael@0: { a: 1, b: 2 }, michael@0: "void removes property if exists"); michael@0: } michael@0: michael@0: exports["test delete deleted"] = function(assert) { michael@0: assert.deepEqual(patch({ a: null, b: 2, c: 3, d: void(0)}, michael@0: { a: void(0), b: null, d: null }), michael@0: {c: 3}, michael@0: "removed all existing and non existing"); michael@0: } michael@0: michael@0: exports["test update deleted"] = function(assert) { michael@0: assert.deepEqual(patch({ a: null, b: void(0), c: 3}, michael@0: { a: { b: 2 } }), michael@0: { a: { b: 2 }, c: 3 }, michael@0: "replace deleted"); michael@0: } michael@0: michael@0: exports["test patch delete with void"] = function(assert) { michael@0: var hash = { a: 1, b: 2 } michael@0: michael@0: assert.deepEqual(patch(hash, { a: void(0) }), { b: 2 }, michael@0: "void(0) removes property") michael@0: } michael@0: michael@0: michael@0: exports["test patch addition"] = function(assert) { michael@0: var hash = { a: 1, b: 2 } michael@0: michael@0: assert.deepEqual(patch(hash, { c: 3 }), { a: 1, b: 2, c: 3 }, michael@0: "new properties are added") michael@0: } michael@0: michael@0: exports["test patch addition"] = function(assert) { michael@0: var hash = { a: 1, b: 2 } michael@0: michael@0: assert.deepEqual(patch(hash, { c: 3 }), { a: 1, b: 2, c: 3 }, michael@0: "new properties are added") michael@0: } michael@0: michael@0: exports["test hash on itself"] = function(assert) { michael@0: var hash = { a: 1, b: 2 } michael@0: michael@0: assert.deepEqual(patch(hash, hash), hash, michael@0: "applying hash to itself returns hash itself") michael@0: } michael@0: michael@0: exports["test patch with empty delta"] = function(assert) { michael@0: var hash = { a: 1, b: 2 } michael@0: michael@0: assert.deepEqual(patch(hash, {}), hash, michael@0: "applying empty delta results in no changes") michael@0: } michael@0: michael@0: exports["test patch nested data"] = function(assert) { michael@0: assert.deepEqual(patch({ a: { b: 1 }, c: { d: 2 } }, michael@0: { a: { b: null, e: 3 }, c: { d: 4 } }), michael@0: { a: { e: 3 }, c: { d: 4 } }, michael@0: "nested structures can also be patched") michael@0: }