Skip to content

Instantly share code, notes, and snippets.

@takkaria
Created October 22, 2014 12:23
Show Gist options
  • Save takkaria/d560bc8f85a22dee2eb7 to your computer and use it in GitHub Desktop.
Save takkaria/d560bc8f85a22dee2eb7 to your computer and use it in GitHub Desktop.
tester for echo feedfetch
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