Skip to content
Permalink
Browse files

test, feat: basic test cases about io (#506)

  • Loading branch information...
richardo2016 authored and xicilion committed May 29, 2019
1 parent babc961 commit 9f71c3969516d19d0ad22a1e72d7f2d7174633ee
Showing with 75 additions and 0 deletions.
  1. +64 −0 test/io_test.js
  2. +1 −0 test/main.js
  3. +10 −0 test/process/exec.chargeable.js
@@ -0,0 +1,64 @@
const test = require("test");
test.setup();

const io = require("io");
const LF = `\n`
const CRLF = `\r\n`
let EOL = null

describe('io', () => {
before(() => {
const ms = new io.MemoryStream()
const bs = new io.BufferedStream(ms)
EOL = bs.EOL
});

describe('BufferedStream', () => {
it('readLines', () => {
const ms = new io.MemoryStream()
const bs = new io.BufferedStream(ms)

ms.write(`line1${bs.EOL}`)
ms.write(`line2${bs.EOL}`)
ms.rewind()

assert.deepEqual(
bs.readLines(),
[
`line1`,
`line2`,
]
)
});

describe('readUntil', () => {
;[
['system EOL' , EOL ],
['LF' , LF ],
['CRLF' , CRLF ],
['\\0' , '\0' ],
['\\r' , '\r' ],
].forEach(([
desc,
eol,
]) => {
it(desc, () => {
const ms = new io.MemoryStream()
const bs = new io.BufferedStream(ms)

assert.deepEqual(bs.readUntil(eol), null)

ms.write(`line1${eol}`)
ms.write(`line2${eol}`)
ms.rewind()

assert.deepEqual(bs.readUntil(eol), `line1`)
assert.deepEqual(bs.readUntil(eol), `line2`)
assert.deepEqual(bs.readUntil(eol), null)
})
})
})
});
});

require.main === module && test.run(console.DEBUG);
@@ -27,6 +27,7 @@ run("./trigger_test.js");
run("./lock_test.js");
run("./fs_test.js");
run("./ms_test.js");
run("./io_test.js");
run("./os_test.js");
run("./process_test.js");
run("./encoding_test.js");
@@ -2,6 +2,16 @@ var io = require('io')

var is = new io.BufferedStream(process.stdin)

/**
* @why in platform win32, EOL may be one of [`\r\n`, `\n`];
*
* @todo normalize behavior about `EOL` of
* BufferesStream **from stdio** in the future
*/
if (process.platform === 'win32') {
is.EOL = '\n';
}

var input = null
while (true) {
input = is.readLine()

0 comments on commit 9f71c39

Please sign in to comment.
You can’t perform that action at this time.