1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use KiokuDB::Backend::Hash;
use KiokuDB::Entry;
my @entries = ( map { KiokuDB::Entry->new($_) }
{ id => 1, root => 1, data => { name => "foo", age => 3 } },
{ id => 2, root => 1, data => { name => "bar", age => 3 } },
{ id => 3, root => 1, data => { name => "gorch", age => 5 } },
{ id => 4, data => { name => "zot", age => 3 } },
);
my $backend = KiokuDB::Backend::Hash->new;
$backend->insert(@entries);
can_ok( $backend, qw(root_entries simple_search) );
my $root_entries = $backend->root_entries;
isa_ok( $root_entries, "Data::Stream::Bulk::Array" );
is_deeply(
[ sort { $a->id <=> $b->id } $root_entries->all ],
[ sort { $a->id <=> $b->id } @entries[0 .. 2] ],
"root set",
);
my $three = $backend->simple_search({ age => 3 });
isa_ok( $three, "Data::Stream::Bulk::Array" );
is_deeply(
[ sort { $a->id <=> $b->id } $three->all ],
[ sort { $a->id <=> $b->id } @entries[0 .. 1] ],
"search",
);
done_testing;
|