Permalink
Browse files

New test + fixture.

  • Loading branch information...
1 parent 181566b commit ba371c2994b701b1942efd9247c257039a2b39e3 @pangyre committed May 24, 2012
Showing with 29 additions and 11 deletions.
  1. +1 −1 fixture/rtf/hello.rtf
  2. +5 −0 fixture/rtf/lines.rtf
  3. +7 −10 lib/tRTF.pm
  4. +16 −0 t/rtf-tree.t
@@ -1,3 +1,3 @@
{\rtf1\ansi\deff0 {\fonttbl {\f0 Helvetica Neue UltraLight;}}
-\f0\fs60 Hello, World!
+\f0\fs144 Hello, World!
}
@@ -0,0 +1,5 @@
+{\rtf1\ansi\deff0 {\fonttbl {\f0 Helvetica Neue UltraLight;}}
+one\line
+two\line
+five\par
+}
View
@@ -44,35 +44,32 @@ sub BUILD {
sub text_content {
my $self = shift;
my $text = "";
- $text = $self->argument if $self->is_text;
+ $text = $self->is_text;
-# and $self->parent->first_child->argument eq "rtlch";
-# and $self->parent->first_child->argument ne "*";
+# and $self->parent->first_child->argument eq "rtlch";
+# and $self->parent->first_child->argument ne "*";
for my $kid ( $self->children )
{
- #$text .= $kid->parent->argument . " : ";
$text .= $kid->text_content;
- #$text .= "\n";
}
$text;
}
my %TEXT = map {; $_ => 1 }
qw( rtf pard plain );
+my %CONTROL = ( line => "\n" );
+
sub is_text {
my $self = shift;
+ return $CONTROL{$self->control} if $CONTROL{$self->control};
return unless $self->type eq "text";
- # print join(" + ", map { $_->control } $self->siblings), $/;
return if $self->argument =~ /(?<!\\);\z/;
my @siblings = $self->siblings;
return if @siblings > 1 and $self->parent->first_child->control eq "*";
- return 1 if grep { $TEXT{$_->control} } $self->siblings;
-# return 1 if grep { $TEXT{$_->control} } $self->parent->previous ? $self->parent->previous->children : ();
- return;
+ return $self->argument if grep { $TEXT{$_->control} } $self->siblings;
}
-#
# sub add_text { +shift->{text} .= join "", @_ }
View
@@ -47,6 +47,22 @@ subtest "Minimal" => sub {
is( $rtf->text_content, $expect, $expect );
};
+subtest "Lines" => sub {
+ my $fixture = file($fixtures,"lines.rtf");
+
+ plan -e $fixture ?
+ ( tests => 2 ) : ( skip_all => "fixture $fixture is missing" );
+
+ my $rtf = tRTF->new( type => "rtf" );
+
+ ok( $rtf->parse( file => $fixture ),
+ '$rtf->parse( file => $fixture )' );
+
+ my $esc = "one\\ntwo\\nfive";
+ my $expect = eval '"' . $esc . '"';
+ is( $rtf->text_content, $expect, "Lines work: $esc" );
+};
+
done_testing();
exit 0;

0 comments on commit ba371c2

Please sign in to comment.