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