-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(jmespath): 100% coverage and spec compliance (#2271)
* feat(jmespath): add parser component * feat: add envelopes & entrypoint * test(jmespath): full test coverage * test(jmespath): full test coverage * chore: add missing export file --------- Co-authored-by: Simon Thulbourn <[email protected]>
- Loading branch information
1 parent
90d3b84
commit fc37010
Showing
20 changed files
with
8,608 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export { search } from './search.js'; | ||
export { | ||
JMESPathError, | ||
LexerError, | ||
ParseError, | ||
IncompleteExpressionError, | ||
ArityError, | ||
VariadicArityError, | ||
JMESPathTypeError, | ||
EmptyExpressionError, | ||
UnknownFunctionError, | ||
} from './errors.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* Test Compliance with the JMESPath specification | ||
* | ||
* @group unit/jmespath/compliance/base | ||
*/ | ||
import { search } from '../../../src/index.js'; | ||
|
||
describe('Base tests', () => { | ||
it.each([ | ||
{ | ||
expression: 'foo', | ||
expected: { bar: { baz: 'correct' } }, | ||
}, | ||
{ | ||
expression: 'foo.bar', | ||
expected: { baz: 'correct' }, | ||
}, | ||
{ | ||
expression: 'foo.bar.baz', | ||
expected: 'correct', | ||
}, | ||
{ | ||
expression: 'foo\n.\nbar\n.baz', | ||
expected: 'correct', | ||
}, | ||
{ | ||
expression: 'foo.bar.baz.bad', | ||
expected: null, | ||
}, | ||
{ | ||
expression: 'foo.bar.bad', | ||
expected: null, | ||
}, | ||
{ | ||
expression: 'foo.bad', | ||
expected: null, | ||
}, | ||
{ | ||
expression: 'bad', | ||
expected: null, | ||
}, | ||
{ | ||
expression: 'bad.morebad.morebad', | ||
expected: null, | ||
}, | ||
])( | ||
'should parse a multi-level nested object: $expression', | ||
({ expression, expected }) => { | ||
// Prepare | ||
const data = { foo: { bar: { baz: 'correct' } } }; | ||
|
||
// Act | ||
const result = search(expression, data); | ||
|
||
// Assess | ||
expect(result).toStrictEqual(expected); | ||
} | ||
); | ||
|
||
it.each([ | ||
{ | ||
expression: 'foo', | ||
expected: { bar: ['one', 'two', 'three'] }, | ||
}, | ||
{ | ||
expression: 'foo.bar', | ||
expected: ['one', 'two', 'three'], | ||
}, | ||
])( | ||
'should parse multi-level objects with arrays: $expression', | ||
({ expression, expected }) => { | ||
// Prepare | ||
const data = { foo: { bar: ['one', 'two', 'three'] } }; | ||
|
||
// Act | ||
const result = search(expression, data); | ||
|
||
// Assess | ||
expect(result).toStrictEqual(expected); | ||
} | ||
); | ||
|
||
it.each([ | ||
{ | ||
expression: 'one', | ||
expected: null, | ||
}, | ||
{ | ||
expression: 'two', | ||
expected: null, | ||
}, | ||
{ | ||
expression: 'three', | ||
expected: null, | ||
}, | ||
{ | ||
expression: 'one.two', | ||
expected: null, | ||
}, | ||
])('should parse an array: $expression', ({ expression, expected }) => { | ||
// Prepare | ||
const data = ['one', 'two', 'three']; | ||
|
||
// Act | ||
const result = search(expression, data); | ||
|
||
// Assess | ||
expect(result).toStrictEqual(expected); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
expression: 'foo."1"', | ||
expected: ['one', 'two', 'three'], | ||
}, | ||
{ | ||
expression: 'foo."1"[0]', | ||
expected: 'one', | ||
}, | ||
{ | ||
expression: 'foo."-1"', | ||
expected: 'bar', | ||
}, | ||
])( | ||
'should parse an object with arrays and numeric values as keys: $expression', | ||
({ expression, expected }) => { | ||
// Prepare | ||
const data = { foo: { '1': ['one', 'two', 'three'], '-1': 'bar' } }; | ||
|
||
// Act | ||
const result = search(expression, data); | ||
|
||
// Assess | ||
expect(result).toStrictEqual(expected); | ||
} | ||
); | ||
}); |
Oops, something went wrong.