Skip to content

Commit

Permalink
collect errors, parse every line in the input file
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Mar 5, 2018
1 parent 79d9bfe commit 74d23bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/Markua/Parser.pm
Expand Up @@ -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;
}


Expand Down
6 changes: 4 additions & 2 deletions t/01-test.t
Expand Up @@ -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.