Skip to content

Commit dc3cd07

Browse files
committed
CI test prior to release
1 parent 3cabd31 commit dc3cd07

File tree

8 files changed

+86
-25
lines changed

8 files changed

+86
-25
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Revision history for String-Utils
22

33
{{$NEXT}}
4+
- Added support for "text-from-url"
5+
- Tightened up coverage testing to 96%
46

57
0.0.34 2025-07-23T12:51:51+02:00
68
- Ordered code alphabetically for better maintainability

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ say sha1("foo bar baz"; # C7567E8B39E...
7979
say stem "foo.tar.gz"; # foo
8080
say stem "foo.tar.gz", 1; # foo.tar
8181

82+
say text-from-url $url, :verbose; # ...
83+
8284
dd trailing-whitespace("bar \t "); # " \t "
8385

8486
say word-at("foo bar baz", 5); # (4 3 1)
@@ -454,6 +456,17 @@ say stem "foo.tar.gz", *; # foo
454456

455457
Return the stem of a string with all of its extensions removed. Optionally accepts a second argument indicating the number of extensions to be removed. This may be `*` (aka `Whatever`) to indicate to remove all extensions.
456458

459+
text-from-url
460+
-------------
461+
462+
```raku
463+
my $text = text-from-url $url, :verbose;
464+
```
465+
466+
Returns the text found at the given URL, or `Nil` if the fetch of the text failed for some reason. Takes an optional `:verbose` named argument: if specified with a trueish value, will show any error output that was received on `STDERR`: defaults to False, to quietly just return `Nil` on error.
467+
468+
Assumes the `curl` command-line program is installed and a network connection is available.
469+
457470
trailing-whitespace
458471
-------------------
459472

doc/String-Utils.rakudoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ say sha1("foo bar baz"; # C7567E8B39E...
7777
say stem "foo.tar.gz"; # foo
7878
say stem "foo.tar.gz", 1; # foo.tar
7979

80+
say text-from-url $url, :verbose; # ...
81+
8082
dd trailing-whitespace("bar \t "); # " \t "
8183

8284
say word-at("foo bar baz", 5); # (4 3 1)
@@ -477,6 +479,21 @@ Optionally accepts a second argument indicating the number of extensions
477479
to be removed. This may be C<*> (aka C<Whatever>) to indicate to
478480
remove all extensions.
479481

482+
=head2 text-from-url
483+
484+
=begin code :lang<raku>
485+
my $text = text-from-url $url, :verbose;
486+
=end code
487+
488+
Returns the text found at the given URL, or C<Nil> if the fetch of the
489+
text failed for some reason. Takes an optional C<:verbose> named
490+
argument: if specified with a trueish value, will show any error output
491+
that was received on C<STDERR>: defaults to False, to quietly just
492+
return C<Nil> on error.
493+
494+
Assumes the C<curl> command-line program is installed and a network
495+
connection is available.
496+
480497
=head2 trailing-whitespace
481498

482499
=begin code :lang<raku>

lib/String/Utils.rakumod

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ my sub expand-tab(str $spec, int $size) {
184184
nqp::islt_i(++$i,$end),
185185
nqp::stmts(
186186
(my str $part = nqp::atpos_s(@parts,$i)),
187-
($width = $width + nqp::chars($part)),
188-
(my int $add = $size - nqp::mod_i($width,$size)),
189-
nqp::bindpos_s(@parts,$i,nqp::concat($part,nqp::x(' ',$add))),
190-
($width = $width + $add)
187+
($width = $width + nqp::chars($part)), # UNCOVERABLE
188+
(my int $add = $size - nqp::mod_i($width,$size)), # UNCOVERABLE
189+
nqp::bindpos_s(@parts,$i,nqp::concat($part,nqp::x(' ',$add))), # UNCOVERABLE
190+
($width = $width + $add) # UNCOVERABLE
191191
)
192192
);
193193
nqp::join('',@parts)
@@ -218,7 +218,7 @@ my sub is-sha1(str $needle) {
218218
if nqp::chars($needle) == 40 {
219219
my $map := BEGIN {
220220
my int @map;
221-
@map[.ord] = 1 for "0123456789ABCDEF".comb;
221+
@map[.ord] = 1 for "0123456789ABCDEF".comb; # UNCOVERABLE
222222
@map;
223223
}
224224

@@ -243,7 +243,7 @@ my sub is-whitespace(str $string) {
243243
}
244244

245245
#- leading-whitespace ----------------------------------------------------------
246-
my sub leading-whitespace(str $string) {
246+
my sub leading-whitespace(str $string) { # UNCOVERABLE
247247
nqp::substr($string,0,nqp::findnotcclass(
248248
nqp::const::CCLASS_WHITESPACE,$string,0,nqp::chars($string)
249249
))
@@ -322,17 +322,17 @@ my class NGrams does PredictiveIterator {
322322
has int $!pos;
323323
has int $!todo;
324324
method !SET-SELF($string, $size, $limit, $step, $partial) {
325-
$!str = $string;
325+
$!str = $string; # UNCOVERABLE
326326
$!what := $string.WHAT;
327327
$!size = $size < 1 ?? 1 !! $size;
328328
$!step = $step < 1 ?? 1 !! $step;
329329
$!pos = -$step;
330-
$!todo = (
330+
$!todo = ( # UNCOVERABLE
331331
nqp::chars($!str) + $!step - ($partial ?? 1 !! $!size)
332332
) div $!step;
333333
$!todo = $limit
334334
unless nqp::istype($limit,Whatever) || $limit > $!todo;
335-
$!todo = $!todo + 1;
335+
$!todo = $!todo + 1; # UNCOVERABLE
336336
self
337337
}
338338
method new($string, $size, $limit, $step, $partial) {
@@ -341,7 +341,7 @@ my class NGrams does PredictiveIterator {
341341
!! Rakudo::Iterator.Empty
342342
}
343343
method pull-one() {
344-
--$!todo
344+
--$!todo # UNCOVERABLE
345345
?? nqp::box_s(
346346
nqp::substr($!str,($!pos = $!pos + $!step),$!size),
347347
$!what
@@ -430,7 +430,7 @@ my sub nomark(str $string) {
430430
}
431431

432432
#- non-word --------------------------------------------------------------------
433-
my sub non-word(str $string) {
433+
my sub non-word(str $string) { # UNCOVERABLE
434434
nqp::hllbool(
435435
nqp::islt_i(
436436
nqp::findnotcclass(
@@ -475,8 +475,8 @@ my multi sub paragraphs(@source, Int:D $initial = 0, :$Pair = Pair) {
475475
}
476476

477477
my sub paragraph(str $next) {
478-
$!line = $line;
479-
$!next = $next;
478+
$!line = $line; # UNCOVERABLE
479+
$!next = $next; # UNCOVERABLE
480480

481481
$!Pair.new(
482482
$line - nqp::elems($collected),
@@ -506,14 +506,14 @@ my multi sub paragraphs(@source, Int:D $initial = 0, :$Pair = Pair) {
506506

507507
# Single line after last paraghraph
508508
if $!next {
509-
$!iterator := nqp::null;
509+
$!iterator := nqp::null; # UNCOVERABLE
510510
$!next
511511
}
512512

513513
# Still need to produce final paragraph
514-
elsif nqp::elems($collected) {
515-
$!iterator := nqp::null;
516-
++$line;
514+
elsif nqp::elems($collected) { # UNCOVERABLE
515+
$!iterator := nqp::null; # UNCOVERABLE
516+
++$line; # UNCOVERABLE
517517
paragraph("")
518518
}
519519

@@ -580,7 +580,7 @@ my sub root(*@s) {
580580
}
581581

582582
#- sha1 ------------------------------------------------------------------------
583-
my sub sha1(str $needle) { nqp::sha1($needle) }
583+
my sub sha1(str $needle) { nqp::sha1($needle) } # UNCOVERABLE
584584

585585
#- stem ------------------------------------------------------------------------
586586
my sub stem(str $basename, $parts = *) {
@@ -595,6 +595,18 @@ my sub stem(str $basename, $parts = *) {
595595
!! $basename
596596
}
597597

598+
#- text-from-url ---------------------------------------------------------------
599+
my sub text-from-url(str $url, :$verbose) {
600+
my $proc := run 'curl', '--fail', $url, :out, :err ;
601+
if $proc.exitcode {
602+
$*ERR.put: $proc.err.slurp if $verbose;
603+
Nil
604+
}
605+
else {
606+
$proc.out.slurp
607+
}
608+
}
609+
598610
#- trailing-whitespace ---------------------------------------------------------
599611
my sub trailing-whitespace(str $string) {
600612
nqp::substr($string,nqp::chars($string) - nqp::findnotcclass(
@@ -619,7 +631,7 @@ my sub word-at(str $string, int $cursor) {
619631
)) < $cursor,
620632
nqp::stmts(
621633
nqp::if($pos > $last, ++$index),
622-
($last = $pos + 1)
634+
($last = $pos + 1) # UNCOVERABLE
623635
)
624636
);
625637
$last >= $length || $pos == $last

t/01-basic.rakutest

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

4-
plan 115;
4+
plan 117;
55

66
is after("foobar","foo"), "bar", 'after(foo) ok?';
77
is "foobar".&after("foo"), "bar", '.&after(foo) ok?';
@@ -137,8 +137,11 @@ is-deeply word-at($string, $_), ( 1,3,0), "'foo' at $_" for 1 .. 4;
137137
is-deeply word-at($string, $_), ( 6,3,1), "'bar' at $_" for 6 .. 9;
138138
is-deeply word-at($string, $_), (10,3,2), "'baz' at $_" for 10 .. 13;
139139

140-
is-deeply abbrev(<yes no>), <n no no no y yes ye yes yes yes>.Map,
141-
"did yes/no abbreviate correctly";
140+
is-deeply abbrev(), Map.new, 'No arguments give an empty Map';
141+
for \(<yes no>), \("yes","no") -> \c {
142+
is-deeply abbrev(|c), <n no no no y yes ye yes yes yes>.Map,
143+
"did yes/no abbreviate correctly";
144+
}
142145
is-deeply abbrev(<foo bar baz>), <bar bar baz baz f foo fo foo foo foo>.Map,
143146
"did foo/bar/baz abbreviate correctly";
144147

t/02-selective-importing.rakutest

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ my constant @subs = <
44
abbrev after all-same around before between between-included
55
chomp-needle consists-of expand-tab has-marks is-lowercase is-sha1
66
is-uppercase is-whitespace leading-whitespace leaf letters ngram
7-
non-word regexify root sha1 stem trailing-whitespace word-at
7+
non-word regexify root sha1 stem text-from-url trailing-whitespace
8+
word-at
89
>;
910

1011
plan @subs + 2;

xt/coverage.rakutest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use Test::Coverage;
22

33
plan 2;
44

5-
coverage-at-least 79;
5+
coverage-at-least 96;
66

7-
uncovered-at-most 24;
7+
uncovered-at-most 4;
88

99
report;
1010

xt/networked.rakutest

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use Test;
2+
3+
use String::Utils;
4+
5+
plan 2;
6+
7+
my $url := "https://360.zef.pm";
8+
9+
ok text-from-url($url).chars >= 7480122, 'looks like a correct zef index';
10+
11+
is-deeply text-from-url($url.chop), Nil, 'did we get a failure';
12+
13+
# vim: expandtab shiftwidth=4

0 commit comments

Comments
 (0)