/*global md5:true */ module("Discourse.BBCode"); var format = function(input, expected, text) { var cooked = Discourse.Markdown.cook(input, {lookupAvatar: false}); equal(cooked, "
" + 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++", "makes code into pre"); format("[code]\nx++\ny++\nz++\n[/code]", "
\nx++\ny++\nz++", "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"); format("[b]evil [i]trout[/i][/b]", "evil trout", "allows embedding of tags"); }); test('invalid bbcode', function() { var cooked = Discourse.Markdown.cook("[code]I am not closed\n\nThis text exists.", {lookupAvatar: false}); equal(cooked, "
[code]I am not closed
\n\nThis text exists.
", "does not raise an error with an open bbcode tag."); }); test('lists', function() { format("[ul][li]option one[/li][/ul]", "lorem ipsum
", username: "eviltrout", post_number: 1, topic_id: 2 }); var formatQuote = function(val, expected, text) { equal(Discourse.Quote.build(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"); formatQuote("this ishello", "handles new lines properly"); }); test("quotes with trailing formatting", function() { var cooked = Discourse.Markdown.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]\nhello\n[/quote]\n*Test*", {lookupAvatar: false}); equal(cooked, "
\n\nTest
", "it allows trailing formatting"); });