blob: 4ee67e762425b87d3c129c1448492250700b8338 [file] [log] [blame]
Akronf57ed812020-07-27 10:37:52 +02001use strict;
2use warnings;
3
4use FindBin;
5BEGIN {
6 unshift @INC, "$FindBin::Bin/../lib";
7};
8
9use Test::More;
10use Test::KorAP::XML::TEI qw!korap_tempfile!;
11
12require_ok('KorAP::XML::TEI::Header');
13
14my $h;
15
16eval { $h = KorAP::XML::TEI::Header->new('<idsHeader>') };
17
18ok(!$h, 'Header invalid');
19
20subtest 'Corpus Header' => sub {
21 $h = KorAP::XML::TEI::Header->new('<idsHeader type="corpus">');
22 ok($h, 'Header valid');
23
24 is($h->sigle, '', 'Check sigle');
25 is($h->sigle_esc, '', 'Check sigle escaped');
26 is($h->dir, '', 'Check dir');
27 is($h->type, 'corpus', 'Check dir');
28 like($h->to_string, qr!^<\?xml version!, 'String');
29 like($h->to_string, qr!<idsHeader type=\"corpus\">$!, 'String');
30
31 my ($fh, $filename) = korap_tempfile('header_1');
32
33 print $fh <<'HTML';
34<-- mehrzeiliger
35Kommentar
36 --> <fileDesc>
37 <titleStmt>
38 <korpusSigle>GOE</korpusSigle>
39 <c.title>Goethe-Korpus</c.title>
40 </titleStmt>
41</idsHeader>
42Test
43HTML
44
45 seek($fh, 0, 0);
46
47 ok($h->parse($fh), 'Parsing');
48
49 like($h->to_string, qr!^<\?xml version!, 'String');
50 like($h->to_string, qr!<idsHeader type=\"corpus\">!, 'String');
51 like($h->to_string, qr!<-- mehrzeiliger!, 'String');
52 like($h->to_string, qr!titleStmt!, 'String');
53 like($h->to_string, qr!</idsHeader>$!, 'String');
54
55 is($h->sigle, 'GOE', 'Check sigle');
56 is($h->sigle_esc, 'GOE', 'Check sigle escaped');
57 is($h->id, 'GOE', 'Check sigle');
58 is($h->id_esc, 'GOE', 'Check sigle escaped');
59 is($h->dir, 'GOE', 'Check dir');
60 is($h->type, 'corpus', 'Check type');
61};
62
63subtest 'Document Header' => sub {
64 $h = KorAP::XML::TEI::Header->new('<idsHeader type="document">');
65 ok($h, 'Header valid');
66
67 is($h->sigle, '', 'Check sigle');
68 is($h->sigle_esc, '', 'Check sigle escaped');
69 is($h->dir, '', 'Check dir');
70 like($h->to_string, qr!^<\?xml version!, 'String');
71 like($h->to_string, qr!<idsHeader type=\"document\">$!, 'String');
72
73 my ($fh, $filename) = korap_tempfile('header_2');
74
75 print $fh <<'HTML';
76 <fileDesc>
77 <titleStmt>
78 <dokumentSigle>GOE/"AAA"</dokumentSigle>
79 </titleStmt>
80</idsHeader>
81Test
82HTML
83
84 seek($fh, 0, 0);
85
86 ok($h->parse($fh), 'Parsing');
87
88 like($h->to_string, qr!^<\?xml version!, 'String');
89 like($h->to_string, qr!<idsHeader type=\"document\">!, 'String');
90 like($h->to_string, qr!titleStmt!, 'String');
91 like($h->to_string, qr!</idsHeader>$!, 'String');
92
93 is($h->sigle, 'GOE/"AAA"', 'Check sigle');
94 is($h->sigle_esc, 'GOE/&quot;AAA&quot;', 'Check sigle escaped');
95 is($h->id, 'GOE_"AAA"', 'Check sigle');
96 is($h->id_esc, 'GOE_&quot;AAA&quot;', 'Check sigle escaped');
97 is($h->dir, 'GOE/"AAA"', 'Check dir');
98 is($h->type, 'document', 'Check type');
Akron5401bf32021-10-01 14:35:35 +020099
100
101 ($fh, $filename) = korap_tempfile('header_2');
102
103 print $fh <<'HTML';
104 <fileDesc>
105 <titleStmt>
106 <dokumentSigle>ATZ10.</dokumentSigle>
107 </titleStmt>
108</idsHeader>
109Test
110HTML
111
112 seek($fh, 0, 0);
113
114 $h = KorAP::XML::TEI::Header->new('<idsHeader type="document">');
115 eval { $h->parse($fh) };
116 is($h->sigle, '', 'Check sigle');
Akronf57ed812020-07-27 10:37:52 +0200117};
118
119
120subtest 'Text Header' => sub {
121 $h = KorAP::XML::TEI::Header->new('<idsHeader foo="bar" type="text">');
122 ok($h, 'Header valid');
123
124 is($h->sigle, '', 'Check sigle');
125 is($h->sigle_esc, '', 'Check sigle escaped');
126 is($h->dir, '', 'Check dir');
127 like($h->to_string, qr!^<\?xml version!, 'String');
128 like($h->to_string, qr!<idsHeader foo="bar" type=\"text\">$!, 'String');
129
130 my ($fh, $filename) = korap_tempfile('header_3');
131
132 print $fh <<'HTML';
133 <fileDesc>
134 <titleStmt>
135 <textSigle>GOE/"AAA".00003</textSigle>
136 </titleStmt>
137</idsHeader>
138Test
139HTML
140
141 seek($fh, 0, 0);
142
143 ok($h->parse($fh), 'Parsing');
144
145 like($h->to_string, qr!^<\?xml version!, 'String');
146 like($h->to_string, qr!<idsHeader foo="bar" type=\"text\">!, 'String');
147 like($h->to_string, qr!titleStmt!, 'String');
148 like($h->to_string, qr!</idsHeader>$!, 'String');
149
150 like($h->to_string, qr!GOE/&quot;AAA&quot;\.00003!, 'String');
151
152 is($h->sigle, 'GOE/"AAA".00003', 'Check sigle');
153 is($h->sigle_esc, 'GOE/&quot;AAA&quot;.00003', 'Check sigle escaped');
154 is($h->id, 'GOE_"AAA".00003', 'Check sigle');
155 is($h->id_esc, 'GOE_&quot;AAA&quot;.00003', 'Check sigle escaped');
156 is($h->dir, 'GOE/"AAA"/00003', 'Check dir');
157 is($h->type, 'text', 'Check type');
158};
159
160
161done_testing;