stringification.t 1.44 KB
Newer Older
Roy Storey's avatar
Roy Storey committed
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

use strict;
use warnings;

use lib 't/lib/';
use Test::More;
use Data::Dumper;

BEGIN {
    use_ok( 'Bio::EnsEMBL::Hive::Utils', 'stringify', 'destringify' );
}
#########################


my $structure = {
    'foo' => 'bar',
    'bar' => 'foobar'
};

my $struct_string = stringify $structure;
ok($struct_string, 'returned a value');
is($struct_string, q!{"bar" => "foobar","foo" => "bar"}!, 'correct representation');


$struct_string = stringify $structure;
ok($struct_string, 'returned a value');
is($struct_string, q!{"bar" => "foobar","foo" => "bar"}!, 'correct representation');

$structure = {
    foo => 'bar',
    latin => {
	lorem => {
	    ipsum => 'dolor',
	},
	atrium => 'foo bar',
    }
};

$Data::Dumper::Maxdepth = 1;
$struct_string = stringify $structure;
ok($structure, 'value returned');
is($struct_string, 
   q!{"foo" => "bar","latin" => {"atrium" => "foo bar","lorem" => {"ipsum" => "dolor"}}}!,
   'correct depth');

Matthieu Muffato's avatar
typo  
Matthieu Muffato committed
46
my $destructure = destringify $struct_string;
Roy Storey's avatar
Roy Storey committed
47
48
49
50
51
52
53
54
55
56
ok($destructure, 'recreated a hash');
isa_ok($destructure, 'HASH'); ## really is a hash
is($destructure->{'foo'}, 'bar', 'foo value correct');
is($destructure->{'latin'}{'lorem'}{'ipsum'}, 'dolor', 'latin test');

$destructure = destringify "[{ 'alpha' => 'beta' }, { 'gamma' => 'delta'}, {'omega' => undef}]";
isa_ok($destructure, 'ARRAY'); ## got an array
is($destructure->[0]{'alpha'}, 'beta', 'hash entry');
is($destructure->[2]{'omega'}, undef, 'undef values');

Roy Storey's avatar
Roy Storey committed
57
done_testing();