blob: 27c7970cbb156d9b79362bbba4fdc4c0afd67ff0 [file] [log] [blame]
Akron1622dd92015-12-09 22:34:26 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5
Akrone4c2e412016-01-28 15:10:50 +01006use_ok('KorAP::XML::Tokenizer::Range');
Akron1622dd92015-12-09 22:34:26 +01007
Akrone4c2e412016-01-28 15:10:50 +01008my $range = KorAP::XML::Tokenizer::Range->new;
Akron1622dd92015-12-09 22:34:26 +01009
10# Set a gap from 0 to 2, refering to position 0
11$range->gap(0, 2, 0);
12
13# Set a range from 3 to 14, refering to position 0
14$range->set(3, 14, 0);
15
16is($range->lookup(3), 0, 'Lookup is fine');
17
18# Set a gap from 15 to 16, refering to position 1
19$range->gap(15, 16, 1);
20$range->set(17, 20, 1);
21$range->set(21, 28, 2);
22
23is($range->lookup(3), 0, 'Lookup is fine');
24
25is($range->lookup(6), 0, 'Lookup is fine');
26is($range->lookup(14), 0, 'Lookup is fine');
27
28ok(!$range->lookup(1), 'Lookup is fine');
29ok(!$range->lookup(16), 'Lookup is fine');
30
31is($range->before(0), 0, 'Before is fine');
32is($range->before(1), 0, 'Before is fine');
33is($range->before(2), 0, 'Before is fine');
34is($range->before(3), 0, 'Before is fine');
35is($range->before(4), 0, 'Before is fine');
36is($range->before(15), 0, 'Before is fine');
37is($range->before(23), 1, 'Before is fine');
Akron9c0488f2016-01-28 14:17:15 +010038
39{
40 local $SIG{__WARN__} = sub {};
41 ok(!$range->before(590), 'No range here');
42};
Akron1622dd92015-12-09 22:34:26 +010043
44is($range->after(0), 0, 'After is fine');
45is($range->after(1), 0, 'After is fine');
46is($range->after(2), 0, 'After is fine');
47is($range->after(3), 0, 'After is fine');
48is($range->after(14), 0, 'After is fine');
49is($range->after(15), 1, 'After is fine');
50
51is($range->to_string,
52 '[0,2,!-1:0][3,14,0][15,16,!0:1][17,20,1][21,28,2][29,100,...]...',
53 'ToString is fine');
Akron9c0488f2016-01-28 14:17:15 +010054
Akron1622dd92015-12-09 22:34:26 +010055done_testing;
Akron9c0488f2016-01-28 14:17:15 +010056
Akron1622dd92015-12-09 22:34:26 +010057__END__