2011-12-05 10:34:43 +00:00
/ *
Wikifier test rig
* /
var Tiddler = require ( "./js/Tiddler.js" ) . Tiddler ,
TiddlyWiki = require ( "./js/TiddlyWiki.js" ) . TiddlyWiki ,
utils = require ( "./js/Utils.js" ) ,
util = require ( "util" ) ;
2011-12-05 12:26:34 +00:00
var wikiTest = function ( spec ) {
2011-12-06 18:04:40 +00:00
//console.error(util.inspect(spec,false,99));
2011-12-05 12:26:34 +00:00
var t ,
store = new TiddlyWiki ( ) ,
w ;
for ( t = 0 ; t < spec . tiddlers . length ; t ++ ) {
2011-12-05 18:21:52 +00:00
var tid = new Tiddler ( spec . tiddlers [ t ] ) ;
store . addTiddler ( tid ) ;
2011-12-05 12:26:34 +00:00
}
for ( t = 0 ; t < spec . tests . length ; t ++ ) {
2011-12-06 17:26:29 +00:00
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 ) ;
2011-12-05 12:26:34 +00:00
}
}
2011-12-05 16:50:25 +00:00
} ;
2011-12-05 10:34:43 +00:00
2011-12-06 17:26:29 +00:00
wikiTest (
{ tiddlers :
2011-12-05 12:26:34 +00:00
[ { title : 'FirstTiddler' ,
2011-12-06 10:40:49 +00:00
text : 'This is the \'\'text\'\' of the first tiddler, with a @@font-size:8em;color:red;link@@ to the SecondTiddler, too.' } ,
2011-12-05 12:26:34 +00:00
{ 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' ,
2011-12-06 18:04:40 +00:00
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|' } ] ,
2011-12-06 17:26:29 +00:00
tests :
2011-12-05 12:26:34 +00:00
[ { tiddler : 'FirstTiddler' ,
output :
2011-12-06 17:26:29 +00:00
{ 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.' } } ,
2011-12-05 12:26:34 +00:00
{ tiddler : 'SecondTiddler' ,
output :
2011-12-06 17:26:29 +00:00
{ 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 ' } } ,
2011-12-05 12:26:34 +00:00
{ tiddler : 'ThirdTiddler' ,
output :
2011-12-06 17:26:29 +00:00
{ 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' } } ,
2011-12-05 12:26:34 +00:00
{ tiddler : 'Fourth Tiddler' ,
output :
2011-12-06 17:26:29 +00:00
{ tree :
[ { type : 'text' , value : 'An image ' } ,
{ type : 'img' , attributes : { src : 'Something.jpg' } } ] ,
html : 'An image <img src="Something.jpg" />' ,
2011-12-06 18:04:40 +00:00
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' } } ] }
2011-12-05 12:26:34 +00:00
) ;