is-copy-deep.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. module.exports = function (t, a) {
  3. var x, y;
  4. a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2, 3: 3 }), true, "Same");
  5. a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2, 3: 4 }), false, "Different property value");
  6. a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2 }), false, "Property only in source");
  7. a(t({ 1: 1, 2: 2 }, { 1: 1, 2: 2, 3: 4 }), false, "Property only in target");
  8. a(t("raz", "dwa"), false, "String: diff");
  9. a(t("raz", "raz"), true, "String: same");
  10. a(t("32", 32), false, "String & Number");
  11. a(t([1, "raz", true], [1, "raz", true]), true, "Array: same");
  12. a(t([1, "raz", undefined], [1, "raz"]), false, "Array: diff");
  13. a(t(["foo"], ["one"]), false, "Array: One value comparision");
  14. x = { foo: { bar: { mar: {} } } };
  15. y = { foo: { bar: { mar: {} } } };
  16. a(t(x, y), true, "Deep");
  17. a(t({ foo: { bar: { mar: "foo" } } }, { foo: { bar: { mar: {} } } }), false, "Deep: false");
  18. x = { foo: { bar: { mar: {} } } };
  19. x.rec = { foo: x };
  20. y = { foo: { bar: { mar: {} } } };
  21. y.rec = { foo: x };
  22. a(t(x, y), true, "Object: Infinite Recursion: Same #1");
  23. x.rec.foo = y;
  24. a(t(x, y), true, "Object: Infinite Recursion: Same #2");
  25. x.rec.foo = x;
  26. y.rec.foo = y;
  27. a(t(x, y), true, "Object: Infinite Recursion: Same #3");
  28. y.foo.bar.mar = "raz";
  29. a(t(x, y), false, "Object: Infinite Recursion: Diff");
  30. };