-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
59 lines (52 loc) · 1.57 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const _ = require("./");
const myobj = {
foo: {
bar: {
baz: ["winter", "is", "coming"],
fifo(arg1, arg2) {
console.log(
"`console.log` from function, arguments are:",
...arguments
);
return 42;
}
},
astring: "John Doe"
}
};
// Tests
console.log(`
The tested object is:
\`\`\`
const myobj = ${JSON.stringify(myobj, null, 2)}
\`\`\`
`);
////////////////////////
console.log("Accessing to myobj.foo.bar.baz.2 should log 'coming'\n");
console.log("result>", _("foo.bar.baz.2", myobj), "\n");
////////////////////////
console.log(
"Accessing to myobj.foo.bar.fifo() should call the fifo function\n"
);
// calls the nested function 'fifo' with its arguments and logs its result (42)
console.log("result>", _("foo.bar.fifo()", myobj, "arg1", "arg2"), "\n");
////////////////////////
console.log(
"Accessing to myobj.foo.inexistant.property.baz should log 'undefined'\n"
);
console.log("result>", _("foo.inexistant.property.baz", myobj), "\n");
////////////////////////
console.log(
"Accessing to myobj.foo.inexistant.property.baz with default value should log 'default value'.\n"
);
console.log(
"result>",
_("foo.inexistant.property.baz", myobj, "'default value'"),
"\n"
);
////////////////////////
console.log("Accessing to myobj.foo.inexistantFn() should log 'undefined'\n");
console.log("result>", _("foo.inexistantFn()", myobj, "arg"), "\n");
////////////////////////
console.log("Accessing to myobj.foo.astring.substring(5) should log 'Doe'\n");
console.log("result>", _("foo.astring.substring()", myobj, 5), "\n");