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 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame^] | 21 | ok($archive->check_prefix, 'Archive has dot prefix'); |
| 22 | |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 23 | my @list = $archive->list_texts; |
| 24 | is(scalar @list, 10, 'Found all tests'); |
| 25 | is($list[0], './TEST/BSP/1', 'First document'); |
Akron | e8adfcc | 2016-03-22 13:18:26 +0100 | [diff] [blame] | 26 | is($list[-1], './TEST/BSP/10', 'First document'); |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 27 | |
| 28 | my @path = $archive->split_path('./TEST/BSP/9'); |
| 29 | is($path[0],'.', 'Prefix'); |
| 30 | is($path[1],'TEST', 'Prefix'); |
| 31 | is($path[2],'BSP', 'Prefix'); |
| 32 | is($path[3],'9', 'Prefix'); |
| 33 | |
| 34 | my $dir = tempdir(CLEANUP => 1); |
| 35 | |
| 36 | { |
| 37 | local $SIG{__WARN__} = sub {}; |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame^] | 38 | ok($archive->extract_text('./TEST/BSP/8', $dir), 'Wrong path'); |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | ok(-d catdir($dir, 'TEST'), 'Test corpus directory exists'); |
| 42 | ok(-f catdir($dir, 'TEST', 'header.xml'), 'Test corpus header exists'); |
| 43 | ok(-d catdir($dir, 'TEST', 'BSP'), 'Test doc directory exists'); |
| 44 | ok(-f catdir($dir, 'TEST', 'BSP', 'header.xml'), 'Test doc header exists'); |
| 45 | |
Akron | 2080758 | 2016-10-26 17:11:34 +0200 | [diff] [blame^] | 46 | $file = catfile(dirname(__FILE__), 'corpus','archive_rei.zip'); |
| 47 | $archive = KorAP::XML::Archive->new($file); |
| 48 | ok(!$archive->check_prefix, 'Archive has no prefix'); |
| 49 | |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 50 | |
Akron | f3f0c94 | 2016-06-27 13:27:14 +0200 | [diff] [blame] | 51 | # TODO: Test attaching! |
Akron | 08385f6 | 2016-03-22 20:37:04 +0100 | [diff] [blame] | 52 | |
Akron | 150b29e | 2016-02-14 23:06:48 +0100 | [diff] [blame] | 53 | done_testing; |
| 54 | |
| 55 | __END__ |