add hash slices
[gitmo/Moose-Autobox.git] / t / 001_basic.t
index beb218c..18fecd6 100644 (file)
@@ -3,14 +3,15 @@
 use strict;
 use warnings;
 
-use Test::More tests => 55;
+use Test::More tests => 63;
 
 BEGIN {
     use_ok('Moose::Autobox');
-    use_ok('Moose::Autobox::Undef');
 }
 
-use autobox UNDEF => 'Moose::Autobox::Undef';
+use Moose::Autobox;
+
+my $VAR1; # for eval of dumps
 
 # SCALAR & UNDEF
 
@@ -20,6 +21,12 @@ ok(!$s->defined, '... got a undefined value');
 $s = 5;
 ok($s->defined, '... got a defined value');
 
+eval $s->dump;
+is($VAR1, 5 , '... eval of SCALAR->dump works');
+
+eval $s->perl;
+is($s->perl, $s->dump, '... SCALAR->dump equals SCALAR->perl');
+
 # CODE
 
 my $f1 = sub { @_ };
@@ -93,6 +100,12 @@ is_deeply($a, [ 4, 2, 6, 78, 101, 2 ], '... original value is now changed');
 is($a->shift(), 4, '... got the right unshift-ed value');
 is_deeply($a, [ 2, 6, 78, 101, 2 ], '... original value is now changed');
 
+
+is_deeply(
+$a->slice([ 1, 2, 4 ]), 
+[ 6, 78, 2 ], 
+'... got the right sliced value');
+
 is_deeply(
 $a->unshift(10), 
 [ 10, 2, 6, 78, 101, 2 ], 
@@ -169,6 +182,16 @@ $a,
 [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], 
 '... the value is correctly put');
 
+eval($a->dump);
+is_deeply( $VAR1,
+           [ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], 
+           '... the value is correctly dumped');
+
+is( $a->dump,
+    $a->perl,
+    '... the value is correctly dumped with perl()' );
+
+
 # Hash
 
 my $h = { one => 1, two => 2, three => 3 };
@@ -207,4 +230,20 @@ $h,
 { one => 1, two => 2, three => 3 },
 '... got the value deleted correctly');
 
+is_deeply(
+$h->merge({ three => 33, four => 44 }),
+{ one => 1, two => 2, three => 33, four => 44 },
+'... got the hashes merged correctly');
+
+eval($h->dump);
+is_deeply( $VAR1,
+           { one => 1, two => 2, three => 3 },
+           '... the value is correctly dumped');
+
+is( $h->dump,
+    $h->perl,
+    '... the value is correctly dumped with perl()' );
 
+is_deeply( { one => 1, two => 2, three => 3 }->slice([qw/three one/]),
+           [ qw/3 1/ ],
+           '... hash slices ok' );