Skip to content

Commit e2ee780

Browse files
Merge pull request #25 from plaid/davidchambers/line-endings
accommodate Windows line endings
2 parents 8ebc610 + 684aa7d commit e2ee780

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

bin/transcribe

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var parseFile = R.curry (function(options, filename) {
7272
return R.pipe (
7373
fs.readFileSync,
7474
String,
75+
R.replace (/\r\n?/g, '\n'), // plaid/transcribe#23
7576
R.match (/^.*$/gm),
7677
R.lift (R.zip) (R.pipe (R.length, R.inc, R.range (1)), R.identity),
7778
R.map (R.apply (parseLine (options, filename))),

scripts/test

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
set -euf -o pipefail
3+
4+
rst=$'\x1B[0m'
5+
red=$'\x1B[0;31m'
6+
grn=$'\x1B[0;32m'
7+
cyn=$'\x1B[0;36m'
8+
rev=$'\x1B[7m'
9+
10+
function highlight {
11+
local output
12+
output="${1}${2}${rst}"
13+
output="${output//$'\n'/"${rev}\\n${rst}${1}"$'\n'}"
14+
output="${output//$'\xE2\x81\xA0'/"${rev}<U+2060>${rst}${1}"}"
15+
printf '%s' "$output"
16+
}
17+
18+
function compare {
19+
if [[ "$3" == "$2" ]] ; then
20+
printf '%s\u2714%s %s\n' "$grn" "$rst" "$1"
21+
else
22+
printf '%s\u2718%s %s\n' "$red" "$rst" "$1"
23+
printf '%s\n' "$cyn---------------------------------- expected ----------------------------------$rst"
24+
highlight "$grn" "$2"
25+
printf '%s\n' "$cyn----------------------------------- actual -----------------------------------$rst"
26+
highlight "$red" "$3"
27+
printf '%s\n' "$cyn------------------------------------------------------------------------------$rst"
28+
exit 1
29+
fi
30+
}
31+
32+
set +e
33+
IFS='' read -r -d '' unix <<'EOF'
34+
//# identity :: a -> a
35+
//.
36+
//. The identity function. Returns its argument.
37+
//.
38+
//. ```javascript
39+
//. > identity (1)
40+
//. 1
41+
//. ```
42+
function identity(x) {
43+
return x;
44+
}
45+
exports.identity = identity;
46+
EOF
47+
IFS='' read -r -d '' dos <<'EOF'
48+
//# identity :: a -> a
49+
//.
50+
//. The identity function. Returns its argument.
51+
//.
52+
//. ```javascript
53+
//. > identity (1)
54+
//. 1
55+
//. ```
56+
function identity(x) {
57+
return x;
58+
}
59+
exports.identity = identity;
60+
EOF
61+
IFS='' read -r -d '' expected <<'EOF'
62+
### <a name="identity" href="XXX">`identity :: a -⁠> a`</a>
63+
64+
The identity function. Returns its argument.
65+
66+
```javascript
67+
> identity (1)
68+
1
69+
```
70+
EOF
71+
set -e
72+
73+
# Append an underscore to preserve trailing newlines, then strip it.
74+
actual="$(bin/transcribe --url XXX -- <(printf '%s' "$unix") && printf _)"
75+
compare 'Unix line endings' "$expected" "${actual%_}"
76+
77+
actual="$(bin/transcribe --url XXX -- <(printf '%s' "$dos") && printf _)"
78+
compare 'Windows line endings' "$expected" "${actual%_}"

0 commit comments

Comments
 (0)