Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update tests to cope with newline translation.
  • Loading branch information
jnthn committed Dec 16, 2015
1 parent 5605a58 commit ad0164f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
8 changes: 5 additions & 3 deletions S15-nfg/crlf-encoding.t
Expand Up @@ -21,9 +21,11 @@ for <utf-8 ascii latin-1 windows-1252> -> $encoding {
}
is $temp-file.IO.s, 12, "Wrote file of correct length ($encoding)";

given open($temp-file, :r, enc => $encoding, :!chomp) {
is .get.chars, 5, "Read file and got expected number of chars ($encoding)";
is .get, "boat\r\n", "Chars read from file were correct ($encoding)";
given open($temp-file, :r, :bin) {
my $buf = .read(12);
my $str = $buf.decode($encoding);
is $str.chars, 10, "Read file and got expected number of chars ($encoding)";
is $str, "goat\r\nboat\r\n", "Chars read from file were correct ($encoding)";
.close;
}
}
6 changes: 3 additions & 3 deletions S16-io/comb.t
Expand Up @@ -23,9 +23,9 @@ sub test-comb($text,@result,|c) {
}

# standard text file
for "\r\n", /\r\n/ -> $sep {
my $text = "zero\r\none\r\ntwo\r\nthree\r\nfour";
my @clean = "\r\n" xx 4;
for "\n", /\n/ -> $sep {
my $text = "zero\none\ntwo\nthree\nfour";
my @clean = "\n" xx 4;
test-comb($text,@clean,$sep);
}

Expand Down
1 change: 0 additions & 1 deletion S16-io/lines.t
Expand Up @@ -3,7 +3,6 @@ use Test;

my @endings =
"\n" => "LF",
"\r\n" => "CRLF",
"\r" => "CR",
";" => "semi-colon",
":\n:" => "colons",
Expand Down
4 changes: 2 additions & 2 deletions S16-io/split.t
Expand Up @@ -22,8 +22,8 @@ sub test-split($text,@result,|c) {
}

# standard text file
for "\r\n", /\r\n/ -> $sep {
my $text = "zero\r\none\r\ntwo\r\nthree\r\nfour";
for "\n", /\n/ -> $sep {
my $text = "zero\none\ntwo\nthree\nfour";
my @clean = <zero one two three four>;
test-split($text,@clean,$sep);
}
Expand Down
6 changes: 3 additions & 3 deletions S32-io/slurp.t
Expand Up @@ -17,7 +17,7 @@ plan 17;
}

my $test-path = "tempfile-slurp-test";
my $test-contents = "0123456789\nABCDEFG\n, 薔薇, バズ\n";
my $test-contents = "0123456789ABCDEFG風, 薔薇, バズ";
my $empty-path = "tempfile-slurp-empty";

{ # write the temp files
Expand Down Expand Up @@ -58,15 +58,15 @@ is slurp($empty-path), '', "empty files yield empty string";
is slurp($test-path, :enc('utf8')), $test-contents, "utf8 looks normal";
#mojibake time
is slurp($test-path, enc=>'iso-8859-1'),
"0123456789\nABCDEFG\n風, 薔薇, バズ\n", "iso-8859-1 makes mojibake correctly";
"0123456789ABCDEFG風, 薔薇, バズ", "iso-8859-1 makes mojibake correctly";

}


# slurp in list context

my @slurped_lines = lines(open($test-path));
is +@slurped_lines, 3, "lines() - exactly 3 lines in this file";
is +@slurped_lines, 1, "lines() - exactly 1 line in this file";

# slurp in list context on a directory
{
Expand Down

0 comments on commit ad0164f

Please sign in to comment.