Files
dewedev/node_modules/jsonpath/test/stringify.js
dwindown 7f2dd5260f Initial commit: Developer Tools MVP with visual editor
- Complete React app with 7 developer tools
- JSON Tool with visual structured editor
- Serialize Tool with visual structured editor
- URL, Base64, CSV/JSON, Beautifier, Diff tools
- Responsive navigation with dropdown menu
- Dark/light mode toggle
- Mobile-responsive design with sticky header
- All tools working with copy/paste functionality
2025-08-02 09:31:26 +07:00

55 lines
1.8 KiB
JavaScript

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/);
});
});