6 use Test::More tests => 19;
7 use Test::Moose 'does_ok';
13 use Moose::AttributeHelpers;
22 append_string => 'append',
23 prepend_string => 'prepend',
24 match_string => 'match',
25 replace_string => 'replace',
26 chop_string => 'chop',
27 chomp_string => 'chomp',
28 clear_string => 'clear',
29 exclaim => [ append => ['!'] ],
31 [ replace => [ qr/(.)$/, $uc = sub { uc $1 } ] ],
32 invalid_number => [ match => [qr/\D/] ],
37 my $page = MyHomePage->new();
38 isa_ok( $page, 'MyHomePage' );
40 is( $page->string, '', '... got the default value' );
45 is( $page->string, 'b', '... got the incremented value' );
48 is( $page->string, 'c', '... got the incremented value (again)' );
50 $page->append_string("foo$/");
51 is( $page->string, "cfoo$/", 'appended to string' );
54 is( $page->string, "cfoo", 'chomped string' );
57 is( $page->string, "cfoo", 'chomped is noop' );
60 is( $page->string, "cfo", 'chopped string' );
62 $page->prepend_string("bar");
63 is( $page->string, 'barcfo', 'prepended to string' );
65 is_deeply( [ $page->match_string(qr/([ao])/) ], ["a"], "match" );
67 $page->replace_string( qr/([ao])/, sub { uc($1) } );
68 is( $page->string, 'bArcfo', "substitution" );
71 is( $page->string, 'bArcfo!', 'exclaim!' );
73 $page->string('Moosex');
74 $page->capitalize_last;
75 is( $page->string, 'MooseX', 'capitalize last' );
77 $page->string('1234');
78 ok( !$page->invalid_number, 'string "isn\'t an invalid number' );
80 $page->string('one two three four');
81 ok( $page->invalid_number, 'string an invalid number' );
84 is( $page->string, '', "clear" );
88 my $string = $page->meta->get_attribute('string');
89 does_ok( $string, 'Moose::AttributeHelpers::Trait::String' );
92 $string->type_constraint->name, 'Str',
93 '... got the expected type constraint'
100 append_string => 'append',
101 prepend_string => 'prepend',
102 match_string => 'match',
103 replace_string => 'replace',
104 chop_string => 'chop',
105 chomp_string => 'chomp',
106 clear_string => 'clear',
107 exclaim => [ append => ['!'] ],
108 capitalize_last => [ replace => [ qr/(.)$/, $uc ] ],
109 invalid_number => [ match => [qr/\D/] ],
111 '... got the right handles methods'