6 use Test::More tests => 21;
7 use Test::Moose 'does_ok';
10 use_ok('Moose::AttributeHelpers');
19 traits => [qw/String/],
22 default => sub { '' },
25 append_string => 'append',
26 prepend_string => 'prepend',
27 match_string => 'match',
28 replace_string => 'replace',
29 chop_string => 'chop',
30 chomp_string => 'chomp',
31 clear_string => 'clear',
32 exclaim => [ append => [ '!' ] ],
33 capitalize_last => [ replace => [ qr/(.)$/, $uc = sub { uc $1 } ] ],
34 invalid_number => [ match => [ qr/\D/ ] ],
39 my $page = MyHomePage->new();
40 isa_ok($page, 'MyHomePage');
42 is($page->string, '', '... got the default value');
47 is($page->string, 'b', '... got the incremented value');
50 is($page->string, 'c', '... got the incremented value (again)');
52 $page->append_string("foo$/");
53 is($page->string, "cfoo$/", 'appended to string');
56 is($page->string, "cfoo", 'chomped string');
59 is($page->string, "cfoo", 'chomped is noop');
62 is($page->string, "cfo", 'chopped string');
64 $page->prepend_string("bar");
65 is($page->string, 'barcfo', 'prepended to string');
67 is_deeply( [ $page->match_string(qr/([ao])/) ], [ "a" ], "match" );
69 $page->replace_string(qr/([ao])/, sub { uc($1) });
70 is($page->string, 'bArcfo', "substitution");
73 is($page->string, 'bArcfo!', 'exclaim!');
75 $page->string('Moosex');
76 $page->capitalize_last;
77 is($page->string, 'MooseX', 'capitalize last');
79 $page->string('1234');
80 ok(!$page->invalid_number, 'string "isn\'t an invalid number');
82 $page->string('one two three four');
83 ok($page->invalid_number, 'string an invalid number');
86 is($page->string, '', "clear");
90 my $string = $page->meta->get_attribute('string');
91 does_ok($string, 'Moose::AttributeHelpers::Trait::String');
93 is($string->helper_type, 'Str', '... got the expected helper type');
95 is($string->type_constraint->name, 'Str', '... got the expected type constraint');
97 is_deeply($string->handles, {
99 append_string => 'append',
100 prepend_string => 'prepend',
101 match_string => 'match',
102 replace_string => 'replace',
103 chop_string => 'chop',
104 chomp_string => 'chomp',
105 clear_string => 'clear',
106 exclaim => [ append => [ '!' ] ],
107 capitalize_last => [ replace => [ qr/(.)$/, $uc ] ],
108 invalid_number => [ match => [ qr/\D/ ] ],
109 }, '... got the right handles methods');