File: 02-compile-direct.t

package info (click to toggle)
libfilter-signatures-perl 0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 236 kB
  • sloc: perl: 1,321; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (2)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!perl -w
use strict;
use Test::More tests => 9;
use Data::Dumper;
BEGIN{ $ENV{FORCE_FILTER_SIGNATURES} = 1; };
use Filter::signatures;
use feature 'signatures';
no warnings 'experimental::signatures';

# Anonymous
my $sub = sub ($name, $value) {
        return "'$name' is '$value'"
    };

SKIP: {
    is ref $sub, 'CODE', "we can compile a simple anonymous subroutine"
        or skip 1, $@;
    is $sub->("Foo", 'bar'), "'Foo' is 'bar'", "Passing parameters works";
}

# Named
sub foo1 ($name, $value) {
        return "'$name' is '$value'"
};

SKIP: {
    is foo1("Foo", 'bar'), "'Foo' is 'bar'", "Passing parameters works (named)";
}

# Named, with default
sub foo2 ($name, $value='default') {
        return "'$name' is '$value'"
};

SKIP: {
    is foo2("Foo"), "'Foo' is 'default'", "default parameters works";
}

# Named, with default
sub foo3 ($name, $value='default, with comma') {
        return "'$name' is '$value'"
};

SKIP: {
    is foo3("Foo"), "'Foo' is 'default, with comma'", "default parameters works even with embedded comma";
}

# No parameters
sub foo5 () {
        return "We can call a sub without parameters"
};

is foo5(), "We can call a sub without parameters", "A subroutine with an empty parameter list still compiles";

# Only slurpy discarding parameters
sub foo6 (@) {
        return "We can call a sub with all-slurpy ignored parameters"
};

is foo6('foo','bar','baz'), "We can call a sub with all-slurpy ignored parameters", "A subroutine with an all-slurpy ignored parameter list still compiles";

# Unnamed parameter in the middle
sub foo7 ($foo, $, $bar) {
        return "$foo => $bar"
};

is foo7('Hello','you','World'), "Hello => World", "A subroutine with unnamed parameter still compiles";

# Comments in the signature
sub foo_comment ($foo, # foo
          $bar  # $bar
        ) {
        return "$foo => $bar"
};

is foo_comment('Hello','World'), "Hello => World", "We (well, Filter::Simple) supports ignoring comments";