File: 02get-and-set.t

package info (click to toggle)
libhash-asobject-perl 0.13-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 239; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,071 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
#!/usr/bin/perl -w

use strict;
use warnings;

use Test::More 'tests' => 12;

use_ok( 'Hash::AsObject' );

my $h0 = {
    'one'   => 1,
    'two'   => 2,
    'three' => 3,
};

my ($h1, $h2, $h3, $h4, $h5);

$h1 = Hash::AsObject->new(          );
$h2 = Hash::AsObject->new( {      } );

$h3 = Hash::AsObject->new(   %$h0   );
$h4 = Hash::AsObject->new( { %$h0 } );
$h5 = Hash::AsObject->new(    $h0   );

is_deeply( $h1, {},  'empty'           );
is_deeply( $h2, $h1, 'empty and equal' );

@$h1{keys %$h0} = @$h2{keys %$h0} = values %$h0;

is_deeply( $h1, $h0, 'full'                     );
is_deeply( $h2, $h1, 'full and equal'           );
is_deeply( $h3, $h1, 'full and equal again'     );
is_deeply( $h4, $h1, 'full and equal yet again' );

my ($foo, $bar);

is( $h0->foo('foo'), 'foo', 'set scalar' );
is( $h0->foo,        'foo', 'get scalar' );

is_deeply( $h0->bar($h1), $h1, 'set hash' );
is_deeply( $h0->bar,      $h1, 'get hash' );

# --- Make sure invocations with more than one arg fail
eval { $h0->foo(1, 2) };
ok( $@ eq '', 'fail when more than one arg' );