12 my $file = "crlf$$.dat";
14 1 while unlink($file);
17 if (find PerlIO::Layer 'perlio') {
19 ok(open(FOO,">:crlf",$file));
20 ok(print FOO 'a'.((('a' x 14).qq{\n}) x 2000) || close(FOO));
21 ok(open(FOO,"<:crlf",$file));
24 { local $/; $text = <FOO> }
25 is(count_chars($text, "\015\012"), 0);
26 is(count_chars($text, "\n"), 2000);
30 { local $/; $text = <FOO> }
31 is(count_chars($text, "\015\012"), 2000);
35 eval 'use PerlIO::scalar';
36 skip(q/miniperl cannnot load PerlIO::scalar/)
37 if $@ =~ /dynamic loading not available/;
38 my $fcontents = join "", map {"$_\015\012"} "a".."zzz";
39 open my $fh, "<:crlf", \$fcontents;
42 my $pos = tell $fh; # pos must be behind "xxx", before "\nyyy\n"
51 # binmode :crlf should not cumulate.
52 # Try it first once and then twice so that even UNIXy boxes
53 # get to exercise this, for DOSish boxes even once is enough.
54 # Try also pushing :utf8 first so that there are other layers
55 # in between (this should not matter: CRLF layers still should
57 for my $utf8 ('', ':utf8') {
58 for my $binmode (1..2) {
60 # require PerlIO; print PerlIO::get_layers(FOO), "\n";
61 binmode(FOO, "$utf8:crlf") for 1..$binmode;
62 # require PerlIO; print PerlIO::get_layers(FOO), "\n";
67 my $foo = scalar <FOO>;
69 print join(" ", "#", map { sprintf("%02x", $_) } unpack("C*", $foo)),
71 ok($foo =~ /\x0d\x0a$/);
72 ok($foo !~ /\x0d\x0d/);
77 skip_all("No perlio, so no :crlf");
81 my($text, $chars) = @_;
83 $seen++ while $text =~ /$chars/g;