Skip to content

Commit e82b798

Browse files
committed
[io grant] Test IO::Handle.open respects attributes
Rakudo fix: rakudo/rakudo@95e49dcbe2
1 parent bfca66b commit e82b798

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

S32-io/open.t

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use v6;
2+
use lib <t/spec/packages>;
23
use Test;
4+
use Test::Util;
35

4-
plan 62;
6+
plan 63;
57

68
my \PATH = 't-S32-io-open.tmp';
79
my \PATH-RX = rx/'t-S32-io-open.tmp'/;
@@ -345,4 +347,37 @@ LEAVE unlink PATH;
345347
}
346348
}
347349

350+
subtest '.open uses attributes by default' => {
351+
plan 8;
352+
my $content = "1foo2\nfoo3";
353+
my $path = make-temp-file :$content;
354+
my $fh = IO::Handle.new: :$path,
355+
:nl-in<foo>, :nl-out<meow>, :encoding<bin>, :!chomp;
356+
$fh .= open: :rw;
357+
is-deeply $fh.nl-in, 'foo', '.nl-in remains same after open';
358+
is-deeply $fh.nl-out, 'meow', '.nl-out remains same after open';
359+
is-deeply $fh.encoding, 'bin', '.encoding remains same after open';
360+
is-deeply $fh.chomp, False, '.chomp remains same after open';
361+
362+
is-deeply $fh.slurp, Buf[uint8].new($content.encode),
363+
'.encoding is respected';
364+
$fh.close;
365+
366+
# XXX TODO 6.d: we have an inconsistency between, say, .encoding and .nl-in
367+
# the former takes new value as an arg, but the latter returns a Proxy and
368+
# can be assigned to
369+
$fh.encoding('utf8');
370+
$fh .= open: :rw;
371+
is-deeply $fh.lines.join, $content, '.chomp is respected';
372+
373+
$fh.say: "hello world";
374+
$fh.close;
375+
is-deeply $path.slurp, $content ~ "hello worldmeow", '.nl-out is respected';
376+
377+
$fh.chomp = True; # set chomp back on to test .nl-in;
378+
$fh .= open: :rw;
379+
is-deeply $fh.lines.join, "12\n3hello worldmeow", '.nl-in is respected';
380+
$fh.close;
381+
}
382+
348383
# vim: ft=perl6

0 commit comments

Comments
 (0)