forked from Azure/login
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringify.js
More file actions
54 lines (44 loc) · 1.77 KB
/
Copy pathstringify.js
File metadata and controls
54 lines (44 loc) · 1.77 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
var assert = require('assert');
var jp = require('../');
suite('stringify', function() {
test('simple path stringifies', function() {
var string = jp.stringify(['$', 'a', 'b', 'c']);
assert.equal(string, '$.a.b.c');
});
test('numeric literals end up as subscript numbers', function() {
var string = jp.stringify(['$', 'store', 'book', 0, 'author']);
assert.equal(string, '$.store.book[0].author');
});
test('simple path with no leading root stringifies', function() {
var string = jp.stringify(['a', 'b', 'c']);
assert.equal(string, '$.a.b.c');
});
test('simple parsed path stringifies', function() {
var path = [
{ scope: 'child', operation: 'member', expression: { type: 'identifier', value: 'a' } },
{ scope: 'child', operation: 'member', expression: { type: 'identifier', value: 'b' } },
{ scope: 'child', operation: 'member', expression: { type: 'identifier', value: 'c' } }
];
var string = jp.stringify(path);
assert.equal(string, '$.a.b.c');
});
test('keys with hyphens get subscripted', function() {
var string = jp.stringify(['$', 'member-search']);
assert.equal(string, '$["member-search"]');
});
test('complicated path round trips', function() {
var pathExpression = '$..*[0:2].member["string-xyz"]';
var path = jp.parse(pathExpression);
var string = jp.stringify(path);
assert.equal(string, pathExpression);
});
test('complicated path with filter exp round trips', function() {
var pathExpression = '$..*[0:2].member[?(@.val > 10)]';
var path = jp.parse(pathExpression);
var string = jp.stringify(path);
assert.equal(string, pathExpression);
});
test('throws for no input', function() {
assert.throws(function() { jp.stringify() }, /we need a path/);
});
});