From: Florian Ragwitz Date: Sun, 5 Apr 2009 22:10:42 +0000 (+0200) Subject: Add tests for String::substr. X-Git-Tag: 0.16~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=16d60aabfe02baf366ae39fb2df7bd433bf0c0fc;p=gitmo%2FMooseX-AttributeHelpers.git Add tests for String::substr. --- diff --git a/t/007_basic_string.t b/t/007_basic_string.t index 42d5149..8ff483c 100644 --- a/t/007_basic_string.t +++ b/t/007_basic_string.t @@ -3,10 +3,10 @@ use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 27; BEGIN { - use_ok('MooseX::AttributeHelpers'); + use_ok('MooseX::AttributeHelpers'); } { @@ -27,11 +27,13 @@ BEGIN { chop => 'chop_string', chomp => 'chomp_string', clear => 'clear_string', + substr => 'sub_string', }, curries => { append => {exclaim => [ '!' ]}, replace => {capitalize_last => [ qr/(.)$/, sub { uc $1 } ]}, - match => {invalid_number => [ qr/\D/ ]} + match => {invalid_number => [ qr/\D/ ]}, + substr => {shift_chars => sub { $_[1]->($_[0], 0, $_[2], '') } }, } ); } @@ -72,6 +74,14 @@ is($page->string, 'bArcfo', "substitution"); $page->exclaim; is($page->string, 'bArcfo!', 'exclaim!'); +is($page->sub_string(2), 'rcfo!', 'substr(offset)'); +is($page->sub_string(2, 2), 'rc', 'substr(offset, length)'); +is($page->sub_string(2, 2, ''), 'rc', 'substr(offset, length, replacement)'); +is($page->string, 'bAfo!', 'replacement got inserted'); + +is($page->shift_chars(2), 'bA', 'curried substr'); +is($page->string, 'fo!', 'replacement got inserted'); + $page->string('Moosex'); $page->capitalize_last; is($page->string, 'MooseX', 'capitalize last'); @@ -103,5 +113,6 @@ is_deeply($string->provides, { chop => 'chop_string', chomp => 'chomp_string', clear => 'clear_string', + substr => 'sub_string', }, '... got the right provides methods');