1#!perl
2#
3# Tests for PREPROCESSOR features
4# These tests first appeared in version 1.25.
5
6use Text::Template::Preprocess;
7
8die "This is the test program for Text::Template::Preprocess version 1.46.
9You are using version $Text::Template::Preprocess::VERSION instead.
10That does not make sense.\n
11Aborting"
12  unless $Text::Template::Preprocess::VERSION == 1.46;
13
14$TMPFILE = "tt$$";
15
16print "1..8\n";
17my $n = 1;
18
19my $py = sub { tr/x/y/ };
20my $pz = sub { tr/x/z/ };
21
22my $t = 'xxx The value of $x is {$x}';
23my $outx = 'xxx The value of $x is 119';
24my $outy = 'yyy The value of $y is 23';
25my $outz = 'zzz The value of $z is 5';
26open TF, "> $TMPFILE" or die "Couldn't open test file: $!; aborting";
27print TF $t;
28close TF;
29
30@result = ($outx, $outy, $outz, $outz);
31for my $trial (1, 0) {
32  for my $test (0 .. 3) {
33    my $tmpl;
34    if ($trial == 0) {
35      $tmpl = new Text::Template::Preprocess 
36	(TYPE => 'STRING', SOURCE => $t) or die;
37    } else {
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;
41    }
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";
48    $n++;
49  }
50}
51
52unlink $TMPFILE;
53