Commit 5a9fe7ba authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Fix #3

parent ce6a4bd6
Showing with 18 additions and 9 deletions
+18 -9
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,
......
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()
......
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