]> WPIA git - cassiopeia.git/blob - lib/openssl/external/perl/Text-Template-1.46/t/12-preprocess.t
upd: openssl to 1.1.0
[cassiopeia.git] / lib / openssl / external / perl / Text-Template-1.46 / t / 12-preprocess.t
1 #!perl
2 #
3 # Tests for PREPROCESSOR features
4 # These tests first appeared in version 1.25.
5
6 use Text::Template::Preprocess;
7
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
11 Aborting"
12   unless $Text::Template::Preprocess::VERSION == 1.46;
13
14 $TMPFILE = "tt$$";
15
16 print "1..8\n";
17 my $n = 1;
18
19 my $py = sub { tr/x/y/ };
20 my $pz = sub { tr/x/z/ };
21
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";
27 print TF $t;
28 close TF;
29
30 @result = ($outx, $outy, $outz, $outz);
31 for 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
52 unlink $TMPFILE;