File tree Expand file tree Collapse file tree 4 files changed +74
-0
lines changed Expand file tree Collapse file tree 4 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 245
245
return s . replace ( find , replace )
246
246
}
247
247
248
+ function crlfToLf ( txt ) {
249
+ return txt . replace ( / \r \n / g, '\n' )
250
+ }
251
+
248
252
function strSplit ( str , ch ) {
249
253
return str . split ( ch )
250
254
}
3780
3784
// Parses inputTxt (Clojure code) and returns a String of it formatted according
3781
3785
// to Standard Clojure Style.
3782
3786
function format ( inputTxt ) {
3787
+ // replace any CRLF with LF before we do anything
3788
+ inputTxt = crlfToLf ( inputTxt )
3789
+
3783
3790
// FIXME: wrap this in try/catch and return error code if found
3784
3791
const tree = parse ( inputTxt )
3785
3792
const nodesArr = flattenTree ( tree )
Original file line number Diff line number Diff line change @@ -116,9 +116,28 @@ allTestCases.forEach(testCase => {
116
116
}
117
117
} )
118
118
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
+
119
134
// -----------------------------------------------------------------------------
120
135
// Util
121
136
122
137
function isEnoFile ( f ) {
123
138
return path . extname ( f ) === '.eno'
124
139
}
140
+
141
+ function isString ( s ) {
142
+ return typeof s === 'string'
143
+ }
Original file line number Diff line number Diff line change
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))))
Original file line number Diff line number Diff line change
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))))
You can’t perform that action at this time.
0 commit comments