markdown-magic 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -29
- package/lib/block-parser-js.test.js +148 -156
- package/lib/block-parser.js +255 -262
- package/lib/block-parser.test.js +43 -6
- package/lib/cli.js +30 -19
- package/lib/cli.test.js +73 -73
- package/lib/globals.d.ts +66 -0
- package/lib/index.js +43 -9
- package/lib/process-contents.js +80 -39
- package/lib/process-file.js +4 -1
- package/lib/transforms/code.js +4 -10
- package/lib/transforms/file.js +7 -10
- package/lib/transforms/index.js +0 -0
- package/lib/transforms/remote.js +2 -3
- package/lib/transforms/sectionToc.js +18 -0
- package/lib/transforms/toc.js +10 -335
- package/lib/types.js +11 -0
- package/lib/utils/fs.js +21 -19
- package/lib/utils/fs.test.js +4 -5
- package/lib/utils/logs.js +7 -2
- package/lib/utils/md/filters.js +5 -5
- package/lib/utils/md/find-code-blocks.js +16 -8
- package/lib/utils/md/find-frontmatter.js +11 -13
- package/lib/utils/md/find-frontmatter.test.js +2 -2
- package/lib/utils/md/find-html-tags.js +1 -1
- package/lib/utils/md/find-images-md.js +27 -0
- package/lib/utils/md/find-images.js +39 -34
- package/lib/utils/md/find-links.js +72 -54
- package/lib/utils/md/find-unmatched-html-tags.js +1 -2
- package/lib/utils/md/fixtures/file-with-links.md +10 -0
- package/lib/utils/md/md.test.js +72 -4
- package/lib/utils/md/parse.js +91 -67
- package/lib/utils/regex-timeout.js +2 -1
- package/lib/utils/regex.js +3 -2
- package/lib/utils/remoteRequest.js +1 -0
- package/lib/utils/syntax.js +3 -0
- package/lib/utils/text.js +71 -3
- package/lib/utils/text.test.js +3 -9
- package/lib/utils/toc.js +315 -0
- package/package.json +7 -3
- package/lib/options-parser.js +0 -498
- package/lib/options-parser.test.js +0 -1237
- package/lib/utils/html-to-json/compat.js +0 -42
- package/lib/utils/html-to-json/format.js +0 -64
- package/lib/utils/html-to-json/index.js +0 -37
- package/lib/utils/html-to-json/lexer.js +0 -345
- package/lib/utils/html-to-json/parser.js +0 -146
- package/lib/utils/html-to-json/stringify.js +0 -37
- package/lib/utils/html-to-json/tags.js +0 -171
|
@@ -1,1237 +0,0 @@
|
|
|
1
|
-
const { test } = require('uvu')
|
|
2
|
-
const assert = require('uvu/assert')
|
|
3
|
-
const { optionsParse, options } = require('./options-parser')
|
|
4
|
-
|
|
5
|
-
test('Empty value', () => {
|
|
6
|
-
assert.equal(optionsParse(), {}, 'undefined val')
|
|
7
|
-
assert.equal(optionsParse(''), {}, 'empty string')
|
|
8
|
-
assert.equal(optionsParse(null), {}, 'null')
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
const stringExample = `abc=yo foo=bar baz='hello' bim='boop dop' fizz="pop" pow="bang bang"`
|
|
12
|
-
test('string test', () => {
|
|
13
|
-
const parsedValue = optionsParse(stringExample)
|
|
14
|
-
// console.log('parsedValue', parsedValue)
|
|
15
|
-
assert.equal(parsedValue, {
|
|
16
|
-
abc: 'yo',
|
|
17
|
-
foo: 'bar',
|
|
18
|
-
baz: 'hello',
|
|
19
|
-
bim: 'boop dop',
|
|
20
|
-
fizz: "pop",
|
|
21
|
-
pow: "bang bang"
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const stringExampleWithBoolean = `abc=yo foo=bar bim='boop dop' boo=true`
|
|
26
|
-
test('string test two', () => {
|
|
27
|
-
const parsedValue = optionsParse(stringExampleWithBoolean)
|
|
28
|
-
// console.log('parsedValue', parsedValue)
|
|
29
|
-
assert.equal(parsedValue, {
|
|
30
|
-
abc: 'yo',
|
|
31
|
-
foo: 'bar',
|
|
32
|
-
bim: 'boop dop',
|
|
33
|
-
boo: true
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const bigExample = `width={999}
|
|
38
|
-
height={{111}}
|
|
39
|
-
numberAsString="12345"
|
|
40
|
-
great={["scoot", "sco ot", 'scooo ttt']}
|
|
41
|
-
nice={{ value: nice, cool: "true" }}
|
|
42
|
-
soclose=[jdjdjd, hdhfhfhffh]
|
|
43
|
-
rad="boss"
|
|
44
|
-
cool=true notCool=false
|
|
45
|
-
nooooo={[one, two, 3, 4]}
|
|
46
|
-
numberArray=[3, 7]
|
|
47
|
-
stringArray=["3", "7"]
|
|
48
|
-
numberZero=0,
|
|
49
|
-
xyz=999,
|
|
50
|
-
nope=false,
|
|
51
|
-
// comment
|
|
52
|
-
yes={true}
|
|
53
|
-
isWhat,
|
|
54
|
-
/* comment */
|
|
55
|
-
foo={{ rad: ["whatever", "man", "with spaces"], cool: { beans: 'here' } }}
|
|
56
|
-
# other comment
|
|
57
|
-
what='xnxnx'
|
|
58
|
-
isLoading
|
|
59
|
-
whatever={{ chill: "https://app.netlify.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna", pill: ['yo']}}
|
|
60
|
-
href="https://fooo.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna"
|
|
61
|
-
src="https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg"
|
|
62
|
-
deep={{ rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }}`
|
|
63
|
-
|
|
64
|
-
test('Multi line', () => {
|
|
65
|
-
const parsedValue = optionsParse(bigExample)
|
|
66
|
-
// console.log('parsedValue', parsedValue)
|
|
67
|
-
assert.equal(parsedValue, {
|
|
68
|
-
width: 999,
|
|
69
|
-
height: 111,
|
|
70
|
-
numberAsString: "12345",
|
|
71
|
-
great: [ 'scoot', 'sco ot', 'scooo ttt' ],
|
|
72
|
-
nice: { value: 'nice', cool: 'true' },
|
|
73
|
-
soclose: [ 'jdjdjd', 'hdhfhfhffh' ],
|
|
74
|
-
rad: 'boss',
|
|
75
|
-
cool: true,
|
|
76
|
-
notCool: false,
|
|
77
|
-
nooooo: [ 'one', 'two', 3, 4 ],
|
|
78
|
-
numberArray: [3, 7],
|
|
79
|
-
stringArray: ["3", "7"],
|
|
80
|
-
numberZero: 0,
|
|
81
|
-
xyz: 999,
|
|
82
|
-
nope: false,
|
|
83
|
-
yes: true,
|
|
84
|
-
isWhat: true,
|
|
85
|
-
foo: { rad: [ 'whatever', 'man', "with spaces" ], cool: { beans: 'here' } },
|
|
86
|
-
what: 'xnxnx',
|
|
87
|
-
isLoading: true,
|
|
88
|
-
whatever: {
|
|
89
|
-
chill: "https://app.netlify.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna",
|
|
90
|
-
pill: [ 'yo' ]
|
|
91
|
-
},
|
|
92
|
-
href: "https://fooo.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna",
|
|
93
|
-
src: 'https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg',
|
|
94
|
-
deep: { rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }
|
|
95
|
-
}, 'matches original')
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
const testSpacing = `width={999}
|
|
99
|
-
height={{111}}
|
|
100
|
-
numberAsString="12345"
|
|
101
|
-
great={["scoot", "sco ot", 'scooo ttt']}
|
|
102
|
-
nope=false,
|
|
103
|
-
// comment
|
|
104
|
-
yes={true}
|
|
105
|
-
isWhat,
|
|
106
|
-
/* comment */
|
|
107
|
-
foo={{ rad: ["what ever", "man"], cool: { beans: 'here' } }}
|
|
108
|
-
# other comment
|
|
109
|
-
what='xnxnx'
|
|
110
|
-
isLoading
|
|
111
|
-
href="https://fooo.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna"
|
|
112
|
-
src="https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg"
|
|
113
|
-
deep={{ rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }}
|
|
114
|
-
`
|
|
115
|
-
|
|
116
|
-
// Verify indentation doesnt matter
|
|
117
|
-
test('Multi line indent', () => {
|
|
118
|
-
const parsedValue = optionsParse(testSpacing)
|
|
119
|
-
// console.log('parsedValue', parsedValue)
|
|
120
|
-
assert.equal(parsedValue, {
|
|
121
|
-
width: 999,
|
|
122
|
-
height: 111,
|
|
123
|
-
numberAsString: '12345',
|
|
124
|
-
great: [ 'scoot', 'sco ot', 'scooo ttt' ],
|
|
125
|
-
nope: false,
|
|
126
|
-
yes: true,
|
|
127
|
-
isWhat: true,
|
|
128
|
-
foo: { rad: [ 'what ever', 'man' ], cool: { beans: 'here' } },
|
|
129
|
-
what: 'xnxnx',
|
|
130
|
-
isLoading: true,
|
|
131
|
-
href: "https://fooo.com/start/deploy?repository=https://github.com/netlify/netlify-faunadb-example&stack=fauna",
|
|
132
|
-
src: 'https://user-images.github{user}content.com/532272/123136878-46f1a300-d408-11eb-82f2-ad452498457b.jpg',
|
|
133
|
-
deep: { rad: 'blue', what: { nice: 'cool', wow: { deep: true } } }
|
|
134
|
-
}, 'matches original')
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
test('Single line', () => {
|
|
138
|
-
const parsedValue = optionsParse(`width={999} height={{111}} numberAsString="12345" great={["scoot", "sco ot", 'scooo ttt']} nice={{ value: nice, cool: "true" }} soclose=[jdjdjd, hdhfhfhffh] rad="boss" cool=true isCool notCool=false nooooo={[one, two, 3, 4]}`)
|
|
139
|
-
// console.log('parsedValue', parsedValue)
|
|
140
|
-
assert.equal(parsedValue, {
|
|
141
|
-
width: 999,
|
|
142
|
-
height: 111,
|
|
143
|
-
numberAsString: '12345',
|
|
144
|
-
great: [ 'scoot', 'sco ot', 'scooo ttt' ],
|
|
145
|
-
nice: { value: 'nice', cool: 'true' },
|
|
146
|
-
soclose: [ 'jdjdjd', 'hdhfhfhffh' ],
|
|
147
|
-
rad: 'boss',
|
|
148
|
-
cool: true,
|
|
149
|
-
isCool: true,
|
|
150
|
-
notCool: false,
|
|
151
|
-
nooooo: [ 'one', 'two', 3, 4 ]
|
|
152
|
-
}, 'matches original')
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
test('Simple string equal (single quotes)', () => {
|
|
156
|
-
const parsedValue = optionsParse(`bob='cool'`)
|
|
157
|
-
assert.equal(parsedValue, {
|
|
158
|
-
bob: 'cool',
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
test('Simple string equal (double quotes)', () => {
|
|
163
|
-
const parsedValue = optionsParse(`bob="cool"`)
|
|
164
|
-
assert.equal(parsedValue, {
|
|
165
|
-
bob: 'cool',
|
|
166
|
-
})
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
test('Simple string equal (no quotes). key=value', () => {
|
|
170
|
-
const parsedValue = optionsParse(`bob=cool`)
|
|
171
|
-
assert.equal(parsedValue, {
|
|
172
|
-
bob: 'cool',
|
|
173
|
-
})
|
|
174
|
-
// Booleans are booleans
|
|
175
|
-
assert.equal(optionsParse(`thingy=true`), { thingy: true })
|
|
176
|
-
assert.equal(optionsParse(`thingy=false`), { thingy: false })
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
test('Simple string equal (no quotes with spaces). key = value', () => {
|
|
180
|
-
const answer = { bob: 'cool' }
|
|
181
|
-
const one = optionsParse(`bob = cool`)
|
|
182
|
-
const two = optionsParse(`bob= cool`)
|
|
183
|
-
const three = optionsParse(`bob =cool`)
|
|
184
|
-
|
|
185
|
-
// console.log('parsedValue', parsedValue)
|
|
186
|
-
assert.equal(one, answer)
|
|
187
|
-
assert.equal(two, answer)
|
|
188
|
-
assert.equal(three, answer)
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
test('Simple string react-like syntax. key={"value"}', () => {
|
|
192
|
-
const answer = { bob: 'cool' }
|
|
193
|
-
const four = optionsParse(`bob={'cool'}`)
|
|
194
|
-
const five = optionsParse(`bob={"cool"}`)
|
|
195
|
-
const six = optionsParse(`bob={{"cool"}}`)
|
|
196
|
-
assert.equal(four, answer)
|
|
197
|
-
assert.equal(five, answer)
|
|
198
|
-
assert.equal(six, answer)
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
test('Simple strings mixed', () => {
|
|
202
|
-
const answer = {
|
|
203
|
-
bob: 'cool',
|
|
204
|
-
joe: 'cool',
|
|
205
|
-
bill: "cool",
|
|
206
|
-
steve: 'cool'
|
|
207
|
-
}
|
|
208
|
-
const one = optionsParse(`
|
|
209
|
-
bob = cool
|
|
210
|
-
joe=cool
|
|
211
|
-
bill="cool"
|
|
212
|
-
steve='cool'
|
|
213
|
-
`)
|
|
214
|
-
// console.log('parsedValue', parsedValue)
|
|
215
|
-
assert.equal(one, answer)
|
|
216
|
-
|
|
217
|
-
const two = optionsParse(`bob = cool joe=cool bill="cool" steve='cool'`)
|
|
218
|
-
assert.equal(two, answer)
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
test('Simple numbers', () => {
|
|
222
|
-
const one = optionsParse(`isCool=20`)
|
|
223
|
-
assert.equal(one, { isCool: 20 })
|
|
224
|
-
|
|
225
|
-
const two = optionsParse(`isCool=20.2`)
|
|
226
|
-
assert.equal(two, { isCool: 20.2 })
|
|
227
|
-
|
|
228
|
-
const three = optionsParse(`isCool={20.2}`)
|
|
229
|
-
assert.equal(three, { isCool: 20.2 })
|
|
230
|
-
|
|
231
|
-
const four = optionsParse(`isCool={{20.2}}`)
|
|
232
|
-
assert.equal(four, { isCool: 20.2 })
|
|
233
|
-
|
|
234
|
-
const five = optionsParse(`isCool=0`)
|
|
235
|
-
assert.equal(five, { isCool: 0 })
|
|
236
|
-
|
|
237
|
-
const sixAsString = optionsParse(`isCool="0"`)
|
|
238
|
-
assert.equal(sixAsString, { isCool: "0" })
|
|
239
|
-
|
|
240
|
-
const decimal = optionsParse(`isCool=0.22`)
|
|
241
|
-
assert.equal(decimal, { isCool: 0.22 })
|
|
242
|
-
|
|
243
|
-
const brackets = optionsParse(`isCool={0.22}`)
|
|
244
|
-
assert.equal(brackets, { isCool: 0.22 })
|
|
245
|
-
})
|
|
246
|
-
|
|
247
|
-
test('Simple boolean', () => {
|
|
248
|
-
const answer = { isCool: true }
|
|
249
|
-
const one = optionsParse(`isCool`)
|
|
250
|
-
const two = optionsParse(`isCool = true`)
|
|
251
|
-
const three = optionsParse(`isCool =true`)
|
|
252
|
-
const four = optionsParse(`isCool=true`)
|
|
253
|
-
const fourx = optionsParse(`isCool={true}`)
|
|
254
|
-
const foury = optionsParse(`isCool={{true}}`)
|
|
255
|
-
const boolString = optionsParse(`isCool="true"`)
|
|
256
|
-
const boolStringTwo = optionsParse(`isCool='true'`)
|
|
257
|
-
const boolStringThree = optionsParse(`isCool={'true'}`)
|
|
258
|
-
|
|
259
|
-
assert.equal(one, answer)
|
|
260
|
-
assert.equal(two, answer)
|
|
261
|
-
assert.equal(three, answer)
|
|
262
|
-
assert.equal(four, answer)
|
|
263
|
-
assert.equal(fourx, answer)
|
|
264
|
-
assert.equal(foury, answer)
|
|
265
|
-
assert.equal(boolString, { isCool: 'true' })
|
|
266
|
-
assert.equal(boolStringTwo, { isCool: 'true' })
|
|
267
|
-
assert.equal(boolStringThree, { isCool: 'true' })
|
|
268
|
-
|
|
269
|
-
const answerTwo = { isNotCool: false }
|
|
270
|
-
const five = optionsParse(`isNotCool=false`)
|
|
271
|
-
const six = optionsParse(`isNotCool = false`)
|
|
272
|
-
const seven = optionsParse(`isNotCool =false`)
|
|
273
|
-
const eight = optionsParse(`isNotCool=false`)
|
|
274
|
-
const nine = optionsParse(`isNotCool= false`)
|
|
275
|
-
const ten = optionsParse(`isNotCool={false}`)
|
|
276
|
-
const eleven = optionsParse(`isNotCool={{false}}`)
|
|
277
|
-
const boolStringFalse = optionsParse(`isNotCool="false"`)
|
|
278
|
-
const boolStringFalseTwo = optionsParse(`isNotCool='false'`)
|
|
279
|
-
const boolStringFalseThree = optionsParse(`isNotCool={'false'}`)
|
|
280
|
-
|
|
281
|
-
assert.equal(five, answerTwo, 'five')
|
|
282
|
-
assert.equal(six, answerTwo, 'six')
|
|
283
|
-
assert.equal(seven, answerTwo, 'seven')
|
|
284
|
-
assert.equal(eight, answerTwo, 'eight')
|
|
285
|
-
assert.equal(nine, answerTwo, 'nine')
|
|
286
|
-
assert.equal(ten, answerTwo, 'ten')
|
|
287
|
-
assert.equal(eleven, answerTwo, 'eleven')
|
|
288
|
-
assert.equal(boolStringFalse, { isNotCool: 'false' })
|
|
289
|
-
assert.equal(boolStringFalseTwo, { isNotCool: 'false' })
|
|
290
|
-
assert.equal(boolStringFalseThree, { isNotCool: 'false' })
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
test('Multiline boolean', () => {
|
|
294
|
-
const answer = {
|
|
295
|
-
bob: 'cool',
|
|
296
|
-
joe: 'cool',
|
|
297
|
-
isRad: true,
|
|
298
|
-
isWow: true,
|
|
299
|
-
bill: "cool",
|
|
300
|
-
isNotCool: false,
|
|
301
|
-
steve: 'cool',
|
|
302
|
-
isCool: true
|
|
303
|
-
}
|
|
304
|
-
const one = optionsParse(`
|
|
305
|
-
bob = cool
|
|
306
|
-
joe=cool
|
|
307
|
-
isRad
|
|
308
|
-
isWow,
|
|
309
|
-
bill="cool"
|
|
310
|
-
isNotCool=false
|
|
311
|
-
steve='cool'
|
|
312
|
-
isCool
|
|
313
|
-
`)
|
|
314
|
-
// console.log('parsedValue', parsedValue)
|
|
315
|
-
assert.equal(one, answer)
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
test('Simple object', () => {
|
|
319
|
-
const a = { key: { a: 'b' }}
|
|
320
|
-
assert.equal(a, optionsParse(`key={{ "a": "b" }}`))
|
|
321
|
-
assert.equal(a, optionsParse(`key={{ "a": b }}`))
|
|
322
|
-
assert.equal(a, optionsParse(`key={{ a: "b" }}`))
|
|
323
|
-
assert.equal(a, optionsParse(`key={{ a: b }}`))
|
|
324
|
-
assert.equal(a, optionsParse(`key={ a : b }`), 'single {')
|
|
325
|
-
|
|
326
|
-
const answer = { nice: { value: 'nice', cool: 'true', awesome: false } }
|
|
327
|
-
const one = optionsParse(`nice={{ value: nice, cool: "true", awesome: false, }}`)
|
|
328
|
-
assert.equal(one, answer)
|
|
329
|
-
const two = optionsParse(`nice={{
|
|
330
|
-
value: nice,
|
|
331
|
-
cool: "true",
|
|
332
|
-
awesome: false
|
|
333
|
-
}}`)
|
|
334
|
-
assert.equal(two, answer)
|
|
335
|
-
})
|
|
336
|
-
|
|
337
|
-
test('Object in quotes is string', () => {
|
|
338
|
-
const a = optionsParse(`key="{ xjsjsj }"`)
|
|
339
|
-
assert.equal(a, {
|
|
340
|
-
key: "{ xjsjsj }"
|
|
341
|
-
}, 'a')
|
|
342
|
-
const b = optionsParse(`key='{ foo:bar }'`)
|
|
343
|
-
assert.equal(b, {
|
|
344
|
-
key: "{ foo:bar }"
|
|
345
|
-
}, 'b')
|
|
346
|
-
const c = optionsParse(`key='{ "foo": "bar" }'`)
|
|
347
|
-
assert.equal(c, {
|
|
348
|
-
key: '{ "foo": "bar" }'
|
|
349
|
-
}, 'c')
|
|
350
|
-
const d = optionsParse(`key='{{ "foo": "bar" }}'`)
|
|
351
|
-
assert.equal(d, {
|
|
352
|
-
key: '{{ "foo": "bar" }}'
|
|
353
|
-
}, 'd')
|
|
354
|
-
})
|
|
355
|
-
|
|
356
|
-
test('Deep object', () => {
|
|
357
|
-
const doubleBracket = `
|
|
358
|
-
foo={{
|
|
359
|
-
baz: {
|
|
360
|
-
bar: {
|
|
361
|
-
fuzz: "hello"
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}}
|
|
365
|
-
`
|
|
366
|
-
const val = optionsParse(doubleBracket)
|
|
367
|
-
assert.equal(val, {
|
|
368
|
-
foo: {
|
|
369
|
-
baz: {
|
|
370
|
-
bar: {
|
|
371
|
-
fuzz: "hello"
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}, 'doubleBracket')
|
|
376
|
-
|
|
377
|
-
const singleBracket = `
|
|
378
|
-
foo={
|
|
379
|
-
baz: {
|
|
380
|
-
bar: {
|
|
381
|
-
fuzz: "hello"
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
`
|
|
386
|
-
const valTwo = optionsParse(singleBracket)
|
|
387
|
-
assert.equal(valTwo, {
|
|
388
|
-
foo: {
|
|
389
|
-
baz: {
|
|
390
|
-
bar: {
|
|
391
|
-
fuzz: "hello"
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}, 'singleBracket')
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
test('Deep object with quotes', () => {
|
|
399
|
-
const withQuotes = `
|
|
400
|
-
foo={
|
|
401
|
-
"baz": {
|
|
402
|
-
"bar": {
|
|
403
|
-
"fuzz": "hello there",
|
|
404
|
-
"x": ["hello there"]
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
`
|
|
409
|
-
const valThree = optionsParse(withQuotes)
|
|
410
|
-
assert.equal(valThree, {
|
|
411
|
-
foo: {
|
|
412
|
-
baz: {
|
|
413
|
-
bar: {
|
|
414
|
-
fuzz: "hello there",
|
|
415
|
-
"x": ["hello there"]
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}, 'withQuotes')
|
|
420
|
-
})
|
|
421
|
-
|
|
422
|
-
test('Simple array', () => {
|
|
423
|
-
const x = { key: [ 1, 2, 3 ] }
|
|
424
|
-
const y = optionsParse(`key=[ 1, 2, 3 ]`)
|
|
425
|
-
assert.equal(x, y)
|
|
426
|
-
|
|
427
|
-
const z = optionsParse(`key=[ "1", "2", "3" ]`)
|
|
428
|
-
assert.equal(z, { key: [ "1", "2", "3" ] })
|
|
429
|
-
|
|
430
|
-
const trailingComma = optionsParse(`key=[ "1", "2", "3", ]`)
|
|
431
|
-
assert.equal(trailingComma, { key: [ "1", "2", "3" ] })
|
|
432
|
-
|
|
433
|
-
const a = optionsParse(`key=[ one, two, three ]`)
|
|
434
|
-
assert.equal(a, { key: [ "one", "two", "three" ] })
|
|
435
|
-
|
|
436
|
-
const answer = { great: [ 'scoot', 'sco ot', 'scooo ttt', 'one', 'two', 3, 4, true ] }
|
|
437
|
-
const one = optionsParse(`great={["scoot", "sco ot", 'scooo ttt', one, two, 3, 4, true]} `)
|
|
438
|
-
assert.equal(one, answer)
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
test('Complex array with array', () => {
|
|
442
|
-
const a = optionsParse(`
|
|
443
|
-
key=[ true, two, "three", 2, ["nested", "array"], ["nested", "arrayTwo"]]`)
|
|
444
|
-
assert.equal(a, {
|
|
445
|
-
key: [
|
|
446
|
-
true,
|
|
447
|
-
"two",
|
|
448
|
-
"three",
|
|
449
|
-
2,
|
|
450
|
-
["nested", "array"],
|
|
451
|
-
["nested", "arrayTwo"]
|
|
452
|
-
]
|
|
453
|
-
})
|
|
454
|
-
|
|
455
|
-
const multiLineArray = optionsParse(`
|
|
456
|
-
key={[
|
|
457
|
-
true,
|
|
458
|
-
two,
|
|
459
|
-
"three",
|
|
460
|
-
2,
|
|
461
|
-
["nested", "array"],
|
|
462
|
-
["nested", "arrayTwo"]
|
|
463
|
-
]}`)
|
|
464
|
-
assert.equal(multiLineArray, {
|
|
465
|
-
key: [
|
|
466
|
-
true,
|
|
467
|
-
"two",
|
|
468
|
-
"three",
|
|
469
|
-
2,
|
|
470
|
-
["nested", "array"],
|
|
471
|
-
["nested", "arrayTwo"]
|
|
472
|
-
]
|
|
473
|
-
}, 'multiLineArray')
|
|
474
|
-
})
|
|
475
|
-
|
|
476
|
-
test('Complex array with object', () => {
|
|
477
|
-
const a = optionsParse(`
|
|
478
|
-
key=[ true, two, "three", 2, {
|
|
479
|
-
foo: {
|
|
480
|
-
baz: {
|
|
481
|
-
bar: {
|
|
482
|
-
fuzz: "hello there",
|
|
483
|
-
"x": ["hello there"]
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}]`)
|
|
488
|
-
assert.equal(a, {
|
|
489
|
-
key: [
|
|
490
|
-
true,
|
|
491
|
-
"two",
|
|
492
|
-
"three",
|
|
493
|
-
2,
|
|
494
|
-
{
|
|
495
|
-
foo: {
|
|
496
|
-
baz: {
|
|
497
|
-
bar: {
|
|
498
|
-
fuzz: "hello there",
|
|
499
|
-
"x": ["hello there"]
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
]
|
|
505
|
-
})
|
|
506
|
-
})
|
|
507
|
-
|
|
508
|
-
test('Mixed array syntax', () => {
|
|
509
|
-
const smallExample = `
|
|
510
|
-
lines=[3, 7]
|
|
511
|
-
brackets={[3, 7]}
|
|
512
|
-
bracketsWithStrings={['3', '7']}
|
|
513
|
-
abc=["3", "7", { foo: 'bar' }]
|
|
514
|
-
xyz=['3', '7']
|
|
515
|
-
mixed=["3", '7']
|
|
516
|
-
qwerty=[bob, steve]
|
|
517
|
-
notArray='[]'
|
|
518
|
-
notArrayTwo='[foobar]'
|
|
519
|
-
notArrayThree='["foobar"]'
|
|
520
|
-
notArrayFour='[wrapped, in, quotes]'
|
|
521
|
-
notArrayFive="[wrapped, in, doublequotes]"
|
|
522
|
-
`
|
|
523
|
-
const parsedValue = optionsParse(smallExample)
|
|
524
|
-
// console.log('parsedValue', parsedValue)
|
|
525
|
-
assert.equal(parsedValue, {
|
|
526
|
-
lines: [ 3, 7 ],
|
|
527
|
-
brackets: [3, 7],
|
|
528
|
-
bracketsWithStrings: ['3', '7'],
|
|
529
|
-
abc: [ '3', '7', { foo: 'bar' } ],
|
|
530
|
-
xyz: [ '3', '7' ],
|
|
531
|
-
mixed: [ '3', '7' ],
|
|
532
|
-
notArray: '[]',
|
|
533
|
-
notArrayTwo: '[foobar]',
|
|
534
|
-
notArrayThree: '["foobar"]',
|
|
535
|
-
qwerty: [ 'bob', 'steve' ],
|
|
536
|
-
notArrayFour: '[wrapped, in, quotes]',
|
|
537
|
-
notArrayFive: '[wrapped, in, doublequotes]'
|
|
538
|
-
})
|
|
539
|
-
})
|
|
540
|
-
|
|
541
|
-
test('Strings are NOT arrays', () => {
|
|
542
|
-
const smallExample = `
|
|
543
|
-
lines=[3, 7]
|
|
544
|
-
notArray='[]'
|
|
545
|
-
notArrayTwo='[foobar]'
|
|
546
|
-
notArrayThree='["foobar"]'
|
|
547
|
-
notArrayFour='[wrapped, in, quotes]'
|
|
548
|
-
notArrayFive="[wrapped, in, doublequotes]"
|
|
549
|
-
`
|
|
550
|
-
const parsedValue = optionsParse(smallExample)
|
|
551
|
-
//console.log('parsedValue', parsedValue)
|
|
552
|
-
assert.equal(parsedValue, {
|
|
553
|
-
lines: [ 3, 7 ],
|
|
554
|
-
notArray: '[]',
|
|
555
|
-
notArrayTwo: '[foobar]',
|
|
556
|
-
notArrayThree: '["foobar"]',
|
|
557
|
-
notArrayFour: '[wrapped, in, quotes]',
|
|
558
|
-
notArrayFive: '[wrapped, in, doublequotes]'
|
|
559
|
-
})
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
test('oddly "broken" inner quotes', () => {
|
|
563
|
-
const smallExample = `
|
|
564
|
-
x='[foo'bar]'
|
|
565
|
-
y="[foo"bar]"
|
|
566
|
-
z='''''''
|
|
567
|
-
a=""""""" test="foo"
|
|
568
|
-
b='"'"'"'"'
|
|
569
|
-
// c="tons of" weird inner quotes" // this doesnt work
|
|
570
|
-
d="bar"
|
|
571
|
-
`
|
|
572
|
-
const parsedValue = optionsParse(smallExample)
|
|
573
|
-
// console.log('parsedValue', parsedValue)
|
|
574
|
-
assert.equal(parsedValue, {
|
|
575
|
-
x: "[foo'bar]",
|
|
576
|
-
y: '[foo"bar]',
|
|
577
|
-
z: "'''''",
|
|
578
|
-
a: '"""""',
|
|
579
|
-
test: "foo",
|
|
580
|
-
b: '"\'"\'"\'"',
|
|
581
|
-
// c: "tons of\" weird inner quotes",
|
|
582
|
-
d: 'bar'
|
|
583
|
-
})
|
|
584
|
-
})
|
|
585
|
-
|
|
586
|
-
test('Single quotes inside double quotes', () => {
|
|
587
|
-
const one = optionsParse(`bob="co'ol" steve="co'ol"`)
|
|
588
|
-
// console.log('parsedValue', parsedValue)
|
|
589
|
-
assert.equal(one, {
|
|
590
|
-
bob: "co'ol",
|
|
591
|
-
steve: "co'ol",
|
|
592
|
-
}, 'one')
|
|
593
|
-
|
|
594
|
-
const two = optionsParse(`bob='co "ol' steve='co"ol'`)
|
|
595
|
-
// console.log('parsedValue', parsedValue)
|
|
596
|
-
assert.equal(two, {
|
|
597
|
-
bob: "co \"ol",
|
|
598
|
-
steve: "co\"ol",
|
|
599
|
-
}, 'two')
|
|
600
|
-
|
|
601
|
-
const three = optionsParse(`bob="co ol" steve="co ol"`)
|
|
602
|
-
// console.log('parsedValue', parsedValue)
|
|
603
|
-
assert.equal(three, {
|
|
604
|
-
bob: "co ol",
|
|
605
|
-
steve: "co ol",
|
|
606
|
-
}, 'three')
|
|
607
|
-
|
|
608
|
-
const four = optionsParse(`bob='co "ol' steve='co""""ol'`)
|
|
609
|
-
// console.log('parsedValue', parsedValue)
|
|
610
|
-
assert.equal(four, {
|
|
611
|
-
bob: "co \"ol",
|
|
612
|
-
//steve: "co\"\"\"\"ol",
|
|
613
|
-
steve: 'co""""ol'
|
|
614
|
-
})
|
|
615
|
-
|
|
616
|
-
const five = optionsParse(`title='Wow "this" is great'`)
|
|
617
|
-
assert.equal(five, {
|
|
618
|
-
title: 'Wow "this" is great',
|
|
619
|
-
})
|
|
620
|
-
|
|
621
|
-
const six = optionsParse(`title="Wow \"this\" is great"`)
|
|
622
|
-
assert.equal(six, {
|
|
623
|
-
title: 'Wow "this" is great',
|
|
624
|
-
})
|
|
625
|
-
|
|
626
|
-
const seven = optionsParse(`title='Wow "this" is great'`)
|
|
627
|
-
assert.equal(seven, {
|
|
628
|
-
title: 'Wow "this" is great',
|
|
629
|
-
})
|
|
630
|
-
|
|
631
|
-
const eight = optionsParse(`title='Wow \'this\' is great'`)
|
|
632
|
-
assert.equal(eight, {
|
|
633
|
-
title: "Wow 'this' is great",
|
|
634
|
-
})
|
|
635
|
-
})
|
|
636
|
-
|
|
637
|
-
test('Remove single line comments', () => {
|
|
638
|
-
const answer = {
|
|
639
|
-
bob: 'cool',
|
|
640
|
-
joe: 'cool',
|
|
641
|
-
bill: "cool",
|
|
642
|
-
steve: 'cool',
|
|
643
|
-
}
|
|
644
|
-
const one = optionsParse(`
|
|
645
|
-
bob = cool
|
|
646
|
-
# Remove this
|
|
647
|
-
joe=cool
|
|
648
|
-
/* Remove this */
|
|
649
|
-
bill="cool"
|
|
650
|
-
// Remove this
|
|
651
|
-
steve='cool'
|
|
652
|
-
`)
|
|
653
|
-
// console.log('parsedValue', parsedValue)
|
|
654
|
-
assert.equal(one, answer)
|
|
655
|
-
})
|
|
656
|
-
|
|
657
|
-
test('Remove multi line comments', () => {
|
|
658
|
-
const answer = {
|
|
659
|
-
bob: 'cool',
|
|
660
|
-
joe: 'cool',
|
|
661
|
-
bill: "cool",
|
|
662
|
-
steve: 'cool',
|
|
663
|
-
jim: 'dope'
|
|
664
|
-
}
|
|
665
|
-
const one = optionsParse(`
|
|
666
|
-
bob = cool
|
|
667
|
-
# Remove this
|
|
668
|
-
# And this Remove this
|
|
669
|
-
joe=cool
|
|
670
|
-
// deadOption="foobar"
|
|
671
|
-
/* Remove this
|
|
672
|
-
and this
|
|
673
|
-
and this too
|
|
674
|
-
*/
|
|
675
|
-
bill="cool"
|
|
676
|
-
/*
|
|
677
|
-
Remove this
|
|
678
|
-
and this
|
|
679
|
-
and this too
|
|
680
|
-
*/
|
|
681
|
-
// Remove this
|
|
682
|
-
// And this
|
|
683
|
-
steve='cool'
|
|
684
|
-
/**
|
|
685
|
-
* This is striped out
|
|
686
|
-
* very nice
|
|
687
|
-
*/
|
|
688
|
-
jim="dope"
|
|
689
|
-
`)
|
|
690
|
-
// console.log('parsedValue', parsedValue)
|
|
691
|
-
assert.equal(one, answer)
|
|
692
|
-
})
|
|
693
|
-
|
|
694
|
-
test('Remove multi line comments two', () => {
|
|
695
|
-
const answer = {
|
|
696
|
-
bob: 'cool',
|
|
697
|
-
bill: "cool",
|
|
698
|
-
}
|
|
699
|
-
const one = optionsParse(`
|
|
700
|
-
bob = cool
|
|
701
|
-
/*
|
|
702
|
-
bobby="rad"
|
|
703
|
-
*/
|
|
704
|
-
bill="cool"
|
|
705
|
-
/*
|
|
706
|
-
* bobbyTwo="rad"
|
|
707
|
-
*/
|
|
708
|
-
`)
|
|
709
|
-
// console.log('parsedValue', parsedValue)
|
|
710
|
-
assert.equal(one, answer)
|
|
711
|
-
})
|
|
712
|
-
|
|
713
|
-
test('Handles inner double quotes', () => {
|
|
714
|
-
const answer = {
|
|
715
|
-
funny: 'wh"at',
|
|
716
|
-
}
|
|
717
|
-
const one = optionsParse(`
|
|
718
|
-
funny='wh"at'
|
|
719
|
-
`)
|
|
720
|
-
//console.log('parsedValue', one)
|
|
721
|
-
assert.equal(one, answer)
|
|
722
|
-
})
|
|
723
|
-
|
|
724
|
-
test('Handles inner single quotes', () => {
|
|
725
|
-
const answer = {
|
|
726
|
-
funny: "wh'at",
|
|
727
|
-
}
|
|
728
|
-
const one = optionsParse(`
|
|
729
|
-
funny="wh'at"
|
|
730
|
-
`)
|
|
731
|
-
// console.log('parsedValue', parsedValue)
|
|
732
|
-
assert.equal(one, answer)
|
|
733
|
-
})
|
|
734
|
-
|
|
735
|
-
test('Handles inner equals =', () => {
|
|
736
|
-
const answer = {
|
|
737
|
-
funny: "wh=at",
|
|
738
|
-
}
|
|
739
|
-
const one = optionsParse(`
|
|
740
|
-
funny="wh=at"
|
|
741
|
-
`)
|
|
742
|
-
assert.equal(one, answer, 'one')
|
|
743
|
-
const two = optionsParse(`
|
|
744
|
-
funny=wh=at
|
|
745
|
-
`)
|
|
746
|
-
assert.equal(two, answer, 'two')
|
|
747
|
-
const three = optionsParse(`
|
|
748
|
-
funny='wh=at'
|
|
749
|
-
`)
|
|
750
|
-
assert.equal(three, answer, 'three')
|
|
751
|
-
})
|
|
752
|
-
|
|
753
|
-
test('Handles escaped double quotes', () => {
|
|
754
|
-
const answer = {
|
|
755
|
-
funny: "wh\"at",
|
|
756
|
-
}
|
|
757
|
-
const one = optionsParse(`
|
|
758
|
-
funny="wh\"at",
|
|
759
|
-
`)
|
|
760
|
-
// console.log('parsedValue', parsedValue)
|
|
761
|
-
assert.equal(one, answer)
|
|
762
|
-
})
|
|
763
|
-
|
|
764
|
-
test('Handles escaped single quotes', () => {
|
|
765
|
-
const answer = {
|
|
766
|
-
funny: 'wh\'at',
|
|
767
|
-
}
|
|
768
|
-
const one = optionsParse(`
|
|
769
|
-
funny='wh\'at',
|
|
770
|
-
`)
|
|
771
|
-
// console.log('parsedValue', parsedValue)
|
|
772
|
-
assert.equal(one, answer)
|
|
773
|
-
})
|
|
774
|
-
|
|
775
|
-
test('Handles commas after key/values', () => {
|
|
776
|
-
const one = optionsParse(`funny='what', funky="cool", woah="co,ol", weird=what,`)
|
|
777
|
-
// console.log('parsedValue', one)
|
|
778
|
-
assert.equal(one, {
|
|
779
|
-
funny: 'what',
|
|
780
|
-
funky: "cool",
|
|
781
|
-
woah: "co,ol",
|
|
782
|
-
weird: 'what'
|
|
783
|
-
})
|
|
784
|
-
})
|
|
785
|
-
|
|
786
|
-
test('Handles commas after key/values multiline', () => {
|
|
787
|
-
const one = optionsParse(`
|
|
788
|
-
funny='what',
|
|
789
|
-
funky="cool",,,,
|
|
790
|
-
woah="co,ol",
|
|
791
|
-
weird=what,
|
|
792
|
-
`)
|
|
793
|
-
// console.log('parsedValue', one)
|
|
794
|
-
assert.equal(one, {
|
|
795
|
-
funny: 'what',
|
|
796
|
-
funky: "cool",
|
|
797
|
-
woah: "co,ol",
|
|
798
|
-
weird: 'what'
|
|
799
|
-
})
|
|
800
|
-
})
|
|
801
|
-
|
|
802
|
-
test('Handles *', () => {
|
|
803
|
-
const answer = {
|
|
804
|
-
funny: '*',
|
|
805
|
-
cool: '*!',
|
|
806
|
-
wow: '*-*',
|
|
807
|
-
trill: "**_**",
|
|
808
|
-
haha: "***",
|
|
809
|
-
rad: "*****"
|
|
810
|
-
}
|
|
811
|
-
const one = optionsParse(`
|
|
812
|
-
funny='*'
|
|
813
|
-
cool=*!
|
|
814
|
-
wow=*-*
|
|
815
|
-
trill={**_**}
|
|
816
|
-
haha={{***}}
|
|
817
|
-
rad="*****"
|
|
818
|
-
`)
|
|
819
|
-
// console.log('parsedValue', parsedValue)
|
|
820
|
-
assert.equal(one, answer)
|
|
821
|
-
})
|
|
822
|
-
|
|
823
|
-
test('Handles inner curly brackets {}', () => {
|
|
824
|
-
const answer = {
|
|
825
|
-
funny: '${funky}',
|
|
826
|
-
one: "weirdval}}}",
|
|
827
|
-
two: "weirdval}",
|
|
828
|
-
three: "weirdval}",
|
|
829
|
-
four: "weirdval",
|
|
830
|
-
five: "{weirdval",
|
|
831
|
-
six: "{{weirdval}}",
|
|
832
|
-
seven: "{{weirdval}}"
|
|
833
|
-
}
|
|
834
|
-
const one = optionsParse(`
|
|
835
|
-
funny='\${funky}'
|
|
836
|
-
one=weirdval}}}
|
|
837
|
-
two={{weirdval}}}
|
|
838
|
-
three={weirdval}}
|
|
839
|
-
four={{weirdval}}
|
|
840
|
-
five={{{weirdval}}
|
|
841
|
-
six="{{weirdval}}"
|
|
842
|
-
seven='{{weirdval}}'
|
|
843
|
-
`)
|
|
844
|
-
// console.log('parsedValue', parsedValue)
|
|
845
|
-
assert.equal(one, answer)
|
|
846
|
-
})
|
|
847
|
-
|
|
848
|
-
test('Handles inner brackets []', () => {
|
|
849
|
-
const answer = {
|
|
850
|
-
nice: '[whatever]x',
|
|
851
|
-
funny: '[[coool]]',
|
|
852
|
-
}
|
|
853
|
-
const one = optionsParse(`
|
|
854
|
-
nice='[whatever]x'
|
|
855
|
-
funny="[[coool]]"
|
|
856
|
-
`)
|
|
857
|
-
// console.log('parsedValue', parsedValue)
|
|
858
|
-
assert.equal(one, answer)
|
|
859
|
-
})
|
|
860
|
-
|
|
861
|
-
test('Handles variable syntax values', () => {
|
|
862
|
-
const one = optionsParse("nice=${file(./foo.js)}")
|
|
863
|
-
assert.equal(one, {
|
|
864
|
-
nice: '${file(./foo.js)}',
|
|
865
|
-
})
|
|
866
|
-
const two = optionsParse("nice='${file(./foo.js)}'")
|
|
867
|
-
assert.equal(two, {
|
|
868
|
-
nice: '${file(./foo.js)}',
|
|
869
|
-
})
|
|
870
|
-
const three = optionsParse(`nice='\${file("./foo.js")}'`)
|
|
871
|
-
assert.equal(three, {
|
|
872
|
-
nice: '${file("./foo.js")}',
|
|
873
|
-
})
|
|
874
|
-
const four = optionsParse(`nice='\${self:custom.stage}'`)
|
|
875
|
-
assert.equal(four, {
|
|
876
|
-
nice: '${self:custom.stage}',
|
|
877
|
-
})
|
|
878
|
-
})
|
|
879
|
-
|
|
880
|
-
test('Handles ${}', () => {
|
|
881
|
-
const one = optionsParse("what=arn:aws:sns:${self:custom.region}:*:${self:custom.topicName}")
|
|
882
|
-
assert.equal(one, {
|
|
883
|
-
what: 'arn:aws:sns:${self:custom.region}:*:${self:custom.topicName}',
|
|
884
|
-
})
|
|
885
|
-
const two = optionsParse("what=*********")
|
|
886
|
-
assert.equal(two, {
|
|
887
|
-
what: '*********',
|
|
888
|
-
})
|
|
889
|
-
})
|
|
890
|
-
|
|
891
|
-
test('Handles emojis', () => {
|
|
892
|
-
const one = optionsParse(`
|
|
893
|
-
what='😃'
|
|
894
|
-
cool='xyz😃'
|
|
895
|
-
`)
|
|
896
|
-
assert.equal(one, {
|
|
897
|
-
what: '😃',
|
|
898
|
-
cool: 'xyz😃'
|
|
899
|
-
})
|
|
900
|
-
})
|
|
901
|
-
|
|
902
|
-
test('Handles periods', () => {
|
|
903
|
-
const one = optionsParse("what=no.md")
|
|
904
|
-
assert.equal(one, {
|
|
905
|
-
what: 'no.md',
|
|
906
|
-
})
|
|
907
|
-
const two = optionsParse("what='no.md'")
|
|
908
|
-
assert.equal(two, {
|
|
909
|
-
what: 'no.md',
|
|
910
|
-
})
|
|
911
|
-
const three = optionsParse('what="no.md"')
|
|
912
|
-
assert.equal(three, {
|
|
913
|
-
what: 'no.md',
|
|
914
|
-
})
|
|
915
|
-
})
|
|
916
|
-
|
|
917
|
-
test('Handles commas', () => {
|
|
918
|
-
const one = optionsParse("what=no,md")
|
|
919
|
-
assert.equal(one, {
|
|
920
|
-
what: 'no,md',
|
|
921
|
-
})
|
|
922
|
-
const two = optionsParse("what='no,md'")
|
|
923
|
-
assert.equal(two, {
|
|
924
|
-
what: 'no,md',
|
|
925
|
-
})
|
|
926
|
-
const three = optionsParse('what="no,md"')
|
|
927
|
-
assert.equal(three, {
|
|
928
|
-
what: 'no,md',
|
|
929
|
-
})
|
|
930
|
-
const trimExtraTrailingComma = optionsParse('what="no,md",')
|
|
931
|
-
assert.equal(trimExtraTrailingComma, {
|
|
932
|
-
what: 'no,md',
|
|
933
|
-
})
|
|
934
|
-
})
|
|
935
|
-
|
|
936
|
-
test('Handles multiline values (indentation matters)', () => {
|
|
937
|
-
const one = optionsParse(`
|
|
938
|
-
what="
|
|
939
|
-
import {foo} from 'lodash'
|
|
940
|
-
import {bar} from 'lodash'
|
|
941
|
-
import {zaz} from 'lodash'
|
|
942
|
-
"`)
|
|
943
|
-
assert.equal(one, {
|
|
944
|
-
what: `
|
|
945
|
-
import {foo} from 'lodash'
|
|
946
|
-
import {bar} from 'lodash'
|
|
947
|
-
import {zaz} from 'lodash'
|
|
948
|
-
`,
|
|
949
|
-
})
|
|
950
|
-
})
|
|
951
|
-
|
|
952
|
-
test('Handles multiline values two (indentation matters)', () => {
|
|
953
|
-
const one = optionsParse(`
|
|
954
|
-
what="
|
|
955
|
-
import {foo} from 'lodash'
|
|
956
|
-
import {bar} from 'lodash'
|
|
957
|
-
import {zaz} from 'lodash'
|
|
958
|
-
"
|
|
959
|
-
`)
|
|
960
|
-
assert.equal(one, {
|
|
961
|
-
what: `
|
|
962
|
-
import {foo} from 'lodash'
|
|
963
|
-
import {bar} from 'lodash'
|
|
964
|
-
import {zaz} from 'lodash'
|
|
965
|
-
`,
|
|
966
|
-
})
|
|
967
|
-
})
|
|
968
|
-
|
|
969
|
-
test('Handles multiline values single quotes (indentation matters)', () => {
|
|
970
|
-
const one = optionsParse(`
|
|
971
|
-
baz="yolo"
|
|
972
|
-
what='
|
|
973
|
-
import {foo} from 'lodash'
|
|
974
|
-
import {bar} from "lodash"
|
|
975
|
-
import {zaz} from 'lodash'
|
|
976
|
-
'
|
|
977
|
-
bar=true
|
|
978
|
-
`)
|
|
979
|
-
assert.equal(one, {
|
|
980
|
-
baz: 'yolo',
|
|
981
|
-
what: `
|
|
982
|
-
import {foo} from 'lodash'
|
|
983
|
-
import {bar} from "lodash"
|
|
984
|
-
import {zaz} from 'lodash'
|
|
985
|
-
`,
|
|
986
|
-
bar: true
|
|
987
|
-
})
|
|
988
|
-
})
|
|
989
|
-
|
|
990
|
-
test('Handles multiline values {`reactStyle`}', () => {
|
|
991
|
-
const one = optionsParse(`
|
|
992
|
-
baz="yolo"
|
|
993
|
-
what={\`
|
|
994
|
-
import {foo} from 'lodash'
|
|
995
|
-
import {bar} from "lodash"
|
|
996
|
-
import {zaz} from 'lodash'
|
|
997
|
-
\`}
|
|
998
|
-
bar=true
|
|
999
|
-
`)
|
|
1000
|
-
assert.equal(one, {
|
|
1001
|
-
baz: 'yolo',
|
|
1002
|
-
what: `
|
|
1003
|
-
import {foo} from 'lodash'
|
|
1004
|
-
import {bar} from "lodash"
|
|
1005
|
-
import {zaz} from 'lodash'
|
|
1006
|
-
`,
|
|
1007
|
-
bar: true
|
|
1008
|
-
})
|
|
1009
|
-
})
|
|
1010
|
-
|
|
1011
|
-
// Doesnt work need to wrap in {} brackets
|
|
1012
|
-
test.skip('Handles multiline values wrapped in ``', () => {
|
|
1013
|
-
const one = optionsParse(`
|
|
1014
|
-
baz="yolo"
|
|
1015
|
-
what=\`
|
|
1016
|
-
import {foo} from 'lodash'
|
|
1017
|
-
import {bar} from "lodash"
|
|
1018
|
-
import {zaz} from 'lodash'
|
|
1019
|
-
\`
|
|
1020
|
-
bar=true
|
|
1021
|
-
`)
|
|
1022
|
-
console.log('one', one)
|
|
1023
|
-
assert.equal(one, {
|
|
1024
|
-
baz: 'yolo',
|
|
1025
|
-
what: `
|
|
1026
|
-
import {foo} from 'lodash'
|
|
1027
|
-
import {bar} from "lodash"
|
|
1028
|
-
import {zaz} from 'lodash'
|
|
1029
|
-
`,
|
|
1030
|
-
bar: true
|
|
1031
|
-
})
|
|
1032
|
-
})
|
|
1033
|
-
|
|
1034
|
-
test('Handles multiline values lorum ipsum', () => {
|
|
1035
|
-
const one = optionsParse(`
|
|
1036
|
-
baz="yolo"
|
|
1037
|
-
what={\`
|
|
1038
|
-
Lorem ipsum dolor sit amet, has te paulo sententiae argumentum, ius id saepe moderatius adversarium.
|
|
1039
|
-
Porro iudico deserunt mei ex. Est quas denique nostrum eu, ne sit eius mundi omnium.
|
|
1040
|
-
Eam labitur recteque dissentiet an. Fugit facer delectus ad quo, an vel debet vidisse percipitur, ex facilisi nominati laboramus cum. Mea lobortis accusamus ex. Nam id apeirian forensibus, in qui nisl illud mucius.
|
|
1041
|
-
\`}
|
|
1042
|
-
bar=true
|
|
1043
|
-
funky='fresh'
|
|
1044
|
-
`)
|
|
1045
|
-
assert.equal(one, {
|
|
1046
|
-
baz: 'yolo',
|
|
1047
|
-
what: `
|
|
1048
|
-
Lorem ipsum dolor sit amet, has te paulo sententiae argumentum, ius id saepe moderatius adversarium.
|
|
1049
|
-
Porro iudico deserunt mei ex. Est quas denique nostrum eu, ne sit eius mundi omnium.
|
|
1050
|
-
Eam labitur recteque dissentiet an. Fugit facer delectus ad quo, an vel debet vidisse percipitur, ex facilisi nominati laboramus cum. Mea lobortis accusamus ex. Nam id apeirian forensibus, in qui nisl illud mucius.
|
|
1051
|
-
`,
|
|
1052
|
-
bar: true,
|
|
1053
|
-
funky: 'fresh'
|
|
1054
|
-
})
|
|
1055
|
-
})
|
|
1056
|
-
|
|
1057
|
-
test('Big array', () => {
|
|
1058
|
-
const one = optionsParse(`
|
|
1059
|
-
foo=[
|
|
1060
|
-
{
|
|
1061
|
-
color: "red",
|
|
1062
|
-
value: "#f00"
|
|
1063
|
-
},
|
|
1064
|
-
{
|
|
1065
|
-
color: "green",
|
|
1066
|
-
value: "#0f0"
|
|
1067
|
-
},
|
|
1068
|
-
{
|
|
1069
|
-
color: "blue",
|
|
1070
|
-
value: "#00f"
|
|
1071
|
-
},
|
|
1072
|
-
{
|
|
1073
|
-
color: "cyan",
|
|
1074
|
-
value: "#0ff"
|
|
1075
|
-
},
|
|
1076
|
-
{
|
|
1077
|
-
color: "magenta",
|
|
1078
|
-
value: "#f0f"
|
|
1079
|
-
},
|
|
1080
|
-
{
|
|
1081
|
-
color: "yellow",
|
|
1082
|
-
value: "#ff0"
|
|
1083
|
-
},
|
|
1084
|
-
]
|
|
1085
|
-
`)
|
|
1086
|
-
assert.equal(one, {
|
|
1087
|
-
foo: [
|
|
1088
|
-
{
|
|
1089
|
-
color: "red",
|
|
1090
|
-
value: "#f00"
|
|
1091
|
-
},
|
|
1092
|
-
{
|
|
1093
|
-
color: "green",
|
|
1094
|
-
value: "#0f0"
|
|
1095
|
-
},
|
|
1096
|
-
{
|
|
1097
|
-
color: "blue",
|
|
1098
|
-
value: "#00f"
|
|
1099
|
-
},
|
|
1100
|
-
{
|
|
1101
|
-
color: "cyan",
|
|
1102
|
-
value: "#0ff"
|
|
1103
|
-
},
|
|
1104
|
-
{
|
|
1105
|
-
color: "magenta",
|
|
1106
|
-
value: "#f0f"
|
|
1107
|
-
},
|
|
1108
|
-
{
|
|
1109
|
-
color: "yellow",
|
|
1110
|
-
value: "#ff0"
|
|
1111
|
-
}
|
|
1112
|
-
],
|
|
1113
|
-
})
|
|
1114
|
-
})
|
|
1115
|
-
|
|
1116
|
-
test('Big array react style', () => {
|
|
1117
|
-
const one = optionsParse(`
|
|
1118
|
-
foo={[
|
|
1119
|
-
{
|
|
1120
|
-
color: "red",
|
|
1121
|
-
value: "#f00"
|
|
1122
|
-
},
|
|
1123
|
-
{
|
|
1124
|
-
color: "green",
|
|
1125
|
-
value: "#0f0"
|
|
1126
|
-
},
|
|
1127
|
-
{
|
|
1128
|
-
color: "blue",
|
|
1129
|
-
value: "#00f"
|
|
1130
|
-
},
|
|
1131
|
-
{
|
|
1132
|
-
color: "cyan",
|
|
1133
|
-
value: "#0ff"
|
|
1134
|
-
},
|
|
1135
|
-
{
|
|
1136
|
-
color: "magenta",
|
|
1137
|
-
value: "#f0f"
|
|
1138
|
-
},
|
|
1139
|
-
{
|
|
1140
|
-
color: "yellow",
|
|
1141
|
-
value: "#ff0"
|
|
1142
|
-
},
|
|
1143
|
-
{
|
|
1144
|
-
color: "black",
|
|
1145
|
-
value: "#000"
|
|
1146
|
-
}
|
|
1147
|
-
]}
|
|
1148
|
-
`)
|
|
1149
|
-
assert.equal(one, {
|
|
1150
|
-
foo: [
|
|
1151
|
-
{
|
|
1152
|
-
color: "red",
|
|
1153
|
-
value: "#f00"
|
|
1154
|
-
},
|
|
1155
|
-
{
|
|
1156
|
-
color: "green",
|
|
1157
|
-
value: "#0f0"
|
|
1158
|
-
},
|
|
1159
|
-
{
|
|
1160
|
-
color: "blue",
|
|
1161
|
-
value: "#00f"
|
|
1162
|
-
},
|
|
1163
|
-
{
|
|
1164
|
-
color: "cyan",
|
|
1165
|
-
value: "#0ff"
|
|
1166
|
-
},
|
|
1167
|
-
{
|
|
1168
|
-
color: "magenta",
|
|
1169
|
-
value: "#f0f"
|
|
1170
|
-
},
|
|
1171
|
-
{
|
|
1172
|
-
color: "yellow",
|
|
1173
|
-
value: "#ff0"
|
|
1174
|
-
},
|
|
1175
|
-
{
|
|
1176
|
-
color: "black",
|
|
1177
|
-
value: "#000"
|
|
1178
|
-
}
|
|
1179
|
-
],
|
|
1180
|
-
})
|
|
1181
|
-
})
|
|
1182
|
-
|
|
1183
|
-
test('Handles Multiline breaks', () => {
|
|
1184
|
-
const one = optionsParse(`
|
|
1185
|
-
|
|
1186
|
-
foo='bar'
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
baz='fuzz'
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
funky=true
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
`)
|
|
1199
|
-
assert.equal(one, {
|
|
1200
|
-
foo: 'bar',
|
|
1201
|
-
baz: 'fuzz',
|
|
1202
|
-
funky: true,
|
|
1203
|
-
})
|
|
1204
|
-
})
|
|
1205
|
-
|
|
1206
|
-
test('Weird ones', () => {
|
|
1207
|
-
const one = optionsParse("debug 1")
|
|
1208
|
-
assert.equal(one, {
|
|
1209
|
-
debug: true,
|
|
1210
|
-
1: true,
|
|
1211
|
-
})
|
|
1212
|
-
const two = optionsParse("_debug 33")
|
|
1213
|
-
assert.equal(two, {
|
|
1214
|
-
_debug: true,
|
|
1215
|
-
33: true,
|
|
1216
|
-
})
|
|
1217
|
-
})
|
|
1218
|
-
|
|
1219
|
-
test('Template tage ones', () => {
|
|
1220
|
-
const one = options`foo=bar`
|
|
1221
|
-
assert.equal(one, {
|
|
1222
|
-
foo: 'bar',
|
|
1223
|
-
})
|
|
1224
|
-
|
|
1225
|
-
const two = options`
|
|
1226
|
-
foo=bar
|
|
1227
|
-
bob="xyz"
|
|
1228
|
-
lol='cool'
|
|
1229
|
-
`
|
|
1230
|
-
assert.equal(two, {
|
|
1231
|
-
foo: 'bar',
|
|
1232
|
-
bob: 'xyz',
|
|
1233
|
-
lol: 'cool',
|
|
1234
|
-
})
|
|
1235
|
-
})
|
|
1236
|
-
|
|
1237
|
-
test.run()
|