blob: 22ad61f52d85a61f5e1b2bf01e1d3481a5ec3c1e [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');
19like($archive->path, qr/archive\.zip$/, 'Archive path');
20
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
45done_testing;
46
47__END__