| 1 | #!perl |
| 2 | |
| 3 | BEGIN { chdirscip-perl cpan Text-MediawikiFormat 1.04 main/chdir(). 't' if -d 't' } |
| 4 | |
| 5 | use strictscip-perl cpan Text-MediawikiFormat 1.04 strict/; |
| 6 | use warningsscip-perl cpan Text-MediawikiFormat 1.04 warnings/; |
| 7 | |
| 8 | use Test::Morescip-perl cpan Text-MediawikiFormat 1.04 Test/More/ tests => 16; |
| 9 | use Test::NoWarningsscip-perl cpan Text-MediawikiFormat 1.04 Test/NoWarnings/; |
| 10 | |
| 11 | use_okscip-perl cpan Text-MediawikiFormat 1.04 main/use_ok(). 'Text::MediawikiFormat', as => 'wf', process_html => 0; |
| 12 | |
| 13 | my $wikitext = <<WIKI; |
| 14 | |
| 15 | |
| 16 | * unordered |
| 17 | |
| 18 | Final paragraph. |
| 19 | |
| 20 | WIKI |
| 21 | |
| 22 | my $htmltext = eval { wfscip-perl cpan Text-MediawikiFormat 1.04 main/wf().($wikitext) }; |
| 23 | |
| 24 | isscip-perl cpan Text-MediawikiFormat 1.04 main/is(). $@scip-perl cpan Text-MediawikiFormat 1.04 main/`$@`., '', 'format() should throw no warnings for text starting with newlines'; |
| 25 | |
| 26 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $htmltext, qr!<li>unordered</li>!, 'ensure that lists followed by paragraphs are included correctly'; |
| 27 | |
| 28 | package Bazscip-perl cpan Text-MediawikiFormat 1.04 Baz/; |
| 29 | use Text::MediawikiFormatscip-perl cpan Text-MediawikiFormat 1.04 Text/MediawikiFormat/ as => 'wf', process_html => 0; |
| 30 | |
| 31 | ::can_okscip-perl cpan Text-MediawikiFormat 1.04 Baz/can_ok().( 'Baz', 'wf' ); |
| 32 | |
| 33 | package mainscip-perl cpan Text-MediawikiFormat 1.04 main/; |
| 34 | |
| 35 | ## |
| 36 | ## make sure tag overrides work for Kake |
| 37 | ## |
| 38 | |
| 39 | $wikitext = <<WIKI; |
| 40 | |
| 41 | * foo |
| 42 | ** bar |
| 43 | |
| 44 | WIKI |
| 45 | |
| 46 | my %format_tags = ( |
| 47 | indent => qr/^(?:\t+|\s{4,}|(?=\*+))/, |
| 48 | blocks => { unordered => qr/^\s*\*+\s*/ }, |
| 49 | nests => { unordered => 1 }, |
| 50 | ); |
| 51 | |
| 52 | $htmltext = wfscip-perl cpan Text-MediawikiFormat 1.04 main/wf().( $wikitext, \%format_tags ); |
| 53 | |
| 54 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $htmltext, qr/<li>foo<\/li>/, "first level of unordered list"; |
| 55 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $htmltext, qr/<li>bar<\/li>/, "nested unordered lists OK"; |
| 56 | |
| 57 | ## |
| 58 | ## Check that blocks not in blockorder are not fatal |
| 59 | ## |
| 60 | %format_tags = ( |
| 61 | blocks => { |
| 62 | definition => qr/^:\s*/ |
| 63 | }, |
| 64 | definition => [ "<dl>\n", "</dl>\n", '<dt><dd>', "\n" ], |
| 65 | blockorder => ['definition'], |
| 66 | ); |
| 67 | |
| 68 | my $warning; |
| 69 | local $SIGscip-perl cpan Text-MediawikiFormat 1.04 main/`%SIG`.{__WARN__} = sub { $warning = shiftscip-perl cpan Text-MediawikiFormat 1.04 main/shift(). }; |
| 70 | eval { wfscip-perl cpan Text-MediawikiFormat 1.04 main/wf().( $wikitext, \%format_tags ) }; |
| 71 | isscip-perl cpan Text-MediawikiFormat 1.04 main/is(). $@scip-perl cpan Text-MediawikiFormat 1.04 main/`$@`., '', 'format() should not die if a block is missing from blockorder'; |
| 72 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $warning, qr/No order specified/, '... warning instead'; |
| 73 | |
| 74 | my $foo = 'x'; |
| 75 | $foo .= '' unless $foo =~ /x/; |
| 76 | my $html = wfscip-perl cpan Text-MediawikiFormat 1.04 main/wf().('test'); |
| 77 | isscip-perl cpan Text-MediawikiFormat 1.04 main/is(). $html, "<p>test</p>\n", 'successful prior match should not whomp format()'; |
| 78 | |
| 79 | $wikitext = <<'WIKI'; |
| 80 | Here is some example code: |
| 81 | |
| 82 | sub example_code |
| 83 | { |
| 84 | my ($foo) = @_; |
| 85 | my $this = call_that $foo; |
| 86 | } |
| 87 | |
| 88 | Isn't it nice? |
| 89 | WIKI |
| 90 | |
| 91 | $htmltext = wfscip-perl cpan Text-MediawikiFormat 1.04 main/wf().( $wikitext, { blocks => { code => qr/^\t/ } } ); |
| 92 | |
| 93 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $htmltext, qr!<pre>sub example_code[^<]+}\s*</pre>!m, 'pre tags should work'; |
| 94 | |
| 95 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $htmltext, qr!^\tmy \(\$foo\)!m, '... not removing further indents'; |
| 96 | |
| 97 | $wikitext = <<WIKI; |
| 98 | CamelCase |
| 99 | CamooseCase |
| 100 | NOTCAMELCASE |
| 101 | WIKI |
| 102 | |
| 103 | $htmltext = wfscip-perl cpan Text-MediawikiFormat 1.04 main/wf().( $wikitext, {}, { implicit_links => 1 } ); |
| 104 | |
| 105 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $htmltext, qr!<a href='CamelCase'>CamelCase</a>!, 'parse actual CamelCase words into links'; |
| 106 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $htmltext, qr!<a href='CamooseCase'>CamooseCase</a>!, '... not repeating if using link as title'; |
| 107 | likescip-perl cpan Text-MediawikiFormat 1.04 main/like(). $htmltext, qr!^NOTCAMELCASE!m, '... but not words in all uppercase'; |
| 108 | |
| 109 | my @processed = Text::MediawikiFormat::_nest_blocksscip-perl cpan Text-MediawikiFormat 1.04 Text/MediawikiFormat/_nest_blocks().( [] ); |
| 110 | isscip-perl cpan Text-MediawikiFormat 1.04 main/is(). @processed, 0, '_nest_blocks() should not autovivify empty blocks array'; |