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