3 # Tests for PREPROCESSOR features
4 # These tests first appeared in version 1.25.
6 use Text::Template::Preprocess;
8 die "This is the test program for Text::Template::Preprocess version 1.46.
9 You are using version $Text::Template::Preprocess::VERSION instead.
10 That does not make sense.\n
12 unless $Text::Template::Preprocess::VERSION == 1.46;
19 my $py = sub { tr/x/y/ };
20 my $pz = sub { tr/x/z/ };
22 my $t = 'xxx The value of $x is {$x}';
23 my $outx = 'xxx The value of $x is 119';
24 my $outy = 'yyy The value of $y is 23';
25 my $outz = 'zzz The value of $z is 5';
26 open TF, "> $TMPFILE" or die "Couldn't open test file: $!; aborting";
30 @result = ($outx, $outy, $outz, $outz);
31 for my $trial (1, 0) {
32 for my $test (0 .. 3) {
35 $tmpl = new Text::Template::Preprocess
36 (TYPE => 'STRING', SOURCE => $t) or die;
38 open TF, "< $TMPFILE" or die "Couldn't open test file: $!; aborting";
39 $tmpl = new Text::Template::Preprocess
40 (TYPE => 'FILEHANDLE', SOURCE => \*TF) or die;
42 $tmpl->preprocessor($py) if ($test & 1) == 1;
43 my @args = ((($test & 2) == 2) ? (PREPROCESSOR => $pz) : ());
44 my $o = $tmpl->fill_in(@args,
45 HASH => {x => 119, 'y' => 23, z => 5});
46 # print STDERR "$o/$result[$test]\n";
47 print +(($o eq $result[$test]) ? '' : 'not '), "ok $n\n";