Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-work line seps tests to use high-level I/O.
- Loading branch information
Showing
1 changed file
with
46 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,73 @@ | ||
#! nqp | ||
|
||
# Test nqp::op line reading operations. | ||
# Test line reading operations. | ||
|
||
plan(18); | ||
|
||
my $test-file := 'line-seps-test-file'; | ||
|
||
{ | ||
my $wfh := nqp::open($test-file, 'w'); | ||
nqp::printfh($wfh, 'abc|def>ghi'); | ||
nqp::closefh($wfh); | ||
my $wfh := open($test-file, :w); | ||
$wfh.print('abc|def>ghi'); | ||
close($wfh); | ||
|
||
my $rfh := nqp::open($test-file, 'r'); | ||
nqp::setinputlineseps($rfh, nqp::list_s('|', '>')); | ||
ok(nqp::readlinefh($rfh) eq "abc|", 'first separator used'); | ||
ok(nqp::readlinefh($rfh) eq "def>", 'second separator used'); | ||
ok(nqp::readlinefh($rfh) eq "ghi", 'final read to end of file worked'); | ||
nqp::closefh($rfh); | ||
my $rfh := open($test-file, :r, :!chomp); | ||
$rfh.set-nl-in(nqp::list('|', '>')); | ||
ok($rfh.get eq "abc|", 'first separator used'); | ||
ok($rfh.get eq "def>", 'second separator used'); | ||
ok($rfh.get eq "ghi", 'final read to end of file worked'); | ||
close($rfh); | ||
|
||
$rfh := nqp::open($test-file, 'r'); | ||
nqp::setinputlineseps($rfh, nqp::list_s('|', '>')); | ||
ok(nqp::readlinechompfh($rfh) eq "abc", 'first separator used and chomped'); | ||
ok(nqp::readlinechompfh($rfh) eq "def", 'second separator used and chomped'); | ||
ok(nqp::readlinechompfh($rfh) eq "ghi", 'final read to end of file worked'); | ||
nqp::closefh($rfh); | ||
$rfh := open($test-file, :r); | ||
$rfh.set-nl-in(nqp::list('|', '>')); | ||
ok($rfh.get eq "abc", 'first separator used and chomped'); | ||
ok($rfh.get eq "def", 'second separator used and chomped'); | ||
ok($rfh.get eq "ghi", 'final read to end of file worked'); | ||
close($rfh); | ||
|
||
nqp::unlink($test-file); | ||
} | ||
|
||
{ | ||
my $wfh := nqp::open($test-file, 'w'); | ||
nqp::printfh($wfh, 'abc|def||ghi>jkl>>mno'); | ||
nqp::closefh($wfh); | ||
my $wfh := open($test-file, :w); | ||
$wfh.print('abc|def||ghi>jkl>>mno'); | ||
close($wfh); | ||
|
||
my $rfh := nqp::open($test-file, 'r'); | ||
nqp::setinputlineseps($rfh, nqp::list_s('||', '>>')); | ||
ok(nqp::readlinefh($rfh) eq "abc|def||", 'first multi-char separator used'); | ||
ok(nqp::readlinefh($rfh) eq "ghi>jkl>>", 'second multi-char separator used'); | ||
ok(nqp::readlinefh($rfh) eq "mno", 'final read to end of file worked'); | ||
nqp::closefh($rfh); | ||
my $rfh := open($test-file, :r, :!chomp); | ||
$rfh.set-nl-in(nqp::list('||', '>>')); | ||
ok($rfh.get eq "abc|def||", 'first multi-char separator used'); | ||
ok($rfh.get eq "ghi>jkl>>", 'second multi-char separator used'); | ||
ok($rfh.get eq "mno", 'final read to end of file worked'); | ||
close($rfh); | ||
|
||
$rfh := nqp::open($test-file, 'r'); | ||
nqp::setinputlineseps($rfh, nqp::list_s('||', '>>')); | ||
ok(nqp::readlinechompfh($rfh) eq "abc|def", 'first multi-char separator used and chomped'); | ||
ok(nqp::readlinechompfh($rfh) eq "ghi>jkl", 'second multi-char separator used and chomped'); | ||
ok(nqp::readlinechompfh($rfh) eq "mno", 'final read to end of file worked'); | ||
nqp::closefh($rfh); | ||
$rfh := open($test-file, :r); | ||
$rfh.set-nl-in(nqp::list('||', '>>')); | ||
ok($rfh.get eq "abc|def", 'first multi-char separator used and chomped'); | ||
ok($rfh.get eq "ghi>jkl", 'second multi-char separator used and chomped'); | ||
ok($rfh.get eq "mno", 'final read to end of file worked'); | ||
close($rfh); | ||
|
||
nqp::unlink($test-file); | ||
} | ||
|
||
{ | ||
my $wfh := nqp::open($test-file, 'w'); | ||
nqp::printfh($wfh, "abc\ndef\r\nghi"); | ||
nqp::closefh($wfh); | ||
my $wfh := open($test-file, :w); | ||
$wfh.print("abc\ndef\r\nghi"); | ||
close($wfh); | ||
|
||
my $rfh := nqp::open($test-file, 'r'); | ||
nqp::setinputlineseps($rfh, nqp::list_s("\n", "\r\n")); | ||
ok(nqp::readlinefh($rfh) eq "abc\n", '\n separator used'); | ||
ok(nqp::readlinefh($rfh) eq "def\n", '\r\n separator used'); # \n due to translation | ||
ok(nqp::readlinefh($rfh) eq "ghi", 'final read to end of file worked'); | ||
nqp::closefh($rfh); | ||
my $rfh := open($test-file, :r, :!chomp); | ||
$rfh.set-nl-in(nqp::list("\n", "\r\n")); | ||
ok($rfh.get eq "abc\n", '\n separator used'); | ||
ok($rfh.get eq "def\n", '\r\n separator used'); # \n due to translation | ||
ok($rfh.get eq "ghi", 'final read to end of file worked'); | ||
close($rfh); | ||
|
||
$rfh := nqp::open($test-file, 'r'); | ||
nqp::setinputlineseps($rfh, nqp::list_s("\n", "\r\n")); | ||
ok(nqp::readlinechompfh($rfh) eq "abc", '\n separator used and chomped'); | ||
ok(nqp::readlinechompfh($rfh) eq "def", '\r\n separator used and chomped'); | ||
ok(nqp::readlinechompfh($rfh) eq "ghi", 'final read to end of file worked'); | ||
nqp::closefh($rfh); | ||
$rfh := open($test-file, :r); | ||
$rfh.set-nl-in(nqp::list("\n", "\r\n")); | ||
ok($rfh.get eq "abc", '\n separator used and chomped'); | ||
ok($rfh.get eq "def", '\r\n separator used and chomped'); | ||
ok($rfh.get eq "ghi", 'final read to end of file worked'); | ||
close($rfh); | ||
|
||
nqp::unlink($test-file); | ||
} |