Chemistry-Mol-0.35/t/Obj.t

filter: Statementstmt 100% 51 / 51 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 57 / 57 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Chemistry-Mol-0.35/t/Mol.t ↑ Summary Chemistry-Mol-0.35/t/add_implicit_h.t »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 #use Test::More "no_plan";
5 1 ▶use Test::More tests => 19;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use_ok('Chemistry::Obj');
Subroutine BEGIN: called CC=1 SCAR=0.0
9 };
10  
11 1 my ($obj, $obj2, $obj3);
12  
13 # constructor
14 1 $obj = Chemistry::Obj->new;
15 1 isa_ok( $obj, 'Chemistry::Obj', 'blank obj' );
16  
17 # obj using standard attributes
18 1 $obj = Chemistry::Obj->new(name => 'joe', id => 'joe01', type => 'funny');
19 1 is( $obj->name, 'joe', 'name' );
20 1 is( $obj->id, 'joe01', 'joe01' );
21 1 is( $obj->type, 'funny', 'type' );
22 1 is( "$obj", 'joe01', 'stringify' );
23  
24 # relational operators
25 1 $obj2 = Chemistry::Obj->new(name => 'joe', id => 'joe01', type => 'funny');
26 1 $obj3 = $obj;
27 1 is( $obj, $obj2, 'eq' );
28 1 ok( $obj != $obj2, '!=' );
29 1 ok( $obj == $obj3, '==' );
30  
31 1 $obj2->id('joe02');
32 1 ok( $obj ne $obj2, 'ne' );
33  
34 # user attributes
35 1 $obj->attr(color => 123);
36 1 is ($obj->attr('color'), 123, 'attr');
37  
38 # attr(list)
39 1 $obj->attr(1,2,3,4);
40 1 is ($obj->attr(3), 4, 'attr list');
41 1 is ($obj->attr('color'), 123, 'attr list');
42  
43 # attr(hashref)
44 1 $obj->attr({ a => 1, b => 2 });
45 1 is ($obj->attr('a'), 1, 'attr hashref');
46 1 is ($obj->attr('color'), undef, 'attr hashref');
47  
48 # attr()
49 1 my $attr = $obj->attr;
50 1 is ($attr->{b}, 2, 'attr get hashref');
51  
52 # del_attr
53 1 $obj->del_attr('b');
54 1 $attr = $obj->attr;
55 1 ok( ! exists $attr->{b}, 'del_attr');
56  
57 # accessor
58 package _test;
59 1 our @ISA = ('Chemistry::Obj');
60 1 Chemistry::Obj::accessor(qw(a b c d));
61  
62 package main;
63 1 $obj = _test->new(a => 1, b => 2);
64 1 is ($obj->a, 1, 'accessor');
65  
66 1 $obj->a(3)->c(4);
67 1 is ($obj->c, 4, 'chained accessor');
68  
69  
« Chemistry-Mol-0.35/t/Mol.t ↑ Summary Chemistry-Mol-0.35/t/add_implicit_h.t »