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 => 'append_string',
25 prepend => 'prepend_string',
26 match => 'match_string',
27 replace => 'replace_string',
28 chop => 'chop_string',
29 chomp => 'chomp_string',
30 clear => 'clear_string',
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->provides, {
82 append => 'append_string',
83 prepend => 'prepend_string',
84 match => 'match_string',
85 replace => 'replace_string',
86 chop => 'chop_string',
87 chomp => 'chomp_string',
88 clear => 'clear_string',
89 }, '... got the right provides methods');