-{
-ok(my $index = List::Index->new(['aa'..'zz', 1..193]), 'non-alphabetic values (uniform)');
-is_deeply($index->ranges, [map { [split /-/, $_, 2] } qw(
- .-.a ..-.a ..-..a ...-
- a-bv bw-dr ds-fn fo-hk hl-jg jh-k l-m n-ov ow-qr qs-sn so-uk ul-wg wh-x y-
-)], 'default ranges');
-is_deeply($index->ranges({pagesize => 300}), [map { [split /-/, $_, 2] } qw(
- .-c d-ov ow-
-)], 'large pagesize');
+ is_deeply(
+ $index->ranges(\@data),
+ [qw(
+ -.
+ .-bp bq-dm dn-fi fj-hf hg-i j-k l-m n-os ot-qp qq-sm sn-uj uk-wf wg-x y-
+ )],
+ 'default ranges'
+ );
+ is_deeply(
+ $index->ranges(\@data, { pagesize => 300 }),
+ [qw(-c d-n o-)],
+ 'large pagesize'
+ );
+};
+
+subtest 'context' => sub {
+ plan tests => 9;
+ my @data = qw(
+ kkeg kl km kmlu knsy koxb kpeo kuaa kuab kuac
+ kuapa kuq kur kux kzb lc lg lgu lgua lguc
+ lguq lgur lgws lgx lka lkq lks lln llq llx
+ );
+ my $index = List::Index->new({ pagesize => 10 }) or return;
+
+ is_deeply(
+ $index->ranges(\@data, { context => 0, length => 5 }),
+ # ranges should match offsets exactly
+ [qw(-kuap. kuapa-lgup lguq-)],
+ 'no context'
+ );
+ is_deeply(
+ $index->ranges(\@data, { context => 0 }),
+ # default length limits to 4 chars
+ [qw(-kuao kuap-lgup lguq-)],
+ 'default length'
+ );
+ is_deeply(
+ $index->ranges(\@data, { context => 1 }),
+ # lookbehinds aren't shorter (kuac<kuap, lguc<lguq)
+ # 'kuap' can advance to 'kuq'
+ [qw(-kup kuq-lgup lguq-)],
+ 'lookahead'
+ );
+TODO: {
+ local $TODO = 'backtrack';
+ is_deeply(
+ $index->ranges(\@data, { context => 2 }),
+ # allowed to advance to 'kur', but provides no benefits over 'kuq'
+ [qw(-kup kuq-lgup lguq-)],
+ 'minimal lookahead'
+ );