blob: 9d2ce681bdb0eac66326849e579ef3a19e435e4b [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
9use_ok('KorAP::XML::Archive');
10
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
21my @list = $archive->list_texts;
22is(scalar @list, 10, 'Found all tests');
23is($list[0], './TEST/BSP/1', 'First document');
Akrone8adfcc2016-03-22 13:18:26 +010024is($list[-1], './TEST/BSP/10', 'First document');
Akron150b29e2016-02-14 23:06:48 +010025
26my @path = $archive->split_path('./TEST/BSP/9');
27is($path[0],'.', 'Prefix');
28is($path[1],'TEST', 'Prefix');
29is($path[2],'BSP', 'Prefix');
30is($path[3],'9', 'Prefix');
31
32my $dir = tempdir(CLEANUP => 1);
33
34{
35 local $SIG{__WARN__} = sub {};
36 ok($archive->extract('./TEST/BSP/8', $dir), 'Wrong path');
37};
38
39ok(-d catdir($dir, 'TEST'), 'Test corpus directory exists');
40ok(-f catdir($dir, 'TEST', 'header.xml'), 'Test corpus header exists');
41ok(-d catdir($dir, 'TEST', 'BSP'), 'Test doc directory exists');
42ok(-f catdir($dir, 'TEST', 'BSP', 'header.xml'), 'Test doc header exists');
43
44
Akronf3f0c942016-06-27 13:27:14 +020045# TODO: Test attaching!
Akron08385f62016-03-22 20:37:04 +010046
Akron150b29e2016-02-14 23:06:48 +010047done_testing;
48
49__END__