require 'spec_helper' describe BBCoder do context "with dirty input" do it "should parse content with \" in it" do '[p]Text phrase: "going away"[/p]'.bbcode_to_html.should == '
Text phrase: "going away"
' end it "should parse content with { in it" do '[p]OMG :-{[/p]'.bbcode_to_html.should == 'OMG :-{
' end it "should parse content with } in it" do '[p]OMG :-}[/p]'.bbcode_to_html.should == 'OMG :-}
' end it "should parse content with } in it round 2" do string = "[quote=weedman]YES I STICKY IT ALL oF YOU WHO DON'T LIKE it SEND YOUR HATE HERE\n\nhttp://www.gamesyn.com/plugin.php?plugin=PrivateMessages&file=message_send.php&id=20&tid=1583\n\n:} have a good day[/quote]" result = <<-EOS EOS string.bbcode_to_html.should == result end it "should return tags as text on blank content" do '[img][/img]'.bbcode_to_html.should == '[img][/img]' end end context "with properly formatted input" do it "should parse paragraph statements" do "[p]Text and now [p]nested.[/p][/p]".bbcode_to_html.should == "Text and now
nested.
" end it "should parse paragraph and bold statements" do "[p]Text and now [b]nested.[/b][/p]".bbcode_to_html.should == "Text and now nested.
" end it "should parse a combination of statements" do output = "[p]Text and now [b]bold then [i]italics[/i][/b][/p] and then a [quote]Quote[/quote]".bbcode_to_html output.should == <<-EOSText and now bold then italics
and then a EOS end it "should handle multiple nestings of b elements" do "[b]Now I [b] am [b] extremely [b] bold![/b][/b][/b][/b]".bbcode_to_html.should == "Now I am extremely bold!" end it "should not drop the equal sign in meta" do "[url=http://example.com/?Foo=Bar]Link[/url]".bbcode_to_html.should == "Link" end end context "with incorrectly formatted input" do it "should ignore non-matched tag content" do "[b][img]http://mybad.com[/img][/b]".bbcode_to_html.should == "[img]http://mybad.com[/img]" end it "should ignore tags without required parents" do "[b]Strong list item [li]one of many[/li][/b]".bbcode_to_html.should == "Strong list item [li]one of many[/li]" end it "should ignore un-opened tags" do "[p]Text aint it grand![/p][/p]".bbcode_to_html.should == "Text aint it grand!
[/p]" end it "should ignore un-closed tags" do "[p]Text aint it grand!".bbcode_to_html.should == "[p]Text aint it grand!" end it "should ignore un-closed and un-opened tags" do "[p]Text aint it grand!".bbcode_to_html.should == "[p]Text aint it grand!" end it "shouldn't choke on extremely bad input" do "[p]Text and [/b] with a [p] and [quote] a [/p] care in sight oh [i] my [/b].".bbcode_to_html.should == "[p]Text and [/b] with aand [quote] a
care in sight oh [i] my [/b]." end it "shouldn't choke on extremely bad input with meta weirdness" do "[p]Text and [/b] with a [p] and [quote='Hahah'] a [/p] care in sight oh [i=nometaforyou] my [/b].".bbcode_to_html.should == "[p]Text and [/b] with aand [quote='Hahah'] a
care in sight oh [i=nometaforyou] my [/b]." end end context "with case-insensitive input" do it "should handle upper case tags" do "[P]Text and now [B]nested.[/B][/P]".bbcode_to_html.should == "Text and now nested.
" end it "should handle mixed upper and lower case tags" do "[p]Text and now [B]nested.[/b][/P]".bbcode_to_html.should == "Text and now nested.
" end end end