Skip to content

Commit d3fdb4a

Browse files
authored
GitHub Issue #103 - convert CRLF to LF line endings (#133)
1 parent d5d1302 commit d3fdb4a

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

lib/standard-clojure-style.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@
245245
return s.replace(find, replace)
246246
}
247247

248+
function crlfToLf (txt) {
249+
return txt.replace(/\r\n/g, '\n')
250+
}
251+
248252
function strSplit (str, ch) {
249253
return str.split(ch)
250254
}
@@ -3780,6 +3784,9 @@
37803784
// Parses inputTxt (Clojure code) and returns a String of it formatted according
37813785
// to Standard Clojure Style.
37823786
function format (inputTxt) {
3787+
// replace any CRLF with LF before we do anything
3788+
inputTxt = crlfToLf(inputTxt)
3789+
37833790
// FIXME: wrap this in try/catch and return error code if found
37843791
const tree = parse(inputTxt)
37853792
const nodesArr = flattenTree(tree)

test/format.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,28 @@ allTestCases.forEach(testCase => {
116116
}
117117
})
118118

119+
const inputFileWithCRLF = fs.readFileSync(path.join(rootDir, 'test_format/line_endings/crlf_input.clj'), 'utf8')
120+
const outputFileWithLF = fs.readFileSync(path.join(rootDir, 'test_format/line_endings/lf_output.clj'), 'utf8')
121+
122+
test('crlf to lf', () => {
123+
expect(isString(inputFileWithCRLF)).toBe(true)
124+
expect(isString(outputFileWithLF)).toBe(true)
125+
expect(inputFileWithCRLF.includes('\r\n')).toBe(true)
126+
expect(outputFileWithLF.includes('\r\n')).toBe(false)
127+
128+
const result = scsLib.format(inputFileWithCRLF)
129+
130+
expect(result.status).toBe('success')
131+
expect(result.out + '\n').toBe(outputFileWithLF)
132+
})
133+
119134
// -----------------------------------------------------------------------------
120135
// Util
121136

122137
function isEnoFile (f) {
123138
return path.extname(f) === '.eno'
124139
}
140+
141+
function isString (s) {
142+
return typeof s === 'string'
143+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(ns wolframite.base.cep
2+
(:require
3+
[wolframite.lib.options :as options]
4+
[wolframite.base.convert :as convert]
5+
[wolframite.base.evaluate :as evaluate]
6+
[wolframite.base.parse :as parse]))
7+
8+
(defn- identity-first [x & _] x)
9+
10+
(defn cep
11+
"Convert-Evaluate-Parse pipeline.
12+
Convert: from clj data to jlink Expr
13+
Evaluate: the Expr on (some) Wolfram Engine
14+
Parse: returned result into clj data.
15+
Each stage can be skipped with appropriate `opts` `:flag` e.g. `:no-parse`"
16+
[expr {:keys [flags]
17+
:as opts}]
18+
(let [convert (if (options/flag?' flags :convert) convert/convert identity-first)
19+
evaluate (if (options/flag?' flags :evaluate) evaluate/evaluate identity-first)
20+
parse (if (options/flag?' flags :parse) parse/parse identity-first)]
21+
(-> expr
22+
(convert opts)
23+
(evaluate opts)
24+
(parse opts))))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(ns wolframite.base.cep
2+
(:require
3+
[wolframite.base.convert :as convert]
4+
[wolframite.base.evaluate :as evaluate]
5+
[wolframite.base.parse :as parse]
6+
[wolframite.lib.options :as options]))
7+
8+
(defn- identity-first [x & _] x)
9+
10+
(defn cep
11+
"Convert-Evaluate-Parse pipeline.
12+
Convert: from clj data to jlink Expr
13+
Evaluate: the Expr on (some) Wolfram Engine
14+
Parse: returned result into clj data.
15+
Each stage can be skipped with appropriate `opts` `:flag` e.g. `:no-parse`"
16+
[expr {:keys [flags]
17+
:as opts}]
18+
(let [convert (if (options/flag?' flags :convert) convert/convert identity-first)
19+
evaluate (if (options/flag?' flags :evaluate) evaluate/evaluate identity-first)
20+
parse (if (options/flag?' flags :parse) parse/parse identity-first)]
21+
(-> expr
22+
(convert opts)
23+
(evaluate opts)
24+
(parse opts))))

0 commit comments

Comments
 (0)