VirtualBox

source: vbox/trunk/src/libs/openssl-3.1.7/external/perl/Text-Template-1.56/t/preprocess.t@ 107406

Last change on this file since 107406 was 104078, checked in by vboxsync, 11 months ago

openssl-3.1.5: Applied and adjusted our OpenSSL changes to 3.1.4. bugref:10638

File size: 1.3 KB
Line 
1#!perl
2#
3# Tests for PREPROCESSOR features
4# These tests first appeared in version 1.25.
5
6use strict;
7use warnings;
8use Test::More tests => 9;
9use File::Temp;
10
11use_ok 'Text::Template::Preprocess' or exit 1;
12
13my $tmpfile = File::Temp->new;
14my $TMPFILE = $tmpfile->filename;
15
16my $py = sub { tr/x/y/ };
17my $pz = sub { tr/x/z/ };
18
19my $t = 'xxx The value of $x is {$x}';
20my $outx = 'xxx The value of $x is 119';
21my $outy = 'yyy The value of $y is 23';
22my $outz = 'zzz The value of $z is 5';
23open my $tfh, '>', $TMPFILE or die "Couldn't open test file: $!; aborting";
24print $tfh $t;
25close $tfh;
26
27my @result = ($outx, $outy, $outz, $outz);
28for my $trial (1, 0) {
29 for my $test (0 .. 3) {
30 my $tmpl;
31 if ($trial == 0) {
32 $tmpl = Text::Template::Preprocess->new(TYPE => 'STRING', SOURCE => $t) or die;
33 }
34 else {
35 open $tfh, '<', $TMPFILE or die "Couldn't open test file: $!; aborting";
36 $tmpl = Text::Template::Preprocess->new(TYPE => 'FILEHANDLE', SOURCE => $tfh) or die;
37 }
38 $tmpl->preprocessor($py) if ($test & 1) == 1;
39 my @args = ((($test & 2) == 2) ? (PREPROCESSOR => $pz) : ());
40 my $o = $tmpl->fill_in(@args, HASH => { x => 119, 'y' => 23, z => 5 });
41 is $o, $result[$test];
42 }
43}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette