summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-08-18 20:56:15 -0500
committerJesse Luehrs <doy@tozt.net>2012-08-18 21:00:28 -0500
commit7b834c33ef2b0838f92151e73d1a27c8db536131 (patch)
tree0aa764465f1db1cd5dfa6150d789decc16558dbe /t
parent3ce18c876e750d53fa5df8d283e3f4ff8d2dfa94 (diff)
downloadfun-7b834c33ef2b0838f92151e73d1a27c8db536131.tar.gz
fun-7b834c33ef2b0838f92151e73d1a27c8db536131.zip
working implementation of parameter defaults
Diffstat (limited to 't')
-rw-r--r--t/defaults.t35
1 files changed, 35 insertions, 0 deletions
diff --git a/t/defaults.t b/t/defaults.t
new file mode 100644
index 0000000..0780f50
--- /dev/null
+++ b/t/defaults.t
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+use Fun;
+
+fun foo ($x, $y = 5) {
+ return $x + $y;
+}
+
+is(foo(3, 4), 7);
+is(foo(3), 8);
+{
+ my $warning;
+ local $SIG{__WARN__} = sub { $warning = $_[0] };
+ is(foo, 5);
+ like($warning, qr/Use of uninitialized value \$x in addition \(\+\)/);
+}
+
+fun bar ($baz, $quux = foo(1) * 2, $blorg = sub { return "ran sub, got " . $_[0] }) {
+ $blorg->($baz + $quux);
+}
+
+is(bar(3, 4, sub { $_[0] }), 7);
+is(bar(5, 6), "ran sub, got 11");
+is(bar(7), "ran sub, got 19");
+{
+ my $warning;
+ local $SIG{__WARN__} = sub { $warning = $_[0] };
+ is(bar, "ran sub, got 12");
+ like($warning, qr/Use of uninitialized value \$baz in addition \(\+\)/);
+}
+
+done_testing;