From: Lukas Mai Date: Tue, 9 Aug 2011 08:58:49 +0000 (+0200) Subject: preliminary tests for new import syntax X-Git-Tag: v0.05_01~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=20f5d15a6c056c4cd8e946277e373a04d7a8bd1a;p=p5sagit%2FFunction-Parameters.git preliminary tests for new import syntax --- diff --git a/t/named.t b/t/named.t new file mode 100644 index 0000000..e5f836d --- /dev/null +++ b/t/named.t @@ -0,0 +1,49 @@ +use warnings; +use strict; + +use Test::More tests => 4; + +use Dir::Self; + +use Function::Parameters { + func => { + name => 'required', + }, + + f => { + name => 'prohibited', + }, + + method => { + name => 'required', + shift => '$this', + }, +}; + +func foo($x, $y, $z) { + $x .= $z; + return $y . $x . $y; +} + +method bar($k, $d) { + $d = $k . $d; + return $d . $this->{$k} . $d; +} + +is foo('a', 'b', 'c'), 'bacb'; +is bar({ab => 'cd'}, 'ab', 'e'), 'eabcdeab'; + +my $baz = f ($x) { $x * 2 + 1 }; +is $baz->(11), 23; +is $baz->(-0.5), 0; + +for my $fail (map [__DIR__ . "/named_$_.fail"], '1', '2', '3', '4') { + my ($file) = @$fail; + my $done = do $file; + my $exc = $@; + my $err = $!; + + is $done, undef, "faulty code doesn't load"; + $exc or die "$file: $err"; + warn "$exc\n"; +} diff --git a/t/named_1.fail b/t/named_1.fail new file mode 100644 index 0000000..7a9af01 --- /dev/null +++ b/t/named_1.fail @@ -0,0 +1,20 @@ +#!perl +use warnings; +use strict; + +use Function::Parameters { + func => { + name => 'required', + }, + + f => { + name => 'prohibited', + }, + + method => { + name => 'required', + shift => '$this', + }, +}; + +my $bad = func () { 1 }; diff --git a/t/named_2.fail b/t/named_2.fail new file mode 100644 index 0000000..2ddbf0a --- /dev/null +++ b/t/named_2.fail @@ -0,0 +1,21 @@ +#!perl +use warnings; +use strict; + +use Function::Parameters { + func => { + name => 'required', + }, + + f => { + name => 'prohibited', + }, + + method => { + name => 'required', + shift => '$this', + }, +}; + +f bad() { +} diff --git a/t/named_3.fail b/t/named_3.fail new file mode 100644 index 0000000..46f7855 --- /dev/null +++ b/t/named_3.fail @@ -0,0 +1,20 @@ +#!perl +use warnings; +use strict; + +use Function::Parameters { + func => { + name => 'required', + }, + + f => { + name => 'prohibited', + }, + + method => { + name => 'required', + shift => '$this', + }, +}; + +my $bad = method () { $this }; diff --git a/t/named_4.fail b/t/named_4.fail new file mode 100644 index 0000000..67e92bd --- /dev/null +++ b/t/named_4.fail @@ -0,0 +1,22 @@ +#!perl +use warnings; +use strict; + +use Function::Parameters { + func => { + name => 'required', + }, + + f => { + name => 'prohibited', + }, + + method => { + name => 'required', + shift => '$this', + }, +}; + +method bad2() { + my $what = $self; +}