File: parameters.t

package info (click to toggle)
libmethod-signatures-perl 20141021-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 620 kB
  • ctags: 133
  • sloc: perl: 3,561; makefile: 2
file content (66 lines) | stat: -rw-r--r-- 1,882 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
#!/usr/bin/perl -w

use strict;
use warnings;

use Test::More 'no_plan';

use Method::Signatures::Signature;

my %tests = (
    '$foo'              => ['$foo'],
    '$foo, $bar'        => ['$foo', '$bar'],
    ':$foo, $bar?'      => [':$foo', '$bar?'],
    ''                  => [],
    '$sum = 2+2, $div = 2/2'    => ['$sum = 2+2', '$div = 2/2'],
    '$foo = "Hello, world!"'    => ['$foo = "Hello, world!"'],
    '@args = (1,2,3)'   => ['@args = (1,2,3)'],
    '$foo = [1,2,3], $bar = { this => 23, that => 42 }' => [
        '$foo = [1,2,3]', '$bar = { this => 23, that => 42 }'
    ],
    '$code = sub { my $bar = 2+2; }, :$this'    =>  ['$code = sub { my $bar = 2+2; }', ':$this'],

    q[
        $num    = 42,
        $string = q[Hello, world!],
        $hash   = { this => 42, that => 23 },
        $code   = sub { $num + 4 },
        @nums   = (1,2,3)
    ]   =>
    [
        '$num    = 42',
        '$string = q[Hello, world!]',
        '$hash   = { this => 42, that => 23 }',
        '$code   = sub { $num + 4 }',
        '@nums   = (1,2,3)'
    ],
);

while(my($args, $expect) = each %tests) {
    my $sig = Method::Signatures::Signature->new(
        signature_string        => $args,
        # we just want to test the tokenizing
        no_checks               => 1,
    );
    is_deeply [map { $_->original_code } @{$sig->parameters}], $expect, "parameters - $args";
}


note "line numbers"; {
    my $code = q[
        $num    = 42,
        $hash   = { this => 42,
                    that => 23 },
        $code   = sub { $num + 4 },
    ];
    my $sig = Method::Signatures::Signature->new(
        signature_string        => $code,
        no_checks               => 1,
    );

    my $parameters = $sig->parameters;

    is $parameters->[0]->first_line_number, 2;
    is $parameters->[1]->first_line_number, 3;
    is $parameters->[2]->first_line_number, 5;
}