2011-12-12 10:52:04 +00:00
|
|
|
(function(){
|
|
|
|
|
2011-12-05 10:34:43 +00:00
|
|
|
/*
|
|
|
|
Wikifier test rig
|
2011-12-07 13:18:07 +00:00
|
|
|
|
|
|
|
Usage:
|
|
|
|
node wikitest.js <testdirectory>
|
|
|
|
|
|
|
|
This command creates a store and loads up all the `*.tid` files in the test directory. Then it wikifies each tiddler in turn,
|
|
|
|
verifying that the output matches `<tiddlername>.html` and `<tiddlername>.txt`.
|
|
|
|
|
2011-12-05 10:34:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-12-09 16:34:02 +00:00
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
2011-12-05 10:34:43 +00:00
|
|
|
|
|
|
|
var Tiddler = require("./js/Tiddler.js").Tiddler,
|
2011-12-06 18:29:53 +00:00
|
|
|
WikiStore = require("./js/WikiStore.js").WikiStore,
|
2011-12-11 18:28:09 +00:00
|
|
|
TextProcessors = require("./js/TextProcessors.js").TextProcessors,
|
|
|
|
WikiTextProcessor = require("./js/WikiTextProcessor.js").WikiTextProcessor,
|
2011-12-11 14:51:48 +00:00
|
|
|
TiddlerConverters = require("./js/TiddlerConverters.js").TiddlerConverters,
|
|
|
|
tiddlerInput = require("./js/TiddlerInput.js"),
|
2011-12-05 10:34:43 +00:00
|
|
|
utils = require("./js/Utils.js"),
|
2011-12-07 13:18:07 +00:00
|
|
|
util = require("util"),
|
|
|
|
fs = require("fs"),
|
|
|
|
path = require("path");
|
2011-12-05 10:34:43 +00:00
|
|
|
|
2011-12-07 13:18:07 +00:00
|
|
|
var testdirectory = process.argv[2],
|
2011-12-11 18:28:09 +00:00
|
|
|
textProcessors = new TextProcessors(),
|
2011-12-11 14:51:48 +00:00
|
|
|
tiddlerConverters = new TiddlerConverters(),
|
2011-12-11 18:28:09 +00:00
|
|
|
store = new WikiStore({
|
|
|
|
textProcessors: textProcessors
|
|
|
|
}),
|
2011-12-07 13:18:07 +00:00
|
|
|
files = fs.readdirSync(testdirectory),
|
|
|
|
titles = [],
|
|
|
|
f,t,extname,basename;
|
|
|
|
|
2011-12-13 12:30:09 +00:00
|
|
|
textProcessors.registerTextProcessor("text/x-tiddlywiki",new WikiTextProcessor({
|
|
|
|
textProcessors: textProcessors
|
|
|
|
}));
|
2011-12-11 14:51:48 +00:00
|
|
|
tiddlerInput.register(tiddlerConverters);
|
|
|
|
|
2011-12-07 13:18:07 +00:00
|
|
|
for(f=0; f<files.length; f++) {
|
|
|
|
extname = path.extname(files[f]);
|
|
|
|
if(extname === ".tid") {
|
2011-12-11 14:51:48 +00:00
|
|
|
var tiddlers = tiddlerConverters.deserialize(extname,fs.readFileSync(path.resolve(testdirectory,files[f]),"utf8"));
|
2011-12-07 13:18:07 +00:00
|
|
|
if(tiddlers.length > 1) {
|
|
|
|
throw "Cannot use .JSON files";
|
2011-12-05 12:26:34 +00:00
|
|
|
}
|
2011-12-07 13:18:07 +00:00
|
|
|
store.addTiddler(new Tiddler(tiddlers[0]));
|
|
|
|
titles.push(tiddlers[0].title);
|
2011-12-05 12:26:34 +00:00
|
|
|
}
|
2011-12-07 13:18:07 +00:00
|
|
|
}
|
2011-12-05 10:34:43 +00:00
|
|
|
|
2011-12-07 13:18:07 +00:00
|
|
|
for(t=0; t<titles.length; t++) {
|
2011-12-09 18:29:29 +00:00
|
|
|
var htmlTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".html"),"utf8"),
|
|
|
|
plainTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".txt"),"utf8"),
|
2011-12-11 18:28:09 +00:00
|
|
|
tiddler = store.getTiddler(titles[t]),
|
|
|
|
htmlRender = store.renderTiddler("text/html",titles[t]),
|
|
|
|
plainRender = store.renderTiddler("text/plain",titles[t]);
|
2011-12-07 13:18:07 +00:00
|
|
|
if(htmlTarget !== htmlRender) {
|
2011-12-09 08:59:49 +00:00
|
|
|
console.error("Tiddler %s html error\nTarget: %s\nFound: %s\n",titles[t],htmlTarget,htmlRender);
|
2011-12-07 13:18:07 +00:00
|
|
|
}
|
|
|
|
if(plainTarget !== plainRender) {
|
2011-12-09 08:59:49 +00:00
|
|
|
console.error("Tiddler %s plain text error\nTarget: %s\nFound: %s\n",titles[t],plainTarget,plainRender);
|
2011-12-07 13:18:07 +00:00
|
|
|
}
|
2011-12-07 16:44:23 +00:00
|
|
|
}
|
2011-12-12 10:52:04 +00:00
|
|
|
|
|
|
|
})();
|