1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-28 02:50:27 +00:00

Experimenting with test rigs for the wikifier

This approach seems to be a bit too verbose for comfort
This commit is contained in:
Jeremy Ruston 2011-12-05 12:26:34 +00:00
parent e43237e282
commit 9d37633f15

View File

@ -10,29 +10,79 @@ var Tiddler = require("./js/Tiddler.js").Tiddler,
utils = require("./js/Utils.js"),
util = require("util");
// Create a store
var store = new TiddlyWiki();
// Create some tiddlers
store.addTiddler(new Tiddler({
title: "First tiddler",
text: "This is the ''text'' of the first tiddler"
}));
store.addTiddler(new Tiddler({
title: "Second tiddler",
text: "!!Heading\nThis is the text of the second tiddler. It has a list:\n* Item one\n* Item two\n* Item three\nAnd a <<macro invocation>>\n"
}));
// Create the formatter
var formatter = new Formatter();
// Create the wikifier attached to the store and the formatter
var wikifier = new Wikifier(store,formatter);
function wikifyTiddler(title) {
wikifier.wikify(store.getTiddlerText(title));
console.error(title + " wikified to:\n" + util.inspect(wikifier.tree,false,10));
var wikiTest = function(spec) {
var t,
store = new TiddlyWiki(),
formatter = new Formatter(),
wikifier = new Wikifier(store,formatter),
w;
for(t=0; t<spec.tiddlers.length; t++) {
store.addTiddler(new Tiddler(spec.tiddlers[t]));
}
for(t=0; t<spec.tests.length; t++) {
w = wikifier.wikify(store.getTiddlerText(spec.tests[t].tiddler));
if(JSON.stringify(w) !== JSON.stringify(spec.tests[t].output)) {
console.error("Failed at tiddler: " + spec.tests[t].tiddler + " with JSON:\n" + util.inspect(w,false,8));
}
}
}
wikifyTiddler("First tiddler");
wikifyTiddler("Second tiddler");
wikiTest({ tiddlers:
[ { title: 'FirstTiddler',
text: 'This is the \'\'text\'\' of the first tiddler, with a link to the SecondTiddler, too.' },
{ title: 'SecondTiddler',
text: '!!Heading\nThis is the second tiddler. It has a list:\n* Item one\n* Item two\n* Item three\nAnd a <<macro invocation>>\n' },
{ title: 'ThirdTiddler',
text: 'An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]]' },
{ title: 'Fourth Tiddler',
text: 'An image [img[Something.jpg]]' } ],
tests:
[ { tiddler: 'FirstTiddler',
output:
[ { type: 'text', value: 'This is the ' },
{ type: 'strong',
children: [ { type: 'text', value: 'text' } ] },
{ type: 'text',
value: ' of the first tiddler, with a link to the ' },
{ type: 'tiddlerLink',
href: 'SecondTiddler',
children: [ { type: 'text', value: 'SecondTiddler' } ] },
{ type: 'text', value: ', too.' } ] },
{ tiddler: 'SecondTiddler',
output:
[ { type: 'h2',
attributes: {},
children: [ { type: 'text', value: 'Heading' } ] },
{ type: 'text',
value: 'This is the second tiddler. It has a list:' },
{ type: 'br' },
{ type: 'ul',
attributes: {},
children:
[ { type: 'li',
attributes: {},
children: [ { type: 'text', value: ' Item one' } ] },
{ type: 'li',
attributes: {},
children: [ { type: 'text', value: ' Item two' } ] },
{ type: 'li',
attributes: {},
children: [ { type: 'text', value: ' Item three' } ] } ] },
{ type: 'text', value: 'And a ' },
{ type: 'macro', name: 'macro', params: 'invocation' },
{ type: 'br' } ] },
{ tiddler: 'ThirdTiddler',
output:
[ { type: 'text', value: 'An explicit link ' },
{ type: 'tiddlerLink',
href: 'Fourth Tiddler',
children: [ { type: 'text', value: 'Fourth Tiddler' } ] },
{ type: 'text', value: ' and ' },
{ type: 'tiddlerLink',
href: 'Fourth Tiddler',
children: [ { type: 'text', value: 'a pretty link' } ] } ] },
{ tiddler: 'Fourth Tiddler',
output:
[ { type: 'text', value: 'An image ' },
{ type: 'img', attributes: {}, src: 'Something.jpg' } ] } ] }
);