blob: 77026d7e71f58f6d58b472ca7a99f4a58f3a528e [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/;
Akrona3518372024-01-22 23:29:00 +01009use Test::Output qw/:stdout :stderr :functions/;
Akron150b29e2016-02-14 23:06:48 +010010
Nils Diewaldb3e9ccd2016-10-24 15:16:52 +020011use KorAP::XML::Archive;
Akron150b29e2016-02-14 23:06:48 +010012
13my $file = catfile(dirname(__FILE__), 'corpus','archive.zip');
14my $archive = KorAP::XML::Archive->new($file);
15
16unless ($archive->test_unzip) {
17 plan skip_all => 'unzip not found';
18};
19
20ok($archive->test, 'Test archive');
Akron08385f62016-03-22 20:37:04 +010021like($archive->path(0), qr/archive\.zip$/, 'Archive path');
Akron150b29e2016-02-14 23:06:48 +010022
Akron20807582016-10-26 17:11:34 +020023ok($archive->check_prefix, 'Archive has dot prefix');
24
Akron150b29e2016-02-14 23:06:48 +010025my @list = $archive->list_texts;
26is(scalar @list, 10, 'Found all tests');
27is($list[0], './TEST/BSP/1', 'First document');
Akrone8adfcc2016-03-22 13:18:26 +010028is($list[-1], './TEST/BSP/10', 'First document');
Akron150b29e2016-02-14 23:06:48 +010029
30my @path = $archive->split_path('./TEST/BSP/9');
31is($path[0],'.', 'Prefix');
32is($path[1],'TEST', 'Prefix');
33is($path[2],'BSP', 'Prefix');
34is($path[3],'9', 'Prefix');
35
36my $dir = tempdir(CLEANUP => 1);
37
38{
39 local $SIG{__WARN__} = sub {};
Akrona3518372024-01-22 23:29:00 +010040 my $stdout = stdout_from(
41 sub {
42 ok($archive->extract_sigle(0, ['TEST/BSP/8'], $dir), 'Wrong path');
43 }
44 );
45 like($stdout, qr!Extract unzip!);
Akron150b29e2016-02-14 23:06:48 +010046};
47
48ok(-d catdir($dir, 'TEST'), 'Test corpus directory exists');
49ok(-f catdir($dir, 'TEST', 'header.xml'), 'Test corpus header exists');
50ok(-d catdir($dir, 'TEST', 'BSP'), 'Test doc directory exists');
51ok(-f catdir($dir, 'TEST', 'BSP', 'header.xml'), 'Test doc header exists');
52
Akron20807582016-10-26 17:11:34 +020053$file = catfile(dirname(__FILE__), 'corpus','archive_rei.zip');
54$archive = KorAP::XML::Archive->new($file);
55ok(!$archive->check_prefix, 'Archive has no prefix');
56
Akron60a8caa2017-02-17 21:51:27 +010057# No leading '.'
58$file = catfile(dirname(__FILE__), 'corpus','archive_rei.zip');
59$archive = KorAP::XML::Archive->new($file);
60ok(!$archive->check_prefix, 'Archive has no dot prefix');
Akron08385f62016-03-22 20:37:04 +010061
Akron31a08cb2019-02-20 20:43:26 +010062my @cmd = map { join ' ', @{$_} } $archive->cmds_from_sigle(['REI/RB*', 'REI/BNG/00071']);
63
64like($cmd[0], qr!unzip -qo -uo t/corpus/archive_rei\.zip!);
65like($cmd[0], qr!\QREI/header.xml REI/RB*/header.xml REI/RB* REI/BNG/header.xml REI/BNG/00071/*\E!);
66ok(!$cmd[1]);
67
68# New temporary directory
69$dir = tempdir(CLEANUP => 1);
70
71{
72 local $SIG{__WARN__} = sub {};
Akrona3518372024-01-22 23:29:00 +010073 my $stdout = stdout_from(
74 sub {
75 ok($archive->extract_sigle(1, ['REI/RB*', 'REI/BNG/00071'], $dir), 'Fine');
76 }
77 );
78 is($stdout, '');
Akron31a08cb2019-02-20 20:43:26 +010079};
80
Akrona3518372024-01-22 23:29:00 +010081
Akron31a08cb2019-02-20 20:43:26 +010082ok(-d catdir($dir, 'REI'), 'Test corpus directory exists');
83ok(-d catdir($dir, 'REI','BNG'), 'Test corpus directory exists');
84ok(-d catdir($dir, 'REI','BNG','00071'), 'Test corpus directory exists');
85
86ok(-f catdir($dir, 'REI', 'header.xml'), 'Test corpus directory exists');
87ok(-f catdir($dir, 'REI','BNG', 'header.xml'), 'Test corpus directory exists');
88ok(-f catdir($dir, 'REI','BNG','00071', 'header.xml'), 'Test corpus directory exists');
89
90ok(-f catdir($dir, 'REI','RBR', 'header.xml'), 'Test corpus directory exists');
91ok(-f catdir($dir, 'REI','RBR','00610', 'header.xml'), 'Test corpus directory exists');
92ok(-f catdir($dir, 'REI','RBR','00610', 'header.xml'), 'Test corpus directory exists');
93
94ok(!-e catdir($dir, 'REI','BNG','00128'), 'Test corpus directory does not exist');
95
96
Akron150b29e2016-02-14 23:06:48 +010097done_testing;
98
99__END__