Skip to content

Commit

Permalink
Re-work line seps tests to use high-level I/O.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed May 30, 2017
1 parent 9d6643c commit 913012c
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions t/moar/03-line-seps.t
@@ -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);
}

0 comments on commit 913012c

Please sign in to comment.