public
Created

Test for bug with .slurp after .get

  • Download Gist
rakudo-slurp-bug.p6
Perl6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/env perl6
use Test;
plan 4;
 
my $temp-file = '/tmp/nulltest';
my $test-string = 'test line';
 
my $lines = 6;
shell "echo $test-string > $temp-file";
shell "echo $test-string >> $temp-file" for ^($lines - 1);
my $content-length = $lines * ($test-string ~ "\n").chars;
diag "Content-Length: $content-length";
 
given open $temp-file {
my @lines = .get xx ($lines - 1); # Leave one line
my $rest = .slurp;
 
is @lines[0], $test-string, 'First line read back correctly';
is @lines[*-1], $test-string, 'Penultimate line read back correctly';
is $rest.chars, ($test-string ~ "\n").chars, '.slurp on remaining content';
ok $rest !~~ /\x00+/, 'Slurped content has no null bytes';
}
 
unlink $temp-file;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.