File: 027_lambda.t

package info (click to toggle)
libtext-xslate-perl 3.5.9-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,108 kB
  • sloc: perl: 19,756; ansic: 214; pascal: 182; makefile: 9; cs: 8
file content (61 lines) | stat: -rw-r--r-- 782 bytes parent folder | download | duplicates (5)
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
#!perl -w

use strict;
use Test::More;

use Text::Xslate;
use Text::Xslate::Compiler;
use Text::Xslate::Util qw(p);

my $tx = Text::Xslate->new();

my @set = (
    [<<'T', {}, <<'X'],
<: -> $x { $x + 10 }(0) :>
<: -> $x { $x + 10 }(1) :>
<: -> $x { $x + 10 }(2) :>
T
10
11
12
X
    [<<'T', {}, <<'X'],
<: my $y = 10; -> $x { $x + $y }(15) :>
T
25
X

    [<<'T', {}, <<'X'],
<: my $add10 = -> $x { $x + 10 }; $add10(20) :>
T
30
X

    [<<'T', {}, <<'X'],
<: constant add10 = -> $x { $x + 10 }; add10(20) :>
T
30
X

    [<<'T', {}, <<'X'],
: for [1, 2, 3] -> $v {
<: my $addv = -> $x { $x + $v }; $addv(20) :>
: }
T
21
22
23
X


);

foreach my $d(@set) {
    my($in, $vars, $out, $msg) = @$d;

    is $tx->render_string($in, $vars), $out, $msg
        or diag($in);
}


done_testing;