preliminary tests for new import syntax
Lukas Mai [Tue, 9 Aug 2011 08:58:49 +0000 (10:58 +0200)]
t/named.t [new file with mode: 0644]
t/named_1.fail [new file with mode: 0644]
t/named_2.fail [new file with mode: 0644]
t/named_3.fail [new file with mode: 0644]
t/named_4.fail [new file with mode: 0644]

diff --git a/t/named.t b/t/named.t
new file mode 100644 (file)
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 (file)
index 0000000..7a9af01
--- /dev/null
@@ -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 (file)
index 0000000..2ddbf0a
--- /dev/null
@@ -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 (file)
index 0000000..46f7855
--- /dev/null
@@ -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 (file)
index 0000000..67e92bd
--- /dev/null
@@ -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;
+}