Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Parse paragraph and abbreviated blocks, import tests for those (every…
…thing passes)
  • Loading branch information
Tadeusz Sośnierz committed Jul 7, 2011
1 parent 587360f commit 25cc743
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Perl6/Actions.pm
Expand Up @@ -233,6 +233,14 @@ class Perl6::Actions is HLL::Actions {
make $<pod_block>.ast;
}

method pod_block:sym<paragraph>($/) {
make self.any_block($/);
}

method pod_block:sym<abbreviated>($/) {
make self.any_block($/);
}

method pod_block:sym<delimited>($/) {
make self.any_block($/);
}
Expand Down
107 changes: 107 additions & 0 deletions t/pod/02-paragraph.t
@@ -0,0 +1,107 @@
use Test;
plan 26;
my $r;

=for foo
$r = $POD[0];
isa_ok $r, Pod__Block, 'returns a Pod6 Block';
isa_ok $r, Pod__Block__Named, 'returns a named Block';
is $r.name, 'foo', 'name is ok';
is $r.content, [], 'no content, all right';

=for foo
some text
$r = $POD[1];
is $r.content[0], "some text", 'the content is all right';

=for foo
some
spaced text
$r = $POD[2];
is $r.content[0], "some spaced text", 'additional whitespace removed ' ~
'from the content';
=begin pod
=for got
Inside got
=for bidden
Inside bidden
Outside blocks
=end pod

$r = $POD[3];
isa_ok $r.content[0], Pod__Block;
is $r.content[0].content[0], "Inside got",
'paragraph block content ok, 1/2';
isa_ok $r.content[1], Pod__Block;
is $r.content[1].content[0], "Inside bidden",
'paragraph block content ok, 1/2';
isa_ok $r.content[2], Str;
is $r.content[2], "Outside blocks",
'content outside blocks is all right';

# mixed blocks
=begin pod
=begin one
one, delimited block
=end one
=for two
two, paragraph block
=for three
three, still a parablock
=begin four
four, another delimited one
=end four
=end pod
$r = $POD[4];
is $r.content[0].content[0], "one, delimited block", "mixed blocks, 1";
is $r.content[1].content[0], "two, paragraph block", "mixed blocks, 2";
is $r.content[2].content[0], "three, still a parablock", "mixed blocks, 3";
is $r.content[3].content[0], "four, another delimited one", "mixed blocks, 4";

# tests without Albi would still be tests, but definitely very, very sad
# also, Albi without paragraph blocks wouldn't be the happiest dragon
# either
=begin foo
and so, all of the villages chased
Albi, The Racist Dragon, into the
very cold and very scary cave

and it was so cold and so scary in
there, that Albi began to cry

=for bar
Dragon Tears!
Which, as we all know...

=for bar
Turn into Jelly Beans!
=end foo
$r = $POD[5];
isa_ok $r, Pod__Block;
is $r.content.elems, 5, '5 sub-nodes in foo';
is $r.name, 'foo';
is $r.content[0],
'and so, all of the villages chased Albi, The Racist Dragon, ' ~
'into the very cold and very scary cave',
'...in the marmelade forest';
is $r.content[1],
'and it was so cold and so scary in there, that Albi began to cry',
'...between the make-believe trees';
is $r.content[2].name, 'bar';
is $r.content[2].content[0], "Dragon Tears!",
'...in a cottage cheese cottage';
is $r.content[3], "Which, as we all know...",
'...lives Albi! Albi!';
is $r.content[4].name, 'bar';
is $r.content[4].content[0], "Turn into Jelly Beans!",
'...Albi, the Racist Dragon';
114 changes: 114 additions & 0 deletions t/pod/03-abbreviated.t
@@ -0,0 +1,114 @@
use Test;
plan 26;
my $r;

=foo

$r = $POD[0];
isa_ok $r, Pod__Block, 'returns a Pod6 Block';
isa_ok $r, Pod__Block__Named, 'returns a named Block';
is $r.content, [], 'no content, all right';

=foo some text
$r = $POD[1];
is $r.content[0], "some text", 'the content is all right';

=foo some text
and some more
$r = $POD[2];
is $r.content[0], "some text and some more", 'the content is all right';

=begin pod
=got Inside
got
=bidden Inside
bidden
Outside blocks
=end pod

$r = $POD[3];
isa_ok $r.content[0], Pod__Block;
is $r.content[0].content[0], "Inside got",
'paragraph block content ok, 1/2';
isa_ok $r.content[1], Pod__Block;
is $r.content[1].content[0], "Inside bidden",
'paragraph block content ok, 1/2';
isa_ok $r.content[2], Str;
is $r.content[2], "Outside blocks",
'content outside blocks is all right';

# mixed blocks
=begin pod
=begin one
one, delimited block
=end one
=two two,
paragraph block
=for three
three, still a parablock
=begin four
four, another delimited one
=end four
=head1 And just for the sake of having a working =head1 :)
=end pod
$r = $POD[4];
is $r.content[0].content[0], "one, delimited block", "mixed blocks, 1";
is $r.content[1].content[0], "two, paragraph block", "mixed blocks, 2";
is $r.content[2].content[0], "three, still a parablock", "mixed blocks, 3";
is $r.content[3].content[0], "four, another delimited one", "mixed blocks, 4";
is $r.content[4].content[0], "And just for the sake of having a working =head1 :)", 'mixed blocks, 5';

=begin foo
and so, all of the villages chased
Albi, The Racist Dragon, into the
very cold and very scary cave
and it was so cold and so scary in
there, that Albi began to cry
=bold Dragon Tears!
Which, as we all know...
=bold Turn
into
Jelly
Beans!
=end foo

$r = $POD[5];
isa_ok $r, Pod__Block;
is $r.content.elems, 5, '5 sub-nodes in foo';
is $r.content[0],
'and so, all of the villages chased Albi, The Racist Dragon, ' ~
'into the very cold and very scary cave',
'...in the marmelade forest';
is $r.content[1],
'and it was so cold and so scary in there, that Albi began to cry',
'...between the make-believe trees';
is $r.content[2].content[0], "Dragon Tears!",
'...in a cottage cheese cottage';
is $r.content[3], "Which, as we all know...",
'...lives Albi! Albi!';
is $r.content[4].content[0], "Turn into Jelly Beans!",
'...Albi, the Racist Dragon';

# from S26
=table_not
Constants 1
Variables 10
Subroutines 33
Everything else 57

$r = $POD[6];
isa_ok $r, Pod__Block;
is $r.content.elems, 1;
is $r.content[0],
'Constants 1 Variables 10 Subroutines 33 Everything else 57';

0 comments on commit 25cc743

Please sign in to comment.