#! /usr/bin/env perl # -*- perl -*-
my
$with_include
=
<<EOF;
[%- USE q = Qgoda -%]
[%- q.include('_includes/other.md', asset, extra => '04') -%]
EOF
my
$no_extra
=
<<EOF;
[%- USE q = Qgoda -%]
[%- q.include('_includes/other.md', asset) -%]
EOF
my
$include
=
<<EOF;
included [% asset.overlay %][% asset.extra %]
EOF
my
$no_path
=
<<EOF;
[% USE q = Qgoda %]
before
[% q.include %]
after
EOF
my
$no_overlay
=
<<EOF;
[% USE q = Qgoda %]
before
[% q.include('_includes/other.md') %]
after
EOF
my
$not_existing
=
<<EOF;
[% USE q = Qgoda %]
before
[% q.include('_includes/not/there.md', asset, extra = '1234') %]
after
EOF
my
$include_invalid_template
=
<<EOF;
[% USE q = Qgoda %]
[%- q.include('_includes/invalid.md', asset, extra => '04') -%]
EOF
my
$invalid_include
=
<<EOF;
[% USE q = Qgoda %]
[% q.list('foo', 'bar', 'baz') %]
EOF
my
$site
= TestSite->new(
name
=>
'tpq-include'
,
assets
=> {
'with-include.md'
=> {
content
=>
$with_include
,
overlay
=> 23},
'no-extra.md'
=> {
content
=>
$no_extra
},
'no-path.md'
=> {
content
=>
$no_path
},
'no-overlay.md'
=> {
content
=>
$no_overlay
},
'not-there.md'
=> {
content
=>
$not_existing
},
'invalid.md'
=> {
content
=>
$include_invalid_template
},
'_includes/other.md'
=> {
content
=>
$include
},
'_includes/invalid.md'
=> {
content
=>
$invalid_include
},
},
files
=> {
'_views/default.html'
=>
"[% asset.content %]"
,
}
);
open
my
$olderr
,
'>&STDERR'
or
die
"cannot dup stderr: $!"
;
close
STDERR;
ok(Qgoda::CLI->new([
'build'
])->dispatch);
open
STDERR,
'>&'
,
$olderr
;
ok -e
'_site/with-include/index.html'
;
is ((read_file
'_site/with-include/index.html'
),
'<p>included 2304</p>'
,
'include'
);
ok -e
'_site/no-extra/index.html'
;
is ((read_file
'_site/no-extra/index.html'
),
'<p>included</p>'
,
'include'
);
my
$invalid
=
qr/^\[\% '' \%\]/
;
ok -e
'_site/no-path/index.html'
;
like ((read_file
'_site/no-path/index.html'
),
$invalid
,
'no path'
);
ok -e
'_site/no-overlay/index.html'
;
like ((read_file
'_site/no-overlay/index.html'
),
$invalid
,
'no overlay'
);
ok -e
'_site/not-there/index.html'
;
like ((read_file
'_site/not-there/index.html'
),
$invalid
,
'not found'
);
ok -e
'_site/invalid/index.html'
;
like ((read_file
'_site/invalid/index.html'
),
$invalid
,
'invalid include'
);
$site
->tearDown;
done_testing;