blob: 2ee7fabe8c8bb285320ff35f73e1547298a4055e [file] [log] [blame]
Akron85717512020-07-08 11:19:19 +02001use strict;
2use warnings;
3use Test::More;
Akron85717512020-07-08 11:19:19 +02004use File::Spec::Functions qw/catfile/;
Akron5fb5e8d2020-07-23 17:45:13 +02005use Test::KorAP::XML::TEI qw!korap_tempfile!;
Akron85717512020-07-08 11:19:19 +02006use IO::Uncompress::Unzip;
7
8use FindBin;
9BEGIN {
10 unshift @INC, "$FindBin::Bin/../lib";
11};
12
13require_ok('KorAP::XML::TEI::Zipper');
14
15my $data;
Akron5fb5e8d2020-07-23 17:45:13 +020016my ($fh, $outzip) = korap_tempfile('zipper');
Akron85717512020-07-08 11:19:19 +020017
18my $zip = KorAP::XML::TEI::Zipper->new($outzip);
Peter Harders57c884e2020-07-16 01:28:52 +020019$fh->close;
Akron85717512020-07-08 11:19:19 +020020
21ok($zip, 'Zipper initialized');
22
23ok($zip->new_stream('data/file1.txt')->print('hello'), 'Write to initial stream');
24ok($zip->new_stream('data/file2.txt')->print('world'), 'Write to appended stream');
25
26$zip->close;
27
28ok(-e $outzip, 'Zip exists');
29
30# Uncompress GOE/header.xml from zip file
31my $unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file1.txt');
32
33$data .= $unzip->getline while !$unzip->eof;
34ok($unzip->close, 'Closed');
35
36is($data, 'hello', 'Data correct');
37
38
39# Uncompress GOE/header.xml from zip file
40$unzip = IO::Uncompress::Unzip->new($outzip, Name => 'data/file2.txt');
41
42$data = '';
43$data .= $unzip->getline while !$unzip->eof;
44ok($unzip->close, 'Closed');
45
46is($data, 'world', 'Data correct');
47
48done_testing;