Akron | 1622dd9 | 2015-12-09 22:34:26 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use Test::More; |
| 5 | |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 6 | use_ok('KorAP::XML::Tokenizer::Range'); |
Akron | 1622dd9 | 2015-12-09 22:34:26 +0100 | [diff] [blame] | 7 | |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 8 | my $range = KorAP::XML::Tokenizer::Range->new; |
Akron | 1622dd9 | 2015-12-09 22:34:26 +0100 | [diff] [blame] | 9 | |
| 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 | |
| 16 | is($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 | |
| 23 | is($range->lookup(3), 0, 'Lookup is fine'); |
| 24 | |
| 25 | is($range->lookup(6), 0, 'Lookup is fine'); |
| 26 | is($range->lookup(14), 0, 'Lookup is fine'); |
| 27 | |
| 28 | ok(!$range->lookup(1), 'Lookup is fine'); |
| 29 | ok(!$range->lookup(16), 'Lookup is fine'); |
| 30 | |
| 31 | is($range->before(0), 0, 'Before is fine'); |
| 32 | is($range->before(1), 0, 'Before is fine'); |
| 33 | is($range->before(2), 0, 'Before is fine'); |
| 34 | is($range->before(3), 0, 'Before is fine'); |
| 35 | is($range->before(4), 0, 'Before is fine'); |
| 36 | is($range->before(15), 0, 'Before is fine'); |
| 37 | is($range->before(23), 1, 'Before is fine'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 38 | |
| 39 | { |
| 40 | local $SIG{__WARN__} = sub {}; |
| 41 | ok(!$range->before(590), 'No range here'); |
| 42 | }; |
Akron | 1622dd9 | 2015-12-09 22:34:26 +0100 | [diff] [blame] | 43 | |
| 44 | is($range->after(0), 0, 'After is fine'); |
| 45 | is($range->after(1), 0, 'After is fine'); |
| 46 | is($range->after(2), 0, 'After is fine'); |
Akron | b62d92a | 2020-03-01 16:32:00 +0100 | [diff] [blame^] | 47 | is($range->after(3), 1, 'After is fine'); |
| 48 | is($range->after(14), 1, 'After is fine'); |
Akron | 1622dd9 | 2015-12-09 22:34:26 +0100 | [diff] [blame] | 49 | is($range->after(15), 1, 'After is fine'); |
| 50 | |
| 51 | is($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'); |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 54 | |
Akron | 1622dd9 | 2015-12-09 22:34:26 +0100 | [diff] [blame] | 55 | done_testing; |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 56 | |
Akron | 1622dd9 | 2015-12-09 22:34:26 +0100 | [diff] [blame] | 57 | __END__ |