mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-04-01 08:16:55 +00:00
Revised wikification test rig
This commit is contained in:
parent
9cd2d970e0
commit
cb15e1c8d6
1
test/wikitests/Fifth Tiddler.html
Normal file
1
test/wikitests/Fifth Tiddler.html
Normal file
@ -0,0 +1 @@
|
||||
<table className="twtable"><caption align="top">A caption above the table</caption><thead><tr className="evenRow"><td align="center">Left</td><td align="center">Middle</td><td align="center">Right</td></tr></thead><tbody><tr className="oddRow"><td>North West</td><td>North</td><td>North East</td></tr><tr className="evenRow"><td>West</td><td>Here</td><td>East</td></tr><tr className="oddRow"><td>South West</td><td>South</td><td>South East</td></tr></tbody></table>
|
7
test/wikitests/Fifth Tiddler.tid
Normal file
7
test/wikitests/Fifth Tiddler.tid
Normal file
@ -0,0 +1,7 @@
|
||||
title: Fifth Tiddler
|
||||
|
||||
|A caption above the table|c
|
||||
| Left | Middle | Right |h
|
||||
|North West|North|North East|
|
||||
|West|Here|East|
|
||||
|South West|South|South East|
|
1
test/wikitests/Fifth Tiddler.txt
Normal file
1
test/wikitests/Fifth Tiddler.txt
Normal file
@ -0,0 +1 @@
|
||||
A caption above the tableLeftMiddleRightNorth WestNorthNorth EastWestHereEastSouth WestSouthSouth East
|
1
test/wikitests/FirstTiddler.html
Normal file
1
test/wikitests/FirstTiddler.html
Normal file
@ -0,0 +1 @@
|
||||
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.
|
3
test/wikitests/FirstTiddler.tid
Normal file
3
test/wikitests/FirstTiddler.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: FirstTiddler
|
||||
|
||||
This is the ''text'' of the first tiddler, with a @@font-size:8em;color:red;link@@ to the SecondTiddler, too.
|
1
test/wikitests/FirstTiddler.txt
Normal file
1
test/wikitests/FirstTiddler.txt
Normal file
@ -0,0 +1 @@
|
||||
This is the text of the first tiddler, with a link to the SecondTiddler, too.
|
1
test/wikitests/Fourth Tiddler.html
Normal file
1
test/wikitests/Fourth Tiddler.html
Normal file
@ -0,0 +1 @@
|
||||
An image <img src="Something.jpg" />
|
3
test/wikitests/Fourth Tiddler.tid
Normal file
3
test/wikitests/Fourth Tiddler.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: Fourth Tiddler
|
||||
|
||||
An image [img[Something.jpg]]
|
1
test/wikitests/Fourth Tiddler.txt
Normal file
1
test/wikitests/Fourth Tiddler.txt
Normal file
@ -0,0 +1 @@
|
||||
An image
|
1
test/wikitests/SecondTiddler.html
Normal file
1
test/wikitests/SecondTiddler.html
Normal file
@ -0,0 +1 @@
|
||||
<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 />
|
8
test/wikitests/SecondTiddler.tid
Normal file
8
test/wikitests/SecondTiddler.tid
Normal file
@ -0,0 +1,8 @@
|
||||
title: SecondTiddler
|
||||
|
||||
!!Heading
|
||||
This is the second tiddler. It has a list:
|
||||
* Item one
|
||||
* Item two
|
||||
* Item three
|
||||
And a <<macro invocation>>
|
1
test/wikitests/SecondTiddler.txt
Normal file
1
test/wikitests/SecondTiddler.txt
Normal file
@ -0,0 +1 @@
|
||||
HeadingThis is the second tiddler. It has a list: Item one Item two Item threeAnd a
|
1
test/wikitests/ThirdTiddler.html
Normal file
1
test/wikitests/ThirdTiddler.html
Normal file
@ -0,0 +1 @@
|
||||
An explicit link <a href="Fourth Tiddler" className="tiddlyLink">Fourth Tiddler</a> and <a href="Fourth Tiddler" className="tiddlyLink">a pretty link</a>
|
3
test/wikitests/ThirdTiddler.tid
Normal file
3
test/wikitests/ThirdTiddler.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: ThirdTiddler
|
||||
|
||||
An explicit link [[Fourth Tiddler]] and [[a pretty link|Fourth Tiddler]]
|
1
test/wikitests/ThirdTiddler.txt
Normal file
1
test/wikitests/ThirdTiddler.txt
Normal file
@ -0,0 +1 @@
|
||||
An explicit link Fourth Tiddler and a pretty link
|
188
wikitest.js
188
wikitest.js
@ -1,157 +1,51 @@
|
||||
/*
|
||||
Wikifier test rig
|
||||
|
||||
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`.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
var Tiddler = require("./js/Tiddler.js").Tiddler,
|
||||
WikiStore = require("./js/WikiStore.js").WikiStore,
|
||||
tiddlerInput = require("./js/TiddlerInput"),
|
||||
utils = require("./js/Utils.js"),
|
||||
util = require("util");
|
||||
util = require("util"),
|
||||
fs = require("fs"),
|
||||
path = require("path");
|
||||
|
||||
var wikiTest = function(spec) {
|
||||
//console.error(util.inspect(spec,false,99));
|
||||
var t,
|
||||
store = new WikiStore(),
|
||||
w;
|
||||
for(t=0; t<spec.tiddlers.length; t++) {
|
||||
var tid = new Tiddler(spec.tiddlers[t]);
|
||||
store.addTiddler(tid);
|
||||
}
|
||||
for(t=0; t<spec.tests.length; t++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
var testdirectory = process.argv[2],
|
||||
store = new WikiStore(),
|
||||
files = fs.readdirSync(testdirectory),
|
||||
titles = [],
|
||||
f,t,extname,basename;
|
||||
|
||||
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',
|
||||
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]]' },
|
||||
{ title: 'Fifth Tiddler',
|
||||
text: '|A caption above the table|c\n| Left | Middle | Right |h\n|North West|North|North East|\n|West|Here|East|\n|South West|South|South East|' } ],
|
||||
tests:
|
||||
[ { tiddler: 'FirstTiddler',
|
||||
output:
|
||||
{ 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:
|
||||
{ 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:
|
||||
{ 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:
|
||||
{ tree:
|
||||
[ { type: 'text', value: 'An image ' },
|
||||
{ type: 'img', attributes: { src: 'Something.jpg' } } ],
|
||||
html: 'An image <img src="Something.jpg" />',
|
||||
plain: 'An image ' } },
|
||||
{ tiddler: 'Fifth Tiddler',
|
||||
output:
|
||||
{ tree:
|
||||
[ { type: 'table',
|
||||
attributes: { className: 'twtable' },
|
||||
children:
|
||||
[ { type: 'caption',
|
||||
children: [ { type: 'text', value: 'A caption above the table' } ],
|
||||
attributes: { align: 'top' } },
|
||||
{ type: 'thead',
|
||||
children:
|
||||
[ { type: 'tr',
|
||||
children:
|
||||
[ { type: 'td',
|
||||
children: [ { type: 'text', value: 'Left' } ],
|
||||
attributes: { align: 'center' } },
|
||||
{ type: 'td',
|
||||
children: [ { type: 'text', value: 'Middle' } ],
|
||||
attributes: { align: 'center' } },
|
||||
{ type: 'td',
|
||||
children: [ { type: 'text', value: 'Right' } ],
|
||||
attributes: { align: 'center' } } ],
|
||||
attributes: { className: 'evenRow' } } ],
|
||||
attributes: {} },
|
||||
{ type: 'tbody',
|
||||
children:
|
||||
[ { type: 'tr',
|
||||
children:
|
||||
[ { type: 'td',
|
||||
children: [ { type: 'text', value: 'North West' } ] },
|
||||
{ type: 'td', children: [ { type: 'text', value: 'North' } ] },
|
||||
{ type: 'td',
|
||||
children: [ { type: 'text', value: 'North East' } ] } ],
|
||||
attributes: { className: 'oddRow' } },
|
||||
{ type: 'tr',
|
||||
children:
|
||||
[ { type: 'td', children: [ { type: 'text', value: 'West' } ] },
|
||||
{ type: 'td', children: [ { type: 'text', value: 'Here' } ] },
|
||||
{ type: 'td', children: [ { type: 'text', value: 'East' } ] } ],
|
||||
attributes: { className: 'evenRow' } },
|
||||
{ type: 'tr',
|
||||
children:
|
||||
[ { type: 'td',
|
||||
children: [ { type: 'text', value: 'South West' } ] },
|
||||
{ type: 'td', children: [ { type: 'text', value: 'South' } ] },
|
||||
{ type: 'td',
|
||||
children: [ { type: 'text', value: 'South East' } ] } ],
|
||||
attributes: { className: 'oddRow' } } ],
|
||||
attributes: {} } ] } ],
|
||||
html: '<table className="twtable"><caption align="top">A caption above the table</caption><thead><tr className="evenRow"><td align="center">Left</td><td align="center">Middle</td><td align="center">Right</td></tr></thead><tbody><tr className="oddRow"><td>North West</td><td>North</td><td>North East</td></tr><tr className="evenRow"><td>West</td><td>Here</td><td>East</td></tr><tr className="oddRow"><td>South West</td><td>South</td><td>South East</td></tr></tbody></table>',
|
||||
plain: 'A caption above the tableLeftMiddleRightNorth WestNorthNorth EastWestHereEastSouth WestSouthSouth East' } } ] }
|
||||
);
|
||||
for(f=0; f<files.length; f++) {
|
||||
extname = path.extname(files[f]);
|
||||
if(extname === ".tid") {
|
||||
var tiddlers = tiddlerInput.parseTiddlerFile(fs.readFileSync(path.resolve(testdirectory,files[f]),"utf8"),extname);
|
||||
if(tiddlers.length > 1) {
|
||||
throw "Cannot use .JSON files";
|
||||
}
|
||||
store.addTiddler(new Tiddler(tiddlers[0]));
|
||||
titles.push(tiddlers[0].title);
|
||||
}
|
||||
}
|
||||
|
||||
for(t=0; t<titles.length; t++) {
|
||||
var tree = store.getTiddler(titles[t]).getParseTree(),
|
||||
htmlRender = tree.render("text/html"),
|
||||
htmlTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".html"),"utf8"),
|
||||
plainRender = tree.render("text/plain"),
|
||||
plainTarget = fs.readFileSync(path.resolve(testdirectory,titles[t] + ".txt"),"utf8");
|
||||
if(htmlTarget !== htmlRender) {
|
||||
console.error("Tiddler %s html error\nTarget: %s\nFound: %s",titles[t],htmlTarget,htmlRender);
|
||||
}
|
||||
if(plainTarget !== plainRender) {
|
||||
console.error("Tiddler %s plain text error\nTarget: %s\nFound: %s",titles[t],plainTarget,plainRender);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user