1
0

is-copy-deep.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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,
  6. "Different property value");
  7. a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2 }), false,
  8. "Property only in source");
  9. a(t({ 1: 1, 2: 2 }, { 1: 1, 2: 2, 3: 4 }), false,
  10. "Property only in target");
  11. a(t("raz", "dwa"), false, "String: diff");
  12. a(t("raz", "raz"), true, "String: same");
  13. a(t("32", 32), false, "String & Number");
  14. a(t([1, 'raz', true], [1, 'raz', true]), true, "Array: same");
  15. a(t([1, 'raz', undefined], [1, 'raz']), false, "Array: diff");
  16. a(t(['foo'], ['one']), false, "Array: One value comparision");
  17. x = { foo: { bar: { mar: {} } } };
  18. y = { foo: { bar: { mar: {} } } };
  19. a(t(x, y), true, "Deep");
  20. a(t({ foo: { bar: { mar: 'foo' } } }, { foo: { bar: { mar: {} } } }),
  21. false, "Deep: false");
  22. x = { foo: { bar: { mar: {} } } };
  23. x.rec = { foo: x };
  24. y = { foo: { bar: { mar: {} } } };
  25. y.rec = { foo: x };
  26. a(t(x, y), true, "Object: Infinite Recursion: Same #1");
  27. x.rec.foo = y;
  28. a(t(x, y), true, "Object: Infinite Recursion: Same #2");
  29. x.rec.foo = x;
  30. y.rec.foo = y;
  31. a(t(x, y), true, "Object: Infinite Recursion: Same #3");
  32. y.foo.bar.mar = 'raz';
  33. a(t(x, y), false, "Object: Infinite Recursion: Diff");
  34. };