Advertisement
happy-barney

parqus - tests example

Oct 20th, 2020 (edited)
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. use Context::Singleton;
  2. use Test::Warnings qw[ had_no_warnings :no_end_tests ];
  3.  
  4. sub expect_parser;
  5.  
  6. frame {
  7. proclaim parser => Parqus->new ...;
  8.  
  9. expect_parser 'it should parse empty string' => (
  10. with_query => '',
  11. expect => { },
  12. );
  13.  
  14. expect_parse 'it should parse single word ...' => (
  15. with_query => ' foo ',
  16. expect => { words => ['foo'] },
  17. );
  18. };
  19.  
  20. frame {
  21. proclaim parser => ...;
  22. };
  23.  
  24. had_no_warnings;
  25.  
  26. done_testing;
  27.  
  28. sub expect_parser {
  29. my ($msg, %args) = @_;
  30. my $parser = deduce 'parser';
  31.  
  32. local $Test::Builder::Level = $Test::Builder::Level + 1;
  33.  
  34. my $res = $parser->process($args{with_query});
  35.  
  36. if (exists $res->{errors}) {
  37. my $rv = fail $msg;
  38. diag "Expected success but error was reported:\n\t$res->{errors}";
  39. return $rv;
  40. }
  41.  
  42. is_deeply( $res, $args{expect}, $msg)
  43. }
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement