]> git.r.bdr.sh - rbdr/dotfiles/blob
4f14cbbe8108b2cd413110fc9f4d7d6b71736b7e
[rbdr/dotfiles] /
1 'use strict';
2
3 module.exports = function (t, a) {
4 var x, y;
5
6 a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2, 3: 3 }), true, "Same");
7 a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2, 3: 4 }), false,
8 "Different property value");
9 a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2 }), false,
10 "Property only in source");
11 a(t({ 1: 1, 2: 2 }, { 1: 1, 2: 2, 3: 4 }), false,
12 "Property only in target");
13
14 a(t("raz", "dwa"), false, "String: diff");
15 a(t("raz", "raz"), true, "String: same");
16 a(t("32", 32), false, "String & Number");
17
18 a(t([1, 'raz', true], [1, 'raz', true]), true, "Array: same");
19 a(t([1, 'raz', undefined], [1, 'raz']), false, "Array: diff");
20 a(t(['foo'], ['one']), false, "Array: One value comparision");
21
22 x = { foo: { bar: { mar: {} } } };
23 y = { foo: { bar: { mar: {} } } };
24 a(t(x, y), true, "Deep");
25
26 a(t({ foo: { bar: { mar: 'foo' } } }, { foo: { bar: { mar: {} } } }),
27 false, "Deep: false");
28
29 x = { foo: { bar: { mar: {} } } };
30 x.rec = { foo: x };
31
32 y = { foo: { bar: { mar: {} } } };
33 y.rec = { foo: x };
34
35 a(t(x, y), true, "Object: Infinite Recursion: Same #1");
36
37 x.rec.foo = y;
38 a(t(x, y), true, "Object: Infinite Recursion: Same #2");
39
40 x.rec.foo = x;
41 y.rec.foo = y;
42 a(t(x, y), true, "Object: Infinite Recursion: Same #3");
43
44 y.foo.bar.mar = 'raz';
45 a(t(x, y), false, "Object: Infinite Recursion: Diff");
46 };