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 | |
| 9 | use_ok('KorAP::XML::Archive'); |
| 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'); |
| 19 | like($archive->path, qr/archive\.zip$/, 'Archive path'); |
| 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 | |
| 45 | done_testing; |
| 46 | |
| 47 | __END__ |