5 use Test::More tests => 16;
9 BEGIN { use_ok('List::Index'); }
10 ok(eval { List::Index->VERSION(1) }, 'version 1.00 compatibility');
13 my @uniform = 'a'..'z';
14 ok(my $index = List::Index->new(\@uniform), 'object (single-char values)');
15 is_deeply(\@uniform, ['a'..'z'], 'original data unaltered');
16 is_deeply($index->ranges, [['','']], 'single page');
17 is_deeply($index->ranges({pages => 3}), [map { [split /-/, $_, 3] } qw(
20 is_deeply($index->ranges({pagesize => @uniform / 2.1}), [map { [split /-/, $_, 2] } qw(
22 )], 'equivalent pagesize');
26 ok(my $index = List::Index->new(['aa'..'zz', 1..193]), 'non-alphabetic values (uniform)');
27 is_deeply($index->ranges, [map { [split /-/, $_, 2] } qw(
29 a-b c-dr ds-fn fo-hk hl-jg jh-k l-m n-o p-qr qs-sn so-uk ul-wg wh-x y-
30 )], 'default ranges');
31 is_deeply($index->ranges({pagesize => 300}), [map { [split /-/, $_, 2] } qw(
33 )], 'large pagesize');
37 ok(my $index = List::Index->new([qw(
38 baa1 baa2 baa3 baaa bbc cbc daaa ea eaaa zed
39 )]), 'variable length values');
40 is_deeply($index->ranges({pagesize => 2, context => 0}), [
41 map { [split /-/, $_, 2] } qw(-baa. baa.-bbb bbc-daa. daaa-eaa. eaaa-)
43 is_deeply($index->ranges({pagesize => 2}), [
44 map { [split /-/, $_, 2] } qw(-a b c d-ea. eaa-)
45 ], 'default context'); # context should be 1
46 is_deeply($index->ranges({pagesize => 2, context => 2}), [
47 map { [split /-/, $_, 2] } qw(-a b-c d-c d e-)
48 ], 'overlap'); # first item equals second due to large context
49 is_deeply($index->ranges({pagesize => 2, length => 1}), [
50 map { [split /-/, $_, 2] } qw(-a b-a b-c d e-)
53 #pp($index->ranges({pagesize => 2, context => 2, length => 1}));