File: 040_Tree_Indexer.t

package info (click to toggle)
libforest-perl 0.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 344 kB
  • sloc: perl: 3,257; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,691 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 36;

BEGIN {
    use_ok('Forest::Tree::Pure');
    use_ok('Forest::Tree');
    use_ok('Forest::Tree::Reader::SimpleTextFile');
    use_ok('Forest::Tree::Indexer');
    use_ok('Forest::Tree::Indexer::SimpleUIDIndexer');
};

{
    my $tree = Forest::Tree::Pure->new(
        node => 3,
        uid  => "three",
        children => [
            Forest::Tree::Pure->new(
                node => 10,
                uid => "ten",
            ),
        ],
    );

    my $index = Forest::Tree::Indexer::SimpleUIDIndexer->new(tree => $tree);

    isa_ok($index, 'Forest::Tree::Indexer::SimpleUIDIndexer');

    $index->build_index;

    my @keys = $index->get_index_keys;
    is_deeply([ sort @keys ], [sort qw(ten three)], '... got the right keys');

    foreach my $key (@keys) {
        my $tree = $index->get_tree_at($key);
        isa_ok($tree, 'Forest::Tree::Pure');
        is($tree->uid, $key, '... indexed by uid');
    }
}

{
    my $reader = Forest::Tree::Reader::SimpleTextFile->new;
    isa_ok($reader, 'Forest::Tree::Reader::SimpleTextFile');
    
    $reader->read(\*DATA);

    my $index = Forest::Tree::Indexer::SimpleUIDIndexer->new(tree => $reader->tree);
    isa_ok($index, 'Forest::Tree::Indexer::SimpleUIDIndexer');

    $index->build_index;

    my @keys = $index->get_index_keys;
    is(scalar @keys, 11, '... got the right amount of keys');

    foreach my $key (@keys) {
        my $tree = $index->get_tree_at($key);
        isa_ok($tree, 'Forest::Tree');
        is($tree->uid, $key, '... indexed by uid');
    }
}

__DATA__
1.0
    1.1
    1.2
        1.2.1
2.0
    2.1
3.0
4.0
    4.1
        4.1.1