2011-11-20 00:15:38 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
window.HeadlessReporterResult = (function() {
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
function HeadlessReporterResult(name, splitName) {
|
|
|
|
this.name = name;
|
|
|
|
this.splitName = splitName;
|
|
|
|
this.results = [];
|
|
|
|
}
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
HeadlessReporterResult.prototype.addResult = function(message) {
|
|
|
|
return this.results.push(message);
|
|
|
|
};
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
HeadlessReporterResult.prototype.print = function() {
|
|
|
|
var bestChoice, output, result, _i, _len, _ref, _results;
|
|
|
|
output = this.name.foreground('red');
|
|
|
|
bestChoice = HeadlessReporterResult.findSpecLine(this.splitName);
|
|
|
|
if (bestChoice.file) {
|
|
|
|
output += (" (" + bestChoice.file + ":" + bestChoice.lineNumber + ")").foreground('blue');
|
|
|
|
}
|
|
|
|
JHW.stdout.puts("\n\n" + output);
|
|
|
|
_ref = this.results;
|
|
|
|
_results = [];
|
|
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
|
|
result = _ref[_i];
|
|
|
|
output = result.message.foreground('red');
|
|
|
|
if (result.lineNumber) {
|
|
|
|
output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright();
|
|
|
|
}
|
|
|
|
JHW.stdout.puts(" " + output);
|
2011-11-20 00:15:38 +00:00
|
|
|
if (result.line != null) {
|
|
|
|
_results.push(JHW.stdout.puts((" " + result.line).foreground('yellow')));
|
|
|
|
} else {
|
|
|
|
_results.push(void 0);
|
|
|
|
}
|
2011-10-24 20:40:08 +00:00
|
|
|
}
|
|
|
|
return _results;
|
|
|
|
};
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
HeadlessReporterResult.findSpecLine = function(splitName) {
|
|
|
|
var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref;
|
|
|
|
bestChoice = {
|
|
|
|
accuracy: 0,
|
|
|
|
file: null,
|
|
|
|
lineNumber: null
|
|
|
|
};
|
|
|
|
_ref = HeadlessReporterResult.specLineNumbers;
|
|
|
|
for (file in _ref) {
|
|
|
|
lines = _ref[file];
|
|
|
|
index = 0;
|
|
|
|
lineNumber = 0;
|
|
|
|
while (newLineNumberInfo = lines[splitName[index]]) {
|
|
|
|
if (newLineNumberInfo.length === 0) {
|
|
|
|
lineNumber = newLineNumberInfo[0];
|
|
|
|
} else {
|
|
|
|
lastLine = null;
|
|
|
|
for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) {
|
|
|
|
line = newLineNumberInfo[_i];
|
|
|
|
lastLine = line;
|
2011-11-20 00:15:38 +00:00
|
|
|
if (line > lineNumber) break;
|
2011-10-24 20:40:08 +00:00
|
|
|
}
|
|
|
|
lineNumber = lastLine;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
if (index > bestChoice.accuracy) {
|
|
|
|
bestChoice = {
|
|
|
|
accuracy: index,
|
|
|
|
file: file,
|
|
|
|
lineNumber: lineNumber
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bestChoice;
|
|
|
|
};
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
return HeadlessReporterResult;
|
2011-11-20 00:15:38 +00:00
|
|
|
|
2011-10-24 20:40:08 +00:00
|
|
|
})();
|