File: class.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 (85 lines) | stat: -rw-r--r-- 1,570 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use strict;
use warnings;

use Test::More 'no_plan';

use ok 'Search::GIN::Query::Class';
use ok 'Search::GIN::Extract::Class';
use ok 'Search::GIN::Query::Manual';

{
    package MyGIN;
    use Moose;

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

    __PACKAGE__->meta->make_immutable;

    # this is an indexable object
    package Base;
    use Moose;

    __PACKAGE__->meta->make_immutable;

    package Foo;
    use Moose;

    extends qw(Base);

    __PACKAGE__->meta->make_immutable;

    package Bar;
    use Moose;

    extends qw(Base);

    __PACKAGE__->meta->make_immutable;

    package Gorch;
    use Moose;

    extends qw(Bar);

    __PACKAGE__->meta->make_immutable;
}


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

my @objs = (
    Base->new,
    Foo->new,
    Bar->new,
    Bar->new,
    Gorch->new,
);

$gin->insert(@objs);

{
    my @res = $gin->query( Search::GIN::Query::Class->new( class => "Base" ) )->all;
    is_deeply( [ sort @res ], [ sort @objs ] );
}

{
    my @res = $gin->query( Search::GIN::Query::Class->new( class => "Foo" ) )->all;
    is_deeply( [ @res ], [ $objs[1] ] );
}

{
    my @res = $gin->query( Search::GIN::Query::Class->new( class => "Bar" ) )->all;
    is_deeply( [ sort @res ], [ sort @objs[2, 3, 4] ] );
}


{
    my @res = $gin->query( Search::GIN::Query::Manual->new( values => { class => "Foo" } ) )->all;
    is_deeply( [ @res ], [ $objs[1] ] );
}