Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use File::Basename 'dirname'; |
| 4 | use File::Spec::Functions qw/catfile/; |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 5 | use File::Temp ':POSIX'; |
| 6 | use IO::Uncompress::Unzip qw(unzip $UnzipError); |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 7 | |
| 8 | use Test::More; |
| 9 | use Test::Output; |
| 10 | |
Akron | 9721c41 | 2020-02-17 12:42:09 +0100 | [diff] [blame^] | 11 | use Test::XML::Loy; |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 12 | |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 13 | my $f = dirname(__FILE__); |
| 14 | my $script = catfile($f, '..', 'script', 'tei2korapxml'); |
| 15 | ok(-f $script, 'Script found'); |
| 16 | |
| 17 | stderr_is( |
| 18 | sub { system('perl', $script, '--help') }, |
| 19 | "This program is called from inside another script.\n", |
| 20 | 'Help' |
| 21 | ); |
| 22 | |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 23 | # Load example file |
| 24 | my $file = catfile($f, 'data', 'goe_sample.i5.xml'); |
| 25 | my $outzip = tmpnam(); |
| 26 | |
| 27 | # Generate zip file (unportable!) |
| 28 | stderr_like( |
| 29 | sub { `cat '$file' | perl '$script' > '$outzip'` }, |
| 30 | qr!tei2korapxml: .*? text_id=GOE_AGA\.00000!, |
| 31 | 'Processing' |
| 32 | ); |
| 33 | |
| 34 | # Uncompress GOE/header.xml from zip file |
| 35 | my $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/header.xml'); |
| 36 | |
| 37 | ok($zip, 'Zip-File is created'); |
| 38 | |
| 39 | # Read GOE/header.xml |
| 40 | my $header_xml = ''; |
| 41 | $header_xml .= $zip->getline while !$zip->eof; |
| 42 | ok($zip->close, 'Closed'); |
| 43 | |
Akron | 9721c41 | 2020-02-17 12:42:09 +0100 | [diff] [blame^] | 44 | my $t = Test::XML::Loy->new($header_xml); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 45 | |
Akron | 9721c41 | 2020-02-17 12:42:09 +0100 | [diff] [blame^] | 46 | $t->text_is('korpusSigle', 'GOE', 'korpusSigle') |
| 47 | ->text_is('h\.title[type=main]', 'Goethes Werke', 'h.title') |
| 48 | ->text_is('h\.author', 'Goethe, Johann Wolfgang von', 'h.author') |
| 49 | ->text_is('pubDate[type=year]', '1982', 'pubDate'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 50 | |
| 51 | # Uncompress GOE/AGA/header.xml from zip file |
| 52 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/header.xml'); |
| 53 | |
| 54 | ok($zip, 'Zip-File is found'); |
| 55 | |
| 56 | # Read GOE/AGA/header.xml |
| 57 | $header_xml = ''; |
| 58 | $header_xml .= $zip->getline while !$zip->eof; |
| 59 | ok($zip->close, 'Closed'); |
| 60 | |
Akron | 9721c41 | 2020-02-17 12:42:09 +0100 | [diff] [blame^] | 61 | $t = Test::XML::Loy->new($header_xml); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 62 | |
Akron | 9721c41 | 2020-02-17 12:42:09 +0100 | [diff] [blame^] | 63 | $t->text_is('dokumentSigle', 'GOE/AGA', 'dokumentSigle') |
| 64 | ->text_is('d\.title', 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', 'd.title') |
| 65 | ->text_is('creatDate', '1820-1822', 'creatDate'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 66 | |
| 67 | # Uncompress GOE/AGA/00000/header.xml from zip file |
| 68 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/00000/header.xml'); |
| 69 | |
| 70 | ok($zip, 'Zip-File is found'); |
| 71 | |
| 72 | # Read GOE/AGA/00000/header.xml |
| 73 | $header_xml = ''; |
| 74 | $header_xml .= $zip->getline while !$zip->eof; |
| 75 | ok($zip->close, 'Closed'); |
| 76 | |
Akron | 9721c41 | 2020-02-17 12:42:09 +0100 | [diff] [blame^] | 77 | $t = Test::XML::Loy->new($header_xml); |
| 78 | $t->text_is('textSigle', 'GOE/AGA.00000', 'textSigle') |
| 79 | ->text_is('analytic > h\.title[type=main]', 'Campagne in Frankreich', 'h.title'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 80 | |
| 81 | # Uncompress GOE/AGA/00000/data.xml from zip file |
| 82 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/00000/data.xml'); |
| 83 | |
| 84 | ok($zip, 'Zip-File is found'); |
| 85 | |
| 86 | # Read GOE/AGA/00000/data.xml |
| 87 | my $data_xml = ''; |
| 88 | $data_xml .= $zip->getline while !$zip->eof; |
| 89 | ok($zip->close, 'Closed'); |
| 90 | |
Akron | 9721c41 | 2020-02-17 12:42:09 +0100 | [diff] [blame^] | 91 | $t = Test::XML::Loy->new($data_xml); |
| 92 | $t->attr_is('raw_text', 'docid', 'GOE_AGA.00000', 'text id') |
| 93 | ->text_like('raw_text > text', qr!^Campagne in Frankreich 1792.*?uns allein begl.*cke\.$!, 'text content'); |
Akron | 2a60c53 | 2020-02-13 15:52:18 +0100 | [diff] [blame] | 94 | |
| 95 | # Uncompress GOE/AGA/00000/struct/structure.xml from zip file |
| 96 | $zip = IO::Uncompress::Unzip->new($outzip, Name => 'GOE/AGA/00000/struct/structure.xml'); |
| 97 | |
| 98 | ok($zip, 'Zip-File is found'); |
| 99 | |
| 100 | # Read GOE/AGA/00000/struct/structure.xml |
| 101 | my $struct_xml = ''; |
| 102 | $struct_xml .= $zip->getline while !$zip->eof; |
| 103 | ok($zip->close, 'Closed'); |
| 104 | |
Akron | 9721c41 | 2020-02-17 12:42:09 +0100 | [diff] [blame^] | 105 | $t = Test::XML::Loy->new($struct_xml); |
| 106 | $t->text_is('span[id=s3] *[name=type]', 'Autobiographie', 'text content'); |
Akron | 797e807 | 2020-02-13 07:59:40 +0100 | [diff] [blame] | 107 | |
| 108 | done_testing; |