# vi:filetype= use Test::Base; use JavaScript::SpiderMonkey; use JSON::XS; #use Test::LongString; #use Data::Structure; use utf8; use Encode; my $json_xs = JSON::XS->new->allow_nonref; plan tests => blocks() * 1; my $jsfile = 'js/pod2html.js'; my $monkey = new JavaScript::SpiderMonkey; $monkey->init(); open my $in, $jsfile or die "Failed to open JS file $jsfile: $!\n"; my $js = do { local $/; <$in> }; close $in; $monkey->eval($js) or die "Failed to load $jsfile: $@"; my $res; $monkey->function_set('get', sub { $res = shift }); run { my $block = shift; my $name = $block->name; my $pod = $block->pod or die "No -- pod specified for $name"; my $json = $json_xs->encode($pod); $monkey->eval("get(pod2html($json))") or die "Error occured when calling the pod2html function: $@"; $res = Encode::decode('utf8', $res); is "$res\n", $block->html, "$name - HTML output okay"; }; $monkey->destroy(); __DATA__ === TEST 1: =image --- pod =image gate.jpg --- html

=== TEST 2: ignore =pod, =cut, =encoding --- pod =pod =cut =encoding utf8 hi --- html

hi

=== TEST 3: L works --- pod L --- html

http://agentzh.org/#elem/home/1

=== TEST 4: indented paragraphs work --- pod hello world --- html
 hello
   world
=== TEST 5: head1 & indented text --- pod =head1 A B C hello world --- html

A B C

 hello
  world
=== TEST 6: head3 & normal paragraphs --- pod =head3 hi hello, world Ahah! dog is here. --- html

hi

hello, world Ahah!

dog is here.

=== TEST 7: C<...> works --- pod C, world --- html

hello, world

=== TEST 8: F<...> works --- pod F --- html

/usr/bin/perl

=== TEST 9: I<...> works --- pod She loves I! --- html

She loves me!

=== TEST 10: B<...> works --- pod She loves B! --- html

She loves me!

=== TEST 11: over & =item * --- pod =over 4 =item * Hello, world *grin* =back --- html
  • Hello, world

    *grin*

=== TEST 12: pre as item title --- pod =over =item * abc hello =back --- html
  •  abc

    hello

=== TEST 13: over & 2 =item * --- pod =over =item * ABC =item * *grin* =back --- html
  • ABC
  • *grin*
=== TEST 14: nested
    --- pod =over =item * ABC =over =item * QQQ =back =back --- html
    • ABC
      • QQQ
    === TEST 15: item 1. item 2. ... --- pod =over =item 1. ABC =item 2. QQQ hello =back --- html
    1. ABC
    2. QQQ

      hello

    === TEST 16: nested
      and
        --- pod =over =item * ABC =over =item 1. QQQ =back =back --- html
        • ABC
          1. QQQ
        === TEST 17: =item XXX --- pod =over =item ABC English words Oh oh! =item hello, world =back --- html
        ABC

        English words

        Oh oh!

        hello, world
        === TEST 18: quotes --- pod C<< 2>3 >> F I B --- html

        2>3 F I B

        === TEST 19: misc --- pod =head1 Hello =over =item * hi =back 3 > 4 532aa L --- html

        Hello

        • hi
          3 > 4
          532aa

        agentzh

        === TEST 20: head4 works --- pod =head4 你好么 ABC --- html

        你好么 ABC

        === TEST 21: misc2 --- pod =over =item 1. cat is not a dog. and he is always here. really? =item 2. hello, world haha =back --- html
        1. cat is not a dog. and he is always here.

          really?

        2.   hello, world
            haha
        === TEST 22: =begin html & =end html --- pod =head1 header =begin html Hello, world
        Nothing!
        =end html Heh, that's cool! --- html

        header

        Hello, world
        Nothing!

        Heh, that's cool!

        === TEST 23: =begin HTML & =end HTML --- pod =begin HTML Hello, world
        Nothing!
        =end HTML Heh, that's cool! --- html Hello, world
        Nothing!

        Heh, that's cool!

        === TEST 24: =begin HTML & =end html --- pod =head1 header =begin HTML Hello, world
        Nothing!
        =end html Heh, that's cool! --- html

        header

        Hello, world
        Nothing!

        Heh, that's cool!

        === TEST 25: =begin comment & =end comment --- pod =head1 header =begin comment Hello, world
        Nothing!
        =end comment Heh, that's cool! --- html

        header

        Heh, that's cool!