-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath-stringifier.js
More file actions
80 lines (72 loc) · 1.92 KB
/
Copy pathpath-stringifier.js
File metadata and controls
80 lines (72 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { assert } from 'chai'
import JSONway from '../index.js'
describe('path-stringifier', () => {
it('stringifyPath does nothing if not path-array', function () {
const input = 'ab.cd'
assert.deepEqual(JSONway.stringify(input), input)
})
const expressions = [
'ab.cd',
'ab[0]',
'ab[c.d]',
`ab['fo''o']`,
`foo.bar[1].baz['[qee[].0]']['o][]]']`,
'foo.bar[]',
'foo.bar[=]',
'foo.bar[*]',
'foo.bar[5,3,7].baz.id',
'bb[#].ee[].hh[].dd',
'foo.bar[0].baz[][].id',
`a(c = 'y').b`,
'foo.bar[]{id,name}',
'foo.bar[]{id: key, name}',
'foo.bar[]{id: id.key = x, name = 10}',
'foo.bar3',
'foo[baz 3]',
'foo[baz.3]',
'foo.bar',
'foo[bar.]',
`foo['bar
baz']`,
"foo['bar\nbaz']",
"foo.bar[' baz 3']",
"foo['bar''baz']",
"foo['baz]3']",
"foo['baz[3']",
`foo['baz"3']`,
`foo['baz,3']`,
'ab[==]',
'ab[>]',
'ab.<',
'ab.!',
`ab['|']`,
]
const normalizedMapper = new Map([
['ab[0]', 'ab[]'],
[
"foo.bar[1].baz['[qee[].0]']['o][]]']",
"foo.bar[].baz['[qee[].0]']['o][]]']",
],
['foo.bar[=]', 'foo.bar[]'],
['foo.bar[*]', 'foo.bar[]'],
['foo.bar[5,3,7].baz.id', 'foo.bar[].baz.id'],
['bb[#].ee[].hh[].dd', 'bb[].ee[].hh[].dd'],
['foo.bar[0].baz[][].id', 'foo.bar[].baz[][].id'],
])
/* eslint-disable mocha/no-setup-in-describe */
expressions.forEach(expression => {
//
it(expression, function () {
const input = JSONway.parse(this.test.title)
let out = this.test.title
assert.deepEqual(JSONway.stringify(input), out)
if (normalizedMapper.has(out)) out = normalizedMapper.get(out)
assert.deepEqual(JSONway.normalizePath(input), out)
})
})
/* eslint-enable mocha/no-setup-in-describe */
it('normalizePath with path', () => {
const input = 'foo.bar[].baz'
assert.deepEqual(JSONway.normalizePath(input), input)
})
})