Skip to content

Commit

Permalink
Add sub version of .head / .skip / .tail (#4973)
Browse files Browse the repository at this point in the history
As requested in Raku/problem-solving#328

There is one biggish issue with this, as the sub "skip" clashes with
the "skip" sub as exported by Test.  Fixed this by giving the version
of "skip" from Test its own proto.

Since we added 3 more subs to the core, these tests all needed to be
adapted as well.
  • Loading branch information
lizmat committed Jul 7, 2022
1 parent 6dc2f92 commit af31b1d
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/Test.rakumod
Expand Up @@ -400,12 +400,13 @@ multi sub todo($reason, $count = 1) is export {
$time_before = nqp::time;
}

proto sub skip(|) is export {*}
multi sub skip() {
$time_after = nqp::time;
proclaim(1, '', "# SKIP");
$time_before = nqp::time;
}
multi sub skip($reason, $count = 1) is export {
multi sub skip($reason, $count = 1) {
$time_after = nqp::time;
die "skip() was passed a non-integer number of tests. Did you get the arguments backwards or use a non-integer number?" if $count !~~ Int;
my $i = 1;
Expand Down
9 changes: 9 additions & 0 deletions src/core.c/Any-iterable-methods.pm6
Expand Up @@ -2624,6 +2624,15 @@ multi sub grep(Mu $test, +values, *%a) {
}
multi sub grep(Bool:D $t, |) { X::Match::Bool.new(:type<grep>).throw }

proto sub head(Mu, |) {*}
multi sub head($head, +values) { values.head($head) }

proto sub tail(Mu, |) {*}
multi sub tail($tail, +values) { values.tail($tail) }

proto sub skip(Mu, |) {*}
multi sub skip($skip, +values) { values.skip($skip) }

proto sub first(Mu, |) {*}
multi sub first(Bool:D $t, |) { X::Match::Bool.new(:type<first>).Failure }
multi sub first(Mu $test, +values, *%a) { values.first($test,|%a) }
Expand Down
3 changes: 3 additions & 0 deletions t/02-rakudo/03-corekeys-6c.t
Expand Up @@ -166,6 +166,7 @@ my @expected = (
Q{&goto},
Q{&grep},
Q{&hash},
Q{&head},
Q{&index},
Q{&indices},
Q{&indir},
Expand Down Expand Up @@ -423,6 +424,7 @@ my @expected = (
Q{&signal},
Q{&sin},
Q{&sinh},
Q{&skip},
Q{&sleep},
Q{&sleep-timer},
Q{&sleep-until},
Expand All @@ -443,6 +445,7 @@ my @expected = (
Q{&succeed},
Q{&sum},
Q{&symlink},
Q{&tail},
Q{&take},
Q{&take-rw},
Q{&tan},
Expand Down
3 changes: 3 additions & 0 deletions t/02-rakudo/03-corekeys-6d.t
Expand Up @@ -166,6 +166,7 @@ my @expected = (
Q{&goto},
Q{&grep},
Q{&hash},
Q{&head},
Q{&index},
Q{&indices},
Q{&indir},
Expand Down Expand Up @@ -423,6 +424,7 @@ my @expected = (
Q{&signal},
Q{&sin},
Q{&sinh},
Q{&skip},
Q{&sleep},
Q{&sleep-timer},
Q{&sleep-until},
Expand All @@ -443,6 +445,7 @@ my @expected = (
Q{&succeed},
Q{&sum},
Q{&symlink},
Q{&tail},
Q{&take},
Q{&take-rw},
Q{&tan},
Expand Down
3 changes: 3 additions & 0 deletions t/02-rakudo/03-corekeys-6e.t
Expand Up @@ -168,6 +168,7 @@ my @expected = (
Q{&goto},
Q{&grep},
Q{&hash},
Q{&head},
Q{&index},
Q{&indices},
Q{&indir},
Expand Down Expand Up @@ -426,6 +427,7 @@ my @expected = (
Q{&signal},
Q{&sin},
Q{&sinh},
Q{&skip},
Q{&sleep},
Q{&sleep-timer},
Q{&sleep-until},
Expand All @@ -446,6 +448,7 @@ my @expected = (
Q{&succeed},
Q{&sum},
Q{&symlink},
Q{&tail},
Q{&take},
Q{&take-rw},
Q{&tan},
Expand Down
3 changes: 3 additions & 0 deletions t/02-rakudo/03-corekeys.t
Expand Up @@ -169,6 +169,7 @@ my @allowed =
Q{&goto},
Q{&grep},
Q{&hash},
Q{&head},
Q{&index},
Q{&indices},
Q{&indir},
Expand Down Expand Up @@ -426,6 +427,7 @@ my @allowed =
Q{&signal},
Q{&sin},
Q{&sinh},
Q{&skip},
Q{&sleep},
Q{&sleep-timer},
Q{&sleep-until},
Expand All @@ -446,6 +448,7 @@ my @allowed =
Q{&succeed},
Q{&sum},
Q{&symlink},
Q{&tail},
Q{&take},
Q{&take-rw},
Q{&tan},
Expand Down
3 changes: 3 additions & 0 deletions t/02-rakudo/04-settingkeys-6c.t
Expand Up @@ -165,6 +165,7 @@ my %allowed = (
Q{&goto},
Q{&grep},
Q{&hash},
Q{&head},
Q{&index},
Q{&indices},
Q{&indir},
Expand Down Expand Up @@ -422,6 +423,7 @@ my %allowed = (
Q{&signal},
Q{&sin},
Q{&sinh},
Q{&skip},
Q{&sleep},
Q{&sleep-timer},
Q{&sleep-until},
Expand All @@ -442,6 +444,7 @@ my %allowed = (
Q{&succeed},
Q{&sum},
Q{&symlink},
Q{&tail},
Q{&take},
Q{&take-rw},
Q{&tan},
Expand Down
3 changes: 3 additions & 0 deletions t/02-rakudo/04-settingkeys-6e.t
Expand Up @@ -165,6 +165,7 @@ my %allowed = (
Q{&goto},
Q{&grep},
Q{&hash},
Q{&head},
Q{&index},
Q{&indices},
Q{&indir},
Expand Down Expand Up @@ -423,6 +424,7 @@ my %allowed = (
Q{&signal},
Q{&sin},
Q{&sinh},
Q{&skip},
Q{&sleep},
Q{&sleep-timer},
Q{&sleep-until},
Expand All @@ -443,6 +445,7 @@ my %allowed = (
Q{&succeed},
Q{&sum},
Q{&symlink},
Q{&tail},
Q{&take},
Q{&take-rw},
Q{&tan},
Expand Down
6 changes: 3 additions & 3 deletions t/02-rakudo/07-implementation-detail-6.c.t
Expand Up @@ -21,7 +21,7 @@ my @lower = ("",<<
chars chdir chmod chomp chop chr chrs cis classify close comb
combinations copy cos cosec cosech cosh cotan cotanh deepmap defined
die dir done duckmap elems emit end exit exp expmod fail fc first
flat flip floor full-barrier get getc gist goto grep hash index
flat flip floor full-barrier get getc gist goto grep hash head index
indices indir is-prime item join keys kv last lastcall lc leave
lines link list log log10 log2 lsb make map max min minmax mix
mkdir move msb next nextcallee nextsame nextwith nodemap none
Expand All @@ -30,9 +30,9 @@ my @lower = ("",<<
prompt push put rand redo reduce rename repeated repl return
return-rw reverse rindex rmdir roll roots rotate round roundrobin
run samecase samemark samewith say sec sech set shell shift sign
signal sin sinh sleep sleep-timer sleep-until slip slurp so sort
signal sin sinh skip sleep sleep-timer sleep-until slip slurp so sort
splice split sprintf spurt sqrt squish srand subbuf-rw substr
substr-rw succeed sum symlink take take-rw tan tanh tc tclc trim
substr-rw succeed sum symlink tail take take-rw tan tanh tc tclc trim
trim-leading trim-trailing truncate uc undefine unimatch uniname
uninames uniparse uniprop uniprops unique unival univals unlink
unpolar unshift val values warn wordcase words
Expand Down
6 changes: 3 additions & 3 deletions t/02-rakudo/07-implementation-detail-6.d.t
Expand Up @@ -21,7 +21,7 @@ my @lower = ("",<<
chars chdir chmod chomp chop chr chrs cis classify close comb
combinations copy cos cosec cosech cosh cotan cotanh deepmap defined
die dir done duckmap elems emit end exit exp expmod fail fc first
flat flip floor full-barrier get getc gist goto grep hash index
flat flip floor full-barrier get getc gist goto grep hash head index
indices indir is-prime item join keys kv last lastcall lc leave
lines link list log log10 log2 lsb make map max min minmax mix
mkdir move msb next nextcallee nextsame nextwith nodemap none
Expand All @@ -30,9 +30,9 @@ my @lower = ("",<<
prompt push put rand redo reduce rename repeated repl return
return-rw reverse rindex rmdir roll roots rotate round roundrobin
run samecase samemark samewith say sec sech set shell shift sign
signal sin sinh sleep sleep-timer sleep-until slip slurp so sort
signal sin sinh skip sleep sleep-timer sleep-until slip slurp so sort
splice split sprintf spurt sqrt squish srand subbuf-rw substr
substr-rw succeed sum symlink take take-rw tan tanh tc tclc trim
substr-rw succeed sum symlink tail take take-rw tan tanh tc tclc trim
trim-leading trim-trailing truncate uc undefine unimatch uniname
uninames uniparse uniprop uniprops unique unival univals unlink
unpolar unshift val values warn wordcase words
Expand Down
6 changes: 3 additions & 3 deletions t/02-rakudo/07-implementation-detail-6.e.t
Expand Up @@ -21,7 +21,7 @@ my @lower = ("",<<
chars chdir chmod chomp chop chr chrs cis classify close comb
combinations copy cos cosec cosech cosh cotan cotanh deepmap defined
die dir done duckmap elems emit end exit exp expmod fail fc first
flat flip floor full-barrier get getc gist goto grep hash index
flat flip floor full-barrier get getc gist goto grep hash head index
indices indir is-prime item join keys kv last lastcall lc leave
lines link list log log10 log2 lsb make map max min minmax mix
mkdir move msb next nextcallee nextsame nextwith nodemap none
Expand All @@ -30,9 +30,9 @@ my @lower = ("",<<
prompt push put rand redo reduce rename repeated repl return
return-rw reverse rotor rindex rmdir roll roots rotate round roundrobin
run samecase samemark samewith say sec sech set shell shift sign
signal sin sinh sleep sleep-timer sleep-until slip slurp so sort
signal sin sinh skip sleep sleep-timer sleep-until slip slurp so sort
splice split sprintf spurt sqrt squish srand subbuf-rw substr
substr-rw succeed sum symlink take take-rw tan tanh tc tclc trim
substr-rw succeed sum symlink tail take take-rw tan tanh tc tclc trim
trim-leading trim-trailing truncate uc unimatch uniname
uninames uniparse uniprop uniprops unique unival univals unlink
unpolar unshift val values warn wordcase words
Expand Down

0 comments on commit af31b1d

Please sign in to comment.