diff --git a/tests/it/jsonpath_parser.rs b/tests/it/jsonpath_parser.rs index bb07b2c..928fe1a 100644 --- a/tests/it/jsonpath_parser.rs +++ b/tests/it/jsonpath_parser.rs @@ -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"#, diff --git a/tests/it/testdata/json_path.txt b/tests/it/testdata/json_path.txt index 1938b14..4a5b223 100644 --- a/tests/it/testdata/json_path.txt +++ b/tests/it/testdata/json_path.txt @@ -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 --------- @@ -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 ---------