From: Dave Rolsky Date: Fri, 15 Apr 2011 16:08:33 +0000 (-0500) Subject: Test that Str can handle return value of substr() X-Git-Tag: 2.0100~66 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bb4cf777db43a1e499ed17f7dcff2cdb0c4b93e2;p=gitmo%2FMoose.git Test that Str can handle return value of substr() --- diff --git a/t/type_constraints/util_std_type_constraints.t b/t/type_constraints/util_std_type_constraints.t index 01a1728..c830567 100644 --- a/t/type_constraints/util_std_type_constraints.t +++ b/t/type_constraints/util_std_type_constraints.t @@ -696,6 +696,52 @@ for my $name ( sort keys %tests ) { test_constraint( $name, $tests{$name} ); } +# We need to test that the Str constraint accepts the return val of substr() - +# which means passing that return val directly to the checking code +{ + my $str = 'some string'; + + my $type = Moose::Util::TypeConstraints::find_type_constraint('Str'); + + my $unoptimized + = $type->has_parent + ? $type->_compile_subtype( $type->constraint ) + : $type->_compile_type( $type->constraint ); + + my $inlined; + { + local $@; + $inlined = eval 'sub { ( ' . $type->_inline_check('$_[0]') . ' ) }'; + die $@ if $@; + } + + ok( + $type->check( substr( $str, 1, 3 ) ), + 'Str accepts return val from substr using ->check' + ); + ok( + $unoptimized->( substr( $str, 1, 3 ) ), + 'Str accepts return val from substr using unoptimized constraint' + ); + ok( + $inlined->( substr( $str, 1, 3 ) ), + 'Str accepts return val from substr using inlined constraint' + ); + + ok( + $type->check( substr( $str, 0, 0 ) ), + 'Str accepts empty return val from substr using ->check' + ); + ok( + $unoptimized->( substr( $str, 0, 0 ) ), + 'Str accepts empty return val from substr using unoptimized constraint' + ); + ok( + $inlined->( substr( $str, 0, 0 ) ), + 'Str accepts empty return val from substr using inlined constraint' + ); +} + { my $class_tc = class_type('Thing');