[go: up one dir, main page]

File: helper_hash.t

package info (click to toggle)
rex 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,800 kB
  • sloc: perl: 30,667; xml: 264; makefile: 8
file content (46 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;

use Test::More tests => 6;

use Rex::Helper::Hash;

my %h = (
  name => "FooBar",
  age  => 99,
  data => {
    foo  => "bar",
    blah => "fasel",
    more => {
      a => "eins",
      b => "zwei",
      c => "drei",
      d => {
        germany => "Berlin",
        france  => "Paris",
      },
    },
    emails => [
      'm@m.m', 'a@a.a',
      {
        n1 => "nested_1",
        n2 => "nested_2",
      },
      [ 'eins', 'zwei', 'drei', ],
    ],
  },
  blub => [qw/eins zwei drei/],

);

my $nh = {};
hash_flatten( \%h, $nh, "_" );

is( $nh->{"age"},                99,      "testing flattened hash" );
is( $nh->{"data_more_d_france"}, "Paris", "testing flattened hash - nested" );
is( $nh->{"blub_0"},             "eins",  "testing flattened array" );
is( $nh->{"data_emails_0"},      'm@m.m', "testing flattened array - nested" );
is( $nh->{"data_emails_1"}, 'a@a.a', "testing flattened array - nested (2)" );
is( $nh->{"data_emails_2_n1"},
  'nested_1', "testing flattened hash nested in array" );