|
1 | 1 | use v6;
|
| 2 | +use lib <t/spec/packages>; |
2 | 3 | use Test;
|
| 4 | +use Test::Util; |
3 | 5 |
|
4 |
| -plan 62; |
| 6 | +plan 63; |
5 | 7 |
|
6 | 8 | my \PATH = 't-S32-io-open.tmp';
|
7 | 9 | my \PATH-RX = rx/'t-S32-io-open.tmp'/;
|
@@ -345,4 +347,37 @@ LEAVE unlink PATH;
|
345 | 347 | }
|
346 | 348 | }
|
347 | 349 |
|
| 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 | + |
348 | 383 | # vim: ft=perl6
|
0 commit comments