more tweaks, I think I want to make this into a role
[gitmo/MooseX-AttributeHelpers.git] / t / 002_basic_collection.t
CommitLineData
22d869ff 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7
8BEGIN {
9 use_ok('MooseX::AttributeHelpers');
10}
11
12{
13 package Stuff;
14 use Moose;
15
16 has 'options' => (
d26633fc 17 metaclass => 'Collection::Array',
22d869ff 18 is => 'ro',
19 isa => 'ArrayRef',
20 default => sub { [] },
21 provides => {
22 'push' => 'add_options',
23 'pop' => 'remove_last_option',
24 }
25 );
26}
27
28my $stuff = Stuff->new();
29isa_ok($stuff, 'Stuff');
30
31is_deeply($stuff->options, [], '... no options yet');
32
33$stuff->add_options(1, 2, 3);
34is_deeply($stuff->options, [1, 2, 3], '... got options now');
35
36$stuff->add_options(10, 15);
37is_deeply($stuff->options, [1, 2, 3, 10, 15], '... got more options now');
38
39is($stuff->remove_last_option, 15, '... removed the last option');
40
41is_deeply($stuff->options, [1, 2, 3, 10], '... got diff options now');
42
43
44