Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle IO::Handle.ins deprecation
  • Loading branch information
lizmat committed Nov 14, 2015
1 parent 528a22b commit 3f3e870
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 44 deletions.
36 changes: 1 addition & 35 deletions S16-filehandles/io.t
Expand Up @@ -15,7 +15,7 @@ I/O tests
=end pod

plan 125;
plan 111;

sub nonce () { return ".{$*PID}." ~ (1..1000).pick() }
my $filename = 'tempfile_filehandles_io' ~ nonce();
Expand All @@ -37,16 +37,10 @@ my $in1 = open($filename);
isa-ok($in1, IO::Handle);
my $line1a = get($in1);
is($line1a, "Hello World", 'get($in) worked (and autochomps)');
#?niecza skip 'IO.ins NYI'
is $in1.ins, 1, 'read one line (.ins)';
my $line1b = get($in1);
is($line1b, "Foo Bar Baz", 'get($in) worked (and autochomps)');
#?niecza skip 'IO.ins NYI'
is $in1.ins, 2, 'read two lines (.ins)';
my $line1c = get($in1);
is($line1c, "The End", 'get($in) worked');
#?niecza skip 'IO.ins NYI'
is $in1.ins, 3, 'read three lines (.ins)';
ok($in1.close, 'file closed okay (1)');

my $in2 = open($filename);
Expand Down Expand Up @@ -89,8 +83,6 @@ my $in4 = open($filename);
isa-ok($in4, IO::Handle);
my @lines4 = lines($in4);
is(+@lines4, 4, 'we got four lines from the file');
#?niecza skip 'IO.ins NYI'
is $in4.ins, 4, 'same with .ins';
is(@lines4[0], "Hello World", 'lines($in) worked in list context');
is(@lines4[1], "Foo Bar Baz", 'lines($in) worked in list context');
is(@lines4[2], "The End", 'lines($in) worked in list context');
Expand All @@ -104,8 +96,6 @@ my $in5 = open($filename);
isa-ok($in5, IO::Handle);
my @lines5 = lines($in5, 3);
is(+@lines5, 3, 'we got two lines from the file');
#?niecza skip 'IO.ins NYI'
is $in5.ins, 3, 'same with .ins';
is(@lines5[0], "Hello World", 'lines($in) worked in list context');
is(@lines5[1], "Foo Bar Baz", 'lines($in) worked in list context');
is(@lines5[2], "The End", 'lines($in) worked in list context');
Expand Down Expand Up @@ -149,19 +139,6 @@ is(@lines8[1], "Foo Bar Baz", 'lines($in,3) worked in list context');
is(@lines8[2], "The End", 'lines($in,3) worked in list context');
is(@lines8[3], "and finally... Its not over yet!", 'get($in) worked after lines($in,$n)');
}
{
# test if reading a file with lines() is really lazy
my $in9 = open($filename);
#?niecza skip 'open does not yet produce an IO object'
isa-ok($in9, IO::Handle);
my $lines9 := $in9.lines;
is($in9.ins, 0);
for ^4 {
$lines9[$_];
is($in9.ins, $_ + 1);
}
$in9.close;
}

{
# Test $fh.lines(*) RT #125626
Expand Down Expand Up @@ -376,15 +353,4 @@ unlink($filename);
dies-ok { open('t').get(1) }, '.get on a directory fails';
}

# RT #113100
{
my %r;
%r = get_out(q[for lines() { say $*IN.ins }], "one\ntwo");
is %r<out>, "1\n2\n", "\$*IN.ins gets the right line numbers";
%r = get_out(q[say $*IN.ins], "one\ntwo\nthree", :compiler-args(["-n"]));
is %r<out>, "1\n2\n3\n", "\$*IN.ins gets the right line numbers";
%r = get_out(q[say $*IN.ins], "one\ntwo\nthree\nfour", :args(['-']), :compiler-args(["-n"]));
is %r<out>, "1\n2\n3\n4\n", "\$*IN.ins gets the right line numbers";
}

# vim: ft=perl6
7 changes: 3 additions & 4 deletions S16-filehandles/io_in_for_loops.t
Expand Up @@ -5,7 +5,7 @@ use Test;
# old: L<S16/"Filehandles, files, and directories"/"open">
# old: L<S16/"Filehandles, files, and directories"/"close">

plan 33;
plan 32;

my $filename = 'tempfile_io_in_for_loop';

Expand Down Expand Up @@ -100,12 +100,11 @@ my $filename = 'tempfile_io_in_for_loop';
my $ok-tell = 2|3;

my $fh = open($filename);
for $fh.lines() {
is $fh.ins, 1, "\$fh.lines loop sets .ins";
for $fh.lines.kv -> \k, \v {
is k, 0, "\$fh.lines.kv works";
is $fh.tell, $ok-tell, "\$fh.lines loop sets .tell";
last;
}
is $fh.ins, 1, "last in loop leaves .ins at the same place";
is $fh.tell, $ok-tell, "last in loop leaves .tell at the same place";
$fh.close();
}
Expand Down
7 changes: 2 additions & 5 deletions S16-io/lines.t
Expand Up @@ -10,7 +10,7 @@ my @endings =
("\n","\r\n","\r") => "multi",
;

plan @endings * (1 + 3 * ( (3 * 7) + 7));
plan @endings * (1 + 3 * ( (3 * 5) + 6));

my $filename = 't/spec/S16-io/lines.testing';
my @text = <zero one two three four>;
Expand All @@ -31,17 +31,15 @@ for @endings -> (:key($eol), :value($EOL)) {
my $status = OUTER::<$status> ~ " / {$open ?? 'open' !! 'close'}";

my $first;
for $handle.lines -> $line {
for $handle.lines(|$closing) -> $line {
is $line,"@text[0]$end[0]", "read first line: $status";
$first = $line;
last;
}

is $handle.ins, 1, "read one line: $status";
my @lines = $first, |$handle.lines(|$closing);
is @lines.join, @text.join($end[0]), "rest of file: $status";

is $handle.ins, ($open ?? 5 !! 1), "read five lines: $status";
is $handle.opened, $open, "handle still open: $status";
ok $handle.close, "closed handle: $status";
}
Expand All @@ -53,7 +51,6 @@ for @endings -> (:key($eol), :value($EOL)) {
my @lines = $handle.lines[1,2];
is @lines.join, @text[1,2].join($end[0]) ~ $end[0],
"handle 1,2: $status";
is $handle.ins, 3, "handle read three lines: $status";

is $handle.lines[*-1], @text[*-1], "handle last line: $status";

Expand Down

0 comments on commit 3f3e870

Please sign in to comment.