Commit 82ae5fea authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Add test for multi-chunk lines

parent ba82bc6c
No related merge requests found
Showing with 27 additions and 3 deletions
+27 -3
This diff is collapsed.
......@@ -553,7 +553,7 @@ const TESTS = [
]
for (const {args, expected} of TESTS) {
const flags = args.filter(arg => arg.startsWith('-'))
const flags = args.filter(arg => arg.startsWith('-'))
const parameters = args.filter(arg => !arg.startsWith('-'))
for (const args of reorderings(parameters, flags)) {
test(`grep ${args.join(' ')}`, async t => {
......@@ -593,12 +593,26 @@ test('grep stdin', async t => {
})
// Ensure that the streams deal with lines spread across chunks correctly
test('multiple chunk input file', async t => {
test('multiple-chunk input file', async t => {
const lines = new Array(1e5).fill().map((_, i) => `Line ${i + 1}`)
for (let i = 0; i < 10; i++) {
const search = `${i}`
const {stdout} = await execFilePromise('node', ['../grep.js', search, 'files/long.txt'])
const {stdout} = await execFilePromise(
'node', ['../grep.js', search, 'files/long.txt']
)
const expectedLines = lines.filter(line => line.includes(search))
t.deepEqual(stdout, expectedLines.map(line => `${line}\n`).join(''))
}
})
// Ensure that the streams deal with lines containing multiple chunks
test('multiple-chunk lines', async t => {
const contents = await fs.promises.readFile('files/long-lines.txt', 'utf8')
const lines = contents.trim().split('\n')
for (let i = 0; i < 10; i++) {
const {stdout} = await execFilePromise(
'node', ['../grep.js', `${i}`, 'files/long-lines.txt']
)
t.deepEqual(stdout, lines[i] + '\n')
}
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment