1#!perl
2# test apparatus for Text::Template module
3
4use strict;
5use warnings;
6use Test::More tests => 7;
7
8use_ok 'Text::Template' or exit 1;
9
10# (1) basic error delivery
11{
12    my $r = Text::Template->new(
13        TYPE   => 'string',
14        SOURCE => '{1/0}',)->fill_in();
15    is $r, q{Program fragment delivered error ``Illegal division by zero at template line 1.''};
16}
17
18# (2) BROKEN sub called in ->new?
19{
20    my $r = Text::Template->new(
21        TYPE   => 'string',
22        SOURCE => '{1/0}',
23        BROKEN => sub { '---' },)->fill_in();
24    is $r, q{---};
25}
26
27# (3) BROKEN sub called in ->fill_in?
28{
29    my $r = Text::Template->new(
30        TYPE   => 'string',
31        SOURCE => '{1/0}',)->fill_in(BROKEN => sub { '---' });
32    is $r, q{---};
33}
34
35# (4) BROKEN sub passed correct args when called in ->new?
36{
37    my $r = Text::Template->new(
38        TYPE   => 'string',
39        SOURCE => '{1/0}',
40        BROKEN => sub {
41            my %a = @_;
42            qq{$a{lineno},$a{error},$a{text}};
43        },)->fill_in();
44    is $r, qq{1,Illegal division by zero at template line 1.\n,1/0};
45}
46
47# (5) BROKEN sub passed correct args when called in ->fill_in?
48{
49    my $r = Text::Template->new(
50        TYPE   => 'string',
51        SOURCE => '{1/0}',
52        )->fill_in(
53        BROKEN => sub {
54            my %a = @_;
55            qq{$a{lineno},$a{error},$a{text}};
56        });
57    is $r, qq{1,Illegal division by zero at template line 1.\n,1/0};
58}
59
60# BROKEN sub handles undef
61{
62    my $r = Text::Template->new(TYPE => 'string', SOURCE => 'abc{1/0}defg')
63        ->fill_in(BROKEN => sub { undef });
64
65    is $r, 'abc';
66}
67