Commit | Line | Data |
fd3835b3 |
1 | #!./perl |
2 | |
3 | # |
4 | # grep() and map() tests |
5 | # |
6 | |
2c38e13d |
7 | print "1..27\n"; |
fd3835b3 |
8 | |
9 | $test = 1; |
10 | |
11 | sub ok { |
12 | my ($got,$expect) = @_; |
13 | print "# expected [$expect], got [$got]\nnot " if $got ne $expect; |
14 | print "ok $test\n"; |
15 | } |
16 | |
17 | { |
18 | my @lol = ([qw(a b c)], [], [qw(1 2 3)]); |
19 | my @mapped = map {scalar @$_} @lol; |
20 | ok "@mapped", "3 0 3"; |
21 | $test++; |
22 | |
23 | my @grepped = grep {scalar @$_} @lol; |
24 | ok "@grepped", "$lol[0] $lol[2]"; |
25 | $test++; |
26 | |
27 | @grepped = grep { $_ } @mapped; |
28 | ok "@grepped", "3 3"; |
29 | $test++; |
30 | } |
31 | |
2c38e13d |
32 | { |
33 | print map({$_} ("ok $test\n")); |
34 | $test++; |
35 | print map |
36 | ({$_} ("ok $test\n")); |
37 | $test++; |
38 | print((map({a => $_}, ("ok $test\n")))[0]->{a}); |
39 | $test++; |
40 | print((map |
41 | ({a=>$_}, |
42 | ("ok $test\n")))[0]->{a}); |
43 | $test++; |
44 | print map { $_ } ("ok $test\n"); |
45 | $test++; |
46 | print map |
47 | { $_ } ("ok $test\n"); |
48 | $test++; |
49 | print((map {a => $_}, ("ok $test\n"))[0]->{a}); |
50 | $test++; |
51 | print((map |
52 | {a=>$_}, |
53 | ("ok $test\n"))[0]->{a}); |
54 | $test++; |
55 | my $x = "ok \xFF\xFF\n"; |
56 | print map($_&$x,("ok $test\n")); |
57 | $test++; |
58 | print map |
59 | ($_ & $x, ("ok $test\n")); |
60 | $test++; |
61 | print map { $_ & $x } ("ok $test\n"); |
62 | $test++; |
63 | print map |
64 | { $_&$x } ("ok $test\n"); |
65 | $test++; |
66 | |
67 | print grep({$_} ("ok $test\n")); |
68 | $test++; |
69 | print grep |
70 | ({$_} ("ok $test\n")); |
71 | $test++; |
72 | print grep({a => $_}->{a}, ("ok $test\n")); |
73 | $test++; |
74 | print grep |
75 | ({a => $_}->{a}, |
76 | ("ok $test\n")); |
77 | $test++; |
78 | print grep { $_ } ("ok $test\n"); |
79 | $test++; |
80 | print grep |
81 | { $_ } ("ok $test\n"); |
82 | $test++; |
83 | print grep {a => $_}->{a}, ("ok $test\n"); |
84 | $test++; |
85 | print grep |
86 | {a => $_}->{a}, |
87 | ("ok $test\n"); |
88 | $test++; |
89 | print grep($_&"X",("ok $test\n")); |
90 | $test++; |
91 | print grep |
92 | ($_&"X", ("ok $test\n")); |
93 | $test++; |
94 | print grep { $_ & "X" } ("ok $test\n"); |
95 | $test++; |
96 | print grep |
97 | { $_ & "X" } ("ok $test\n"); |
98 | $test++; |
99 | } |