Skip to content

Commit 4b608e7

Browse files
committed
Add tests for Bool Matchers
1 parent 750b9da commit 4b608e7

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

S32-list/first-index.t

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use Test;
33

44
# L<S32::Containers/"List"/"=item first-index">
55

6-
plan 21;
6+
plan 25;
77

88
my @list = (1 ... 10);
99

@@ -72,4 +72,12 @@ my @list = (1 ... 10);
7272
1, '.first-index also takes a junction as matcher (sub form)';
7373
}
7474

75+
# Bool handling
76+
{
77+
throws_like { first-index $_ == 1, 1,2,3 }, X::Match::Bool;
78+
throws_like { (1,2,3).first-index: $_== 1 }, X::Match::Bool;
79+
is first-index( Bool,True,False,Int ), 0, 'can we match on Bool as type';
80+
is (True,False,Int).first-index(Bool), 0, 'can we match on Bool as type';
81+
}
82+
7583
#vim: ft=perl6

S32-list/first.t

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use Test;
33

44
# L<S32::Containers/"List"/"=item first">
55

6-
plan 23;
6+
plan 27;
77

88
my @list = (1 ... 10);
99

@@ -79,4 +79,12 @@ my @list = (1 ... 10);
7979
isa_ok @list.first(* < 0 ), Nil, ".first returns Nil when no values match"
8080
}
8181

82+
# Bool handling
83+
{
84+
throws_like { first $_ == 1, 1,2,3 }, X::Match::Bool;
85+
throws_like { (1,2,3).first: $_== 1 }, X::Match::Bool;
86+
is first( Bool,True,False,Int ), True, 'can we match on Bool as type';
87+
is (True,False,Int).first(Bool), True, 'can we match on Bool as type';
88+
}
89+
8290
#vim: ft=perl6

S32-list/grep-index.t

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use Test;
33

44
# L<S32::Containers/"List"/"=item grep-index">
55

6-
plan 35;
6+
plan 39;
77

88
my @list = (1 .. 10);
99

@@ -76,15 +76,15 @@ is_deeply @list.grep-index( { ($_ % 2) } ), (0,2,4,6,8).list.item,
7676
'mutating $_ in grep-index works (2)';
7777
}
7878

79-
# grep with last, next etc.
79+
# grep-index with last, next etc.
8080
{
8181
is_deeply (1..16).grep-index({last if $_ % 5 == 0; $_ % 2 == 0}),
8282
(1,3).list.item, 'last works in grep-index';
8383
is_deeply (1..12).grep-index({next if $_ % 5 == 0; $_ % 2 == 0}),
8484
(1,3,5,7,11).list.item, 'next works in grep-index';
8585
}
8686

87-
# since the test argument to .grep is a Matcher, we can also
87+
# since the test argument to .grep-index is a Matcher, we can also
8888
# check type constraints:
8989
{
9090
is_deeply (2, [], 4, [], 5).grep-index(Int),
@@ -101,4 +101,12 @@ is_deeply @list.grep-index( { ($_ % 2) } ), (0,2,4,6,8).list.item,
101101

102102
}
103103

104+
# Bool handling
105+
{
106+
throws_like { grep-index $_ == 1, 1,2,3 }, X::Match::Bool;
107+
throws_like { (1,2,3).grep-index: $_== 1 }, X::Match::Bool;
108+
is grep-index( Bool,True,False,Int ), (0,1), 'can we match on Bool as type';
109+
is (True,False,Int).grep-index(Bool), (0,1), 'can we match on Bool as type';
110+
}
111+
104112
# vim: ft=perl6

S32-list/grep.t

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ built-in grep tests
99
1010
=end pod
1111

12-
plan 38;
12+
plan 42;
1313

1414
my @list = (1 .. 10);
1515

@@ -129,6 +129,12 @@ my @list = (1 .. 10);
129129
is ~(1...100).grep(* %% 2).grep(* %% 3), ~(6, 12 ... 96), "chained greps work";
130130
}
131131

132-
done;
132+
# Bool handling
133+
{
134+
throws_like { grep $_ == 1, 1,2,3 }, X::Match::Bool;
135+
throws_like { (1,2,3).grep: $_== 1 }, X::Match::Bool;
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+
}
133139

134140
# vim: ft=perl6

S32-list/last-index.t

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use Test;
33

44
# L<S32::Containers/"List"/"=item last-index">
55

6-
plan 21;
6+
plan 25;
77

88
my @list = (1 ... 10);
99

@@ -72,4 +72,12 @@ my @list = (1 ... 10);
7272
3, '.last-index also takes a junction as matcher (sub form)';
7373
}
7474

75+
# Bool handling
76+
{
77+
throws_like { last-index $_ == 1, 1,2,3 }, X::Match::Bool;
78+
throws_like { (1,2,3).last-index: $_== 1 }, X::Match::Bool;
79+
is last-index( Bool,True,False,Int ), 1, 'can we match on Bool as type';
80+
is (True,False,Int).last-index(Bool), 1, 'can we match on Bool as type';
81+
}
82+
7583
#vim: ft=perl6

0 commit comments

Comments
 (0)