Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 1 | #!/usr/bin/env perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | use Test::More; |
| 5 | use File::Basename 'dirname'; |
| 6 | use File::Spec::Functions qw/catfile catdir/; |
| 7 | use File::Temp qw/tempdir/; |
| 8 | |
Nils Diewald | b3e9ccd | 2016-10-24 15:16:52 +0200 | [diff] [blame] | 9 | use KorAP::XML::Archive; |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 10 | |
| 11 | my $file = catfile(dirname(__FILE__), 'corpus','archive.zip'); |
| 12 | my $archive = KorAP::XML::Archive->new($file); |
| 13 | |
| 14 | unless ($archive->test_unzip) { |
| 15 | plan skip_all => 'unzip not found'; |
| 16 | }; |
| 17 | |
| 18 | ok($archive->test, 'Test archive'); |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 19 | like($archive->path(0), qr/archive\.zip$/, 'Archive path'); |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 20 | |
| 21 | my @list = $archive->list_texts; |
| 22 | is(scalar @list, 10, 'Found all tests'); |
| 23 | is($list[0], './TEST/BSP/1', 'First document'); |
Akron | e8adfcc | 2016-03-22 13:18:26 +0100 | [diff] [blame] | 24 | is($list[-1], './TEST/BSP/10', 'First document'); |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 25 | |
| 26 | my @path = $archive->split_path('./TEST/BSP/9'); |
| 27 | is($path[0],'.', 'Prefix'); |
| 28 | is($path[1],'TEST', 'Prefix'); |
| 29 | is($path[2],'BSP', 'Prefix'); |
| 30 | is($path[3],'9', 'Prefix'); |
| 31 | |
| 32 | my $dir = tempdir(CLEANUP => 1); |
| 33 | |
| 34 | { |
| 35 | local $SIG{__WARN__} = sub {}; |
| 36 | ok($archive->extract('./TEST/BSP/8', $dir), 'Wrong path'); |
| 37 | }; |
| 38 | |
| 39 | ok(-d catdir($dir, 'TEST'), 'Test corpus directory exists'); |
| 40 | ok(-f catdir($dir, 'TEST', 'header.xml'), 'Test corpus header exists'); |
| 41 | ok(-d catdir($dir, 'TEST', 'BSP'), 'Test doc directory exists'); |
| 42 | ok(-f catdir($dir, 'TEST', 'BSP', 'header.xml'), 'Test doc header exists'); |
| 43 | |
| 44 | |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 45 | # TODO: Test attaching! |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 46 | |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 47 | done_testing; |
| 48 | |
| 49 | __END__ |