Skip to content

Commit

Permalink
refactor: support jsme index negativ
Browse files Browse the repository at this point in the history
  • Loading branch information
waynevanson committed Sep 10, 2023
1 parent a92887e commit 686c2b0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/jmespath_optic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod test {

// todo - negative indexes
#[test]
fn index() {
fn index_positive() {
let expression = jmespath::compile("[0]").unwrap();
let ast = expression.as_ast();

Expand All @@ -61,6 +61,18 @@ mod test {
assert_eq!(result, expected);
}

#[test]
fn index_negative() {
let expression = jmespath::compile("[-1]").unwrap();
let ast = expression.as_ast();

let source = json!(["world", "earth", "globe"]);
let target = json!("sup");
let expected = json!(["world", "earth", target]);
let result: Value = ast.modify_json_value(source, target.clone()).unwrap();
assert_eq!(result, expected);
}

// todo - negative indexes
#[test]
fn field() {
Expand Down

0 comments on commit 686c2b0

Please sign in to comment.