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 61 62 63 64 65 66 67 68 69
|
#!/usr/bin/perl -w
# Test the custom attributes.
use Test::More;
use strict;
BEGIN
{
plan tests => (4*4+4) * 6 + (8+2) * 4 + 3;
chdir 't' if -d 't';
use lib '../lib';
use_ok ("Graph::Easy::Attributes") or die($@);
use_ok ("Graph::Easy") or die($@);
};
can_ok ("Graph::Easy", qw/
valid_attribute
/);
#############################################################################
# valid_attribute:
my $att = Graph::Easy->new();
$att->no_fatal_errors(1);
for my $n (qw/ foo-bar bar-foo b-f-a boo-f-bar bar b-f /)
{
my $new_value = $att->valid_attribute( "x-$n", 'furble, barble' );
is ($new_value, "furble, barble", "x-$n is valid");
my @new_value = $att->validate_attribute( "x-$n", 'furble, barble' );
is ($new_value[0], undef, "x-$n is valid");
is ($new_value[1], "x-$n", "x-$n is valid");
is ($new_value[2], "furble, barble", "x-$n is valid");
for my $class (qw/ graph group node edge /)
{
my $new_value = $att->valid_attribute( "x-$n", 'furble, barble', $class );
is ($new_value, "furble, barble", "x-$n is valid in class $class");
my @new_value = $att->validate_attribute( "x-$n", 'furble, barble', $class );
is ($new_value[0], undef, "x-$n is valid in class $class");
is ($new_value[1], "x-$n", "x-$n is valid");
is ($new_value[2], "furble, barble", "x-$n is valid in class $class");
}
}
for my $n (qw/ -foo-bar bar-foo- b--a -boo-f-bar- /)
{
my $new_value = $att->valid_attribute( "x-$n", 'furble, barble' );
is (ref($new_value), 'ARRAY', "x-$n is not valid");
my @new_value = $att->validate_attribute( "x-$n", 'furble, barble' );
is ($new_value[0], 1, "x-$n is not valid");
for my $class (qw/ graph group node edge /)
{
my $new_value = $att->valid_attribute( "x-$n", 'furble, barble', $class );
is (ref($new_value), 'ARRAY', "x-$n is not valid in class $class");
my @new_value = $att->validate_attribute( "x-$n", 'furble, barble', $class );
is ($new_value[0], 1, "x-$n is not valid in class $class");
}
}
1;
|