/*global md5:true */ module("Discourse.BBCode"); var format = function(input, expected, text) { // testing 1 2 3 equal(Discourse.BBCode.format(input, {lookupAvatar: false}), expected, text); }; test('basic bbcode', function() { format("[b]strong[/b]", "strong", "bolds text"); format("[i]emphasis[/i]", "emphasis", "italics text"); format("[u]underlined[/u]", "underlined", "underlines text"); format("[s]strikethrough[/s]", "strikethrough", "strikes-through text"); format("[code]\nx++\n[/code]", "
\nx++\n
", "makes code into pre"); format("[spoiler]it's a sled[/spoiler]", "it's a sled", "supports spoiler tags"); format("[img]http://eviltrout.com/eviltrout.png[/img]", "", "links images"); format("[url]http://bettercallsaul.com[/url]", "http://bettercallsaul.com", "supports [url] without a title"); format("[email]eviltrout@mailinator.com[/email]", "eviltrout@mailinator.com", "supports [email] without a title"); }); test('lists', function() { format("[ul][li]option one[/li][/ul]", "", "creates an ul"); format("[ol][li]option one[/li][/ol]", "
  1. option one
", "creates an ol"); }); test('color', function() { format("[color=#00f]blue[/color]", "blue", "supports [color=] with a short hex value"); format("[color=#ffff00]yellow[/color]", "yellow", "supports [color=] with a long hex value"); format("[color=red]red[/color]", "red", "supports [color=] with an html color"); format("[color=javascript:alert('wat')]noop[/color]", "noop", "it performs a noop on invalid input"); }); test('tags with arguments', function() { format("[size=35]BIG[/size]", "BIG", "supports [size=]"); format("[url=http://bettercallsaul.com]better call![/url]", "better call!", "supports [url] with a title"); format("[email=eviltrout@mailinator.com]evil trout[/email]", "evil trout", "supports [email] with a title"); format("[u][i]abc[/i][/u]", "abc", "can nest tags"); format("[b]first[/b] [b]second[/b]", "first second", "can bold two things on the same line"); }); test("quotes", function() { var post = Discourse.Post.create({ cooked: "

lorem ipsum

", username: "eviltrout", post_number: 1, topic_id: 2 }); var formatQuote = function(val, expected, text) { equal(Discourse.BBCode.buildQuoteBBCode(post, val), expected, text); }; formatQuote(undefined, "", "empty string for undefined content"); formatQuote(null, "", "empty string for null content"); formatQuote("", "", "empty string for empty string content"); formatQuote("lorem", "[quote=\"eviltrout, post:1, topic:2\"]\nlorem\n[/quote]\n\n", "correctly formats quotes"); formatQuote(" lorem \t ", "[quote=\"eviltrout, post:1, topic:2\"]\nlorem\n[/quote]\n\n", "trims white spaces before & after the quoted contents"); formatQuote("lorem ipsum", "[quote=\"eviltrout, post:1, topic:2, full:true\"]\nlorem ipsum\n[/quote]\n\n", "marks quotes as full when the quote is the full message"); formatQuote("**lorem** ipsum", "[quote=\"eviltrout, post:1, topic:2, full:true\"]\n**lorem** ipsum\n[/quote]\n\n", "keeps BBCode formatting"); }); test("quote formatting", function() { // TODO: This HTML matching is quite ugly. format("[quote=\"eviltrout, post:1, topic:1\"]abc[/quote]", "

\n

", "renders quotes properly"); format("[quote=\"eviltrout, post:1, topic:1\"]abc[quote=\"eviltrout, post:2, topic:2\"]nested[/quote][/quote]", "

\n

", "can nest quotes"); format("before[quote=\"eviltrout, post:1, topic:1\"]first[/quote]middle[quote=\"eviltrout, post:2, topic:2\"]second[/quote]after", "before

\n

middle

\n

after", "can handle more than one quote"); }); test("extract quotes", function() { var q = "[quote=\"eviltrout, post:1, topic:2\"]hello[/quote]"; var result = Discourse.BBCode.extractQuotes(q + " world"); equal(result.text, md5(q) + "\n world"); present(result.template); });