Skip to content
Permalink
Browse files

collect errors, parse every line in the input file

  • Loading branch information
szabgab committed Mar 5, 2018
1 parent 79d9bfe commit 74d23bf0077661f2667893378afbbe62e4eef9e3
Showing with 18 additions and 3 deletions.
  1. +14 −1 lib/Markua/Parser.pm
  2. +4 −2 t/01-test.t
@@ -14,15 +14,28 @@ sub new {
sub parse_file {
my ($self, $filename) = @_;
my @entries;
my @errors;
my $cnt = 0;
for my $line (path($filename)->lines_utf8) {
$cnt++;
if ($line =~ /^(#{1,6}) (\S.*)/) {
push @entries, {
tag => 'h' . length($1),
text => $2,
};
next;
}

if ($line =~ /^\s*$/) {
next;
}

push @errors, {
row => $cnt,
line => $line,
}
}
return \@entries;
return \@entries, \@errors;
}


@@ -8,13 +8,15 @@ use Markua::Parser;

my @cases = ('heading1', 'headers');

plan tests => 1 + scalar @cases;
plan tests => 1 + 2 * scalar @cases;

my $m = Markua::Parser->new;
isa_ok $m, 'Markua::Parser';

for my $case (@cases) {
my $result = $m->parse_file("t/input/$case.md");
my ($result, $errors) = $m->parse_file("t/input/$case.md");
is_deeply $result, decode_json( path("t/dom/$case.json")->slurp_utf8 );
is_deeply $errors, [], "Errors of $case";
#diag explain $errors;
}

0 comments on commit 74d23bf

Please sign in to comment.
You can’t perform that action at this time.