Remove register_implementation, warn about future deprecation
[gitmo/MooseX-AttributeHelpers.git] / t / 207_trait_string.t
CommitLineData
0951a229 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 17;
7use Test::Moose 'does_ok';
8
9BEGIN {
10 use_ok('MooseX::AttributeHelpers');
11}
12
13{
14 package MyHomePage;
15 use Moose;
16
17 has 'string' => (
c1984b5c 18 traits => [qw/MooseX::AttributeHelpers::Trait::String/],
0951a229 19 is => 'rw',
20 isa => 'Str',
21 default => sub { '' },
22 provides => {
23 inc => 'inc_string',
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',
31 }
32 );
33}
34
35my $page = MyHomePage->new();
36isa_ok($page, 'MyHomePage');
37
38is($page->string, '', '... got the default value');
39
40$page->string('a');
41
42$page->inc_string;
43is($page->string, 'b', '... got the incremented value');
44
45$page->inc_string;
46is($page->string, 'c', '... got the incremented value (again)');
47
48$page->append_string("foo$/");
49is($page->string, "cfoo$/", 'appended to string');
50
51$page->chomp_string;
52is($page->string, "cfoo", 'chomped string');
53
54$page->chomp_string;
55is($page->string, "cfoo", 'chomped is noop');
56
57$page->chop_string;
58is($page->string, "cfo", 'chopped string');
59
60$page->prepend_string("bar");
61is($page->string, 'barcfo', 'prepended to string');
62
63is_deeply( [ $page->match_string(qr/([ao])/) ], [ "a" ], "match" );
64
65$page->replace_string(qr/([ao])/, sub { uc($1) });
66is($page->string, 'bArcfo', "substitution");
67
68$page->clear_string;
69is($page->string, '', "clear");
70
71# check the meta ..
72
73my $string = $page->meta->get_attribute('string');
74does_ok($string, 'MooseX::AttributeHelpers::Trait::String');
75
76is($string->helper_type, 'Str', '... got the expected helper type');
77
78is($string->type_constraint->name, 'Str', '... got the expected type constraint');
79
80is_deeply($string->provides, {
81 inc => 'inc_string',
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');
90