summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2015-09-11 15:32:51 +0100
committerdakkar <dakkar@thenautilus.net>2015-09-11 15:32:51 +0100
commitdf354d91e7e315b839d5c292e386e64ca339cb07 (patch)
tree476314347374acc122848a6d0202fb137aba225f /t
parentfix deps out-of-date comparison (diff)
downloadWebCoso-p6-df354d91e7e315b839d5c292e386e64ca339cb07.tar.gz
WebCoso-p6-df354d91e7e315b839d5c292e386e64ca339cb07.tar.bz2
WebCoso-p6-df354d91e7e315b839d5c292e386e64ca339cb07.zip
filesets! don't work
I think I'm trying to be too clever, merging "these files make up a document, a file per language" with "these files are needed to build a result file in a certain language". Those should probably be separate classes.
Diffstat (limited to 't')
-rw-r--r--t/lib/Test/WebCoso.pm11
-rw-r--r--t/tests/deps.t48
-rw-r--r--t/tests/fileset.t99
-rw-r--r--t/tests/page.t14
4 files changed, 159 insertions, 13 deletions
diff --git a/t/lib/Test/WebCoso.pm b/t/lib/Test/WebCoso.pm
index 566e4bc..c179e47 100644
--- a/t/lib/Test/WebCoso.pm
+++ b/t/lib/Test/WebCoso.pm
@@ -1,19 +1,20 @@
# -*- mode: perl6 -*-
unit module Test::WebCoso;
use Test;
+use WebCoso::FileSet;
-sub cmp-files($a,$b,$msg) is export {
+sub cmp-files(WebCoso::FileSet $a,$b,$msg) is export {
ok(
- ($a.defined and $b.defined and $a.keys eqv $b.keys and
+ ($a.defined and $b.defined and $a.langs eqv $b.keys and
[and] map {
my $cmp = $b{$_};
if $cmp ~~ Callable {
- $cmp.($a{$_})
+ $cmp.($a.for-lang($_))
}
else {
- $a{$_}.path.IO.abspath eq $cmp.IO.abspath
+ $a.for-lang($_).path.IO.abspath eq $cmp.IO.abspath
}
- }, $a.keys),
+ }, $a.langs),
$msg,
);
}
diff --git a/t/tests/deps.t b/t/tests/deps.t
new file mode 100644
index 0000000..2fde79b
--- /dev/null
+++ b/t/tests/deps.t
@@ -0,0 +1,48 @@
+# -*- mode: perl6 -*-
+use Test;
+use lib 't/lib';
+use Test::WebCoso;
+use File::Temp;
+use WebCoso;
+use WebCoso::FileSet;
+
+my $testdir = tempdir.IO;
+my $srcdir = $testdir.child('src');
+my $destdir = $testdir.child('dst');
+
+$srcdir.mkdir;
+$destdir.mkdir;
+
+my $wc = WebCoso.new(:$srcdir,:$destdir);
+$wc.save-deps(
+ 'foo','document','du.xml',
+ WebCoso::FileSet.new(files-hash=>{it=>['some.xsl']}),
+);
+
+my $no-deps = $wc.load-deps('bar','random','txt');
+ok($no-deps.files.elems == 0,
+ 'no deps is empty');
+
+my $deps = $wc.load-deps('foo','document','du.xml');
+cmp-files(
+ $deps,
+ { it => { $^x.path eq 'some.xsl' } },
+ 'deps round-tripped',
+);
+
+my @d;
+$no-deps.set-for-lang('x',@d);
+dd $no-deps;
+dd $no-deps.export-hash;
+$wc.save-deps('bar','random','txt',$no-deps);
+say $srcdir.child('deps.json').IO.slurp;
+my $empty-deps = $wc.load-deps('bar','random','txt');
+dd $empty-deps;
+cmp-files(
+ $deps,
+ { x=> {$^x.elems == 0} },
+ 'empty deps is empty',
+);
+
+
+done-testing;
diff --git a/t/tests/fileset.t b/t/tests/fileset.t
new file mode 100644
index 0000000..7723dc2
--- /dev/null
+++ b/t/tests/fileset.t
@@ -0,0 +1,99 @@
+# -*- mode: perl6 -*-
+use Test;
+use lib 't/lib';
+use Test::WebCoso;
+use File::Temp;
+use WebCoso::FileSet;
+
+my $testdir = tempdir.IO;
+
+$testdir.child('document.it.tt').spurt('it');
+$testdir.child('document.en.rest.txt').spurt('en');
+$testdir.child('du2xhtml.xsl').spurt('<>');
+
+subtest {
+ my $fs1 = WebCoso::FileSet.new(
+ basename=>'document',
+ ext=>'tt',
+ path=>$testdir,
+ );
+ cmp-files(
+ $fs1,
+ { it => { $^x.contents eq 'it' } },
+ 'simple ext works',
+ );
+
+ my $fs2 = WebCoso::FileSet.new(
+ basename=>'document',
+ ext=>'rest.txt',
+ path=>$testdir,
+ );
+ cmp-files(
+ $fs2,
+ { en => { $^x.contents eq 'en' } },
+ 'harder ext works',
+ );
+
+ my $fs3 = WebCoso::FileSet.new(
+ files => [$testdir.child('du2xhtml.xsl')],
+ );
+ cmp-files(
+ $fs3,
+ { '' => { $^x.contents eq '<>' } },
+ 'direct files works',
+ );
+
+ my $fs4 = WebCoso::FileSet.new(
+ files-hash => {
+ xml => $testdir.child('du2xhtml.xsl'),
+ it => $testdir.child('document.it.tt'),
+ }
+ );
+ cmp-files(
+ $fs4,
+ {
+ xml => { $^x.contents eq '<>' },
+ it => { $^x.contents eq 'it' },
+ },
+ 'files hash works',
+ );
+},'construction';
+
+subtest {
+ my $fs-merged = WebCoso::FileSet.new(
+ basename=>'document',
+ ext=>'tt',
+ path=>$testdir,
+ ).merged-with(WebCoso::FileSet.new(
+ basename=>'document',
+ ext=>'rest.txt',
+ path=>$testdir,
+ ));
+ cmp-files(
+ $fs-merged,
+ {
+ it => { $^x.contents eq 'it' },
+ en => { $^x.contents eq 'en' },
+ },
+ 'merging works',
+ );
+},'merging';
+
+subtest {
+ my $fs1 = WebCoso::FileSet.new(
+ basename=>'document',
+ ext=>'tt',
+ path=>$testdir,
+ );
+ $fs1.set-for-lang('en',$testdir.child('document.en.rest.txt'));
+ cmp-files(
+ $fs1,
+ {
+ it => { $^x.contents eq 'it' },
+ en => { $^x.contents eq 'en' },
+ },
+ 'set-for-lang works',
+ );
+},'set-for-lang';
+
+done-testing;
diff --git a/t/tests/page.t b/t/tests/page.t
index 62faf98..9cff6d7 100644
--- a/t/tests/page.t
+++ b/t/tests/page.t
@@ -20,11 +20,11 @@ my $wc = WebCoso.new(:$srcdir,:$destdir);
$wc.new-page('');
$wc.run();
-my %output = $wc.get-files('','document','html');
-dd %output;
+my $output = $wc.get-files('','document','html');
+dd $output;
cmp-files(
- %output,
+ $output,
{
it => { $^x.contents eq 'it expanded parsed converted (<>) decorated' },
en => { $^x.contents eq 'en parsed converted (<>) decorated' },
@@ -34,13 +34,11 @@ cmp-files(
$wc.get-file('','du2xhtml.xsl').contents('<new>');
-%output = $wc.get-files('','document','html');
-dd %output;
-dd %output<it>.contents;
-dd %output<en>.contents;
+$output = $wc.get-files('','document','html');
+dd $output;
cmp-files(
- %output,
+ $output,
{
it => { $^x.contents eq 'it expanded parsed converted (<new>) decorated' },
en => { $^x.contents eq 'en parsed converted (<new>) decorated' },