default to the github repo in META.*
[p5sagit/Function-Parameters.git] / t / 01-compiles.t
CommitLineData
7a63380c 1#!perl
2
3use Test::More tests => 10;
4
5use warnings FATAL => 'all';
6use strict;
7
8use Function::Parameters;
9
10fun id_1($x) { $x }
11
12fun id_2
13 (
14 $x
15 )
5bf140a1 16 : #hello
7a63380c 17 (
18 $
19 )
5bf140a1 20 {@_ == 1 or return;
7a63380c 21 $x
22 }
23
24fun id_3 ##
25 ( $x ##
5bf140a1 26 ) ##AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
7a63380c 27 { ##
28 $x ##
29 } ##
30
31fun add($x, $y) {
32 $x + $y
33}
34
35fun mymap($fun, @args) :(&@) {
36 my @res;
37 for (@args) {
38 push @res, $fun->($_);
39 }
40 @res
41}
42
43fun fac_1($n) {
44 $n < 2 ? 1 : $n * fac_1 $n - 1
45}
46
47fun fac_2($n) :($) {
48 $n < 2 ? 1 : $n * fac_2 $n - 1
49}
50
51ok id_1 1;
52ok id_1(1), 'basic sanity';
53ok id_2 1, 'simple prototype';
54ok id_3(1), 'definition over multiple lines';
55is add(2, 2), 4, '2 + 2 = 4';
56is add(39, 3), 42, '39 + 3 = 42';
57is_deeply [mymap { $_ * 2 } 2, 3, 5, 9], [4, 6, 10, 18], 'mymap works';
58is fac_1(5), 120, 'fac_1';
59is fac_2 6, 720, 'fac_2';
60is fun ($x, $y) { $x . $y }->(fun ($foo) { $foo + 1 }->(3), fun ($bar) { $bar * 2 }->(1)), '42', 'anonyfun';