blob: 0a171651b6ea095f14db0add9da70cff364fddfe [file] [log] [blame]
Akron150b29e2016-02-14 23:06:48 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use File::Basename 'dirname';
6use File::Spec::Functions qw/catfile catdir/;
7use File::Temp qw/tempdir/;
8
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +02009use KorAP::XML::Archive;
Akron150b29e2016-02-14 23:06:48 +010010
11my $file = catfile(dirname(__FILE__), 'corpus','archive.zip');
12my $archive = KorAP::XML::Archive->new($file);
13
14unless ($archive->test_unzip) {
15 plan skip_all => 'unzip not found';
16};
17
18ok($archive->test, 'Test archive');
Akron08385f62016-03-22 20:37:04 +010019like($archive->path(0), qr/archive\.zip$/, 'Archive path');
Akron150b29e2016-02-14 23:06:48 +010020
Akron20807582016-10-26 17:11:34 +020021ok($archive->check_prefix, 'Archive has dot prefix');
22
Akron150b29e2016-02-14 23:06:48 +010023my @list = $archive->list_texts;
24is(scalar @list, 10, 'Found all tests');
25is($list[0], './TEST/BSP/1', 'First document');
Akrone8adfcc2016-03-22 13:18:26 +010026is($list[-1], './TEST/BSP/10', 'First document');
Akron150b29e2016-02-14 23:06:48 +010027
28my @path = $archive->split_path('./TEST/BSP/9');
29is($path[0],'.', 'Prefix');
30is($path[1],'TEST', 'Prefix');
31is($path[2],'BSP', 'Prefix');
32is($path[3],'9', 'Prefix');
33
34my $dir = tempdir(CLEANUP => 1);
35
36{
37 local $SIG{__WARN__} = sub {};
Akron20807582016-10-26 17:11:34 +020038 ok($archive->extract_text('./TEST/BSP/8', $dir), 'Wrong path');
Akron150b29e2016-02-14 23:06:48 +010039};
40
41ok(-d catdir($dir, 'TEST'), 'Test corpus directory exists');
42ok(-f catdir($dir, 'TEST', 'header.xml'), 'Test corpus header exists');
43ok(-d catdir($dir, 'TEST', 'BSP'), 'Test doc directory exists');
44ok(-f catdir($dir, 'TEST', 'BSP', 'header.xml'), 'Test doc header exists');
45
Akron20807582016-10-26 17:11:34 +020046$file = catfile(dirname(__FILE__), 'corpus','archive_rei.zip');
47$archive = KorAP::XML::Archive->new($file);
48ok(!$archive->check_prefix, 'Archive has no prefix');
49
Akron150b29e2016-02-14 23:06:48 +010050
Akronf3f0c942016-06-27 13:27:14 +020051# TODO: Test attaching!
Akron08385f62016-03-22 20:37:04 +010052
Akron150b29e2016-02-14 23:06:48 +010053done_testing;
54
55__END__