File: 02-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 (62 lines) | stat: -rw-r--r-- 1,077 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
61
62
#!perl

use Test::More tests => 10;

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

use Function::Parameters;

method id_1() { $self }

method id_2
 (

 )
 : #hello
 prototype(
  $
 )
 {@_ == 0 or return;
 	 $self
 }

method##
    id_3 ##
 (   ##
 	 #
 ) ##AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
 { ##
 	$self ##
 } ##

method add($y) {
    $self + $y
}

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

method fac_1() {
    $self < 2 ? 1 : $self * fac_1 $self - 1
}

method fac_2() :prototype($) {
    $self < 2 ? 1 : $self * fac_2 $self - 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 method ($y) { $self . $y }->(method () { $self + 1 }->(3), method () { $self * 2 }->(1)), '42', 'anonyfun';