Trog-DataModule.t 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env perl
  2. use 5.040;
  3. use re '/aasx';
  4. use warnings FATAL => 'all';
  5. use Test::More;
  6. use Test::Fatal qw{exception};
  7. use FindBin::libs;
  8. require_ok('Trog::DataModule') or BAIL_OUT("Can't find SUT");
  9. subtest 'filter, with a search' => sub {
  10. my %stored = ( version => 0, created => 1, tags => ['public'] );
  11. my @posts = (
  12. { %stored, id => 'titled', title => 'A Spec Title', data => 'body' },
  13. { %stored, id => 'untitled', data => 'a spec body' },
  14. { %stored, id => 'slides', title => 'Deck', data => [ 'first slide', 'a spec slide' ] },
  15. { %stored, id => 'other', title => 'Other', data => 'nothing here' },
  16. );
  17. my $search = sub ($like) {
  18. my @found;
  19. my $err = exception { @found = Trog::DataModule::filter( undef, { like => $like, acls => ['admin'] }, @posts ) };
  20. return ( $err, [ map { $_->{id} } @found ] );
  21. };
  22. my ( $err, $found ) = $search->('spec');
  23. is( $err, undef, 'a post with no title does not stop the search' );
  24. is_deeply( $found, [qw{titled untitled slides}], 'which finds a title, a body, and a slide of a body that is a list' );
  25. ( $err, $found ) = $search->('ARRAY');
  26. is_deeply( $found, [], 'and never the address of that list' );
  27. };
  28. done_testing();