remove useless use_ok tests
[gitmo/Moose.git] / t / 070_attribute_helpers / 206_trait_bag.t
CommitLineData
e3c07b19 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a5209c26 6use Test::More tests => 19;
e3c07b19 7use Test::Exception;
8use Test::Moose 'does_ok';
9
e3c07b19 10{
d50fc84a 11
e3c07b19 12 package Stuff;
13 use Moose;
a41de825 14 use Moose::AttributeHelpers;
e3c07b19 15
16 has 'word_histogram' => (
d50fc84a 17 traits => ['Collection::Bag'],
18 is => 'ro',
19 handles => {
20 'add_word' => 'add',
21 'get_count_for' => 'get',
22 'has_any_words' => 'empty',
23 'num_words' => 'count',
24 'delete_word' => 'delete',
e3c07b19 25 }
26 );
27}
28
29my $stuff = Stuff->new();
d50fc84a 30isa_ok( $stuff, 'Stuff' );
e3c07b19 31
d50fc84a 32can_ok( $stuff, $_ ) for qw[
e3c07b19 33 add_word
34 get_count_for
35 has_any_words
36 num_words
37 delete_word
38];
39
d50fc84a 40ok( !$stuff->has_any_words, '... we have no words' );
41is( $stuff->num_words, 0, '... we have no words' );
e3c07b19 42
43lives_ok {
44 $stuff->add_word('bar');
d50fc84a 45}
46'... set the words okay';
e3c07b19 47
d50fc84a 48ok( $stuff->has_any_words, '... we have words' );
49is( $stuff->num_words, 1, '... we have 1 word(s)' );
50is( $stuff->get_count_for('bar'), 1, '... got words now' );
e3c07b19 51
52lives_ok {
53 $stuff->add_word('foo');
54 $stuff->add_word('bar') for 0 .. 3;
55 $stuff->add_word('baz') for 0 .. 10;
d50fc84a 56}
57'... set the words okay';
e3c07b19 58
d50fc84a 59is( $stuff->num_words, 3, '... we still have 1 word(s)' );
60is( $stuff->get_count_for('foo'), 1, '... got words now' );
61is( $stuff->get_count_for('bar'), 5, '... got words now' );
62is( $stuff->get_count_for('baz'), 11, '... got words now' );
e3c07b19 63
64## test the meta
65
66my $words = $stuff->meta->get_attribute('word_histogram');
d50fc84a 67does_ok( $words, 'Moose::AttributeHelpers::Trait::Collection::Bag' );
68
69is_deeply(
70 $words->handles,
71 {
72 'add_word' => 'add',
73 'get_count_for' => 'get',
74 'has_any_words' => 'empty',
75 'num_words' => 'count',
76 'delete_word' => 'delete',
77 },
78 '... got the right handles mapping'
79);
e3c07b19 80