#!perl use strict; use warnings; # for testing 'rootdir' in links my %constants = ( rootdir => 'rootdir', ); local *Text::WikiFormat::getCurrentStatic; *Text::WikiFormat::getCurrentStatic = sub { return \%constants; }; use Test::More tests => 32; use_ok( 'Text::WikiFormat' ); my $wikitext =< 'rootdir/wiki.pl?page=', ); my $htmltext = Text::WikiFormat::format_line($wikitext, \%tags, \%opts); like( $htmltext, qr!\[!, 'format_line () should link StudlyCaps where found)' ); like( $htmltext, qr!hello!, 'three ticks should mark strong'); like( $htmltext, qr!hi!, 'two ticks should mark emphasized' ); like( $htmltext, qr!LinkMeSomewhere\n!m, 'should catch StudlyCaps' ); like( $htmltext, qr!\[!, 'should not handle extended links without flag' ); $opts{extended} = 1; $htmltext = Text::WikiFormat::format_line($wikitext, \%tags, \%opts); like( $htmltext, qr!^!m, 'should handle extended links with flag' ); $htmltext = Text::WikiFormat::format($wikitext); like( $htmltext, qr!hello!, 'three ticks should mark strong'); like( $htmltext, qr!hi!, 'two ticks should mark emphasized' ); is( scalar @{ $tags{ordered} }, 3, '... default ordered entry should have three items' ); is( ref( $tags{ordered}->[2] ), 'CODE', '... and should have subref' ); # make sure this starts a paragraph (buglet) $htmltext = Text::WikiFormat::format("nothing to see here\nmoveAlong\n", {}, { prefix => 'foo=' }); like( $htmltext, qr!^

nothing!, '... should start new text with paragraph' ); # another buglet had the wrong tag pairs when ending a list my $wikiexample =< 'foo=' }); like( $htmltext, qr!^

I am modifying this!, '... should use correct tags when ending lists' ); like( $htmltext, qr!

Here is a paragraph.
!, '... should add no newline before paragraph, but at newline in paragraph '); like( $htmltext, qr!

Here is another paragraph.

!, '... should add no newline at end of paragraph' ); like( $htmltext, qr|''literal'' double single|, '... should treat code sections literally' ); unlike( $htmltext, qr!<(\w+)>!, '... but should not create empty lists' ); $wikitext =< 'rootdir/wiki.pl?page=', extended => 1, ); $htmltext = Text::WikiFormat::format($wikitext, {}, \%opts); like( $htmltext, qr!
!m, '... should escape spaces in extended links' ); like( $htmltext, qr!escape spaces in links!m, '... should leave spaces alone in titles of extended links' ); $wikitext =<<'WIKI'; = heading = == sub heading == some text === sub sub heading === more text WIKI $htmltext = Text::WikiFormat::format($wikitext, \%tags, \%opts); like( $htmltext, qr!

heading

!, 'headings should be marked' ); like( $htmltext, qr!

sub heading

!, '... and numbered appropriately' ); # test overridable tags ok( ! main->can( 'wikiformat' ), 'Module should import nothing by default' ); can_ok( 'Text::WikiFormat', 'import' ); # given an argument, export wikiformat() somehow package Foo; Text::WikiFormat->import('wikiformat'); ::can_ok( 'Foo', 'wikiformat' ); package Bar; Text::WikiFormat->import( as => 'wf', prefix => 'foo', tag => 'bar' ); ::can_ok( 'Bar', 'wf' ); ::isnt( \&wf, \&Text::WikiFormat::format, '... and should be a wrapper around format()' ); my @args; local *Text::WikiFormat::format; *Text::WikiFormat::format = sub { @args = @_; }; wf(); ::is( $args[2]{prefix}, 'foo', 'imported sub should pass through default option' ); ::is( $args[1]{tag}, 'bar', '... and default tag' ); wf('text', { tag2 => 1 }, { prefix => 'baz' }); ::is( $args[0], 'text', '... passing through text unharmed' ); ::is( $args[1]{tag2}, 1, '... along with new tags' ); ::is( $args[2]{prefix}, 'baz', '... overriding default args as needed' ); 1;