This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
97 lines (89 loc) · 3.12 KB
/
test.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var _ = require('../../lib/squishy-pants');
_ = _
.property('check', _.curry(function(property, args, test) {
var report = _.forAll(property, args);
test.ok(report.isNone, report.fold(
function(fail) {
return 'Failed after ' + fail.tries + ' tries: ' + fail.inputs.toString();
},
function() {
return 'OK';
}
));
test.done();
}))
.property('checkTaggedArgs', _.curry(function(type, args, access, test) {
// Go through and check all the tagged arguments.
var length = _.functionLength(type);
_.fill(length)(_.identity).forEach(function (value, index) {
function property() {
return access(type.apply(this, arguments), index) === arguments[index];
}
property._length = length;
var report = _.forAll(property, args);
test.ok(report.isNone, report.fold(
function(fail) {
return 'Failed after ' + fail.tries + ' tries: ' + fail.inputs.toString();
},
function() {
return 'OK';
}
));
});
test.done();
}))
.property('checkStream', _.curry(function(property, args, test) {
var env = this,
failures = [],
expected = 0,
inputs,
applied,
i,
check = env.curry(function(state, inputs, index, result) {
state(
!result ?
env.Some(
_.failureReporter(
inputs,
index + 1
)
) :
env.None
);
}),
reporter = function(report) {
failures.push({
valid: report.isNone,
msg: report.fold(
function(fail) {
return 'Failed after ' + fail.tries + ' tries: ' + fail.inputs.toString();
},
function() {
return 'OK';
}
)
});
},
checkDone = function() {
return function() {
test.ok(true, 'OK');
};
};
for(i = 0; i < env.goal; i++) {
inputs = env.generateInputs(env, args, i);
applied = property.apply(this, inputs);
applied.fork(check(reporter, inputs, i), checkDone());
}
var valid = _.fold(failures, true, function(a, b) {
return a && b.valid;
}),
words = valid ? 'OK' : _.fold(failures, '', function(a, b) {
return b.valid ? a : a + '\n' + b.msg;
});
test.expect(env.goal + 1);
test.ok(valid, words);
test.done();
}))
.property('badLeft', _.error("Got Left side"))
.property('badRight', _.error("Got Right side"));
exports = module.exports = _;