Akron | 09e0b2c | 2020-07-28 15:57:01 +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 | |
Akron | 7501ca0 | 2020-08-01 21:05:25 +0200 | [diff] [blame] | 11 | use_ok('KorAP::XML::TEI::Annotations::Annotation'); |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 12 | |
| 13 | subtest 'Initialization' => sub { |
Akron | 7501ca0 | 2020-08-01 21:05:25 +0200 | [diff] [blame] | 14 | my $t = KorAP::XML::TEI::Annotations::Annotation->new; |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 15 | |
| 16 | ok(!defined($t->from), 'Undefined from'); |
| 17 | ok(!defined($t->to), 'Undefined to'); |
| 18 | ok(!defined($t->level), 'Undefined level'); |
| 19 | |
| 20 | $t->add_attribute('foo' => 'bar'); |
| 21 | $t->add_attribute('x' => 'y'); |
| 22 | $t->set_from(7); |
| 23 | $t->set_to(5); |
| 24 | $t->set_from(4); |
| 25 | |
| 26 | my $loy = Test::XML::Loy->new($t->to_string(3)); |
| 27 | |
| 28 | $loy->attr_is('span', 'id', 's3') |
| 29 | ->attr_is('span', 'from', 4) |
| 30 | ->attr_is('span', 'to', 5) |
| 31 | ->attr_is('span fs f', 'name', 'lex') |
| 32 | ->attr_is('span fs f fs f:nth-of-type(1)', 'name', 'foo') |
| 33 | ->text_is('span fs f fs f:nth-of-type(1)', 'bar') |
| 34 | ->attr_is('span fs f fs f:nth-of-type(2)', 'name', 'x') |
| 35 | ->text_is('span fs f fs f:nth-of-type(2)', 'y') |
| 36 | ; |
| 37 | |
| 38 | is($t->from,4); |
| 39 | is($t->to,5); |
| 40 | is($t->level,undef); |
| 41 | $t->set_level(19); |
| 42 | is($t->level,19); |
| 43 | |
| 44 | $loy = Test::XML::Loy->new($t->to_string(3)); |
| 45 | |
| 46 | $loy->attr_is('span', 'id', 's3') |
| 47 | ->attr_is('span', 'from', 4) |
| 48 | ->attr_is('span', 'to', 5) |
| 49 | ->attr_is('span', 'l', 19) |
| 50 | ; |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | subtest 'Test inline annotations' => sub { |
Akron | 7501ca0 | 2020-08-01 21:05:25 +0200 | [diff] [blame] | 55 | my $t = KorAP::XML::TEI::Annotations::Annotation->new('x1', 0, 6); |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 56 | $t->add_attribute('ana' => 'DET @PREMOD'); |
| 57 | $t->add_attribute('lemma' => 'C & A'); |
| 58 | |
| 59 | my $loy = Test::XML::Loy->new($t->to_string(1)); |
| 60 | |
| 61 | $loy->attr_is('span', 'id', 's1') |
| 62 | ->attr_is('span', 'to', 6) |
| 63 | ->attr_is('span > fs > f > fs f:nth-of-type(1)', 'name', 'ana') |
| 64 | ->text_is('span > fs > f > fs f:nth-of-type(1)', 'DET @PREMOD') |
| 65 | ->attr_is('span > fs > f > fs f:nth-of-type(2)', 'name', 'lemma') |
| 66 | ->text_is('span > fs > f > fs f:nth-of-type(2)', 'C & A') |
| 67 | ; |
| 68 | |
| 69 | $loy = Test::XML::Loy->new($t->to_string_with_inline_annotations(1)); |
| 70 | |
| 71 | $loy->attr_is('span', 'id', 's1') |
| 72 | ->attr_is('span', 'to', 6) |
| 73 | ->attr_is('span > fs > f > fs f:nth-of-type(1)', 'name', 'pos') |
| 74 | ->text_is('span > fs > f > fs f:nth-of-type(1)', 'DET') |
| 75 | ->attr_is('span > fs > f > fs f:nth-of-type(2)', 'name', 'msd') |
| 76 | ->text_is('span > fs > f > fs f:nth-of-type(2)', '@PREMOD') |
| 77 | ->attr_is('span > fs > f > fs f:nth-of-type(3)', 'name', 'lemma') |
| 78 | ->text_is('span > fs > f > fs f:nth-of-type(3)', 'C & A') |
| 79 | }; |
| 80 | |
Akron | 997aa22 | 2023-02-10 11:26:28 +0100 | [diff] [blame] | 81 | subtest 'Wrong annotations' => sub { |
| 82 | ok(!KorAP::XML::TEI::Annotations::Annotation->new('p','Error',0)); |
| 83 | ok(!KorAP::XML::TEI::Annotations::Annotation->new('p',0,'Occurred')); |
| 84 | ok(!KorAP::XML::TEI::Annotations::Annotation->new('p',0,5,'Fehler')); |
| 85 | }; |
Akron | 09e0b2c | 2020-07-28 15:57:01 +0200 | [diff] [blame] | 86 | |
| 87 | done_testing; |
| 88 | |