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