Akron | 7501ca0 | 2020-08-01 21:05:25 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Test::XML::Loy; |
| 5 | |
| 6 | use FindBin; |
| 7 | BEGIN { |
| 8 | unshift @INC, "$FindBin::Bin/../lib"; |
| 9 | }; |
| 10 | |
| 11 | use_ok('KorAP::XML::TEI::Annotations::Collector'); |
| 12 | use_ok('KorAP::XML::TEI::Annotations::Annotation'); |
| 13 | |
| 14 | my $t = KorAP::XML::TEI::Annotations::Collector->new; |
| 15 | |
| 16 | $t->add_new_annotation('x1',0,8); |
| 17 | my $token = $t->add_new_annotation('x2',9,14,2); |
| 18 | $t->add_new_annotation('x3',15,20); |
| 19 | |
| 20 | my $loy = Test::XML::Loy->new($token->to_string(2)); |
| 21 | |
| 22 | $loy->attr_is('span', 'id', 's2') |
| 23 | ->attr_is('span', 'from', 9) |
| 24 | ->attr_is('span', 'to', 14) |
| 25 | ->attr_is('span', 'l', 2) |
| 26 | ->attr_is('span fs f', 'name', 'lex') |
| 27 | ; |
| 28 | |
Akron | 031a4f0 | 2020-09-29 08:04:14 +0200 | [diff] [blame] | 29 | $loy = Test::XML::Loy->new($t->[-1]->to_string(3)); |
Akron | 7501ca0 | 2020-08-01 21:05:25 +0200 | [diff] [blame] | 30 | |
| 31 | $loy->attr_is('span', 'id', 's3') |
| 32 | ->attr_is('span', 'from', 15) |
| 33 | ->attr_is('span', 'to', 20) |
| 34 | ->attr_is('span fs f', 'name', 'lex') |
| 35 | ; |
| 36 | |
| 37 | $loy = Test::XML::Loy->new($t->to_string('text', 0)) |
| 38 | ->attr_is('layer', 'docid', 'text') |
| 39 | ->attr_is('span#s0', 'to', '8') |
| 40 | ->attr_is('span#s1', 'to', '14') |
| 41 | ->attr_is('span#s1', 'l', '2') |
| 42 | ->attr_is('span#s2', 'to', '20') |
| 43 | ; |
| 44 | |
| 45 | my $anno = KorAP::XML::TEI::Annotations::Annotation->new('x4', 20 => 21); |
| 46 | |
Akron | 997aa22 | 2023-02-10 11:26:28 +0100 | [diff] [blame^] | 47 | ok($anno); |
| 48 | |
| 49 | ok($t->add_annotation($anno)); |
| 50 | |
| 51 | $loy = Test::XML::Loy->new($t->to_string('text',0)) |
| 52 | ->attr_is('layer', 'docid', 'text') |
| 53 | ->attr_is('span#s0', 'to', '8') |
| 54 | ->attr_is('span#s1', 'to', '14') |
| 55 | ->attr_is('span#s1', 'l', '2') |
| 56 | ->attr_is('span#s2', 'to', '20') |
| 57 | ->attr_is('span#s3', 'from', '20') |
| 58 | ->attr_is('span#s3', 'to', '21') |
| 59 | ; |
| 60 | |
| 61 | ok(!$t->add_new_annotation('x1','error','occurred')); |
Akron | 7501ca0 | 2020-08-01 21:05:25 +0200 | [diff] [blame] | 62 | |
| 63 | $loy = Test::XML::Loy->new($t->to_string('text',0)) |
| 64 | ->attr_is('layer', 'docid', 'text') |
| 65 | ->attr_is('span#s0', 'to', '8') |
| 66 | ->attr_is('span#s1', 'to', '14') |
| 67 | ->attr_is('span#s1', 'l', '2') |
| 68 | ->attr_is('span#s2', 'to', '20') |
| 69 | ->attr_is('span#s3', 'from', '20') |
| 70 | ->attr_is('span#s3', 'to', '21') |
| 71 | ; |
| 72 | |
| 73 | done_testing; |
| 74 | |