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