1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Improved wikification test rig

Now it checks the HTML and plain text representations too.
This commit is contained in:
Jeremy Ruston 2011-12-06 17:26:29 +00:00
parent e1e510cea2
commit fa7669bcd5

View File

@ -9,29 +9,32 @@ var Tiddler = require("./js/Tiddler.js").Tiddler,
util = require("util");
var wikiTest = function(spec) {
// console.error(util.inspect(spec,false,99));
var t,
store = new TiddlyWiki(),
w;
for(t=0; t<spec.tiddlers.length; t++) {
var tid = new Tiddler(spec.tiddlers[t]);
store.addTiddler(tid);
console.error("%s in HTML:\n%s\nAnd in plain:\n%s",
tid.fields.title,
tid.getParseTree().render("text/html",store,tid.fields.title),
tid.getParseTree().render("text/plain",store,tid.fields.title));
}
for(t=0; t<spec.tests.length; t++) {
w = store.getTiddler(spec.tests[t].tiddler).getParseTree().tree;
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) + "\nTarget was:\n" + util.inspect(spec.tests[t].output,false,8));
w = store.getTiddler(spec.tests[t].tiddler).getParseTree();
if(JSON.stringify(w.tree) !== JSON.stringify(spec.tests[t].output.tree)) {
console.error("Failed at tiddler: " + spec.tests[t].tiddler + " with JSON:\n" + util.inspect(w.tree,false,50) + "\nTarget was:\n" + util.inspect(spec.tests[t].output.tree,false,50));
}
var r = w.render("text/html",store,spec.tests[t].tiddler);
if(r !== spec.tests[t].output.html) {
console.error("Failed at tiddler: " + spec.tests[t].tiddler + " with HTML:\n" + r + "\nTarget was:\n" + spec.tests[t].output.html);
}
var r = w.render("text/plain",store,spec.tests[t].tiddler);
if(r !== spec.tests[t].output.plain) {
console.error("Failed at tiddler: " + spec.tests[t].tiddler + " with plain text:\n" + r + "\nTarget was:\n" + spec.tests[t].output.plain);
}
}
};
wikiTest({ tiddlers:
wikiTest(
{ tiddlers:
[ { title: 'FirstTiddler',
text: 'This is the \'\'text\'\' of the first tiddler, with a @@font-size:8em;color:red;link@@ to the SecondTiddler, too.' },
{ title: 'SecondTiddler',
@ -43,48 +46,59 @@ wikiTest({ tiddlers:
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 ' },
{ type: 'span',
children: [ { type: 'text', value: 'link' } ],
attributes: { style: { 'font-size': '8em', color: 'red' } } },
{ type: 'text', value: ' to the ' },
{ type: 'a',
children: [ { type: 'text', value: 'SecondTiddler' } ],
attributes: { href: 'SecondTiddler', className: 'tiddlyLink' } },
{ type: 'text', value: ', too.' } ] },
{ tree:
[ { type: 'text', value: 'This is the ' },
{ type: 'strong',
children: [ { type: 'text', value: 'text' } ] },
{ type: 'text', value: ' of the first tiddler, with a ' },
{ type: 'span',
children: [ { type: 'text', value: 'link' } ],
attributes: { style: { 'font-size': '8em', color: 'red' } } },
{ type: 'text', value: ' to the ' },
{ type: 'a',
children: [ { type: 'text', value: 'SecondTiddler' } ],
attributes: { href: 'SecondTiddler', className: 'tiddlyLink' } },
{ type: 'text', value: ', too.' } ],
html: 'This is the <strong>text</strong> of the first tiddler, with a <span style="font-size:8em;color:red;">link</span> to the <a href="SecondTiddler" className="tiddlyLink">SecondTiddler</a>, too.',
plain: 'This is the text of the first tiddler, with a link to the SecondTiddler, too.' } },
{ tiddler: 'SecondTiddler',
output:
[ { type: 'h2',
children: [ { type: 'text', value: 'Heading' } ] },
{ type: 'text',
value: 'This is the second tiddler. It has a list:' },
{ type: 'br' },
{ type: 'ul',
children:
[ { type: 'li',
children: [ { type: 'text', value: ' Item one' } ] },
{ type: 'li',
children: [ { type: 'text', value: ' Item two' } ] },
{ type: 'li',
children: [ { type: 'text', value: ' Item three' } ] } ] },
{ type: 'text', value: 'And a ' },
{ type: 'macro', name: 'macro', params: 'invocation' },
{ type: 'br' } ] },
{ tree:
[ { type: 'h2', children: [ { type: 'text', value: 'Heading' } ] },
{ type: 'text',
value: 'This is the second tiddler. It has a list:' },
{ type: 'br' },
{ type: 'ul',
children:
[ { type: 'li',
children: [ { type: 'text', value: ' Item one' } ] },
{ type: 'li',
children: [ { type: 'text', value: ' Item two' } ] },
{ type: 'li',
children: [ { type: 'text', value: ' Item three' } ] } ] },
{ type: 'text', value: 'And a ' },
{ type: 'macro', name: 'macro', params: 'invocation' },
{ type: 'br' } ],
html: '<h2>Heading</h2>This is the second tiddler. It has a list:<br /><ul><li> Item one</li><li> Item two</li><li> Item three</li></ul>And a <macro></macro><br />',
plain: 'HeadingThis is the second tiddler. It has a list: Item one Item two Item threeAnd a ' } },
{ tiddler: 'ThirdTiddler',
output:
[ { type: 'text', value: 'An explicit link ' },
{ type: 'a',
children: [ { type: 'text', value: 'Fourth Tiddler' } ],
attributes: { href: 'Fourth Tiddler', className: 'tiddlyLink' } },
{ type: 'text', value: ' and ' },
{ type: 'a',
children: [ { type: 'text', value: 'a pretty link' } ],
attributes: { href: 'Fourth Tiddler', className: 'tiddlyLink' } } ] },
{ tree:
[ { type: 'text', value: 'An explicit link ' },
{ type: 'a',
children: [ { type: 'text', value: 'Fourth Tiddler' } ],
attributes: { href: 'Fourth Tiddler', className: 'tiddlyLink' } },
{ type: 'text', value: ' and ' },
{ type: 'a',
children: [ { type: 'text', value: 'a pretty link' } ],
attributes: { href: 'Fourth Tiddler', className: 'tiddlyLink' } } ],
html: 'An explicit link <a href="Fourth Tiddler" className="tiddlyLink">Fourth Tiddler</a> and <a href="Fourth Tiddler" className="tiddlyLink">a pretty link</a>',
plain: 'An explicit link Fourth Tiddler and a pretty link' } },
{ tiddler: 'Fourth Tiddler',
output:
[ { type: 'text', value: 'An image ' },
{ type: 'img', attributes: {src: 'Something.jpg' } } ] } ] }
{ tree:
[ { type: 'text', value: 'An image ' },
{ type: 'img', attributes: { src: 'Something.jpg' } } ],
html: 'An image <img src="Something.jpg" />',
plain: 'An image ' } } ] }
);