-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (51 loc) · 1.74 KB
/
index.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
#!/usr/bin/env node
var _ = require("highland");
module.exports = function() {
var plan = { start : 0, end : 0 };
var previousId = 0;
var seenFirstVersionHeader = false;
return _.pipeline(_.split(),
_.map(renumber),
_.reject(isNull),
_.consume(addFinalPlan),
_.intersperse("\n"),
_.append("\n"));
function renumber(line) {
var match;
// Matches assert
if (match = line.match(/^((?:not )?ok)(?:\s+(\d+))?\s+(.*)$/)) {
var okString = match[1];
var id = parseInt(match[2], 10);
var rest = match[3];
var nextId = ++previousId;
return okString + " " + nextId + " " + rest;
// Matches plan
} else if (match = line.match(/^(\d+)..(\d+)$/)) {
var start = parseInt(match[1], 10);
var end = parseInt(match[2], 10);
plan.start = start;
plan.end += end;
nextId = start;
return null;
// Matches version header
} else if (line === "TAP version 13") {
if ( ! seenFirstVersionHeader ) {
seenFirstVersionHeader = true;
return line;
} else return null;
} else return line; // Everything else: passthrough
}
function addFinalPlan(err, x, push, next) {
if (err) {
push(err);
next();
} else if (x === _.nil) { // Ended
push(null, "" + (plan.start || 0) + ".." + plan.end);
push(null, x);
} else {
push(null, x);
next();
}
}
function isNull(line) { return line === null }
};