File: 01-compiles.t

package info (click to toggle)
libfunction-parameters-perl 2.002005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: perl: 3,945; makefile: 3
file content (60 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!perl

use Test::More tests => 10;

use warnings FATAL => 'all';
use strict;

use Function::Parameters;

fun id_1($x) { $x }

fun id_2
 (
 	 $x
 )
 : #hello
 prototype(
  $
 )
 {@_ == 1 or return;
 	 $x
 }

fun id_3 ##
 (  $x ##
 ) ##AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
 { ##
 	 $x ##
 } ##

fun add($x, $y) {
    $x + $y
}

fun mymap($fun, @args) :prototype(&@) {
  my @res;
  for (@args) {
    push @res, $fun->($_);
  }
  @res
}

fun fac_1($n) {
    $n < 2 ? 1 : $n * fac_1 $n - 1
}

fun fac_2($n) :prototype($) {
    $n < 2 ? 1 : $n * fac_2 $n - 1
}

ok id_1 1;
ok id_1(1), 'basic sanity';
ok id_2 1, 'simple prototype';
ok id_3(1), 'definition over multiple lines';
is add(2, 2), 4, '2 + 2 = 4';
is add(39, 3), 42, '39 + 3 = 42';
is_deeply [mymap { $_ * 2 } 2, 3, 5, 9], [4, 6, 10, 18], 'mymap works';
is fac_1(5), 120, 'fac_1';
is fac_2 6, 720, 'fac_2';
is fun ($x, $y) { $x . $y }->(fun ($foo) { $foo + 1 }->(3), fun ($bar) { $bar * 2 }->(1)), '42', 'anonyfun';