Debian Codegraph @

deferred/test/lib/some-every.js

raw
1 "use strict";
2
3 var deferred = require("../../deferred")
4 , isPromise = require("../../is-promise");
5
6 module.exports = function (t, a) {
7 var x = {}, y, z = 0, w;
8 t = t(true);
9 a(t.call([]).valueOf(), false, "Empty, no cb");
10 a(t.call([], function () { return true; }).valueOf(), false, "Empty, cb");
11 a(t.call([{}]).valueOf(), true, "One, truthy, no cb");
12 a(t.call([0]).valueOf(), false, "One, falsy, no cb");
13 a(t.call([0, {}]).valueOf(), true, "Two, falsy & truthy, no cb");
14 a(t.call([0, false]).valueOf(), false, "Two, falsy & falsy, no cb");
15 a(
16 t
17 .call(
18 (y = [false]),
19 function (a1, a2, a3) {
20 ++z;
21 a(a1, false, "Argument");
22 a(a2, 0, "Index");
23 a(a3, y, "List");
24 a(this, x, "Context");
25 return true;
26 },
27 x
28 )
29 .valueOf(),
30 true,
31 "One, falsy, cb truthy"
32 );
33 a(z, 1, "Callback called");
34 a(t.call([1], function () { return false; }).valueOf(), false, "One, truthy, cb falsy");
35 a(
36 t
37 .call([1, 0], function (x) {
38 ++z;
39 return !x;
40 })
41 .valueOf(),
42 true,
43 "Two, cb, Second truthy"
44 );
45 a(z, 3, "Callback called twice");
46
47 y = deferred();
48 w = t.call([y.promise, 3, 4]);
49 a(isPromise(w.valueOf()), true, "In order");
50 y.resolve(0);
51 a(w.valueOf(), true, "In order, resolved");
52
53 y = deferred();
54 z = [];
55 w = t.call([y.promise, 3, 4], function (val) {
56 z.push(val);
57 return Boolean(val);
58 });
59 a(isPromise(w.valueOf()), true, "In order, cb");
60 y.resolve(0);
61 a(w.valueOf(), true, "In order, cb, resolved");
62 a.deep(z, [0, 3], "In order, cb, called");
63
64 y = deferred();
65 z = [];
66 w = t.call([0, 3, 4], function (val) {
67 z.push(val);
68 return y.promise;
69 });
70 a(isPromise(w.valueOf()), true, "Promise cb");
71 a.deep(z, [0], "Promise cb, processed one");
72 y.resolve(3);
73 a(w.valueOf(), true, "Promise cb, resolved");
74 a.deep(z, [0], "Promise cb, processed, resolved");
75 };