######################### use Test::More tests => 24; BEGIN { use_ok 'HTML::BBCode'; } ######################### use strict; use warnings; my $bbc = HTML::BBCode->new(); isa_ok($bbc, 'HTML::BBCode', 'default'); # Basic parsing is($bbc->parse('[b]foo[/b]'), 'foo', 'bold'); is($bbc->parse('[u]foo[/u]'), 'foo', 'underline'); is($bbc->parse('[i]foo[/i]'), 'foo', 'italic'); is($bbc->parse('[color=red]foo[/color]'), 'foo', 'color'); is($bbc->parse('[size=24]foo[/size]'), 'foo', 'font size'); is($bbc->parse('[quote]foo[/quote]'), '
Quote:
foo
', 'quote (simple)'); is($bbc->parse('[quote="foo"]bar[/quote]'), '
"foo" wrote:
bar
', 'quote (with author)'); is($bbc->parse('[code][/code]'), '
Code:
<foo>
', 'code'); is($bbc->parse('[url]http://www.b10m.net/[/url]'), 'http://www.b10m.net/', 'hyperlink (simple)'); is($bbc->parse('[url=http://www.b10m.net/]lame site[/url]'), 'lame site', 'hyperlink (with link-text)'); is($bbc->parse('[email]foo@bar.com[/email]'), 'foo@bar.com', 'mailto-links'); is($bbc->parse('[img]foo.png[/img]'), '', 'image'); is($bbc->parse('[url=http://b10m.net][img]/b10m/logo.png.noway[/img][/url]'), '', 'linked image'); is($bbc->parse('[list][*]foo[*]bar[/list]'), "", 'unordered list'); is($bbc->parse('[list=1][*]foo[*]bar[/list]'), "
  1. foo
  2. \n
  3. bar
  4. \n
", 'ordered list'); is($bbc->parse('[list=a][*]foo[*]bar[/list]'), "
  1. foo
  2. \n
  3. bar
  4. \n
", 'ordered list (alpha style)'); # Mix them and do 'em wrong! is($bbc->parse('[b]bold, [i]bold and italic[/i][/b][/b]'), 'bold, bold and italic[/b]', 'mixed, and "wrong"'); # Nested quotes is($bbc->parse('[quote="world population"][quote="B10m"]no one listens[/quote]you\'ve got that right[/quote] boohoo'), '
"world population" wrote:
"B10m" wrote:
no one listens
you've got that right
boohoo', 'nested quotes'); # new object, with stripscripts off $bbc = HTML::BBCode->new({ stripscripts => 0 }); isa_ok($bbc, 'HTML::BBCode', 'default'); is($bbc->parse('[b]bold[/b]'), 'bold', 'stripscripts off'); # new object, with linebreak $bbc = HTML::BBCode->new({ linebreaks => 1 }); isa_ok($bbc, 'HTML::BBCode', 'default'); my $test=<<'__TEXT__'; This is a test to see whether linebreaks can be converted. __TEXT__ is($bbc->parse($test), "This is a test to see
\nwhether linebreaks can be converted.
\n", 'linebreaks');