Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start spec of IO::Handle.READ/.WRITE/.EOF
Blocked by R#2039 rakudo/rakudo#2039
as without explicitly calling .encoding on handle creation
the character read/write methods explode.
  • Loading branch information
zoffixznet committed Jul 9, 2018
1 parent ea5ed9d commit 3cefe0d
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion S32-io/io-handle.t
Expand Up @@ -3,7 +3,7 @@ use lib $?FILE.IO.parent(2).add("packages");
use Test;
use Test::Util;

plan 29;
plan 30;

my $path = "io-handle-testfile";

Expand Down Expand Up @@ -286,3 +286,43 @@ subtest 'opened filehandles get closed on exit automatically' => {
is-deeply my class Z is IO::Handle { }.new.nl-in, $[\n, \r\n],
.nl-in in subclasses has \n and \r\n;
}

subtest '.WRITE method' => {
my $fh := my class MyHandle is IO::Handle {
has Buf[uint8] $.data .= new;
submethod TWEAK { self.encoding: 'utf8' }
method WRITE (Blob:D \data --> True) { $!data.append: data }
}.new;

$fh.print: 'print ';
$fh.printf: 'pri%s', 'ntf ';
$fh.put: 'put';
$fh.say: my class { method gist { 'say' } }.new;
$fh.spurt: 'spurt text ';
$fh.spurt: 'spurt bin '.encode;
$fh.write: 'write'.encode;
$fh.print-nl;

is $fh.data.decode, "print printf put\nsay\nspurt text spurt bin write\n",
'all writing methods work';
}

subtest '.EOF method' => {
my $fh := my class MyHandle is IO::Handle {
has Buf[uint8] $.data .= new;
submethod TWEAK { self.encoding: 'utf8' }
method WRITE (Blob:D \data --> True) { $!data.append: data }
}.new;

$fh.print: 'print ';
$fh.printf: 'pri%s', 'ntf ';
$fh.put: 'put';
$fh.say: my class { method gist { 'say' } }.new;
$fh.spurt: 'spurt text ';
$fh.spurt: 'spurt bin '.encode;
$fh.write: 'write'.encode;
$fh.print-nl;

is $fh.data.decode, "print printf put\nsay\nspurt text spurt bin write\n",
'all writing methods work';
}

0 comments on commit 3cefe0d

Please sign in to comment.