6 use Test::More tests => 22;
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 => ['!'] ],
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' );
41 is( $page->length_string, 0,'... length is zero' );
44 is( $page->length_string, 1,'... new string has length of one' );
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" );
71 is( $page->length_string, 6, 'right length' );
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::Meta::Attribute::Native::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 length_string => 'length',
111 exclaim => [ append => ['!'] ],
112 capitalize_last => [ replace => [ qr/(.)$/, $uc ] ],
113 invalid_number => [ match => [qr/\D/] ],
115 '... got the right handles methods'