Skip to content

Commit

Permalink
Verify.js:
Browse files Browse the repository at this point in the history
use clean() only if there is a string, else output json
  • Loading branch information
mdunisch committed Aug 19, 2014
1 parent c41a67c commit 779b27a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ var exerciser = require('workshopper-exercise');
var filecheck = require('workshopper-exercise/filecheck');
var execute = require('workshopper-exercise/execute');

var cleanAndStringify = _.compose(clean, stringify);

module.exports = function (tests, run) {
var exercise = _.compose(execute, filecheck)(exerciser());

Expand Down Expand Up @@ -38,7 +36,7 @@ module.exports = function (tests, run) {

logcompare(run.json, result, run.expect);

if (!result || !_.isEqual(result, run.expect)) {
if (!result || !_.isEqual(clean(result), clean(run.expect))) {
this.emit('fail', 'Test');
return callback(null, false);
}
Expand All @@ -50,7 +48,7 @@ module.exports = function (tests, run) {
var allPassed = _(tests).map(function(item, element){
var isCorrect;
try {
isCorrect = _.isEqual(item.shouldbe, usersolution(item.input));
isCorrect = _.isEqual(clean(item.shouldbe), clean(usersolution(item.input)));
} catch (e) { }

if(!isCorrect) {
Expand All @@ -74,21 +72,26 @@ function logcompare(input, output, shouldbe){
line(),
'Input',
line(),
stringify(input).replace(/\\n/g,"\n"),
stringify(input),
line(),
'Output: ' + cleanAndStringify(output).replace(/\\n/g,"\n"),
'Output: ' + stringify(output),
line(),
'Output should be: ' + cleanAndStringify(shouldbe).replace(/\\n/g,"\n"),
'Output should be: ' + stringify(shouldbe),
line()
].join('\n'));
}

function stringify(obj) {
return JSON.stringify(obj, null, 2);
return JSON.stringify(obj, null, 2).replace(/\\n/g,"\n");
}

function clean(str) {
if (!str) return void 0;

if (typeof str !== "string") {
return str;
}

return str.replace(/\r?\n|\r/g, '').replace(/(\s)+/g, '$1');
}

Expand Down

0 comments on commit 779b27a

Please sign in to comment.