1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#============================================================= -*-perl-*-
#
# t/prefix.t
#
# Test template prefixes within INCLUDE, etc., directives.
#
# Written by Andy Wardley <abw@kfs.org>
#
# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id$
#
#========================================================================
use strict;
use lib qw( ./lib ../lib );
use Template;
use Template::Test;
use Template::Config;
$^W = 1;
#$Template::Test::DEBUG = 0;
#$Template::Context::DEBUG = 0;
# script may be being run in distribution root or 't' directory
my $dir = -d 't' ? 't/test' : 'test';
my $src_prov = Template::Config->provider( INCLUDE_PATH => "$dir/src" );
my $lib_prov = Template::Config->provider( INCLUDE_PATH => "$dir/lib" );
my $config = {
LOAD_TEMPLATES => [ $src_prov, $lib_prov ],
PREFIX_MAP => {
src => '0',
lib => '1',
all => '0, 1',
},
};
test_expect(\*DATA, $config);
__DATA__
-- test --
[% INCLUDE foo a=10 %]
-- expect --
This is the foo file, a is 10
-- test --
[% INCLUDE src:foo a=20 %]
-- expect --
This is the foo file, a is 20
-- test --
[% INCLUDE all:foo a=30 %]
-- expect --
This is the foo file, a is 30
-- test --
[% TRY;
INCLUDE lib:foo a=30 ;
CATCH;
error;
END
%]
-- expect --
file error - lib:foo: not found
-- test --
[% INSERT src:foo %]
-- expect --
This is the foo file, a is [% a -%]
|