Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 4 | use Data::Dumper; |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 5 | use Test::More; |
| 6 | use File::Basename 'dirname'; |
| 7 | use File::Spec::Functions qw/catfile catdir/; |
| 8 | use File::Temp qw/tempdir/; |
| 9 | |
Nils Diewald | b3e9ccd | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 10 | use KorAP::XML::Archive; |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 11 | |
| 12 | my $file = catfile(dirname(__FILE__), 'corpus','archive.zip'); |
| 13 | my $archive = KorAP::XML::Archive->new($file); |
| 14 | |
| 15 | unless ($archive->test_unzip) { |
| 16 | plan skip_all => 'unzip not found'; |
| 17 | }; |
| 18 | |
| 19 | ok($archive->test, 'Test archive'); |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 20 | like($archive->path(0), qr/archive\.zip$/, 'Archive path'); |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 21 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 22 | ok($archive->check_prefix, 'Archive has dot prefix'); |
| 23 | |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 24 | my @list = $archive->list_texts; |
| 25 | is(scalar @list, 10, 'Found all tests'); |
| 26 | is($list[0], './TEST/BSP/1', 'First document'); |
Akron | e8adfcc | 2016-03-22 13:18:26 +0100 | [diff] [blame] | 27 | is($list[-1], './TEST/BSP/10', 'First document'); |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 28 | |
| 29 | my @path = $archive->split_path('./TEST/BSP/9'); |
| 30 | is($path[0],'.', 'Prefix'); |
| 31 | is($path[1],'TEST', 'Prefix'); |
| 32 | is($path[2],'BSP', 'Prefix'); |
| 33 | is($path[3],'9', 'Prefix'); |
| 34 | |
| 35 | my $dir = tempdir(CLEANUP => 1); |
| 36 | |
| 37 | { |
| 38 | local $SIG{__WARN__} = sub {}; |
Akron | 955b75b | 2019-02-21 14:28:41 +0100 | [diff] [blame] | 39 | ok($archive->extract_sigle(['TEST/BSP/8'], $dir), 'Wrong path'); |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | ok(-d catdir($dir, 'TEST'), 'Test corpus directory exists'); |
| 43 | ok(-f catdir($dir, 'TEST', 'header.xml'), 'Test corpus header exists'); |
| 44 | ok(-d catdir($dir, 'TEST', 'BSP'), 'Test doc directory exists'); |
| 45 | ok(-f catdir($dir, 'TEST', 'BSP', 'header.xml'), 'Test doc header exists'); |
| 46 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame] | 47 | $file = catfile(dirname(__FILE__), 'corpus','archive_rei.zip'); |
| 48 | $archive = KorAP::XML::Archive->new($file); |
| 49 | ok(!$archive->check_prefix, 'Archive has no prefix'); |
| 50 | |
Akron | 60a8caa | 2017-02-17 21:51:27 +0100 | [diff] [blame] | 51 | # No leading '.' |
| 52 | $file = catfile(dirname(__FILE__), 'corpus','archive_rei.zip'); |
| 53 | $archive = KorAP::XML::Archive->new($file); |
| 54 | ok(!$archive->check_prefix, 'Archive has no dot prefix'); |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 55 | |
Akron | 31a08cb | 2019-02-20 20:43:26 +0100 | [diff] [blame] | 56 | my @cmd = map { join ' ', @{$_} } $archive->cmds_from_sigle(['REI/RB*', 'REI/BNG/00071']); |
| 57 | |
| 58 | like($cmd[0], qr!unzip -qo -uo t/corpus/archive_rei\.zip!); |
| 59 | like($cmd[0], qr!\QREI/header.xml REI/RB*/header.xml REI/RB* REI/BNG/header.xml REI/BNG/00071/*\E!); |
| 60 | ok(!$cmd[1]); |
| 61 | |
| 62 | # New temporary directory |
| 63 | $dir = tempdir(CLEANUP => 1); |
| 64 | |
| 65 | { |
| 66 | local $SIG{__WARN__} = sub {}; |
| 67 | ok($archive->extract_sigle(['REI/RB*', 'REI/BNG/00071'], $dir), 'Fine'); |
| 68 | }; |
| 69 | |
| 70 | ok(-d catdir($dir, 'REI'), 'Test corpus directory exists'); |
| 71 | ok(-d catdir($dir, 'REI','BNG'), 'Test corpus directory exists'); |
| 72 | ok(-d catdir($dir, 'REI','BNG','00071'), 'Test corpus directory exists'); |
| 73 | |
| 74 | ok(-f catdir($dir, 'REI', 'header.xml'), 'Test corpus directory exists'); |
| 75 | ok(-f catdir($dir, 'REI','BNG', 'header.xml'), 'Test corpus directory exists'); |
| 76 | ok(-f catdir($dir, 'REI','BNG','00071', 'header.xml'), 'Test corpus directory exists'); |
| 77 | |
| 78 | ok(-f catdir($dir, 'REI','RBR', 'header.xml'), 'Test corpus directory exists'); |
| 79 | ok(-f catdir($dir, 'REI','RBR','00610', 'header.xml'), 'Test corpus directory exists'); |
| 80 | ok(-f catdir($dir, 'REI','RBR','00610', 'header.xml'), 'Test corpus directory exists'); |
| 81 | |
| 82 | ok(!-e catdir($dir, 'REI','BNG','00128'), 'Test corpus directory does not exist'); |
| 83 | |
| 84 | |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 85 | done_testing; |
| 86 | |
| 87 | __END__ |