File: 13-sub.t

package info (click to toggle)
libstring-interpolate-named-perl 1.06-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 148 kB
  • sloc: perl: 430; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 792 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! perl

use warnings;
use strict;
use Test::More;

my $tests = 0;

-d "t" && chdir("t");

use_ok('String::Interpolate::Named');
$tests++;

my $args = { title     => "Hi There!",
	     subtitle  => [ "%{capo|CAPO %{}}" ],
	     capo      => [ 1 ],
	     key	      => [ "G" ],
	     h	      => [ "Z" ],
	     head      => [ "yes" ],
	     customer  => [ "Smith", "Jones" ],
	   };

# Using callback.
my $s = { args => sub { $args->{$_[0]} } };

@ARGV = qw( 10-basic.dat );
foreach ( @ARGV ) {
    -s -r $_ ? pass("check $_") : BAIL_OUT("$_ [$!]");
    $tests++;
}

while ( <> ) {
    next if /^#/;
    next unless /\S/;
    chomp;

    my ( $tpl, $exp ) = split( /\t+/, $_ );
    my $res = interpolate( $s, $tpl );
    is( $res, $exp, "$tpl -> $exp" );

    $tests++;
}

done_testing($tests);