/*\ title: test-wikitext.js type: application/javascript tags: [[$:/tags/test-spec]] Tests the wikitext rendering pipeline end-to-end. We also need tests that individually test parsers, rendertreenodes etc., but this gets us started. \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; describe("WikiText tests", function() { // Create a wiki var wiki = new $tw.Wiki(); // Add a couple of tiddlers wiki.addTiddler({title: "TiddlerOne", text: "The quick brown fox"}); wiki.addTiddler({title: "TiddlerTwo", text: "The rain in Spain\nfalls mainly on the plain"}); wiki.addTiddler({title: "TiddlerThree", text: "The speed of sound\n\nThe light of speed"}); wiki.addTiddler({title: "TiddlerFour", text: "\\define my-macro(adjective:'groovy')\nThis is my ''amazingly'' $adjective$ macro!\n\\end\n\n<$link to=<>>This is a link"}); it("should render tiddlers with no special markup as-is", function() { expect(wiki.renderTiddler("text/plain","TiddlerOne")).toBe("The quick brown fox"); }); it("should preserve single new lines", function() { expect(wiki.renderTiddler("text/plain","TiddlerTwo")).toBe("The rain in Spain\nfalls mainly on the plain"); }); it("should use double new lines to create paragraphs", function() { // The paragraphs are lost in the conversion to plain text expect(wiki.renderTiddler("text/plain","TiddlerThree")).toBe("The speed of soundThe light of speed"); }); it("should render plain text tiddlers as a paragraph", function() { expect(wiki.renderTiddler("text/html","TiddlerOne")).toBe("

The quick brown fox

"); }); it("should preserve single new lines", function() { expect(wiki.renderTiddler("text/html","TiddlerTwo")).toBe("

The rain in Spain\nfalls mainly on the plain

"); }); it("should use double new lines to create paragraphs", function() { expect(wiki.renderTiddler("text/html","TiddlerThree")).toBe("

The speed of sound

The light of speed

"); }); it("should support attributes specified as macro invocations", function() { expect(wiki.renderTiddler("text/html","TiddlerFour")).toBe("

This is a link

"); }); it("handles style wikitext notation", function() { expect(wiki.renderText("text/html","text/vnd-tiddlywiki","@@.myclass\n!header\n@@")).toBe("

header

"); expect(wiki.renderText("text/html","text/vnd-tiddlywiki","@@.myclass\n
\n\nContent
\n@@")).toBe("

Content

"); expect(wiki.renderText("text/html","text/vnd-tiddlywiki","@@.myclass\n---\n@@")).toBe("
"); // Test styles can be added too expect(wiki.renderText("text/html","text/vnd-tiddlywiki","@@color:red;\n
\n\nContent
\n@@")).toBe("

Content

"); expect(wiki.renderText("text/html","text/vnd-tiddlywiki","@@color:red;\n---\n@@")).toBe("
"); }); it("handles inline style wikitext notation", function() { expect(wiki.renderText("text/html","text/vnd-tiddlywiki", "some @@highlighted@@ text")).toBe('

some highlighted text

'); expect(wiki.renderText("text/html","text/vnd-tiddlywiki", "some @@color:green;.tc-inline-style 1 style and 1 class@@ text")).toBe('

some 1 style and 1 class text

'); expect(wiki.renderText("text/html","text/vnd-tiddlywiki", "some @@background-color:red;red@@ text")).toBe('

some red text

'); expect(wiki.renderText("text/html","text/vnd-tiddlywiki", "some @@.myClass class@@ text")).toBe('

some class text

'); expect(wiki.renderText("text/html","text/vnd-tiddlywiki", "some @@.myClass.secondClass 2 classes@@ text")).toBe('

some 2 classes text

'); expect(wiki.renderText("text/html","text/vnd-tiddlywiki", "some @@background:red;.myClass style and class@@ text")).toBe('

some style and class text

'); expect(wiki.renderText("text/html","text/vnd-tiddlywiki", "some @@background:red;color:white;.myClass 2 style and 1 class@@ text")).toBe('

some 2 style and 1 class text

'); }); }); })();