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