7 use Test::Moose 'does_ok';
21 append_string => 'append',
22 prepend_string => 'prepend',
23 match_string => 'match',
24 replace_string => 'replace',
25 chop_string => 'chop',
26 chomp_string => 'chomp',
27 clear_string => 'clear',
28 length_string => 'length',
29 exclaim => [ append => '!' ],
30 capitalize_last => [ replace => qr/(.)$/, ($uc = sub { uc $1 }) ],
31 invalid_number => [ match => qr/\D/ ],
36 my $page = MyHomePage->new();
37 isa_ok( $page, 'MyHomePage' );
39 is( $page->string, '', '... got the default value' );
40 is( $page->length_string, 0,'... length is zero' );
43 is( $page->length_string, 1,'... new string has length of one' );
46 is( $page->string, 'b', '... got the incremented value' );
49 is( $page->string, 'c', '... got the incremented value (again)' );
51 $page->append_string("foo$/");
52 is( $page->string, "cfoo$/", 'appended to string' );
55 is( $page->string, "cfoo", 'chomped string' );
58 is( $page->string, "cfoo", 'chomped is noop' );
61 is( $page->string, "cfo", 'chopped string' );
63 $page->prepend_string("bar");
64 is( $page->string, 'barcfo', 'prepended to string' );
66 is_deeply( [ $page->match_string(qr/([ao])/) ], ["a"], "match" );
68 $page->replace_string( qr/([ao])/, sub { uc($1) } );
69 is( $page->string, 'bArcfo', "substitution" );
70 is( $page->length_string, 6, 'right length' );
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::Meta::Attribute::Native::Trait::String' );
94 $string->type_constraint->name, 'Str',
95 '... got the expected type constraint'
102 append_string => 'append',
103 prepend_string => 'prepend',
104 match_string => 'match',
105 replace_string => 'replace',
106 chop_string => 'chop',
107 chomp_string => 'chomp',
108 clear_string => 'clear',
109 length_string => 'length',
110 exclaim => [ append => '!' ],
111 capitalize_last => [ replace => qr/(.)$/, $uc ],
112 invalid_number => [ match => qr/\D/ ],
114 '... got the right handles methods'