Skip to content

Commit b38cc69

Browse files
committed
Adapt last-index tests to first(:end,:k) tests
1 parent 50b91ec commit b38cc69

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

S32-list/first-end-k.t

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
11
use v6;
22
use Test;
33

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

66
plan 25;
77

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

1010
{
11-
my $result = last-index { $^a % 2 }, |@list;
12-
ok($result ~~ Int, "last-index() returns an Int");
13-
is($result, 8, "returned value by last-index() is correct");
11+
my $result = first { $^a % 2 }, |@list, :end, :k;
12+
ok($result ~~ Int, "first(, :end, :k) returns an Int");
13+
is($result, 8, "returned value by first() is correct");
1414
}
1515

1616
{
17-
my $result = last-index { $^a % 2 }, 1, 2, 3, 4, 5, 6, 7, 8;
18-
ok($result ~~ Int, "last-index() returns an Int");
19-
is($result, 6, "returned value by last-index() is correct");
17+
my $result = first { $^a % 2 }, 1, 2, 3, 4, 5, 6, 7, 8, :end, :k;
18+
ok($result ~~ Int, "first(, :end, :k) returns an Int");
19+
is($result, 6, "returned value by first(, :end, :k) is correct");
2020
}
2121

2222

2323
{
24-
my $result = @list.last-index( { $^a == 4} );
25-
ok($result ~~ Int, "method form of last-index returns an Int");
26-
is($result, 3, "method form of last-index returns the expected item");
24+
my $result = @list.first( { $^a == 4}, :end, :k );
25+
ok($result ~~ Int, "method form of first, :end, :k returns an Int");
26+
is($result, 3, "method form of first, :end, :k returns the expected item");
2727
}
2828

2929
#?rakudo skip "adverbial block RT #124754"
3030
#?niecza skip 'No value for parameter Mu $filter in CORE Any.first'
3131
{
32-
my $result = @list.last-index():{ $^a == 4 };
33-
ok($result ~~ Int, "last-index():<block> returns an Int");
34-
is($result, 3, "last-index() returned the expected value");
32+
my $result = @list.first():{ $^a == 4 }, :end, :k;
33+
ok($result ~~ Int, "first(, :end, :k):<block> returns an Int");
34+
is($result, 3, "first(, :end, :k) returned the expected value");
3535
}
3636

3737
{
38-
ok @list.last-index( { $^a == 11 } ) =:= Nil, 'last-index returns Nil on unsuccessful match';
38+
ok @list.first( { $^a == 11 }, :end, :k ) =:= Nil, 'first, :end, :k returns Nil on unsuccessful match';
3939
}
4040

4141
{
4242
my $count = 0;
4343
my $matcher = sub (Int $x) { $count++; $x % 2 };
44-
is @list.last-index($matcher), 8, 'last-index() search for odd elements successful';
45-
is $count, 2, 'Matching closure in last-index() is only executed twice';
44+
is @list.first($matcher, :end, :k), 8, 'first(, :end, :k) search for odd elements successful';
45+
is $count, 2, 'Matching closure in first(, :end, :k) is only executed twice';
4646
}
4747

4848
{
49-
is(@list.last-index(4..6), 5, "method form of last-index with range returns the expected item");
50-
is(@list.last-index(4..^6), 4, "method form of last-index with range returns the expected item");
49+
is(@list.first(4..6, :end, :k), 5, "method form of first, :end, :k with range returns the expected item");
50+
is(@list.first(4..^6, :end, :k), 4, "method form of first, :end, :k with range returns the expected item");
5151
}
5252

5353
{
5454
my @fancy_list = (1, 2, "Hello", 3/4, 4.Num);
55-
is @fancy_list.last-index(Str), 2, "last-index by type Str works";
56-
is @fancy_list.last-index(Int), 1, "last-index by type Int works";
57-
is @fancy_list.last-index(Rat), 3, "last-index by type Rat works";
55+
is @fancy_list.first(Str, :end, :k), 2, "first by type Str works";
56+
is @fancy_list.first(Int, :end, :k), 1, "first by type Int works";
57+
is @fancy_list.first(Rat, :end, :k), 3, "first by type Rat works";
5858
}
5959

6060
{
6161
my @fancy_list = <Philosopher Goblet Prince>;
62-
is @fancy_list.last-index(/o/), 1, "last-index by regex /o/";
63-
is @fancy_list.last-index(/ob/), 1, "last-index by regex /ob/";
64-
is @fancy_list.last-index(/l.*o/), 0, "last-index by regex /l.*o/";
62+
is @fancy_list.first(/o/, :end, :k), 1, "first by regex /o/";
63+
is @fancy_list.first(/ob/, :end, :k), 1, "first by regex /ob/";
64+
is @fancy_list.first(/l.*o/, :end, :k), 0, "first by regex /l.*o/";
6565
}
6666

6767
{
68-
is <a b c b a>.last-index('c' | 'b'),
69-
3, '.last-index also takes a junction as matcher';
68+
is <a b c b a>.first('c' | 'b', :end, :k),
69+
3, '.first, :end, :k also takes a junction as matcher';
7070

71-
is (last-index 'c'|'b', <a b c b a>),
72-
3, '.last-index also takes a junction as matcher (sub form)';
71+
is (first 'c'|'b', <a b c b a>, :end, :k),
72+
3, '.first, :end, :k also takes a junction as matcher (sub form)';
7373
}
7474

7575
# Bool handling
7676
{
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';
77+
throws-like { first $_ == 1, 1,2,3, :end, :k }, X::Match::Bool;
78+
throws-like { (1,2,3).first: $_== 1, :end, :k }, X::Match::Bool;
79+
is first( Bool,True,False,Int, :end, :k ), 1, 'can we match on Bool as type';
80+
is (True,False,Int).first(Bool, :end, :k), 1, 'can we match on Bool as type';
8181
}
8282

8383
#vim: ft=perl6

0 commit comments

Comments
 (0)