blob: aa6793729064619d28c194bf0e497b2713ac8ead [file] [log] [blame]
Akron7501ca02020-08-01 21:05:25 +02001use strict;
2use warnings;
3use Test::More;
4use Test::XML::Loy;
5
6use FindBin;
7BEGIN {
8 unshift @INC, "$FindBin::Bin/../lib";
9};
10
11use_ok('KorAP::XML::TEI::Annotations::Collector');
12use_ok('KorAP::XML::TEI::Annotations::Annotation');
13
14my $t = KorAP::XML::TEI::Annotations::Collector->new;
15
16$t->add_new_annotation('x1',0,8);
17my $token = $t->add_new_annotation('x2',9,14,2);
18$t->add_new_annotation('x3',15,20);
19
20my $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
Akron031a4f02020-09-29 08:04:14 +020029$loy = Test::XML::Loy->new($t->[-1]->to_string(3));
Akron7501ca02020-08-01 21:05:25 +020030
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
45my $anno = KorAP::XML::TEI::Annotations::Annotation->new('x4', 20 => 21);
46
Akron997aa222023-02-10 11:26:28 +010047ok($anno);
48
49ok($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
61ok(!$t->add_new_annotation('x1','error','occurred'));
Akron7501ca02020-08-01 21:05:25 +020062
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
73done_testing;
74