Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 125 lines (100 sloc) 3.494 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 #?rakudo skip 'named args'
27 {
28 my @result = grep({ ($_ % 2) }, :values(@list));
29 is(+@result, 5, 'we got a list back');
30 is(@result[0], 1, 'got the value we expected');
31 is(@result[1], 3, 'got the value we expected');
32 is(@result[2], 5, 'got the value we expected');
33 is(@result[3], 7, 'got the value we expected');
34 is(@result[4], 9, 'got the value we expected');
35 }
36
0960758 Some updates to S29-list.
pmichaud authored
37 #?rakudo skip "adverbial block"
53330f8 Test suite refactoring.
cosimo authored
38 {
39 my @result = @list.grep():{ ($_ % 2) };
40 is(+@result, 5, 'we got a list back');
41 is(@result[0], 1, 'got the value we expected');
42 is(@result[1], 3, 'got the value we expected');
43 is(@result[2], 5, 'got the value we expected');
44 is(@result[3], 7, 'got the value we expected');
45 is(@result[4], 9, 'got the value we expected');
46 }
47
0960758 Some updates to S29-list.
pmichaud authored
48 #?rakudo skip "adverbial block"
53330f8 Test suite refactoring.
cosimo authored
49 {
345293a [spec] S29-list/grep.t fixed adverbial closure test
moritz authored
50 my @result = @list.grep :{ ($_ % 2) };
53330f8 Test suite refactoring.
cosimo authored
51 is(+@result, 5, 'we got a list back');
52 is(@result[0], 1, 'got the value we expected');
53 is(@result[1], 3, 'got the value we expected');
54 is(@result[2], 5, 'got the value we expected');
55 is(@result[3], 7, 'got the value we expected');
56 is(@result[4], 9, 'got the value we expected');
57 }
58
0960758 Some updates to S29-list.
pmichaud authored
59 #?rakudo skip "closure as non-final argument"
53330f8 Test suite refactoring.
cosimo authored
60 {
61 my @result = grep { ($_ % 2) }: @list;
0960758 Some updates to S29-list.
pmichaud authored
62 is(+@result, 5, 'we got a list back');
63 is(@result[0], 1, 'got the value we expected');
64 is(@result[1], 3, 'got the value we expected');
65 is(@result[2], 5, 'got the value we expected');
66 is(@result[3], 7, 'got the value we expected');
67 is(@result[4], 9, 'got the value we expected');
53330f8 Test suite refactoring.
cosimo authored
68 }
69
70 {
a20c69c [t/spec/*.t] :todo whackage
lwall authored
71 #?pugs 2 todo 'bug'
5caad32 [t/spec]: Update map/grep/reduce/kv tests to work with scalar invoca…
pmichaud authored
72 is(42.grep({ 1 }), "42", "method form of grep works on numbers");
73 is('str'.grep({ 1 }), 'str', "method form of grep works on strings");
53330f8 Test suite refactoring.
cosimo authored
74 }
75
76 #
77 # Grep with mutating block
78 #
94ca56c [spec] removed "unspecced" marking of grep tests that mutate $_
moritz authored
79 # L<S02/Names/"$_, $!, and $/ are context<rw> by default">
53330f8 Test suite refactoring.
cosimo authored
80
81 {
82 my @array = <a b c d>;
dae7348 [t/spec]: Refudge test in S32-list/grep.t .
pmichaud authored
83 #?rakudo 2 skip 'test error -- is $_ rw here?'
84 is ~(@array.grep({ $_ ~= "c"; 1 })), "ac bc cc dc",
53330f8 Test suite refactoring.
cosimo authored
85 'mutating $_ in grep works (1)';
86 is ~@array, "ac bc cc dc",
87 'mutating $_ in grep works (2)';
88 }
89
5d12fd9 [t/spec] tests for last and next in grep
moritz authored
90 # grep with last, next etc.
91
92 {
93 is (1..16).grep({last if $_ % 5 == 0; $_ % 2 == 0}).join('|'),
94 '2|4', 'last works in grep';
95 is (1..12).grep({next if $_ % 5 == 0; $_ % 2 == 0}).join('|'),
96 '2|4|6|8|12', 'next works in grep';
97 }
98
5b7f1a9 [t/spec] grep with non-Code matcher
moritz authored
99 # since the test argument to .grep is a Matcher, we can also
100 # check type constraints:
101
102 {
103 is (2, [], 4, [], 5).grep(Int).join(','),
104 '2,4,5', ".grep with non-Code matcher";
105
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
122 done_testing;
123
5b7f1a9 [t/spec] grep with non-Code matcher
moritz authored
124 # vim: ft=perl6
Something went wrong with that request. Please try again.