File: 03-line-seps.t

package info (click to toggle)
nqp 2016.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,960 kB
  • ctags: 3,884
  • sloc: java: 25,027; perl: 910; makefile: 12; sh: 2
file content (73 lines) | stat: -rw-r--r-- 2,739 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! nqp

# Test nqp::op 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 $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);
    
    $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);
    
    nqp::unlink($test-file);
}

{
    my $wfh := nqp::open($test-file, 'w');
    nqp::printfh($wfh, 'abc|def||ghi>jkl>>mno');
    nqp::closefh($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);
    
    $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);
    
    nqp::unlink($test-file);
}

{
    my $wfh := nqp::open($test-file, 'w');
    nqp::printfh($wfh, "abc\ndef\r\nghi");
    nqp::closefh($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);

    $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);

    nqp::unlink($test-file);
}