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