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