Permalink
Browse files

Handle the case where a change starts with no leading whitespace, and…

… still parse continuation lines correctly.
  • Loading branch information...
1 parent 7c44068 commit 2cbfb385a3ced4a212bd0641f283c7557d5a8495 @autarch committed Feb 10, 2011
Showing with 39 additions and 3 deletions.
  1. +5 −3 lib/CPAN/Changes.pm
  2. +3 −0 t/corpus/no-leading-space-for-change.changes
  3. +31 −0 t/read_no-leading-space-for-change.t
View
@@ -71,9 +71,11 @@ sub load_string {
next if $l =~ m{^\s*$};
- if ( !$indent ) {
- $l =~ m{^(\s+)};
- $indent = '\s' x length $1;
+ if ( !defined $indent ) {
+ $indent
+ = $l =~ m{^(\s+)}
+ ? '\s' x length $1
+ : '';
}
$l =~ s{^$indent}{};
@@ -0,0 +1,3 @@
+0.01 2010-06-16
+- Initial release
+ This line is part of the first
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use_ok( 'CPAN::Changes' );
+
+my $changes = CPAN::Changes->load( 't/corpus/no-leading-space-for-change.changes' );
+
+isa_ok( $changes, 'CPAN::Changes' );
+is( $changes->preamble, '', 'no preamble' );
+
+my @releases = $changes->releases;
+
+is( scalar @releases, 1, 'has 1 release' );
+isa_ok( $releases[ 0 ], 'CPAN::Changes::Release' );
+is( $releases[ 0 ]->version, '0.01', 'version' );
+is( $releases[ 0 ]->date, '2010-06-16', 'date' );
+is_deeply(
+ $releases[ 0 ]->changes,
+ { '' => [ "Initial release This line is part of the first" ] },
+ 'full changes'
+);
+is_deeply( [ $releases[ 0 ]->groups ], [ '' ], 'only the main group' );
+is_deeply(
+ $releases[ 0 ]->changes( '' ),
+ [ "Initial release This line is part of the first" ],
+ 'one change line'
+);
+
+done_testing;

0 comments on commit 2cbfb38

Please sign in to comment.