Skip to content

Commit

Permalink
* added tests for dynamic paths
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@436 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information
abw committed Jul 8, 2002
1 parent 653aeb2 commit fc832bb
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion t/provider.t
Expand Up @@ -39,6 +39,7 @@ my $factory = 'Template::Config';

# script may be being run in distribution root or 't' directory
my $dir = -d 't' ? 't/test/src' : 'test/src';
my $lib = -d 't' ? 't/test/lib' : 'test/lib';
my $file = 'foo';
my $relfile = "./$dir/$file";
my $absfile = abs_path($dir) . '/' . $file;
Expand Down Expand Up @@ -156,7 +157,45 @@ my $ttrel = Template->new( LOAD_TEMPLATES => [ $provrel ] )
ok( $ttrel );


my $uselist = [ ttinc => $ttinc, ttabs => $ttabs, ttrel => $ttrel ];
#------------------------------------------------------------------------
# here's a test of the dynamic path capability. we'll define a handler
# sub and an object to return a dynamic list of paths
#------------------------------------------------------------------------

package My::DPaths;

sub new {
my ($class, @paths) = @_;
bless \@paths, $class;
}
sub paths {
my $self = shift;
return [ @$self ];
}

package main;

sub dpaths {
return [ "$lib/one", "$lib/two" ],
}

my $dpaths = My::DPaths->new("$lib/two", "$lib/one");

my $ttd1 = Template->new({
INCLUDE_PATH => [ \&dpaths, $dir ],
PARSER => $parser,
}) || die "$Template::ERROR\n";
ok( $ttd1, 'dynamic path (sub) template object created' );

my $ttd2 = Template->new({
INCLUDE_PATH => [ $dpaths, $dir ],
PARSER => $parser,
}) || die "$Template::ERROR\n";
ok( $ttd1, 'dynamic path (obj) template object created' );


my $uselist = [ ttinc => $ttinc, ttabs => $ttabs, ttrel => $ttrel,
ttd1 => $ttd1, ttd2 => $ttd2 ];

test_expect(\*DATA, $uselist, $vars);

Expand Down Expand Up @@ -286,4 +325,26 @@ This is the old content
-- expect --
This is the new content
#------------------------------------------------------------------------
# dynamic path tests
#------------------------------------------------------------------------
-- test --
-- use ttd1 --
foo: [% PROCESS foo | trim +%]
bar: [% PROCESS bar | trim +%]
baz: [% PROCESS baz a='alpha' | trim %]
-- expect --
foo: This is one/foo
bar: This is two/bar
baz: This is the baz file, a: alpha
-- test --
-- use ttd2 --
foo: [% PROCESS foo | trim +%]
bar: [% PROCESS bar | trim +%]
baz: [% PROCESS baz a='alpha' | trim %]
-- expect --
foo: This is two/foo
bar: This is two/bar
baz: This is the baz file, a: alpha

0 comments on commit fc832bb

Please sign in to comment.