From df354d91e7e315b839d5c292e386e64ca339cb07 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 11 Sep 2015 15:32:51 +0100 Subject: 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. --- t/lib/Test/WebCoso.pm | 11 +++--- t/tests/deps.t | 48 +++++++++++++++++++++++++ t/tests/fileset.t | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ t/tests/page.t | 14 ++++---- 4 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 t/tests/deps.t create mode 100644 t/tests/fileset.t (limited to 't') 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(''); -%output = $wc.get-files('','document','html'); -dd %output; -dd %output.contents; -dd %output.contents; +$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' }, -- cgit v1.2.3