3 # Tests for user-specified delimiter functions
4 # These tests first appeared in version 1.20.
8 die "This is the test program for Text::Template version 1.46.
9 You are using version $Text::Template::VERSION instead.
10 That does not make sense.\n
12 unless $Text::Template::VERSION == 1.46;
17 # (1) Try a simple delimiter: <<..>>
18 # First with the delimiters specified at object creation time
20 $template = q{The value of $V is <<$V>>.};
21 $result = q{The value of $V is 119.};
22 $template1 = Text::Template->new(TYPE => STRING,
24 DELIMITERS => ['<<', '>>']
26 or die "Couldn't construct template object: $Text::Template::ERROR; aborting";
27 $text = $template1->fill_in();
28 print +($text eq $result ? '' : 'not '), "ok $n\n";
31 # (2) Now with delimiter choice deferred until fill-in time.
32 $template1 = Text::Template->new(TYPE => STRING, SOURCE => $template);
33 $text = $template1->fill_in(DELIMITERS => ['<<', '>>']);
34 print +($text eq $result ? '' : 'not '), "ok $n\n";
37 # (3) Now we'll try using regex metacharacters
38 # First with the delimiters specified at object creation time
39 $template = q{The value of $V is [$V].};
40 $template1 = Text::Template->new(TYPE => STRING,
42 DELIMITERS => ['[', ']']
44 or die "Couldn't construct template object: $Text::Template::ERROR; aborting";
45 $text = $template1->fill_in();
46 print +($text eq $result ? '' : 'not '), "ok $n\n";
49 # (4) Now with delimiter choice deferred until fill-in time.
50 $template1 = Text::Template->new(TYPE => STRING, SOURCE => $template);
51 $text = $template1->fill_in(DELIMITERS => ['[', ']']);
52 print +($text eq $result ? '' : 'not '), "ok $n\n";
57 # (5-18) Make sure \ is working properly
58 # (That is to say, it is ignored.)
59 # These tests are similar to those in 01-basic.t.
60 my @tests = ('{""}' => '', # (5)
62 # Backslashes don't matter
64 '{"\\}"}' => undef, # One backslash
65 '{"\\\\}"}' => undef, # Two backslashes
66 '{"\\\\\\}"}' => undef, # Three backslashes
67 '{"\\\\\\\\}"}' => undef, # Four backslashes (10)
68 '{"\\\\\\\\\\}"}' => undef, # Five backslashes
70 # Backslashes are always passed directly to Perl
72 '{"\\x20"}' => ' ', # One backslash
73 '{"\\\\x20"}' => '\\x20', # Two backslashes
74 '{"\\\\\\x20"}' => '\\ ', # Three backslashes (15)
75 '{"\\\\\\\\x20"}' => '\\\\x20', # Four backslashes
76 '{"\\\\\\\\\\x20"}' => '\\\\ ', # Five backslashes
77 '{"\\x20\\}"}' => undef, # (18)
81 for ($i=0; $i<@tests; $i+=2) {
82 my $tmpl = Text::Template->new(TYPE => 'STRING',
84 DELIMITERS => ['{', '}'],
86 my $text = $tmpl->fill_in;
87 my $result = $tests[$i+1];
88 my $ok = (! defined $text && ! defined $result
91 print STDERR "($n) expected .$result., got .$text.\n";
93 print +($ok ? '' : 'not '), "ok $n\n";