7 require "./charset_tools.pl";
8 skip_all_without_perlio();
14 my $file = tempfile();
15 my $crlf = uni_to_native("\015\012");
16 my $crcr = uni_to_native("\x0d\x0d");
18 my $ungetc_count = 8200; # Somewhat over the likely buffer size
21 plan(tests => 16 + 2 * $ungetc_count);
22 ok(open(FOO,">:crlf",$file));
23 ok(print FOO 'a'.((('a' x 14).qq{\n}) x 2000) || close(FOO));
24 ok(open(FOO,"<:crlf",$file));
27 { local $/; $text = <FOO> }
28 is(count_chars($text, $crlf), 0);
29 is(count_chars($text, "\n"), 2000);
33 { local $/; $text = <FOO> }
34 is(count_chars($text, $crlf), 2000);
38 skip_if_miniperl("miniperl can't rely on loading PerlIO::scalar",
39 2 * $ungetc_count + 1);
40 skip("no PerlIO::scalar", 2 * $ungetc_count + 1)
41 unless $Config{extensions} =~ m!\bPerlIO/scalar\b!;
42 require PerlIO::scalar;
43 my $fcontents = join "", map {"$_$crlf"} "a".."zzz";
44 open my $fh, "<:crlf", \$fcontents;
47 my $pos = tell $fh; # pos must be behind "xxx", before "\nxxy\n"
53 for my $i (0 .. $ungetc_count - 1) {
55 is($fh->ungetc($j), $j, "ungetc of $j returns itself");
58 for (my $i = $ungetc_count - 1; $i >= 0; $i--) {
60 is(ord($fh->getc()), $j, "getc gets back $j");
66 # binmode :crlf should not cumulate.
67 # Try it first once and then twice so that even UNIXy boxes
68 # get to exercise this, for DOSish boxes even once is enough.
69 # Try also pushing :utf8 first so that there are other layers
70 # in between (this should not matter: CRLF layers still should
72 for my $utf8 ('', ':utf8') {
73 for my $binmode (1..2) {
75 # require PerlIO; print PerlIO::get_layers(FOO), "\n";
76 binmode(FOO, "$utf8:crlf") for 1..$binmode;
77 # require PerlIO; print PerlIO::get_layers(FOO), "\n";
82 my $foo = scalar <FOO>;
84 print join(" ", "#", map { sprintf("%02x", $_) } unpack("C*", $foo)),
86 like($foo, qr/$crlf$/);
87 unlike($foo, qr/$crcr/);
93 my($text, $chars) = @_;
95 $seen++ while $text =~ /$chars/g;