Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 149 lines (123 sloc) 4.358 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
4295bfc @usev6 Add tests for RT #118755
usev6 authored
12 plan 43;
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
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
26 #?rakudo skip "adverbial block RT #124755"
03b1456 @colomon Fudge for niecza.
colomon authored
27 #?niecza skip 'No value for parameter Mu $sm in Any.grep'
53330f8 Test suite refactoring.
cosimo authored
28 {
29 my @result = @list.grep():{ ($_ % 2) };
30 is(+@result, 5, 'we got a list back');
31 is(@result[0], 1, 'got the value we expected');
32 is(@result[1], 3, 'got the value we expected');
33 is(@result[2], 5, 'got the value we expected');
34 is(@result[3], 7, 'got the value we expected');
35 is(@result[4], 9, 'got the value we expected');
36 }
37
9c40515 @dnmfarrell fixed appended RT number to be within quoted string
dnmfarrell authored
38 #?rakudo skip "adverbial block RT #124756"
03b1456 @colomon Fudge for niecza.
colomon authored
39 #?niecza skip 'No value for parameter Mu $sm in Any.grep'
53330f8 Test suite refactoring.
cosimo authored
40 {
345293a [spec] S29-list/grep.t fixed adverbial closure test
moritz authored
41 my @result = @list.grep :{ ($_ % 2) };
53330f8 Test suite refactoring.
cosimo authored
42 is(+@result, 5, 'we got a list back');
43 is(@result[0], 1, 'got the value we expected');
44 is(@result[1], 3, 'got the value we expected');
45 is(@result[2], 5, 'got the value we expected');
46 is(@result[3], 7, 'got the value we expected');
47 is(@result[4], 9, 'got the value we expected');
48 }
49
50a6760 @usev6 Change fudged tests from 'skipped' to 'todo'
usev6 authored
50 #?rakudo todo "closure as non-final argument RT #124757"
03b1456 @colomon Fudge for niecza.
colomon authored
51 #?niecza skip 'Invocant handling is NYI'
53330f8 Test suite refactoring.
cosimo authored
52 {
53 my @result = grep { ($_ % 2) }: @list;
0960758 Some updates to S29-list.
pmichaud authored
54 is(+@result, 5, 'we got a list back');
55 is(@result[0], 1, 'got the value we expected');
56 is(@result[1], 3, 'got the value we expected');
57 is(@result[2], 5, 'got the value we expected');
58 is(@result[3], 7, 'got the value we expected');
59 is(@result[4], 9, 'got the value we expected');
53330f8 Test suite refactoring.
cosimo authored
60 }
61
62 {
5caad32 [t/spec]: Update map/grep/reduce/kv tests to work with scalar invoca…
pmichaud authored
63 is(42.grep({ 1 }), "42", "method form of grep works on numbers");
64 is('str'.grep({ 1 }), 'str', "method form of grep works on strings");
53330f8 Test suite refactoring.
cosimo authored
65 }
66
67 #
68 # Grep with mutating block
69 #
94ca56c [spec] removed "unspecced" marking of grep tests that mutate $_
moritz authored
70 # L<S02/Names/"$_, $!, and $/ are context<rw> by default">
53330f8 Test suite refactoring.
cosimo authored
71 {
72 my @array = <a b c d>;
dae7348 [t/spec]: Refudge test in S32-list/grep.t .
pmichaud authored
73 is ~(@array.grep({ $_ ~= "c"; 1 })), "ac bc cc dc",
53330f8 Test suite refactoring.
cosimo authored
74 'mutating $_ in grep works (1)';
75 is ~@array, "ac bc cc dc",
76 'mutating $_ in grep works (2)';
77 }
78
5d12fd9 [t/spec] tests for last and next in grep
moritz authored
79 # grep with last, next etc.
80 {
81 is (1..16).grep({last if $_ % 5 == 0; $_ % 2 == 0}).join('|'),
82 '2|4', 'last works in grep';
83 is (1..12).grep({next if $_ % 5 == 0; $_ % 2 == 0}).join('|'),
84 '2|4|6|8|12', 'next works in grep';
85 }
86
5b7f1a9 [t/spec] grep with non-Code matcher
moritz authored
87 # since the test argument to .grep is a Matcher, we can also
88 # check type constraints:
89 {
90 is (2, [], 4, [], 5).grep(Int).join(','),
91 '2,4,5', ".grep with non-Code matcher";
92
93 is grep(Int, 2, [], 4, [], 5).join(','),
94 '2,4,5', "grep() with non-Code matcher";
95 }
96
25668e6 @coke Prefer RT #XXXXXX
coke authored
97 # RT #71544
03b1456 @colomon Fudge for niecza.
colomon authored
98 #?niecza skip 'No value for parameter $b in ANON'
2f8a8f9 [t/spec] Test for RT 71754: grep arity sensitivity different from map
kyle authored
99 {
100 my @in = ( 1, 1, 2, 3, 4, 4 );
101
102 # This test passes, but it's disabled because it doesn't belong here.
103 # It just kind of clarifies the test that follows.
104 # is (map { $^a == $^b }, @in), (?1, ?0, ?1), 'map takes two at a time';
105
25668e6 @coke Prefer RT #XXXXXX
coke authored
106 #?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
107 is (grep { $^a == $^b }, @in), (1, 1, 4, 4), 'grep takes two at a time';
108 }
109
6939ae5 [t/spec] test Junction matchers with .grep
moritz authored
110 {
111 my @a = <a b c>;
112 my @b = <b c d>;
113 is @a.grep(any(@b)).join('|'), 'b|c', 'Junction matcher';
114
115 }
116
9dac81d @coke pugs fudge
coke authored
117 # sensible boolification
861910a [t/spec] test that the return value from .grep Boolifies sensibly (RT…
moritz authored
118 # RT #74056
119 # since rakudo returns an iterator (and not a list) and some internals leaked,
120 # a zero item list/iterator would return True, which is obviously wrong
121 {
122 ok <0 1 2>.grep(1), 'Non-empty return value from grep is true (1)';
123 ok <0 1 2>.grep(0), 'Non-empty return value from grep is true (2)';
124 nok <0 1 2>.grep(3), 'Empty return value from grep is false';
125 }
126
09e8944 [t/spec] Add some tests for doubled gathers.
colomon authored
127 # chained greps
128 {
c3f4ab2 @moritz fix another series misuse
moritz authored
129 is ~(1...100).grep(* %% 2).grep(* %% 3), ~(6, 12 ... 96), "chained greps work";
09e8944 [t/spec] Add some tests for doubled gathers.
colomon authored
130 }
131
4b608e7 @lizmat Add tests for Bool Matchers
lizmat authored
132 # Bool handling
133 {
08b5de5 @lizmat s/throws_like/throws-like/g
lizmat authored
134 throws-like { grep $_ == 1, 1,2,3 }, X::Match::Bool;
135 throws-like { (1,2,3).grep: $_== 1 }, X::Match::Bool;
4b608e7 @lizmat Add tests for Bool Matchers
lizmat authored
136 is grep( Bool,True,False,Int ), (True,False), 'can we match on Bool as type';
137 is (True,False,Int).grep(Bool), (True,False), 'can we match on Bool as type';
138 }
2f8a8f9 [t/spec] Test for RT 71754: grep arity sensitivity different from map
kyle authored
139
4295bfc @usev6 Add tests for RT #118755
usev6 authored
140 # RT #118755
141 {
142 my @a = 1..10;
143 @a.grep(* %% 2).>>++;
144 is @a, <1 3 3 5 5 7 7 9 9 11>,
145 'grep is rw-like, can chain it to modify elements of grepped list/array';
146 }
147
5b7f1a9 [t/spec] grep with non-Code matcher
moritz authored
148 # vim: ft=perl6
Something went wrong with that request. Please try again.