Skip to content

Commit

Permalink
Merge pull request #417 from tbrowder/spew2spurt
Browse files Browse the repository at this point in the history
rename IO sub "spew" to "spurt"
  • Loading branch information
jnthn committed Feb 21, 2018
2 parents b57d933 + bf60675 commit cb4297b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
12 changes: 6 additions & 6 deletions docs/built-ins.md
Expand Up @@ -41,8 +41,8 @@ Close the file attached to file handle `$fh`.

Returns the contents of `$filename` as a single string.

## spew
* `spew($filename, $contents)`
## spurt
* `spurt($filename, $contents)`

Write the string value of `$contents` to `$filename`.

Expand Down Expand Up @@ -87,18 +87,18 @@ Returns a file handle to `stderr`.
Some methods available on the file handle (fh) returned from `open`.
Other methods available of lesser interest not documented below are:
+ flush
+ get
+ seek
+ set-encoding
+ set-nl-in
+ slurp
+ t
+ tell
+ wrap

## fh.slurp
* `$fh.slurp()`
## fh.get
* `$fh.get()`

Reads the entire file attached to file handle `$fh`.
Reads a line from the file attached to file handle `$fh`.

## fh.print
* `$fh.print($string)`
Expand Down
4 changes: 2 additions & 2 deletions src/core/IO.nqp
Expand Up @@ -262,11 +262,11 @@ sub slurp ($filename) {
$contents
}

=begin item spew
=begin item spurt
Write the string value of C<$contents> to C<$filename>.
=end item

sub spew($filename, $contents) {
sub spurt($filename, $contents) {
my $handle := open($filename, :w);
$handle.print($contents);
$handle.close;
Expand Down
12 changes: 11 additions & 1 deletion t/nqp/019-file-ops.t
Expand Up @@ -2,7 +2,7 @@

# Test nqp::op file operations.

plan(107);
plan(109);

ok( nqp::stat('CREDITS', nqp::const::STAT_EXISTS) == 1, 'nqp::stat exists');
ok( nqp::stat('AARDVARKS', nqp::const::STAT_EXISTS) == 0, 'nqp::stat not exists');
Expand Down Expand Up @@ -466,3 +466,13 @@ my sub create_buf($type) {
nqp::unlink($dir ~ '/file2');
nqp::rmdir($dir);
}

# test spurt
{
my $s := "line 1\nline 2";
spurt($test-file, $s);
my $fh := open($test-file);
is($fh.get(), 'line 1', 'read from spurted line 1 ok');
is($fh.get(), 'line 2', 'read from spurted line 2 ok');
nqp::unlink($test-file);
}

0 comments on commit cb4297b

Please sign in to comment.