6 use Test::More tests => 17;
9 use_ok('MooseX::AttributeHelpers');
17 metaclass => 'String',
20 default => sub { '' },
23 append => 'append_string',
24 prepend => 'prepend_string',
25 match => 'match_string',
26 replace => 'replace_string',
27 chop => 'chop_string',
28 chomp => 'chomp_string',
29 clear => 'clear_string',
34 my $page = MyHomePage->new();
35 isa_ok($page, 'MyHomePage');
37 is($page->string, '', '... got the default value');
42 is($page->string, 'b', '... got the incremented value');
45 is($page->string, 'c', '... got the incremented value (again)');
47 $page->append_string("foo$/");
48 is($page->string, "cfoo$/", 'appended to string');
51 is($page->string, "cfoo", 'chomped string');
54 is($page->string, "cfoo", 'chomped is noop');
57 is($page->string, "cfo", 'chopped string');
59 $page->prepend_string("bar");
60 is($page->string, 'barcfo', 'prepended to string');
62 is_deeply( [ $page->match_string(qr/([ao])/) ], [ "a" ], "match" );
64 $page->replace_string(qr/([ao])/, sub { uc($1) });
65 is($page->string, 'bArcfo', "substitution");
68 is($page->string, '', "clear");
72 my $string = $page->meta->get_attribute('string');
73 isa_ok($string, 'MooseX::AttributeHelpers::String');
75 is($string->helper_type, 'Str', '... got the expected helper type');
77 is($string->type_constraint->name, 'Str', '... got the expected type constraint');
79 is_deeply($string->provides, {
81 append => 'append_string',
82 prepend => 'prepend_string',
83 match => 'match_string',
84 replace => 'replace_string',
85 chop => 'chop_string',
86 chomp => 'chomp_string',
87 clear => 'clear_string',
88 }, '... got the right provides methods');