unlink($file);
}
-if ($Config{useperlio}) {
- plan(tests => 6);
+if (find PerlIO::Layer 'perlio') {
+ plan(tests => 8);
ok(open(FOO,">:crlf",$file));
ok(print FOO 'a'.((('a' x 14).qq{\n}) x 2000) || close(FOO));
ok(open(FOO,"<:crlf",$file));
- my $seen = 0;
- while (<FOO>)
- {
- $seen++ if (/\r/);
- }
- is($seen,0);
+
+ my $text;
+ { local $/; $text = <FOO> }
+ is(count_chars($text, "\015\012"), 0);
+ is(count_chars($text, "\n"), 2000);
+
binmode(FOO);
seek(FOO,0,0);
- $seen = 0;
- while (<FOO>)
- {
- $seen++ if (/\r/);
- }
- is($seen,2000);
+ { local $/; $text = <FOO> }
+ is(count_chars($text, "\015\012"), 2000);
+
+ SKIP:
+ {
+ if ($^X =~ /\bminiperl\b/) { skip(q/miniperl can't load PerlIO layers/) }
+ my $fcontents = join "", map {"$_\r\n"} "a".."zzz";
+ open my $fh, "<:crlf", \$fcontents;
+ local $/ = "xxx";
+ local $_ = <$fh>;
+ my $pos = tell $fh; # pos must be behind "xxx", before "\nyyy\n"
+ seek $fh, $pos, 0;
+ $/ = "\n";
+ $s = <$fh>.<$fh>;
+ ok($s eq "\nxxy\n");
+ }
+
ok(close(FOO));
}
else {
skip_all("No perlio, so no :crlf");
}
-
+sub count_chars {
+ my($text, $chars) = @_;
+ my $seen = 0;
+ $seen++ while $text =~ /$chars/g;
+ return $seen;
+}