Browse files

The Pod tree should not contain bare strings. Use Pod::Block::Para, a…

…djust the tests and Pod::To::Text
  • Loading branch information...
1 parent 5ed0e09 commit 585cd06cb25292b815eded43c2b53dd47769848f @tadzik tadzik committed Jul 31, 2011
Showing with 123 additions and 99 deletions.
  1. +15 −12 Pod/To/Text.pm
  2. +12 −5 src/Perl6/Actions.pm
  3. +1 −6 src/Perl6/Pod.pm
  4. +3 −0 src/core/Pod.pm
  5. +23 −16 t/pod/01-delimited.t
  6. +22 −17 t/pod/02-paragraph.t
  7. +23 −18 t/pod/03-abbreviated.t
  8. +11 −11 t/pod/04-code.t
  9. +13 −14 t/pod/06-lists.t
View
27 Pod/To/Text.pm
@@ -3,34 +3,37 @@ module Pod::To::Text;
sub pod2text($pod) is export {
given $pod {
when Pod::Heading { heading2text($pod) }
- when Pod::Block::Code { code2text($pod) }
- when Pod::Block::Named { named2text($pod) }
- when Pod::Item { item2text($pod) }
+ when Pod::Block::Code { code2text($pod) ~ "\n\n" }
+ when Pod::Block::Named { named2text($pod) ~ "\n" }
+ when Pod::Block::Para { para2text($pod) ~ "\n\n" }
+ when Pod::Item { item2text($pod) ~ "\n" }
when Positional { $pod.map({pod2text($_)}).join }
- default { $pod.Str ~ "\n\n" }
+ default { $pod.Str }
}
}
sub heading2text($pod) {
given $pod.level {
- when 1 { pod2text($pod.content) }
- when 2 { ' ' ~ pod2text($pod.content) }
- default { ' ' ~ pod2text($pod.content) }
+ when 1 { pod2text($pod.content) }
+ when 2 { ' ' ~ pod2text($pod.content) }
+ default { ' ' ~ pod2text($pod.content) }
}
}
sub code2text($pod) {
- " " ~ $pod.content.subst(/\n/, "\n ", :g) ~ "\n\n"
+ " " ~ $pod.content.subst(/\n/, "\n ", :g)
}
sub item2text($pod) {
- ' * ' ~ $pod.content.Str ~ "\n"
+ ' * ' ~ pod2text($pod.content).chomp.chomp
}
sub named2text($pod) {
- $pod.name eq 'pod'
- ?? pod2text($pod.content)
- !! $pod.content ~ "\n"
+ $pod.name eq 'pod' ?? pod2text($pod.content) !! para2text($pod)
+}
+
+sub para2text($pod) {
+ $pod.content.join("\n")
}
# vim: ft=perl6
View
17 src/Perl6/Actions.pm
@@ -182,7 +182,7 @@ class Perl6::Actions is HLL::Actions {
else {
$unit.push($mainparam);
}
-
+
# If our caller wants to know the mainline ctx, provide it here.
# (CTXSAVE is inherited from HLL::Actions.) Don't do this when
# there was an explicit {YOU_ARE_HERE}.
@@ -280,7 +280,10 @@ class Perl6::Actions is HLL::Actions {
method pod_text_para($/) {
my $t := Perl6::Pod::formatted_text($<text>.Str);
- my $past := $*ST.add_constant('Str', 'str', $t);
+ my $past := Perl6::Pod::serialize_object(
+ 'Pod::Block::Para',
+ :content(Perl6::Pod::serialize_aos([$t])<compile_time_value>),
+ );
make $past<compile_time_value>;
}
@@ -289,13 +292,17 @@ class Perl6::Actions is HLL::Actions {
for $<pod_textcontent> {
@ret.push($_.ast);
}
- make @ret;
+ my $past := Perl6::Pod::serialize_array(@ret);
+ make $past<compile_time_value>;
}
method pod_textcontent:sym<regular>($/) {
my $t := Perl6::Pod::formatted_text($<text>.Str);
- my $past := $*ST.add_constant('Str', 'str', $t);
- make $past<compile_time_value>;
+ # is only one string now, will be a twine
+ my $twine := Perl6::Pod::serialize_aos([$t])<compile_time_value>;
+ make Perl6::Pod::serialize_object(
+ 'Pod::Block::Para', :content($twine)
+ )<compile_time_value>
}
method pod_textcontent:sym<code>($/) {
View
7 src/Perl6/Pod.pm
@@ -16,12 +16,7 @@ class Perl6::Pod {
}
for $<pod_content> {
- # check if it's a pod node or an array of strings
- if pir::isa($_.ast, 'ResizablePMCArray') {
- for $_.ast { @children.push($_) }
- } else {
- @children.push($_.ast);
- }
+ @children.push($_.ast);
}
my $content := serialize_array(@children);
View
3 src/core/Pod.pm
@@ -3,6 +3,9 @@ my package Pod {
has @.content;
}
+ class Block::Para is Block {
+ }
+
class Block::Named is Block {
has $.name;
}
View
39 t/pod/01-delimited.t
@@ -1,5 +1,5 @@
use Test;
-plan 28;
+plan 33;
my $r;
=begin foo
@@ -16,7 +16,8 @@ some text
=end foo
$r = $=POD[1];
-is $r.content[0], "some text", 'the content is all right';
+isa_ok $r.content[0], Pod::Block::Para;
+is $r.content[0].content, "some text", 'the content is all right';
is $r.name, 'foo', 'name is ok';
=begin foo
@@ -26,8 +27,8 @@ spaced text
$r = $=POD[2];
is $r.name, 'foo', 'name is ok';
-is $r.content[0], "some spaced text", 'additional whitespace removed ' ~
- 'from the content';
+is $r.content[0].content,
+ "some spaced text", 'additional whitespace removed from the content';
=begin foo
paragraph one
@@ -37,8 +38,10 @@ two
=end foo
$r = $=POD[3];
is $r.name, 'foo', 'name is ok';
-is $r.content[0], "paragraph one", 'paragraphs ok, 1/2';
-is $r.content[1], "paragraph two", 'paragraphs ok, 2/2';
+isa_ok $r.content[0], Pod::Block::Para;
+isa_ok $r.content[1], Pod::Block::Para;
+is $r.content[0].content, "paragraph one", 'paragraphs ok, 1/2';
+is $r.content[1].content, "paragraph two", 'paragraphs ok, 2/2';
=begin something
=begin somethingelse
@@ -49,7 +52,8 @@ is $r.content[1], "paragraph two", 'paragraphs ok, 2/2';
$r = $=POD[4];
is $r.name, 'something', 'parent name ok';
isa_ok $r.content[0], Pod::Block, "nested blocks work";
-is $r.content[0].content[0], "toot tooot!", "and their content";
+isa_ok $r.content[0].content[0], Pod::Block::Para, "nested blocks work";
+is $r.content[0].content[0].content, "toot tooot!", "and their content";
is $r.content[0].name, 'somethingelse', 'child name ok';
# Albi
@@ -75,18 +79,18 @@ Which, as we all know...
$r = $=POD[5];
isa_ok $r, Pod::Block;
is $r.content.elems, 5, '5 sub-nodes in foo';
-is $r.content[0],
+is $r.content[0].content,
'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],
+is $r.content[1].content,
'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!",
+is $r.content[2].content[0].content, "Dragon Tears!",
'...in a cottage cheese cottage';
-is $r.content[3], "Which, as we all know...",
+is $r.content[3].content, "Which, as we all know...",
'...lives Albi! Albi!';
-is $r.content[4].content[0], "Turn into Jelly Beans!",
+is $r.content[4].content[0].content, "Turn into Jelly Beans!",
'...Albi, the Racist Dragon';
=begin pod
@@ -99,9 +103,9 @@ between these two paragraphs
$r = $=POD[6];
isa_ok $r, Pod::Block;
-is $r.content[0], 'someone accidentally left a space',
+is $r.content[0].content, 'someone accidentally left a space',
'accidental space, 1/2';
-is $r.content[1], 'between these two paragraphs',
+is $r.content[1].content, 'between these two paragraphs',
'accidental space, 2/2';
# various things which caused the spectest to fail at some point
@@ -114,8 +118,9 @@ foo
=end kwid
$r = $=POD[7];
-is $r.content[0], '= DESCRIPTION bla bla';
-is $r.content[1], 'foo';
+is $r.content[0].content, '= DESCRIPTION bla bla';
+isa_ok $r.content[1], Pod::Block::Para;
+is $r.content[1].content, 'foo';
=begin more-discussion-needed
@@ -126,3 +131,5 @@ XXX: chop(%has) should return a hash of chopped strings?
$r = $=POD[8];
isa_ok $r, Pod::Block;
+
+done;
View
39 t/pod/02-paragraph.t
@@ -1,5 +1,5 @@
use Test;
-plan 26;
+plan 27;
my $r;
=for foo
@@ -14,15 +14,16 @@ is $r.content, [], 'no content, all right';
some text
$r = $=POD[1];
-is $r.content[0], "some text", 'the content is all right';
+isa_ok $r.content[0], Pod::Block::Para;
+is $r.content[0].content, "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';
+is $r.content[0].content,
+ "some spaced text", 'additional whitespace removed from the content';
=begin pod
=for got
@@ -36,13 +37,13 @@ Outside blocks
$r = $=POD[3];
isa_ok $r.content[0], Pod::Block;
-is $r.content[0].content[0], "Inside got",
+is $r.content[0].content[0].content, "Inside got",
'paragraph block content ok, 1/2';
isa_ok $r.content[1], Pod::Block;
-is $r.content[1].content[0], "Inside bidden",
+is $r.content[1].content[0].content, "Inside bidden",
'paragraph block content ok, 1/2';
-isa_ok $r.content[2], Str;
-is $r.content[2], "Outside blocks",
+isa_ok $r.content[2], Pod::Block::Para;
+is $r.content[2].content, "Outside blocks",
'content outside blocks is all right';
# mixed blocks
@@ -61,10 +62,14 @@ four, another delimited one
=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[0].content[0].content,
+ "one, delimited block", "mixed blocks, 1";
+is $r.content[1].content[0].content,
+ "two, paragraph block", "mixed blocks, 2";
+is $r.content[2].content[0].content,
+ "three, still a parablock", "mixed blocks, 3";
+is $r.content[3].content[0].content,
+ "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
@@ -90,18 +95,18 @@ $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],
+is $r.content[0].content,
'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],
+is $r.content[1].content,
'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!",
+is $r.content[2].content[0].content, "Dragon Tears!",
'...in a cottage cheese cottage';
-is $r.content[3], "Which, as we all know...",
+is $r.content[3].content, "Which, as we all know...",
'...lives Albi! Albi!';
is $r.content[4].name, 'bar';
-is $r.content[4].content[0], "Turn into Jelly Beans!",
+is $r.content[4].content[0].content, "Turn into Jelly Beans!",
'...Albi, the Racist Dragon';
View
41 t/pod/03-abbreviated.t
@@ -12,13 +12,13 @@ is $r.content, [], 'no content, all right';
=foo some text
$r = $=POD[1];
-is $r.content[0], "some text", 'the content is all right';
+is $r.content[0].content, "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';
+is $r.content[0].content, "some text and some more", 'the content is all right';
=begin pod
@@ -33,13 +33,13 @@ Outside blocks
$r = $=POD[3];
isa_ok $r.content[0], Pod::Block;
-is $r.content[0].content[0], "Inside got",
+is $r.content[0].content[0].content, "Inside got",
'paragraph block content ok, 1/2';
isa_ok $r.content[1], Pod::Block;
-is $r.content[1].content[0], "Inside bidden",
+is $r.content[1].content[0].content, "Inside bidden",
'paragraph block content ok, 1/2';
-isa_ok $r.content[2], Str;
-is $r.content[2], "Outside blocks",
+isa_ok $r.content[2], Pod::Block::Para;
+is $r.content[2].content, "Outside blocks",
'content outside blocks is all right';
# mixed blocks
@@ -59,11 +59,16 @@ is $r.content[2], "Outside blocks",
=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';
+is $r.content[0].content[0].content,
+ "one, delimited block", "mixed blocks, 1";
+is $r.content[1].content[0].content,
+ "two, paragraph block", "mixed blocks, 2";
+is $r.content[2].content[0].content,
+ "three, still a parablock", "mixed blocks, 3";
+is $r.content[3].content[0].content,
+ "four, another delimited one", "mixed blocks, 4";
+is $r.content[4].content[0].content,
+ "And just for the sake of having a working =head1 :)", 'mixed blocks, 5';
=begin foo
and so, all of the villages chased
@@ -86,18 +91,18 @@ Which, as we all know...
$r = $=POD[5];
isa_ok $r, Pod::Block;
is $r.content.elems, 5, '5 sub-nodes in foo';
-is $r.content[0],
+is $r.content[0].content,
'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],
+is $r.content[1].content,
'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!",
+is $r.content[2].content[0].content, "Dragon Tears!",
'...in a cottage cheese cottage';
-is $r.content[3], "Which, as we all know...",
+is $r.content[3].content, "Which, as we all know...",
'...lives Albi! Albi!';
-is $r.content[4].content[0], "Turn into Jelly Beans!",
+is $r.content[4].content[0].content, "Turn into Jelly Beans!",
'...Albi, the Racist Dragon';
# from S26
@@ -110,7 +115,7 @@ is $r.content[4].content[0], "Turn into Jelly Beans!",
$r = $=POD[6];
isa_ok $r, Pod::Block;
is $r.content.elems, 1;
-is $r.content[0],
+is $r.content[0].content,
'Constants 1 Variables 10 Subroutines 33 Everything else 57';
=head3
@@ -120,4 +125,4 @@ $r = $=POD[7];
isa_ok $r, Pod::Block;
isa_ok $r, Pod::Heading;
is $r.level, '3';
-is $r.content[0], 'Heading level 3';
+is $r.content[0].content, 'Heading level 3';
View
22 t/pod/04-code.t
@@ -10,7 +10,7 @@ This ordinary paragraph introduces a code block:
=end pod
$r = $=POD[0];
-is $r.content[0], 'This ordinary paragraph introduces a code block:';
+is $r.content[0].content, 'This ordinary paragraph introduces a code block:';
isa_ok $r.content[1], Pod::Block::Code;
is $r.content[1].content.Str, q[$this = 1 * code('block');
$which.is_specified(:by<indenting>);];
@@ -33,15 +33,15 @@ But this is just a text. Again
$r = $=POD[1];
is $r.content.elems, 5;
-is $r.content[0], 'This is an ordinary paragraph';
+is $r.content[0].content, 'This is an ordinary paragraph';
isa_ok $r.content[1], Pod::Block::Code;
is $r.content[1].content, "While this is not\nThis is a code block";
isa_ok $r.content[2], Pod::Block;
-is $r.content[2].content, 'Mumble mumble';
+is $r.content[2].content[0].content, 'Mumble mumble';
isa_ok $r.content[3], Pod::Block::Code;
is $r.content[3].content, "Suprisingly, this is a code block again\n"
~ " (with fancy indentation too)";
-is $r.content[4], "But this is just a text. Again";
+is $r.content[4].content, "But this is just a text. Again";
=begin pod
@@ -52,7 +52,7 @@ Tests for the feed operators
=end pod
$r = $=POD[2];
-is $r.content[0], 'Tests for the feed operators';
+is $r.content[0].content, 'Tests for the feed operators';
isa_ok $r.content[1], Pod::Block::Code;
is $r.content[1].content, "==> and <==";
@@ -69,7 +69,7 @@ Fun comes
$r = $=POD[3];
is $r.content.elems, 4;
-is $r.content[0], 'Fun comes';
+is $r.content[0].content, 'Fun comes';
isa_ok $r.content[1], Pod::Block::Code;
is $r.content[1].content, 'This is code';
isa_ok $r.content[2], Pod::Block::Code;
@@ -92,8 +92,8 @@ This is Pod too. Specifically, this is a simple C<para> block
$r = $=POD[4];
is $r.content.elems, 3;
isa_ok $r.content[0], Pod::Block;
-is $r.content[0].content, 'A heading';
-is $r.content[1],
+is $r.content[0].content[0].content, 'A heading';
+is $r.content[1].content,
'This is Pod too. Specifically, this is a simple C<para> block';
isa_ok $r.content[2], Pod::Block::Code;
is $r.content[2].content,
@@ -127,18 +127,18 @@ is $r.content[0].content, 'this is code';
isa_ok $r.content[1], Pod::Block::Named;
is $r.content[1].name, 'podcast';
-is $r.content[1].content, 'this is not';
+is $r.content[1].content[0].content, 'this is not';
isa_ok $r.content[2], Pod::Block::Code;
is $r.content[2].content, 'this is code';
isa_ok $r.content[3], Pod::Block::Named;
is $r.content[3].name, 'itemization';
-is $r.content[3].content, 'this is not';
+is $r.content[3].content[0].content, 'this is not';
isa_ok $r.content[4], Pod::Block::Named;
is $r.content[4].name, 'quitem';
-is $r.content[4].content, 'and this is not';
+is $r.content[4].content[0].content, 'and this is not';
isa_ok $r.content[5].content[0], Pod::Block::Code;
is $r.content[5].content[0].content, 'and this is!';
View
27 t/pod/06-lists.t
@@ -20,9 +20,9 @@ for 1..7 {
isa_ok $r.content[$_], Pod::Item;
}
-is $r.content[1].content, 'Happy', 'content is happy :)';
-is $r.content[2].content, 'Dopey';
-is $r.content[7].content, 'Keyser Soze';
+is $r.content[1].content[0].content, 'Happy', 'content is happy :)';
+is $r.content[2].content[0].content, 'Dopey';
+is $r.content[7].content[0].content, 'Keyser Soze';
nok $r.content[4].level.defined, 'no level information';
=begin pod
@@ -43,13 +43,13 @@ for 0..7 {
isa_ok $r.content[$_], Pod::Item;
}
-$r.content[0].content, 'Animal';
+$r.content[0].content[0].content, 'Animal';
$r.content[0].level, 1;
-$r.content[2].content, 'Invertebrate';
+$r.content[2].content[0].content, 'Invertebrate';
$r.content[2].level, 2;
-$r.content[3].content, 'Phase';
+$r.content[3].content[0].content, 'Phase';
$r.content[3].level, 1;
-$r.content[4].content, 'Solid';
+$r.content[4].content[0].content, 'Solid';
$r.content[4].level, 2;
=begin pod
@@ -96,10 +96,9 @@ As you can see, folk wisdom is often of dubious value.
$r = $=POD[3];
is $r.content.elems, 4;
-is $r.content[0], "Let's consider two common proverbs:";
-skip 'no regexes in nom yet', 2;
-#ok $r.content[1].content.Str
-# ~~ /:s This is a common .+ are extremely attractive/;
-#ok $r.content[2].content.Str
-# ~~ /:s In deciding .+ annelids for breakfast/;
-is $r.content[3], "As you can see, folk wisdom is often of dubious value.";
+is $r.content[0].content, "Let's consider two common proverbs:";
+ok $r.content[1].content[1].content
+ ~~ /:s This is a common .+ are extremely attractive/;
+ok $r.content[2].content[1].content
+ ~~ /:s In deciding .+ annelids for breakfast/;
+is $r.content[3].content, "As you can see, folk wisdom is often of dubious value.";

0 comments on commit 585cd06

Please sign in to comment.