Akron | f57ed81 | 2020-07-27 10:37:52 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | |
| 4 | use FindBin; |
| 5 | BEGIN { |
| 6 | unshift @INC, "$FindBin::Bin/../lib"; |
| 7 | }; |
| 8 | |
| 9 | use Test::More; |
| 10 | use Test::KorAP::XML::TEI qw!korap_tempfile!; |
| 11 | |
| 12 | require_ok('KorAP::XML::TEI::Header'); |
| 13 | |
| 14 | my $h; |
| 15 | |
| 16 | eval { $h = KorAP::XML::TEI::Header->new('<idsHeader>') }; |
| 17 | |
| 18 | ok(!$h, 'Header invalid'); |
| 19 | |
| 20 | subtest '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 |
| 35 | Kommentar |
| 36 | --> <fileDesc> |
| 37 | <titleStmt> |
| 38 | <korpusSigle>GOE</korpusSigle> |
| 39 | <c.title>Goethe-Korpus</c.title> |
| 40 | </titleStmt> |
| 41 | </idsHeader> |
| 42 | Test |
| 43 | HTML |
| 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 | |
| 63 | subtest '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> |
| 81 | Test |
| 82 | HTML |
| 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/"AAA"', 'Check sigle escaped'); |
| 95 | is($h->id, 'GOE_"AAA"', 'Check sigle'); |
| 96 | is($h->id_esc, 'GOE_"AAA"', 'Check sigle escaped'); |
| 97 | is($h->dir, 'GOE/"AAA"', 'Check dir'); |
| 98 | is($h->type, 'document', 'Check type'); |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | subtest 'Text Header' => sub { |
| 103 | $h = KorAP::XML::TEI::Header->new('<idsHeader foo="bar" type="text">'); |
| 104 | ok($h, 'Header valid'); |
| 105 | |
| 106 | is($h->sigle, '', 'Check sigle'); |
| 107 | is($h->sigle_esc, '', 'Check sigle escaped'); |
| 108 | is($h->dir, '', 'Check dir'); |
| 109 | like($h->to_string, qr!^<\?xml version!, 'String'); |
| 110 | like($h->to_string, qr!<idsHeader foo="bar" type=\"text\">$!, 'String'); |
| 111 | |
| 112 | my ($fh, $filename) = korap_tempfile('header_3'); |
| 113 | |
| 114 | print $fh <<'HTML'; |
| 115 | <fileDesc> |
| 116 | <titleStmt> |
| 117 | <textSigle>GOE/"AAA".00003</textSigle> |
| 118 | </titleStmt> |
| 119 | </idsHeader> |
| 120 | Test |
| 121 | HTML |
| 122 | |
| 123 | seek($fh, 0, 0); |
| 124 | |
| 125 | ok($h->parse($fh), 'Parsing'); |
| 126 | |
| 127 | like($h->to_string, qr!^<\?xml version!, 'String'); |
| 128 | like($h->to_string, qr!<idsHeader foo="bar" type=\"text\">!, 'String'); |
| 129 | like($h->to_string, qr!titleStmt!, 'String'); |
| 130 | like($h->to_string, qr!</idsHeader>$!, 'String'); |
| 131 | |
| 132 | like($h->to_string, qr!GOE/"AAA"\.00003!, 'String'); |
| 133 | |
| 134 | is($h->sigle, 'GOE/"AAA".00003', 'Check sigle'); |
| 135 | is($h->sigle_esc, 'GOE/"AAA".00003', 'Check sigle escaped'); |
| 136 | is($h->id, 'GOE_"AAA".00003', 'Check sigle'); |
| 137 | is($h->id_esc, 'GOE_"AAA".00003', 'Check sigle escaped'); |
| 138 | is($h->dir, 'GOE/"AAA"/00003', 'Check dir'); |
| 139 | is($h->type, 'text', 'Check type'); |
| 140 | }; |
| 141 | |
| 142 | |
| 143 | done_testing; |