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
5a9fe7ba
Commit
5a9fe7ba
authored
4 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Fix #3
parent
ce6a4bd6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test.js
+9
-9
tests/test.js
tests/util.js
+9
-0
tests/util.js
with
18 additions
and
9 deletions
+18
-9
tests/test.js
View file @
5a9fe7ba
const
fs
=
require
(
'
fs
'
)
const
test
=
require
(
'
ava
'
)
const
{
execFilePromise
,
matchOutput
,
reorderings
}
=
require
(
'
./util
'
)
const
{
execFilePromise
,
matchOutput
,
reorderings
,
updateExpectedPaths
}
=
require
(
'
./util
'
)
process
.
chdir
(
__dirname
)
const
RUST_MUTABLE_EXPECTED
=
[
const
RUST_MUTABLE_EXPECTED
=
updateExpectedPaths
(
[
[
'
files/rust-book/ch10-03-lifetime-syntax.md:reference to an `i32` that has a lifetime parameter named `
\'
a`, and a mutable
'
,
'
files/rust-book/ch10-03-lifetime-syntax.md:&
\'
a mut i32 // a mutable reference with an explicit lifetime
'
...
...
@@ -210,7 +210,7 @@ const RUST_MUTABLE_EXPECTED = [
'
files/rust-book/ch16-03-shared-state.md:this case, as a mutable reference to the data inside. The type system ensures
'
,
'
files/rust-book/ch16-03-shared-state.md:You might have noticed that `counter` is immutable but we could get a mutable
'
]
]
]
)
const
MULTIPLE_RUST_FILES
=
[
'
files/rust-book/ch04-01-what-is-ownership.md
'
,
'
files/rust-book/ch08-03-hash-maps.md
'
,
...
...
@@ -296,7 +296,7 @@ const TESTS = [
// Test -r with omitted directory.
// This also tests a more deeply-nested recursive structure.
args
:
[
'
-r
'
,
'
crow
'
+
'
n
'
],
expected
:
[
expected
:
updateExpectedPaths
(
[
[
'
files/richard-iii/1/1/3/2.txt:To fight on Edward’s party for the crow
'
+
'
n ;
'
,
'
files/richard-iii/1/1/3/2.txt:When thou didst crow
'
+
'
n his warlike brows with paper ,
'
...
...
@@ -330,12 +330,12 @@ const TESTS = [
],
[
'
files/richard-iii/3/1/2/2.txt:And by that knot looks proudly on the crow
'
+
'
n ,
'
],
[
'
files/richard-iii/3/2.txt:The first was I that helped thee to the crow
'
+
'
n ;
'
]
]
]
)
},
{
// Test a more complicated regex
args
:
[
'
-r
'
,
'
[a-z]{3}
\\
d
'
,
'
files/rust-book
'
],
expected
:
[
expected
:
updateExpectedPaths
(
[
[
'
files/rust-book/ch10-03-lifetime-syntax.md:type stored in the variable `string1`) as well as string literals (which is
'
,
'
files/rust-book/ch10-03-lifetime-syntax.md:what variable `string2` contains).
'
,
...
...
@@ -418,12 +418,12 @@ const TESTS = [
'
files/rust-book/ch15-01-box.md:<img alt="An infinite Cons list" src="img/trpl15-01.svg" class="center" style="width: 50%;" />
'
,
'
files/rust-book/ch15-01-box.md:<img alt="A finite Cons list" src="img/trpl15-02.svg" class="center" />
'
]
]
]
)
},
{
// Test -i with regex
args
:
[
'
-i
'
,
'
-r
'
,
'
[a-z]{3}
\\
d
'
,
'
files/rust-book
'
],
expected
:
[
expected
:
updateExpectedPaths
(
[
[
'
files/rust-book/ch10-03-lifetime-syntax.md:type stored in the variable `string1`) as well as string literals (which is
'
,
'
files/rust-book/ch10-03-lifetime-syntax.md:what variable `string2` contains).
'
,
...
...
@@ -517,7 +517,7 @@ const TESTS = [
'
files/rust-book/ch15-01-box.md:<img alt="An infinite Cons list" src="img/trpl15-01.svg" class="center" style="width: 50%;" />
'
,
'
files/rust-book/ch15-01-box.md:<img alt="A finite Cons list" src="img/trpl15-02.svg" class="center" />
'
]
]
]
)
},
{
// Test -z flag,
...
...
This diff is collapsed.
Click to expand it.
tests/util.js
View file @
5a9fe7ba
const
{
execFile
}
=
require
(
'
child_process
'
)
const
path
=
require
(
'
path
'
)
const
{
promisify
}
=
require
(
'
util
'
)
exports
.
execFilePromise
=
promisify
(
execFile
)
...
...
@@ -16,6 +17,14 @@ function* reorderings(fixed, reorderable) {
}
exports
.
reorderings
=
reorderings
/** Updates the path separators in an expected output to match the OS's separator */
exports
.
updateExpectedPaths
=
expected
=>
expected
.
map
(
lineGroup
=>
lineGroup
.
map
(
line
=>
{
const
pathEnd
=
line
.
indexOf
(
'
:
'
)
if
(
pathEnd
<
0
)
throw
new
Error
(
'
Line does not have a path
'
)
return
path
.
join
(...
line
.
slice
(
0
,
pathEnd
).
split
(
'
/
'
))
+
line
.
slice
(
pathEnd
)
}))
function
toLines
(
text
)
{
const
lines
=
text
.
split
(
'
\n
'
)
if
(
lines
.
length
&&
!
lines
[
lines
.
length
-
1
])
lines
.
pop
()
...
...
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