Integrate mainline.
[p5sagit/p5-mst-13.2.git] / t / io / crlf.t
1 #!./perl -w
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = qw(. ../lib);
6 }
7
8 use Config;
9
10 require "test.pl";
11
12 my $file = "crlf$$.dat";
13 END {
14  unlink($file);
15 }
16
17 if (find PerlIO::Layer 'perlio') {
18  plan(tests => 7);
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));
22
23  my $text;
24  { local $/; $text = <FOO> }
25  is(count_chars($text, "\015\012"), 0);
26  is(count_chars($text, "\n"), 2000);
27
28  binmode(FOO);
29  seek(FOO,0,0);
30  { local $/; $text = <FOO> }
31  is(count_chars($text, "\015\012"), 2000);
32
33  ok(close(FOO));
34 }
35 else {
36  skip_all("No perlio, so no :crlf");
37 }
38
39 sub count_chars {
40   my($text, $chars) = @_;
41   my $seen = 0;
42   $seen++ while $text =~ /$chars/g;
43   return $seen;
44 }