6 use Test::More tests => 17;
7 use Test::Moose 'does_ok';
10 use_ok('Moose::AttributeHelpers');
18 traits => [qw/String/],
21 default => sub { '' },
24 append_string => 'append',
25 prepend_string => 'prepend',
26 match_string => 'match',
27 replace_string => 'replace',
28 chop_string => 'chop',
29 chomp_string => 'chomp',
30 clear_string => 'clear',
35 my $page = MyHomePage->new();
36 isa_ok($page, 'MyHomePage');
38 is($page->string, '', '... got the default value');
43 is($page->string, 'b', '... got the incremented value');
46 is($page->string, 'c', '... got the incremented value (again)');
48 $page->append_string("foo$/");
49 is($page->string, "cfoo$/", 'appended to string');
52 is($page->string, "cfoo", 'chomped string');
55 is($page->string, "cfoo", 'chomped is noop');
58 is($page->string, "cfo", 'chopped string');
60 $page->prepend_string("bar");
61 is($page->string, 'barcfo', 'prepended to string');
63 is_deeply( [ $page->match_string(qr/([ao])/) ], [ "a" ], "match" );
65 $page->replace_string(qr/([ao])/, sub { uc($1) });
66 is($page->string, 'bArcfo', "substitution");
69 is($page->string, '', "clear");
73 my $string = $page->meta->get_attribute('string');
74 does_ok($string, 'Moose::AttributeHelpers::Trait::String');
76 is($string->helper_type, 'Str', '... got the expected helper type');
78 is($string->type_constraint->name, 'Str', '... got the expected type constraint');
80 is_deeply($string->handles, {
82 append_string => 'append',
83 prepend_string => 'prepend',
84 match_string => 'match',
85 replace_string => 'replace',
86 chop_string => 'chop',
87 chomp_string => 'chomp',
88 clear_string => 'clear',
89 }, '... got the right provides methods');