Debian Codegraph @

deferred/test/ext/array/reduce.js

raw
1 "use strict";
2
3 var deferred = require("../../../deferred")
4 , reject = deferred.reject;
5
6 module.exports = function (t) {
7 var x = {}, y = {}, z = {}, e = new Error("Error"), e2 = new Error("Error2");
8
9 return {
10 Empty: {
11 "No initial": function (a) {
12 a.throws(function () { t.call([]); });
13 a.throws(function () {
14 t.call([], function () { return x; });
15 });
16 },
17 "Initial": {
18 "": function (a, d) {
19 t.call([], null, x)(function (res) { a(res, x); }, a.never).done(d, d);
20 },
21 "Undefined": function (a, d) {
22 t.call([], null, undefined)(function (res) {
23 a(res, undefined);
24 }, a.never).done(d, d);
25 },
26 "Callback": function (a, d) {
27 t.call([], a.never, x)(function (res) { a(res, x); }, a.never).done(d, d);
28 },
29 "Promise": function (a, d) {
30 t.call([], a.never, deferred(y))(function (res) { a(res, y); }, a.never).done(
31 d, d
32 );
33 },
34 "Error": function (a, d) {
35 t.call([], a.never, reject(e))(a.never, function (res) { a(res, e); }).done(
36 d, d
37 );
38 }
39 }
40 },
41 One: {
42 "No initial": {
43 Regular: {
44 "": function (a, d) {
45 t.call([x])(function (res) { a(res, x); }, a.never).done(d, d);
46 },
47 "Callback": {
48 "": function (a, d) {
49 var list = [x];
50 t.call(list, a.never)(function (res) { a(res, x); }, a.never).done(
51 d, d
52 );
53 },
54 "Promise": function (a, d) {
55 t.call([x], a.never)(function (res) { a(res, x); }, a.never).done(d, d);
56 },
57 "Throw Error": function (a, d) {
58 t.call([x], function () { throw e; }, null)(a.never, function (res) {
59 a(res, e);
60 }).done(d, d);
61 },
62 "Return Error": function (a, d) {
63 t.call([deferred(e)], function () { return e; }, null)(
64 a.never,
65 function (res) { a(res, e); }
66 ).done(d, d);
67 }
68 }
69 },
70 Promise: {
71 "": function (a, d) {
72 t.call([deferred(x)])(function (res) { a(res, x); }, a.never).done(d, d);
73 },
74 "Callback": function (a, d) {
75 t.call(
76 [deferred(x)],
77 function (acc, arg) {
78 a(acc, null, "Accumulator");
79 a(arg, x, "Argument");
80 return y;
81 },
82 null
83 )(function (res) { a(res, y); }, a.never).done(d, d);
84 }
85 },
86 Undefined: function (a, d) {
87 t.call([undefined])(function (res) { a(res, undefined); }, a.never).done(d, d);
88 },
89 Error: {
90 "": function (a, d) {
91 t.call([reject(e)])(a.never, function (res) { a(res, e); }, a.never).done(
92 d, d
93 );
94 },
95 "Promise": function (a, d) {
96 t.call([deferred(e)])(a.never, function (res) { a(res, e); }, a.never).done(
97 d, d
98 );
99 },
100 "Callback": {
101 "": function (a, d) {
102 t.call(
103 [e],
104 function (acc, arg) {
105 a(acc, null, "Accumulator");
106 a(arg, e, "Argument");
107 return y;
108 },
109 null
110 )(function (res) { a(res, y); }, a.never).done(d, d);
111 },
112 "Promise": function (a, d) {
113 t.call([deferred(e)], a.never)(a.never, function (res) {
114 a(res, e);
115 }).done(d, d);
116 },
117 "Throw Error": function (a, d) {
118 var e2 = new Error("Error");
119 t.call(
120 [e],
121 function (acc, arg) {
122 a(arg, e, "Argument");
123 throw e2;
124 },
125 null
126 )(a.never, function (res) { a(res, e2); }).done(d, d);
127 },
128 "Return Error": function (a, d) {
129 var e2 = new Error("Error");
130 t.call(
131 [e],
132 function (acc, arg) {
133 a(arg, e, "Argument");
134 return e2;
135 },
136 null
137 )(function (res) { a(res, e2); }, a.never).done(d, d);
138 }
139 }
140 }
141 },
142 "Initial": {
143 Regular: {
144 "": function (a, d) {
145 t.call([x], null, y)(function (res) { a(res, x); }, a.never).done(d, d);
146 },
147 "Initial Error": function (a, d) {
148 t.call(
149 [x],
150 function (err) {
151 a(err, e, "Call");
152 throw e;
153 },
154 e
155 )(a.never, function (res) { a(res, e); }).done(d, d);
156 },
157 "Callback": {
158 "": function (a, d) {
159 t.call(
160 [x],
161 function (acc, arg) {
162 a(acc, z, "Accumulator");
163 a(arg, x, "Argument");
164 return y;
165 },
166 z
167 )(function (res) { a(res, y); }, a.never).done(d, d);
168 }
169 }
170 },
171 Promise: {
172 "": function (a, d) {
173 t.call([deferred(x)], null, deferred(y))(function (res) {
174 a(res, x);
175 }, a.never).done(d, d);
176 },
177 "Callback": function (a, d) {
178 t.call(
179 [deferred(x)],
180 function (acc, arg) {
181 a(acc, z, "Accumulator");
182 a(arg, x, "Argument");
183 return deferred(y);
184 },
185 deferred(z)
186 )(function (res) { a(res, y); }, a.never).done(d, d);
187 }
188 },
189 Undefined: function (a, d) {
190 t.call([undefined], null, z)(function (res) {
191 a(res, undefined);
192 }, a.never).done(d, d);
193 }
194 }
195 },
196 Many: {
197 "Initial error": function (a, d) {
198 var list = [x, y, z];
199 t.call(
200 list,
201 function (a1, a2, a3, a4) {
202 a.deep([a1, a2, a3, a4], [e, x, 0, list]);
203 return e;
204 },
205 reject(e)
206 )(a.never, function (res) { a(res, e); }).done(d, d);
207 },
208 "No callback": {
209 "Error": function (a, d) {
210 t.call([x, reject(e), e2])(a.never, function (res) { a(res, e); }).done(d, d);
211 },
212 "Error promise": function (a, d) {
213 t.call([x, deferred(e), e2])(a.never, function (res) { a(res, e); }).done(d, d);
214 },
215 "Values": function (a, d) {
216 t.call([x, y, z])(function (res) { a(res, z); }, a.never).done(d, d);
217 },
218 "Values & Promises": function (a, d) {
219 t.call([x, deferred(y), z])(function (res) { a(res, z); }, a.never).done(d, d);
220 },
221 "Values & Promises & Initial": function (a, d) {
222 t.call([x, deferred(y), z], null, {})(function (res) {
223 a(res, z);
224 }, a.never).done(d, d);
225 }
226 },
227 "Callback": {
228 "Error": function (a, d) {
229 t.call([x, e, e2], function () { return z; })(function (res) {
230 a(res, z);
231 }, a.never).done(d, d);
232 },
233 "Error promise": function (a, d) {
234 t.call([x, deferred(e), e2], function () { return z; })(a.never, function (
235 res
236 ) { a(res, e); }).done(d, d);
237 },
238 "Values": function (a, d) {
239 t.call([1, 2, 3], function (acc, res) { return acc * res; }, 1)(function (res) {
240 a(res, 6);
241 }, a.never).done(d, d);
242 },
243 "Values & Promises": function (a, d) {
244 t.call(
245 [1, deferred(2), 3], function (acc, res) { return deferred(acc * res); },
246 deferred(1)
247 )(function (res) { a(res, 6); }, a.never).done(d, d);
248 }
249 }
250 }
251 };
252 };