Created
October 22, 2014 12:23
-
-
Save takkaria/d560bc8f85a22dee2eb7 to your computer and use it in GitHub Desktop.
tester for echo feedfetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require('fs') | |
text = fs.readFileSync('findDate.json', 'utf8'); | |
tests = JSON.parse(text); | |
Date.prototype.toShortISOString = function() { | |
function pad(number) { | |
if (number < 10) | |
return '0' + number; | |
else | |
return number; | |
} | |
return this.getUTCFullYear() + | |
'-' + pad( this.getUTCMonth() + 1 ) + | |
'-' + pad( this.getUTCDate() ) + | |
'T' + pad( this.getUTCHours() ) + | |
':' + pad( this.getUTCMinutes() ); | |
}; | |
var data = { | |
total: 0, | |
passed: 0, | |
}; | |
console.log("Starting tests..."); | |
for (key in tests) { | |
if (!p.hasOwnProperty(prop)) { | |
// The current property is not a direct property of p | |
continue; | |
} | |
data.total++; | |
var test = tests[key]; | |
var date = findDate(new Date(test.today), test.content); | |
if (date) | |
date = date.toShortISOString(); | |
if (date == test.result) { | |
data.passsed++; | |
} else { | |
console.log("Test '" + key + "' failed:"); | |
console.log("- expected '" + test.result + "'"); | |
console.log("- got '" + date + "'"); | |
} | |
} | |
console.log("Tests finished. " + data.passed + "/" + data.total + " passed."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment