File: 02string.t

package info (click to toggle)
libstring-expand-perl 0.04-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 112 kB
  • sloc: perl: 120; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 1,118 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w

use strict;

use Test::More tests => 7;
use Test::Exception;

use String::Expand qw(
   expand_string
);

my $s;

$s = expand_string( "hello world", {} );
is( $s, "hello world", 'Plain string' );

$s = expand_string( "value of \$FOO", { FOO => 'expansion' } );
is( $s, "value of expansion", 'String with $FOO' );

$s = expand_string( "All the leaves are \${A_LONG_VAR_NAME_HERE}", { A_LONG_VAR_NAME_HERE => "brown" } );
is( $s, "All the leaves are brown", 'String with $A_LONG_VAR_NAME_HERE' );

$s = expand_string( "Some \${delimited}_text", { delimited => "delimited" } );
is( $s, "Some delimited_text", 'String with ${delimited}_text' );

dies_ok( sub { expand_string( "\${someunknownvariable}", {} ) },
         'Undefined variable raises exception' );

$s = expand_string( "Some literal text \\\$here", {} );
is( $s, "Some literal text \$here", 'Variable with literal \$dollar' );

$s = expand_string( "This has \\\\literal \\\$escapes and \$EXPANSION", { EXPANSION => "text expansion" } );
is( $s, "This has \\literal \$escapes and text expansion", 'Variable with literals and expansions' );