Permalink
Browse files

make decreasing indent work too

  • Loading branch information...
masak committed Mar 22, 2014
1 parent b3e390b commit 3f9b71b7a8f4c0f35cc1f0c97d4bad898bcaa227
Showing with 19 additions and 0 deletions.
  1. +4 −0 lib/Text/Indented.pm
  2. +15 −0 t/parse-indent.t
View
@@ -22,6 +22,7 @@ sub current_suite { @*SUITES[indent] }
sub add_to_current_suite($item) { current_suite.items.push($item) }
sub increase_indent($new_suite) { @*SUITES.push($new_suite) }
+sub decrease_indent { pop @*SUITES }
regex line {
^^ (<{ "\\x20" x TABSTOP }>*) (\h*) (\N*) $$ \n?
@@ -38,6 +39,9 @@ regex line {
add_to_current_suite($new_suite);
increase_indent($new_suite);
}
+ elsif $new_indent < indent() {
+ decrease_indent;
+ }
add_to_current_suite($line);
}
View
@@ -64,4 +64,19 @@ sub fails_with($input, $ex_type, $message = $ex_type.^name) {
isa_ok $root.items[1], Text::Indented::Suite, 'and a suite';
}
+{
+ my $input = q:to/EOF/;
+ Level 1
+ Level 2
+ Level 1 again
+ EOF
+
+ my $root = parse($input);
+
+ is $root.items.elems, 3, 'three things were parsed:';
+ isa_ok $root.items[0], Str, 'a string';
+ isa_ok $root.items[1], Text::Indented::Suite, 'a suite';
+ isa_ok $root.items[2], Str, 'and a string';
+}
+
done;

0 comments on commit 3f9b71b

Please sign in to comment.