Class/Accessor/UnitTests/Array.pm

filter: Statementstmt 100% 98 / 98 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 27 / 27 Podpod 0.0% 0 / 10 totaltotal 92.2% 130 / 141 CC 5 SCAR 2.8
CC
5
Cov
99%
__ANON__
3.0
unset_value
2.0
compare_values_to_array
2.0
CRAP 1.3
« Class/Accessor/UnitTests/Hash.pm ↑ Summary Class/Accessor/UnitTests/Ref.pm »
1 #!/usr/bin/perl
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 {
5 package OOP::Perlish::Class::Accessor::UnitTests::Array;
6 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use OOP::Perlish::Class::Accessor::UnitTests::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use base 'OOP::Perlish::Class::Accessor::UnitTests::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use OOP::Perlish::Class::Accessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶ use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶ sub setup : Test(setup)
Subroutine setup: called CC=1 SCAR=0.0
Pod undocumented
15 {
16 6 my ($self) = @_;
17 6 $self->{accessor} = OOP::Perlish::Class::Accessor->new( type => 'ARRAY', name => 'test', self => bless( {}, __PACKAGE__ ) );
18 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 sub get_value
21 9 ▶ {
Subroutine get_value: called CC=1 SCAR=0.0
Pod undocumented
22 9 my ($self) = @_;
23  
24 9 my @values = $self->{accessor}->value();
25 9 return( @values );
26 }
27  
28 # Utility function to test positive/negative assignment for validators
29 # Adds 2 + N to your test count
30 sub use_validator(@)
31 4 ▶ {
Subroutine use_validator: called CC=1 SCAR=0.0
Pod undocumented
32 4 my ( $self, @values ) = @_;
33  
34 4 $self->{accessor}->value(@values);
35 4 $self->compare_values_to_array(@values);
36  
37 4 $self->{accessor}->value( 'invalid1', 'invalid2', 'invalid3' );
38 4 my @compare_values = $self->get_value();
39 4 is( scalar @compare_values, 0, 'we pass negative assertion of validation' );
40 }
41  
42 # Utility function for testing equality
43 # Adds 1 + N to test count
44 sub compare_values_to_array(@)
45 12 ▶ {
Subroutine compare_values_to_array: called CC=2 SCAR=6.9
Pod undocumented
46 12 my ( $self, @values ) = @_;
47  
48 12 my @test_values = $self->get_value();
49  
50 12 is( scalar @test_values, scalar @values, 'we pass positive assertion of validation' );
51 12 ▶ for(my $n=0; $n < scalar @values; $n++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < scalar @values) 36 12 48
52 36 is( $values[$n], $test_values[$n], "possitive assertion that \$test_values[$n] == \$values[$n]" );
53 }
54 }
55  
56 2 ▶ sub test_type_with_array(@) : Test(5)
Subroutine test_type_with_array: called CC=1 SCAR=0.0
Pod undocumented
57 {
58 2 my ($self) = @_;
59 2 my @values = ( 'foo', 'bar', 'baz', 'bup' );
60  
61 2 $self->{accessor}->value(@values);
62 2 $self->compare_values_to_array(@values);
63 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 2 ▶ sub test_type_with_arrayref(@) : Test(5)
Subroutine test_type_with_arrayref: called CC=1 SCAR=0.0
Pod undocumented
66 {
67 2 my ($self) = @_;
68 2 my @values = ( 'foo', 'bar', 'baz', 'bup');
69  
70 2 $self->{accessor}->value( \@values );
71 2 $self->compare_values_to_array(@values);
72 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 2 ▶ sub test_handling_of_references_to_other_types : Test(4)
Subroutine test_handling_of_references_to_other_types: called CC=1 SCAR=0.0
Pod undocumented
75 {
76 2 my ($self) = @_;
77 2 my @values = ( {'foo' => 'bar' } );
78  
79 2 $self->{accessor}->value( @values );
80 2 $self->compare_values_to_array( @values );
81
82 2 @values = ( \'foo' );
83 2 $self->{accessor}->value( @values );
84 2 $self->compare_values_to_array( @values );
85 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 2 ▶ sub test_setting_array_with_regex_validator(@) : Test(6)
Subroutine test_setting_array_with_regex_validator: called CC=1 SCAR=0.0
Pod undocumented
88 {
89 2 my ($self) = @_;
90 2 my @values = ( 'test1', 'test2', 'test3', 'test4' );
91  
92 2 $self->{accessor}->validator(qr/.*test.*/i);
93 2 $self->use_validator(@values);
94 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96 2 ▶ sub test_setting_array_with_sub_validator(@) : Test(6)
Subroutine test_setting_array_with_sub_validator: called CC=1 SCAR=0.0
Pod undocumented
97 {
98 2 my ($self) = @_;
99 2 my @values = ( 'test1', 'test2', 'test3', 'test4' );
100  
101 $self->{accessor}->validator(
102 8 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
103 8 my ( $self, @values ) = @_;
104 8 my @checked = ();
105 8 ▶ for( @values ) { return unless( $_ =~ m/^(.*test.*)$/ ); push(@checked, $1) }
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ /^(.*test.*)$/ 4 16 20
106 4 return @checked;
107 }
108 2 );
109 2 $self->use_validator(@values);
110 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 2 ▶ sub unset_value : Test
Subroutine unset_value: called CC=2 SCAR=7.1
Pod undocumented
113 {
114 2 my ($self) = @_;
115  
116 2 my @test = $self->get_value();
117 2 ▶ ok( ! @test, 'we get an empty list when nothing has been set' ) || diag( Dumper( [ @test ] ) );
Branch: 1 branch
BranchTrueFalseTotal
&ok(!@test, "we get an empty list when nothing has been set") or diag(Dumper([@test])) 2 0 2
118 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
119 }
120 1 1;
121 =head1 NAME
122  
123 =head1 VERSION
124  
125 =head1 SYNOPSIS
126  
127 =head1 METHODS
128  
129 =head1 AUTHOR
130  
131 Jamie Beverly, C<< <jbeverly at cpan.org> >>
132  
133 =head1 BUGS
134  
135 Please report any bugs or feature requests to C<bug-foo-bar at rt.cpan.org>,
136 or through
137 the web interface at
138 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=OOP-Perlish-Class>. I will be
139 notified, and then you'll
140 automatically be notified of progress on your bug as I make changes.
141  
142 =head1 SUPPORT
143  
144 You can find documentation for this module with the perldoc command.
145  
146 perldoc OOP::Perlish::Class
147  
148  
149 You can also look for information at:
150  
151 =over 4
152  
153 =item * RT: CPAN's request tracker
154  
155 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=OOP-Perlish-Class>
156  
157 =item * AnnoCPAN: Annotated CPAN documentation
158  
159 L<http://annocpan.org/dist/OOP-Perlish-Class>
160  
161 =item * CPAN Ratings
162  
163 L<http://cpanratings.perl.org/d/OOP-Perlish-Class>
164  
165 =item * Search CPAN
166  
167 L<http://search.cpan.org/dist/OOP-Perlish-Class/>
168  
169 =back
170  
171  
172 =head1 ACKNOWLEDGEMENTS
173  
174 =head1 COPYRIGHT & LICENSE
175  
176 Copyright 2009 Jamie Beverly
177  
178 This program is free software; you can redistribute it and/or modify it
179 under the terms of either: the GNU General Public License as published
180 by the Free Software Foundation; or the Artistic License.
181  
182 See http://dev.perl.org/licenses/ for more information.
183  
184 =cut
« Class/Accessor/UnitTests/Hash.pm ↑ Summary Class/Accessor/UnitTests/Ref.pm »