Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 132 lines (105 sloc) 3.628 kb
d198f6b [t/spec] s/use v6-alpha;/use v6;/
moritz authored
1 use v6;
53330f8 Test suite refactoring.
cosimo authored
2 use Test;
3
ccace72 [t/spec] fix smartlinks in S32-list
moritz authored
4 # L<S32::Containers/"List"/"=item grep">
53330f8 Test suite refactoring.
cosimo authored
5
8313f3f [t/spec] Converted pod markers to pod6
cosimo authored
6 =begin pod
53330f8 Test suite refactoring.
cosimo authored
7
8 built-in grep tests
9
8313f3f [t/spec] Converted pod markers to pod6
cosimo authored
10 =end pod
53330f8 Test suite refactoring.
cosimo authored
11
2f8a8f9 [t/spec] Test for RT 71754: grep arity sensitivity different from map
kyle authored
12 plan *;
53330f8 Test suite refactoring.
cosimo authored
13
14 my @list = (1 .. 10);
15
16 {
17 my @result = grep { ($_ % 2) }, @list;
18 is(+@result, 5, 'we got a list back');
19 is(@result[0], 1, 'got the value we expected');
20 is(@result[1], 3, 'got the value we expected');
21 is(@result[2], 5, 'got the value we expected');
22 is(@result[3], 7, 'got the value we expected');
23 is(@result[4], 9, 'got the value we expected');
24 }
25
3e50caf [t] added named arg test for grep
frew authored
26 {
27 my @result = grep({ ($_ % 2) }, :values(@list));
28 is(+@result, 5, 'we got a list back');
29 is(@result[0], 1, 'got the value we expected');
30 is(@result[1], 3, 'got the value we expected');
31 is(@result[2], 5, 'got the value we expected');
32 is(@result[3], 7, 'got the value we expected');
33 is(@result[4], 9, 'got the value we expected');
34 }
35
0960758 Some updates to S29-list.
pmichaud authored
36 #?rakudo skip "adverbial block"
53330f8 Test suite refactoring.
cosimo authored
37 {
38 my @result = @list.grep():{ ($_ % 2) };
39 is(+@result, 5, 'we got a list back');
40 is(@result[0], 1, 'got the value we expected');
41 is(@result[1], 3, 'got the value we expected');
42 is(@result[2], 5, 'got the value we expected');
43 is(@result[3], 7, 'got the value we expected');
44 is(@result[4], 9, 'got the value we expected');
45 }
46
0960758 Some updates to S29-list.
pmichaud authored
47 #?rakudo skip "adverbial block"
53330f8 Test suite refactoring.
cosimo authored
48 {
345293a [spec] S29-list/grep.t fixed adverbial closure test
moritz authored
49 my @result = @list.grep :{ ($_ % 2) };
53330f8 Test suite refactoring.
cosimo authored
50 is(+@result, 5, 'we got a list back');
51 is(@result[0], 1, 'got the value we expected');
52 is(@result[1], 3, 'got the value we expected');
53 is(@result[2], 5, 'got the value we expected');
54 is(@result[3], 7, 'got the value we expected');
55 is(@result[4], 9, 'got the value we expected');
56 }
57
0960758 Some updates to S29-list.
pmichaud authored
58 #?rakudo skip "closure as non-final argument"
53330f8 Test suite refactoring.
cosimo authored
59 {
60 my @result = grep { ($_ % 2) }: @list;
0960758 Some updates to S29-list.
pmichaud authored
61 is(+@result, 5, 'we got a list back');
62 is(@result[0], 1, 'got the value we expected');
63 is(@result[1], 3, 'got the value we expected');
64 is(@result[2], 5, 'got the value we expected');
65 is(@result[3], 7, 'got the value we expected');
66 is(@result[4], 9, 'got the value we expected');
53330f8 Test suite refactoring.
cosimo authored
67 }
68
69 {
a20c69c [t/spec/*.t] :todo whackage
lwall authored
70 #?pugs 2 todo 'bug'
5caad32 [t/spec]: Update map/grep/reduce/kv tests to work with scalar invoca…
pmichaud authored
71 is(42.grep({ 1 }), "42", "method form of grep works on numbers");
72 is('str'.grep({ 1 }), 'str', "method form of grep works on strings");
53330f8 Test suite refactoring.
cosimo authored
73 }
74
75 #
76 # Grep with mutating block
77 #
94ca56c [spec] removed "unspecced" marking of grep tests that mutate $_
moritz authored
78 # L<S02/Names/"$_, $!, and $/ are context<rw> by default">
53330f8 Test suite refactoring.
cosimo authored
79
80 {
81 my @array = <a b c d>;
dae7348 [t/spec]: Refudge test in S32-list/grep.t .
pmichaud authored
82 #?rakudo 2 skip 'test error -- is $_ rw here?'
83 is ~(@array.grep({ $_ ~= "c"; 1 })), "ac bc cc dc",
53330f8 Test suite refactoring.
cosimo authored
84 'mutating $_ in grep works (1)';
85 is ~@array, "ac bc cc dc",
86 'mutating $_ in grep works (2)';
87 }
88
5d12fd9 [t/spec] tests for last and next in grep
moritz authored
89 # grep with last, next etc.
90
91 {
92 is (1..16).grep({last if $_ % 5 == 0; $_ % 2 == 0}).join('|'),
93 '2|4', 'last works in grep';
94 is (1..12).grep({next if $_ % 5 == 0; $_ % 2 == 0}).join('|'),
95 '2|4|6|8|12', 'next works in grep';
96 }
97
5b7f1a9 [t/spec] grep with non-Code matcher
moritz authored
98 # since the test argument to .grep is a Matcher, we can also
99 # check type constraints:
100
101 {
102 is (2, [], 4, [], 5).grep(Int).join(','),
103 '2,4,5', ".grep with non-Code matcher";
104
ad9be36 [t/spec] Refudge grep.t.
colomon authored
105 #?rakudo skip "sub grep isn't properly slurpy"
5b7f1a9 [t/spec] grep with non-Code matcher
moritz authored
106 is grep(Int, 2, [], 4, [], 5).join(','),
107 '2,4,5', "grep() with non-Code matcher";
108 }
109
2f8a8f9 [t/spec] Test for RT 71754: grep arity sensitivity different from map
kyle authored
110 # RT 71544
111 {
112 my @in = ( 1, 1, 2, 3, 4, 4 );
113
114 # This test passes, but it's disabled because it doesn't belong here.
115 # It just kind of clarifies the test that follows.
116 # is (map { $^a == $^b }, @in), (?1, ?0, ?1), 'map takes two at a time';
117
3ba1e50 [t/spec] fix mislabeled fudge
kyle authored
118 #?rakudo skip 'RT 71544: grep arity sensitivity different from map'
2f8a8f9 [t/spec] Test for RT 71754: grep arity sensitivity different from map
kyle authored
119 is (grep { $^a == $^b }, @in), (1, 1, 4, 4), 'grep takes two at a time';
120 }
121
6939ae5 [t/spec] test Junction matchers with .grep
moritz authored
122 {
123 my @a = <a b c>;
124 my @b = <b c d>;
125 is @a.grep(any(@b)).join('|'), 'b|c', 'Junction matcher';
126
127 }
128
2f8a8f9 [t/spec] Test for RT 71754: grep arity sensitivity different from map
kyle authored
129 done_testing;
130
5b7f1a9 [t/spec] grep with non-Code matcher
moritz authored
131 # vim: ft=perl6
Something went wrong with that request. Please try again.