summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/self-test/readlineBuf.js
blob: 952b1e5453ea193880dca1359d4ee38529dc5a16 (plain)
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
load(libdir + "asserts.js");

assertThrowsInstanceOf(function () { readlineBuf() }, Error);

var testBuffers = [
    "foo\nbar\nbaz\n",
    "foo\nbar\nbaz",
    "foo\n\nbar\nbaz",
    "f",
    "\n",
    "\nf",
    ""
];

var expected = [
    [ "foo", "bar", "baz" ],
    [ "foo", "bar", "baz" ],
    [ "foo", "", "bar", "baz" ],
    [ "f" ],
    [ "" ],
    [ "", "f" ],
    []
];

for (var idx in testBuffers) {
    readlineBuf(testBuffers[idx]);
    var result = [];

    while ((line = readlineBuf()) != null) {
        result.push(line);
    }

    assertDeepEq(result, expected[idx]);
}

readlineBuf(testBuffers[0]);
readlineBuf();
readlineBuf();
readlineBuf(testBuffers[3]);
assertEq(readlineBuf(), expected[3][0]);