File: v2_09_coerce.t

package info (click to toggle)
libparse-plainconfig-perl 3.07-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 360 kB
  • sloc: perl: 1,916; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,182 bytes parent folder | download | duplicates (5)
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
45
46
47
48
49
# 09_coerce.t
#
# Tests coerce method

use Parse::PlainConfig::Legacy;

$|++;
print "1..5\n";

my $test   = 1;
my $rcfile = './t/v2_testrc_smart';
my $conf   = Parse::PlainConfig::Legacy->new(
  FILE          => $rcfile,
  SMART_PARSER  => 1,
  COERCE        => {
      'SCALAR 2'  => 'string',
      'LIST 3'    => 'list',
      },
  );
$conf->read;
my %hash;

# 1 scalar 2
$conf->parameter("SCALAR 2") eq '"these, are, all one => value"' ? 
  print "ok $test\n" : print "not ok $test\n";
$test++;

# 2 list 3
($conf->parameter("LIST 3"))[2] eq "two => parts" ? print "ok $test\n" : 
  print "not ok $test\n";
$test++;

# 3 coerce list 1 into string
$conf->coerce('string', 'LIST 1');
$conf->parameter("LIST 1") eq "value1 , value2 , value3" ? 
  print "ok $test\n" : print "not ok $test\n";
$test++;

# 4 .. 5 coerce scalar 2 into a hash
$conf->parameter('SCALAR 2', 
  ($conf->parameter('SCALAR 2') =~ /^"(.*)"$/)[0]);
$conf->coerce('hash', 'SCALAR 2');
%hash = ( $conf->parameter('SCALAR 2') );
$hash{"these"} eq 'are' ? print "ok $test\n" : print "not ok $test\n";
$test++;
$hash{"all one"} eq 'value' ? print "ok $test\n" : print "not ok $test\n";
$test++;

# end 09_coerce.t