Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
notauserx committed Dec 9, 2024
1 parent 3cfbd0e commit fc73c99
Show file tree
Hide file tree
Showing 2 changed files with 299 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/it/jsonpath_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@ fn test_json_path() {
r#"$"#,
r#"$.*"#,
r#"$[*]"#,
r#"5 + 5"#,
r#"10 - 5"#,
r#"10 * 5"#,
r#"10 / 5"#,
r#"10 % 5"#,
r#"$.store.book[*].*"#,
// r#"$.store.book[*].* + 5"#,
r#"$.store.book[0].price"#,
r#"+$.store.book[0].price"#,
r#"-$.store.book[0].price"#,
r#"$.store.book[0].price + 5"#,
r#"$.store.book[last].isbn"#,
r"$.store.book[last].test_key\uD83D\uDC8E测试",
r#"$.store.book[0,1, last - 2].price"#,
Expand Down
290 changes: 290 additions & 0 deletions tests/it/testdata/json_path.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,166 @@ JsonPath {
}


---------- Input ----------
5 + 5
---------- Output ---------
5 + 5
---------- AST ------------
JsonPath {
paths: [
Predicate(
ArithmeticFunc(
Binary {
op: Add,
left: Value(
Number(
UInt64(
5,
),
),
),
right: Value(
Number(
UInt64(
5,
),
),
),
},
),
),
],
}


---------- Input ----------
10 - 5
---------- Output ---------
10 - 5
---------- AST ------------
JsonPath {
paths: [
Predicate(
ArithmeticFunc(
Binary {
op: Subtract,
left: Value(
Number(
UInt64(
10,
),
),
),
right: Value(
Number(
UInt64(
5,
),
),
),
},
),
),
],
}


---------- Input ----------
10 * 5
---------- Output ---------
10 * 5
---------- AST ------------
JsonPath {
paths: [
Predicate(
ArithmeticFunc(
Binary {
op: Multiply,
left: Value(
Number(
UInt64(
10,
),
),
),
right: Value(
Number(
UInt64(
5,
),
),
),
},
),
),
],
}


---------- Input ----------
10 / 5
---------- Output ---------
10 / 5
---------- AST ------------
JsonPath {
paths: [
Predicate(
ArithmeticFunc(
Binary {
op: Divide,
left: Value(
Number(
UInt64(
10,
),
),
),
right: Value(
Number(
UInt64(
5,
),
),
),
},
),
),
],
}


---------- Input ----------
10 % 5
---------- Output ---------
10 % 5
---------- AST ------------
JsonPath {
paths: [
Predicate(
ArithmeticFunc(
Binary {
op: Modulus,
left: Value(
Number(
UInt64(
10,
),
),
),
right: Value(
Number(
UInt64(
5,
),
),
),
},
),
),
],
}


---------- Input ----------
$.store.book[*].*
---------- Output ---------
Expand Down Expand Up @@ -86,6 +246,136 @@ JsonPath {
}


---------- Input ----------
+$.store.book[0].price
---------- Output ---------
+$.store.book[0].price
---------- AST ------------
JsonPath {
paths: [
Predicate(
ArithmeticFunc(
Unary {
op: Add,
operand: Paths(
[
Root,
DotField(
"store",
),
DotField(
"book",
),
ArrayIndices(
[
Index(
Index(
0,
),
),
],
),
DotField(
"price",
),
],
),
},
),
),
],
}


---------- Input ----------
-$.store.book[0].price
---------- Output ---------
-$.store.book[0].price
---------- AST ------------
JsonPath {
paths: [
Predicate(
ArithmeticFunc(
Unary {
op: Subtract,
operand: Paths(
[
Root,
DotField(
"store",
),
DotField(
"book",
),
ArrayIndices(
[
Index(
Index(
0,
),
),
],
),
DotField(
"price",
),
],
),
},
),
),
],
}


---------- Input ----------
$.store.book[0].price + 5
---------- Output ---------
$.store.book[0].price + 5
---------- AST ------------
JsonPath {
paths: [
Predicate(
ArithmeticFunc(
Binary {
op: Add,
left: Paths(
[
Root,
DotField(
"store",
),
DotField(
"book",
),
ArrayIndices(
[
Index(
Index(
0,
),
),
],
),
DotField(
"price",
),
],
),
right: Value(
Number(
UInt64(
5,
),
),
),
},
),
),
],
}


---------- Input ----------
$.store.book[last].isbn
---------- Output ---------
Expand Down

0 comments on commit fc73c99

Please sign in to comment.