blob: 71bedceec3716de0897e1892114f98e0b671a15b [file] [log] [blame]
Akron150b29e2016-02-14 23:06:48 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
Akron31a08cb2019-02-20 20:43:26 +01004use Data::Dumper;
Akron150b29e2016-02-14 23:06:48 +01005use Test::More;
6use File::Basename 'dirname';
7use File::Spec::Functions qw/catfile catdir/;
8use File::Temp qw/tempdir/;
9
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020010use KorAP::XML::Archive;
Akron150b29e2016-02-14 23:06:48 +010011
12my $file = catfile(dirname(__FILE__), 'corpus','archive.zip');
13my $archive = KorAP::XML::Archive->new($file);
14
15unless ($archive->test_unzip) {
16 plan skip_all => 'unzip not found';
17};
18
19ok($archive->test, 'Test archive');
Akron08385f62016-03-22 20:37:04 +010020like($archive->path(0), qr/archive\.zip$/, 'Archive path');
Akron150b29e2016-02-14 23:06:48 +010021
Akron20807582016-10-26 17:11:34 +020022ok($archive->check_prefix, 'Archive has dot prefix');
23
Akron150b29e2016-02-14 23:06:48 +010024my @list = $archive->list_texts;
25is(scalar @list, 10, 'Found all tests');
26is($list[0], './TEST/BSP/1', 'First document');
Akrone8adfcc2016-03-22 13:18:26 +010027is($list[-1], './TEST/BSP/10', 'First document');
Akron150b29e2016-02-14 23:06:48 +010028
29my @path = $archive->split_path('./TEST/BSP/9');
30is($path[0],'.', 'Prefix');
31is($path[1],'TEST', 'Prefix');
32is($path[2],'BSP', 'Prefix');
33is($path[3],'9', 'Prefix');
34
35my $dir = tempdir(CLEANUP => 1);
36
37{
38 local $SIG{__WARN__} = sub {};
Akron955b75b2019-02-21 14:28:41 +010039 ok($archive->extract_sigle(['TEST/BSP/8'], $dir), 'Wrong path');
Akron150b29e2016-02-14 23:06:48 +010040};
41
42ok(-d catdir($dir, 'TEST'), 'Test corpus directory exists');
43ok(-f catdir($dir, 'TEST', 'header.xml'), 'Test corpus header exists');
44ok(-d catdir($dir, 'TEST', 'BSP'), 'Test doc directory exists');
45ok(-f catdir($dir, 'TEST', 'BSP', 'header.xml'), 'Test doc header exists');
46
Akron20807582016-10-26 17:11:34 +020047$file = catfile(dirname(__FILE__), 'corpus','archive_rei.zip');
48$archive = KorAP::XML::Archive->new($file);
49ok(!$archive->check_prefix, 'Archive has no prefix');
50
Akron60a8caa2017-02-17 21:51:27 +010051# No leading '.'
52$file = catfile(dirname(__FILE__), 'corpus','archive_rei.zip');
53$archive = KorAP::XML::Archive->new($file);
54ok(!$archive->check_prefix, 'Archive has no dot prefix');
Akron08385f62016-03-22 20:37:04 +010055
Akron31a08cb2019-02-20 20:43:26 +010056my @cmd = map { join ' ', @{$_} } $archive->cmds_from_sigle(['REI/RB*', 'REI/BNG/00071']);
57
58like($cmd[0], qr!unzip -qo -uo t/corpus/archive_rei\.zip!);
59like($cmd[0], qr!\QREI/header.xml REI/RB*/header.xml REI/RB* REI/BNG/header.xml REI/BNG/00071/*\E!);
60ok(!$cmd[1]);
61
62# New temporary directory
63$dir = tempdir(CLEANUP => 1);
64
65{
66 local $SIG{__WARN__} = sub {};
67 ok($archive->extract_sigle(['REI/RB*', 'REI/BNG/00071'], $dir), 'Fine');
68};
69
70ok(-d catdir($dir, 'REI'), 'Test corpus directory exists');
71ok(-d catdir($dir, 'REI','BNG'), 'Test corpus directory exists');
72ok(-d catdir($dir, 'REI','BNG','00071'), 'Test corpus directory exists');
73
74ok(-f catdir($dir, 'REI', 'header.xml'), 'Test corpus directory exists');
75ok(-f catdir($dir, 'REI','BNG', 'header.xml'), 'Test corpus directory exists');
76ok(-f catdir($dir, 'REI','BNG','00071', 'header.xml'), 'Test corpus directory exists');
77
78ok(-f catdir($dir, 'REI','RBR', 'header.xml'), 'Test corpus directory exists');
79ok(-f catdir($dir, 'REI','RBR','00610', 'header.xml'), 'Test corpus directory exists');
80ok(-f catdir($dir, 'REI','RBR','00610', 'header.xml'), 'Test corpus directory exists');
81
82ok(!-e catdir($dir, 'REI','BNG','00128'), 'Test corpus directory does not exist');
83
84
Akron150b29e2016-02-14 23:06:48 +010085done_testing;
86
87__END__