Earlier I've mentined that I don't like the fact that we used copy-paste in the test script and duplicate code. Before we go on and add more test, let's refactor the test code.

I've created an array called @cases listing all the (2) test cases. We'll have more.

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

I've also changed the code processing the test cases to be in a loop and use the values from the @cases array:

  1. for my $case (@cases) {
  2. my $result = $m->parse_file("t/input/$case.md");
  3. is_deeply $result, decode_json( path("t/dom/$case.json")->slurp_utf8 );
  4. }

Finally, though in the code it is earlier, I've updated the plan to be based on the number of entries in the @cases array.

The previous test file is here:

examples/markua-parser/c580d63/t/01-test.t

  1. use strict;
  2. use warnings;
  3.  
  4. use Test::More;
  5. use JSON::MaybeXS qw(decode_json);
  6. use Path::Tiny qw(path);
  7. use Markua::Parser;
  8.  
  9. plan tests => 3;
  10.  
  11. my $m = Markua::Parser->new;
  12. isa_ok $m, 'Markua::Parser';
  13.  
  14. my $result = $m->parse_file('t/input/heading1.md');
  15. is_deeply $result, decode_json( path('t/dom/heading1.json')->slurp_utf8 );
  16.  
  17. $result = $m->parse_file('t/input/headers.md');
  18. is_deeply $result, decode_json( path('t/dom/headers.json')->slurp_utf8 );
  19.  

The new test file is here:

examples/markua-parser/79d9bfe/t/01-test.t

  1. use strict;
  2. use warnings;
  3.  
  4. use Test::More;
  5. use JSON::MaybeXS qw(decode_json);
  6. use Path::Tiny qw(path);
  7. use Markua::Parser;
  8.  
  9. my @cases = ('heading1', 'headers');
  10.  
  11. plan tests => 1 + scalar @cases;
  12.  
  13. my $m = Markua::Parser->new;
  14. isa_ok $m, 'Markua::Parser';
  15.  
  16. for my $case (@cases) {
  17. my $result = $m->parse_file("t/input/$case.md");
  18. is_deeply $result, decode_json( path("t/dom/$case.json")->slurp_utf8 );
  19. }
  20.  

We can then record our changes in git:

$ git add .
$ git commit -m "refactor test code"
$ git push

commit