use Test;
use File::Temp;
use WebCoso;
sub cmp-files($a,$b,$msg) {
ok(
($a.defined and $b.defined and $a.keys eqv $b.keys and
[and] map {
my $cmp = $b{$_};
if $cmp ~~ Callable {
$cmp.($a{$_})
}
else {
$a{$_}.abspath eq $cmp.abspath
}
}, $a.keys),
$msg,
);
}
my $testdir = tempdir.IO;
my $srcdir = $testdir.child('src');
my $destdir = $testdir.child('dst');
my $one = $srcdir.child('one');
$one.mkdir;
$destdir.mkdir;
$one.child('document.it.txt').spurt('foo');
$one.child('document.en.txt').spurt('foo');
my $wc = WebCoso.new(:$srcdir,:$destdir);
subtest {
my %one = $wc.get-files('one','document','txt');
cmp-files(
%one,
{
it => $one.child('document.it.txt'),
en => $one.child('document.en.txt'),
},
'get-files works',
);
}, 'getting files';
subtest {
$wc.put-file('two','document','en','txt',
'something');
my %two = $wc.get-files('two','document','txt');
cmp-files(
%two,
{
en => { $^f.abspath ~~ /two\/document\.en\.txt$/ },
},
'put-file works',
);
}, 'putting files';
done-testing;