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