File: attrs.t

package info (click to toggle)
libsearch-gin-perl 0.11-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 404 kB
  • sloc: perl: 1,007; makefile: 28
file content (62 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;

use Test::More 'no_plan';

use ok 'Search::GIN::Query::Attributes';
use ok 'Search::GIN::Extract::Attributes';

{
    package MyGIN;
    use Moose;

    with (
        qw(
            Search::GIN::Core
            Search::GIN::Driver::Hash
            Search::GIN::SelfIDs
            Search::GIN::Extract::Delegate
        ),
    );

    __PACKAGE__->meta->make_immutable;

    package Foo;
    use Moose;

    has age => (
        isa => "Int",
        is  => "rw",
    );

    has name => (
        isa => "Str",
        is  => "rw",
    );

    __PACKAGE__->meta->make_immutable;
}


my $gin = MyGIN->new( extract => Search::GIN::Extract::Attributes->new );

my @objs = ( map { Foo->new($_) } { name => "stevan", age => 47 }, { name => "jon", age => 2 }, { name => "yuval", age => 2 } );

$gin->insert(@objs);

{
    my @res = $gin->query( Search::GIN::Query::Attributes->new( attributes => {} ) )->all;
    is_deeply( \@res, [ ] );
}

{
    my @res = $gin->query( Search::GIN::Query::Attributes->new( attributes => { name => "jon" } ) )->all;
    is_deeply( \@res, [ $objs[1] ] );
}

{
    my @res = $gin->query( Search::GIN::Query::Attributes->new( attributes => { age => 2 } ) )->all;
    is_deeply( [ sort @res ], [ sort @objs[1,2] ] );
}