summaryrefslogtreecommitdiffstats
path: root/external/perl/Text-Template-1.56/t/broken.t
blob: 40e7b74650294fe3a1694f720647f31ecb32b7b8 (plain)
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
#!perl
# test apparatus for Text::Template module

use strict;
use warnings;
use Test::More tests => 7;

use_ok 'Text::Template' or exit 1;

# (1) basic error delivery
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',)->fill_in();
    is $r, q{Program fragment delivered error ``Illegal division by zero at template line 1.''};
}

# (2) BROKEN sub called in ->new?
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',
        BROKEN => sub { '---' },)->fill_in();
    is $r, q{---};
}

# (3) BROKEN sub called in ->fill_in?
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',)->fill_in(BROKEN => sub { '---' });
    is $r, q{---};
}

# (4) BROKEN sub passed correct args when called in ->new?
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',
        BROKEN => sub {
            my %a = @_;
            qq{$a{lineno},$a{error},$a{text}};
        },)->fill_in();
    is $r, qq{1,Illegal division by zero at template line 1.\n,1/0};
}

# (5) BROKEN sub passed correct args when called in ->fill_in?
{
    my $r = Text::Template->new(
        TYPE   => 'string',
        SOURCE => '{1/0}',
        )->fill_in(
        BROKEN => sub {
            my %a = @_;
            qq{$a{lineno},$a{error},$a{text}};
        });
    is $r, qq{1,Illegal division by zero at template line 1.\n,1/0};
}

# BROKEN sub handles undef
{
    my $r = Text::Template->new(TYPE => 'string', SOURCE => 'abc{1/0}defg')
        ->fill_in(BROKEN => sub { undef });

    is $r, 'abc';
}