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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#============================================================= -*-perl-*-
#
# t/stop.t
#
# Test the [% STOP %] directive.
#
# Written by Andy Wardley <abw@kfs.org>
#
# Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved.
# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
#
# 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 ../blib/lib ../blib/arch ./blib/lib ./blib/arch );
use vars qw( $DEBUG );
use Template::Test;
use Template::Parser;
use Template::Exception;
#$Template::Parser::DEBUG = 1;
$DEBUG = 1;
my $ttblocks = {
header => sub { "This is the header\n" },
footer => sub { "This is the footer\n" },
halt1 => sub { die Template::Exception->new('stop', 'big error') },
};
my $ttvars = {
halt => sub { die Template::Exception->new('stop', 'big error') },
};
my $ttbare = Template->new(BLOCKS => $ttblocks);
my $ttwrap = Template->new({
PRE_PROCESS => 'header',
POST_PROCESS => 'footer',
BLOCKS => $ttblocks,
});
test_expect(\*DATA, [ bare => $ttbare, wrapped => $ttwrap ], $ttvars);
__END__
-- test --
This is some text
[% STOP %]
More text
-- expect --
This is some text
-- test --
This is some text
[% halt %]
More text
-- expect --
This is some text
-- test --
This is some text
[% INCLUDE halt1 %]
More text
-- expect --
This is some text
-- test --
This is some text
[% INCLUDE myblock1 %]
More text
[% BLOCK myblock1 -%]
This is myblock1
[% STOP %]
more of myblock1
[% END %]
-- expect --
This is some text
This is myblock1
-- test --
This is some text
[% INCLUDE myblock2 %]
More text
[% BLOCK myblock2 -%]
This is myblock2
[% halt %]
more of myblock2
[% END %]
-- expect --
This is some text
This is myblock2
#------------------------------------------------------------------------
# ensure 'stop' exceptions get ignored by TRY...END blocks
#------------------------------------------------------------------------
-- test --
before
[% TRY -%]
trying
[% STOP -%]
tried
[% CATCH -%]
caught [[% error.type %]] - [% error.info %]
[% END %]
after
-- expect --
before
trying
#------------------------------------------------------------------------
# ensure PRE_PROCESS and POST_PROCESS templates get added with STOP
#------------------------------------------------------------------------
-- test --
-- use wrapped --
This is some text
[% STOP %]
More text
-- expect --
This is the header
This is some text
This is the footer
|