blob: 1176c988770cdbd1a40578ccfd10edbb61edc3cd [file] [log] [blame]
Akron09e0b2c2020-07-28 15:57:01 +02001use strict;
2use warnings;
3use Test::More;
4use Test::XML::Loy;
5
6use FindBin;
7BEGIN {
8 unshift @INC, "$FindBin::Bin/../lib";
9};
10
Akron7501ca02020-08-01 21:05:25 +020011use_ok('KorAP::XML::TEI::Annotations::Annotation');
Akron09e0b2c2020-07-28 15:57:01 +020012
13subtest 'Initialization' => sub {
Akron7501ca02020-08-01 21:05:25 +020014 my $t = KorAP::XML::TEI::Annotations::Annotation->new;
Akron09e0b2c2020-07-28 15:57:01 +020015
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
54subtest 'Test inline annotations' => sub {
Akron7501ca02020-08-01 21:05:25 +020055 my $t = KorAP::XML::TEI::Annotations::Annotation->new('x1', 0, 6);
Akron09e0b2c2020-07-28 15:57:01 +020056 $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
81
82done_testing;
83