Skip to content

Commit b22397e

Browse files
authored
Feature/ternary operator (#33)
* updated project system around poetry (#29) * updated project system around poetry * github workflows * updated package dependencies * added compliance CLI tool * [ternary] supports tokenizing ternary operator expressions * [ternary] supports parsing ternary operator expressions * [ternary] supports ternary operator expressions * Updated reference to compliance tests.
1 parent 8211b50 commit b22397e

35 files changed

+7190
-3
lines changed

jmespath.test

Submodule jmespath.test deleted from edd3251

jmespath.test/.gitattributes

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# .gitattributes snippet to force users to use same line endings for project.
2+
#
3+
# Handle line endings automatically for files detected as text
4+
# and leave all files detected as binary untouched.
5+
* text=auto
6+
7+
#
8+
# The above will handle all files NOT found below
9+
# https://help.github.com/articles/dealing-with-line-endings/
10+
# https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes
11+
12+
# These files are text and should be normalized (Convert crlf => lf)
13+
*.css text
14+
*.htm text
15+
*.html text
16+
*.inc text
17+
*.ini text
18+
*.js text
19+
*.json text
20+
*.php text
21+
*.pl text
22+
*.py text
23+
*.rb text
24+
*.scm text
25+
*.sh text
26+
*.sql text
27+
*.txt text
28+
*.xml text
29+
*.yaml text
30+
*.yml text
31+
32+
.htaccess text
33+
34+
# These files are binary and should be left untouched
35+
# (binary is a macro for -text -diff)
36+
*.7z binary
37+
*.fla binary
38+
*.flv binary
39+
*.gif binary
40+
*.gz binary
41+
*.ico binary
42+
*.jpeg binary
43+
*.jpg binary
44+
*.mov binary
45+
*.mp3 binary
46+
*.mp4 binary
47+
*.png binary
48+
*.pyc binary
49+
*.swf binary
50+
*.ttf binary
51+
*.zip binary

jmespath.test/.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: python
2+
python:
3+
- "3.5"
4+
install: "pip install jsonschema==2.5.1"
5+
script: ls tests/*.json | xargs -I {} jsonschema schema.json -i {}

jmespath.test/README.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# JMESPath Compliance Tests
2+
3+
This repo contains a suite of JMESPath compliance tests. JMESPath
4+
Community implementations can use these tests in order to verify their
5+
implementation adheres to the JMESPath spec.
6+
7+
## Compatibility
8+
9+
JMESPath Community is designed to be fully backwards compatible with [JMESPath.org](https://jmespath.org).
10+
11+
However, in some rare circumstances, some differences may be observed. This paragraph lists the known differences:
12+
13+
|Category|Compliance|Result|JMESPath.org Result|Description
14+
|---|---|---|---|---
15+
|[literal.json](https://github.com/jmespath/jmespath.test/blob/53abcc37901891cf4308fcd910eab287416c4609/tests/literal.json#L193-L197)|`` '\\' ``| `` "\" `` | `` "\\" `` | JMESPath Community `raw-string` supports escaping both `` ' `` (single quote) and `` \ `` (backslash) characters, whereas JMESPath.org can only escape single quotes
16+
|[pipe.json](https://github.com/jmespath-community/jmespath.test/blob/304b287a9537673227c2e300a34ff8e4757579c5/tests/pipe.json#L131-L136)| `` `null`\|[@] ``| `` [null] `` | `` null `` | JMESPath Community lets a `null` left-hand side of a `pipe-expression` propagate to its right-hand side, whereas JMESPath.og shortcuts and does not evaluate the right-hand side if the left-hand side result is `null`.
17+
18+
## Test Organization
19+
20+
The `test/` directory contains JSON files containing the JMESPath
21+
testcase. Each JSON file represents a JMESPath feature. Each JSON file
22+
is a JSON list containing one or more tests suites:
23+
24+
[
25+
<test suite 1>,
26+
<test suite 2>,
27+
]
28+
29+
Each test suite is a JSON object that has the following keys:
30+
31+
- `given` - The input data from which the JMESPath expression is
32+
evaluated.
33+
- `cases` - A list of test cases.
34+
- `comment` - An optional field containing a description of the test
35+
suite.
36+
37+
Each JMESPath test case can have the following keys:
38+
39+
- `expression` - The JMESPath expression being tested.
40+
- `result` - The expected result from evaluating the JMESPath
41+
expression against the `given` input.
42+
- `error` - The type of error that should be raised as a result of
43+
evaluating the JMESPath expression. The valid values for an error
44+
are:
45+
- `syntax` - Syntax error from an invalid JMESPath expression.
46+
- `invalid-arity` - Wrong number of arguments passed to a
47+
function.
48+
- `invalid-type` - Invalid argument type for a function.
49+
- `invalid-value` - Semantically incorrect value (used in slice
50+
tests)
51+
- `unknown-function` - Attempting to invoke an unknown function.
52+
- `not-a-number` - While evaluating arithmetic expressions.
53+
- `bench` - If the case is a benchmark, `bench` contains the type of
54+
benchmark. Available `bench` types are as follows:
55+
- `parse` - Benchmark only the parsing of an expression.
56+
- `interpret` - Benchmark only the interpreting of an expression.
57+
- `full` - Benchmark both parsing and interpreting an expression.
58+
- `comment` - An optional comment containing a description of the
59+
specific test case.
60+
61+
For each test case, either `result`, `error`, or `bench` must be
62+
specified. Only one of these keys can be present in a single test case.
63+
64+
The error type (if the `error` key is present) indicates the type of
65+
error that an implementation should raise, but it does not indicate
66+
**when** this error should be raised. For example, a value of
67+
`"error": "syntax"` does not require that the syntax error be raised
68+
when the expression is compiled. If an implementation does not have a
69+
separate compilation step this won\'t even be possible. Similar for type
70+
errors, implementations are free to check for type errors during
71+
compilation or at run time (when the parsed expression is evaluated). As
72+
long as an implementation can detect that this error occurred at any
73+
point during the evaluation of a JMESPath expression, this is considered
74+
sufficient.
75+
76+
Below are a few examples:
77+
78+
[{
79+
"given":
80+
{"foo": {"bar": {"baz": "correct"}}},
81+
"cases": [
82+
{
83+
"expression": "foo",
84+
"result": {"bar": {"baz": "correct"}}
85+
},
86+
{
87+
"expression": "foo.1",
88+
"error": "syntax"
89+
},
90+
]
91+
}]
92+
93+
This above JSON document specifies 1 test suite that contains 2 test
94+
cases. The two test cases are:
95+
96+
- Given the input `{"foo": {"bar": {"baz": "correct"}}}`, the
97+
expression `foo` should have a result of
98+
`{"bar": {"baz": "correct"}}`.
99+
- Given the input `{"foo": {"bar": {"baz": "correct"}}}`, the
100+
expression `foo.1` should generate a syntax error.
101+
102+
# Utility Tools
103+
104+
Most languages have test frameworks that are capable of reading the JSON
105+
test descriptions and generating testcases. However, a `jp-compliance`
106+
tool is provided to help with any implementation that does not have an
107+
available test framework to generate test cases. The `jp-compliance`
108+
tool takes the name of a jmespath executable and will evaluate all the
109+
compliance tests using this provided executable. This way all that\'s
110+
needed to verify your JMESPath implementation is for you to write a
111+
basic executable. This executable must have the following interface:
112+
113+
- Accept the input JSON data on stdin.
114+
- Accept the jmespath expression as an argument.
115+
- Print the jmespath result as JSON on stdout.
116+
- If an error occurred, it must write the error name to sys.stderr.
117+
This check is case insensitive. The error types in the compliance
118+
tests are hyphenated, but each individual component may appear in
119+
stderr (again case insensitive).
120+
121+
Here are a few examples of error messages that would pass
122+
`jp-compliance`:
123+
124+
- Error type: `unknown-function`
125+
- Valid error messages:
126+
- `unknown-function: somefunction()`
127+
- `error: unknown function 'somefunction()`
128+
- `Unknown function: somefunction()`
129+
- Error type: `syntax`
130+
- Valid error messages:
131+
- `syntax: Unknown token '$'`
132+
- `syntax-error: Unknown token '$'`
133+
- `Syntax error: Unknown token '$'`
134+
- `An error occurred: Syntax error, unknown token '$'`
135+
136+
> This will be substantially slower than using a test framework. Using
137+
> `jp-compliance` each test case is evaluated by executing a new process.
138+
139+
You can run the `bin/jp-compliance --help` for more information and for
140+
examples on how to use this tool.

jmespath.test/schema.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"type": "array",
3+
"items": {
4+
"type": "object",
5+
"additionalProperties": "false",
6+
"properties": {
7+
"given": {},
8+
"comment": {"type": "string"},
9+
"cases": {
10+
"type": "array",
11+
"items": {
12+
"type": "object",
13+
"additionalProperties": false,
14+
"properties": {
15+
"expression": {"type": "string"},
16+
"result": {},
17+
"error": {
18+
"enum": ["invalid-arity", "invalid-type",
19+
"invalid-value", "syntax",
20+
"unknown-function"]
21+
},
22+
"bench": {
23+
"enum": ["parse", "interpret", "full"]
24+
},
25+
"comment": {"type": "string"}
26+
},
27+
"required": ["expression"],
28+
"anyOf": [
29+
{"required": ["result"]},
30+
{"required": ["error"]},
31+
{"required": ["bench"]}
32+
]
33+
}
34+
}
35+
},
36+
"required": ["given", "cases"]
37+
}
38+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"given": {
4+
"a": {
5+
"b": 1
6+
},
7+
"c": {
8+
"d": 2
9+
}
10+
},
11+
"cases": [
12+
{
13+
"expression": "`1` + `2`",
14+
"result": 3.0
15+
},
16+
{
17+
"expression": "`1` - `2`",
18+
"result": -1.0
19+
},
20+
{
21+
"expression": "`2` * `4`",
22+
"result": 8.0
23+
},
24+
{
25+
"expression": "`2` × `4`",
26+
"result": 8.0
27+
},
28+
{
29+
"expression": "`2` / `3`",
30+
"result": 0.6666666666666666
31+
},
32+
{
33+
"expression": "`2` ÷ `3`",
34+
"result": 0.6666666666666666
35+
},
36+
{
37+
"expression": "`10` % `3`",
38+
"result": 1.0
39+
},
40+
{
41+
"expression": "`10` // `3`",
42+
"result": 3.0
43+
},
44+
{
45+
"expression": "-`1` - + `2`",
46+
"result": -3.0
47+
},
48+
{
49+
"expression": "{ ab: a.b, cd: c.d } | ab + cd",
50+
"result": 3.0
51+
},
52+
{
53+
"expression": "{ ab: a.b, cd: c.d } | ab + cd × cd",
54+
"result": 5.0
55+
},
56+
{
57+
"expression": "{ ab: a.b, cd: c.d } | (ab + cd) × cd",
58+
"result": 6.0
59+
}
60+
]
61+
}
62+
]

0 commit comments

Comments
 (0)