Add failing tests for auto_deref, where I'll pick up next time
[gitmo/Mouse.git] / t / 026-auto-deref.t
CommitLineData
615d5d5f 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More tests => 13;
5use Test::Exception;
6
7do {
8 package Class;
9 use Mouse;
10
11 has array => (
12 is => 'rw',
13 isa => 'ArrayRef',
14 auto_deref => 1,
15 );
16
17 has hash => (
18 is => 'rw',
19 isa => 'HashRef',
20 auto_deref => 1,
21 );
22};
23
24my $obj;
25lives_ok {
26 $obj = Class->new;
27} qr/auto_deref without defaults don't explode on new/;
28
29my ($array, @array, $hash, %hash);
30lives_ok {
31 @array = $obj->array;
32 %hash = $obj->hash;
33 $array = $obj->array;
34 $hash = $obj->hash;
35
36 $obj->array;
37 $obj->hash;
38} qr/auto_deref without default doesn't explode on get/;
39
40is($obj->array, undef, "array without value is undef in scalar context");
41is($obj->hash, undef, "hash without value is undef in scalar context");
42
43TODO: {
44 local $TODO = "auto_deref not implemented";
45 is(@array, 0, "array without value is empty in list context");
46 is(keys %hash, 0, "hash without value is empty in list context");
47};
48
49@array = $obj->array([1, 2, 3]);
50%hash = $obj->hash({foo => 1, bar => 2});
51
52TODO: {
53 local $TODO = "auto_deref not implemented";
54 is_deeply(\@array, [1, 2, 3], "setter returns the dereferenced list");
55 is_deeply(\%hash, {foo => 1, bar => 2}, "setter returns the dereferenced hash");
56};
57
58lives_ok {
59 @array = $obj->array;
60 %hash = $obj->hash;
61 $array = $obj->array;
62 $hash = $obj->hash;
63
64 $obj->array;
65 $obj->hash;
66} qr/auto_deref without default doesn't explode on get/;
67
68is_deeply($array, [1, 2, 3], "auto_deref in scalar context gives the reference");
69is_deeply($hash, {foo => 1, bar => 2}, "auto_deref in scalar context gives the reference");
70
71TODO: {
72 local $TODO = "auto_deref not implemented";
73 is_deeply(\@array, [1, 2, 3], "auto_deref in list context gives the list");
74 is_deeply(\%hash, {foo => 1, bar => 2}, "auto_deref in list context gives the hash");
75};
76