6 use Test::More tests => 20;
7 use Test::Moose 'does_ok';
10 use_ok('Moose::AttributeHelpers');
19 traits => [qw/String/],
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 => ['!'] ],
34 [ replace => [ qr/(.)$/, $uc = sub { uc $1 } ] ],
35 invalid_number => [ match => [qr/\D/] ],
40 my $page = MyHomePage->new();
41 isa_ok( $page, 'MyHomePage' );
43 is( $page->string, '', '... got the default value' );
48 is( $page->string, 'b', '... got the incremented value' );
51 is( $page->string, 'c', '... got the incremented value (again)' );
53 $page->append_string("foo$/");
54 is( $page->string, "cfoo$/", 'appended to string' );
57 is( $page->string, "cfoo", 'chomped string' );
60 is( $page->string, "cfoo", 'chomped is noop' );
63 is( $page->string, "cfo", 'chopped string' );
65 $page->prepend_string("bar");
66 is( $page->string, 'barcfo', 'prepended to string' );
68 is_deeply( [ $page->match_string(qr/([ao])/) ], ["a"], "match" );
70 $page->replace_string( qr/([ao])/, sub { uc($1) } );
71 is( $page->string, 'bArcfo', "substitution" );
74 is( $page->string, 'bArcfo!', 'exclaim!' );
76 $page->string('Moosex');
77 $page->capitalize_last;
78 is( $page->string, 'MooseX', 'capitalize last' );
80 $page->string('1234');
81 ok( !$page->invalid_number, 'string "isn\'t an invalid number' );
83 $page->string('one two three four');
84 ok( $page->invalid_number, 'string an invalid number' );
87 is( $page->string, '', "clear" );
91 my $string = $page->meta->get_attribute('string');
92 does_ok( $string, 'Moose::AttributeHelpers::Trait::String' );
95 $string->type_constraint->name, 'Str',
96 '... got the expected type constraint'
103 append_string => 'append',
104 prepend_string => 'prepend',
105 match_string => 'match',
106 replace_string => 'replace',
107 chop_string => 'chop',
108 chomp_string => 'chomp',
109 clear_string => 'clear',
110 exclaim => [ append => ['!'] ],
111 capitalize_last => [ replace => [ qr/(.)$/, $uc ] ],
112 invalid_number => [ match => [qr/\D/] ],
114 '... got the right handles methods'