File: 010_class_trait.t

package info (click to toggle)
libclass-trait-perl 0.31-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 364 kB
  • ctags: 156
  • sloc: perl: 2,467; makefile: 46
file content (60 lines) | stat: -rwxr-xr-x 1,728 bytes parent folder | download | duplicates (4)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 22;

BEGIN {
    unshift @INC => ( 't/test_lib', '/test_lib' );
}

# we have to use it directly because it uses an INIT block to flatten traits
use BasicTrait;

can_ok( BasicTrait => 'getName' );
is( BasicTrait->getName(), 'TSimple',
    '... and it should have the method from the trait' );

ok( BasicTrait->does("TSimple"), '.. BasicTrait is TSimple' );

ok( exists( $BasicTrait::{"TRAITS"} ), '... the $TRAITS are properly stored' );

my $trait;
{
    no strict 'refs';

    # get the trait out
    $trait = ${"BasicTrait::TRAITS"};
}

# check to see what it is
isa_ok( $trait, 'Class::Trait::Config' );

# now examine the trait itself

can_ok( $trait, 'name' );
is( $trait->name, 'TSimple', '... get the traits name' );

can_ok( $trait, 'sub_traits' );
is( ref( $trait->sub_traits ), "ARRAY", '... our sub_trait is an array ref' );
ok( eq_array( $trait->sub_traits, [] ), '... both should be empty' );

can_ok( $trait, 'requirements' );
is( ref( $trait->requirements ), "HASH",
    '... our requirements is an hash ref' );
ok( eq_hash( $trait->requirements, {} ), '... both should be empty' );

can_ok( $trait, 'overloads' );
is( ref( $trait->overloads ), "HASH", '... our overloads is an hash ref' );
ok( eq_hash( $trait->overloads, {} ), '... both should be empty' );

can_ok( $trait, 'conflicts' );
is( ref( $trait->conflicts ), "HASH", '... our conflicts is an hash ref' );
ok( eq_hash( $trait->conflicts, {} ), '... both should be empty' );

can_ok( $trait, 'methods' );
is( ref( $trait->methods ), "HASH", '... our methods is an hash ref' );
ok( eq_hash( $trait->methods, { "getName" => 'TSimple::getName' } ),
    '... both should NOT be empty' );