From: Dave Rolsky Date: Sat, 25 Sep 2010 19:00:10 +0000 (-0500) Subject: Add tests for argument checking with Number trait X-Git-Tag: 1.15~97 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=167ec1853deaca9519679769d16ed59da3adb0ba;p=gitmo%2FMoose.git Add tests for argument checking with Number trait --- diff --git a/t/070_native_traits/004_trait_number.t b/t/070_native_traits/004_trait_number.t index d34a526..35d81c8 100644 --- a/t/070_native_traits/004_trait_number.t +++ b/t/070_native_traits/004_trait_number.t @@ -68,26 +68,50 @@ sub run_tests { is( $obj->integer, 15, 'Add ten for fithteen' ); + throws_ok { $obj->add( 10, 2 ) } + qr/Cannot call add with more than 1 argument/, + 'add throws an error when 2 arguments are passed'; + $obj->sub(3); is( $obj->integer, 12, 'Subtract three for 12' ); + throws_ok { $obj->sub( 10, 2 ) } + qr/Cannot call sub with more than 1 argument/, + 'sub throws an error when 2 arguments are passed'; + $obj->set(10); is( $obj->integer, 10, 'Set to ten' ); + throws_ok { $obj->set( 10, 2 ) } + qr/Cannot call set with more than 1 argument/, + 'set throws an error when 2 arguments are passed'; + $obj->div(2); is( $obj->integer, 5, 'divide by 2' ); + throws_ok { $obj->div( 10, 2 ) } + qr/Cannot call div with more than 1 argument/, + 'div throws an error when 2 arguments are passed'; + $obj->mul(2); is( $obj->integer, 10, 'multiplied by 2' ); + throws_ok { $obj->mul( 10, 2 ) } + qr/Cannot call mul with more than 1 argument/, + 'mul throws an error when 2 arguments are passed'; + $obj->mod(2); is( $obj->integer, 0, 'Mod by 2' ); + throws_ok { $obj->mod( 10, 2 ) } + qr/Cannot call mod with more than 1 argument/, + 'mod throws an error when 2 arguments are passed'; + $obj->set(7); $obj->mod(5); @@ -98,6 +122,10 @@ sub run_tests { $obj->abs; + throws_ok { $obj->abs(10) } + qr/Cannot call abs with any arguments/, + 'abs throws an error when an argument is passed'; + is( $obj->integer, 1, 'abs 1' ); $obj->set(12);