-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NOTE: `cache => 1` has to behave the samy way to `cache => 0`
- Loading branch information
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!perl | ||
# https://github.com/xslate/p5-Text-Xslate/issues/95 | ||
use strict; | ||
use warnings; | ||
use Fatal qw(open close); | ||
use File::Path qw(remove_tree); | ||
use Test::More tests => 2; | ||
|
||
use Text::Xslate; | ||
|
||
# here's some test template files | ||
my $base_a = <<'EOF'; | ||
here is base A | ||
: block body -> {} | ||
EOF | ||
|
||
my $sub_a = <<'EOF'; | ||
: cascade base | ||
: override body { | ||
this is sub A | ||
: } | ||
EOF | ||
|
||
my $sub_b = <<'EOF'; | ||
: cascade base | ||
: override body { | ||
this is sub B | ||
: } | ||
EOF | ||
|
||
# remove old directories if they exist and re-create | ||
remove_tree('path_a', 'path_b'); | ||
END { remove_tree('path_a', 'path_b') } | ||
mkdir 'path_a'; | ||
mkdir 'path_b'; | ||
|
||
write_file('path_a/base.tx', $base_a); | ||
write_file('path_a/sub.tx', $sub_a); | ||
|
||
my $tx = Text::Xslate->new( | ||
path => ['path_b', 'path_a'], | ||
|
||
cache => 1, | ||
); | ||
|
||
my $out = $tx->render('sub.tx'); | ||
|
||
# expect both base and sub A since there is nothing in path B | ||
is($out, "here is base A\nthis is sub A\n", "cascade with base in same directory"); | ||
|
||
# now a new path_b sub file, and render again | ||
write_file('path_b/sub.tx', $sub_b); | ||
my $out2 = $tx->render('sub.tx'); | ||
|
||
# we should get the A base (since there is no B base) with the B sub (since that is first in path) | ||
{ local $TODO = 'not yet'; | ||
is($out2, "here is base A\nthis is sub B\n", "cascade with base in different directory"); | ||
} | ||
done_testing; | ||
|
||
sub write_file { | ||
my($path, $content) = @_; | ||
open my $fh, ">", $path; | ||
print $fh $content; | ||
close $fh; | ||
} |