Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs11-async
grep
Commits
82ae5fea
Commit
82ae5fea
authored
5 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Add test for multi-chunk lines
parent
ba82bc6c
master
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/files/long-lines.txt
+10
-0
tests/files/long-lines.txt
tests/test.js
+17
-3
tests/test.js
with
27 additions
and
3 deletions
+27
-3
tests/files/long-lines.txt
0 → 100644
View file @
82ae5fea
This diff is collapsed.
Click to expand it.
tests/test.js
View file @
82ae5fea
...
...
@@ -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
(
1
e5
).
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
'
)
}
})
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help