Skip to content

Commit

Permalink
Add .apply_to tests for LitExpr::LitPath structures.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Feb 12, 2025
1 parent e1c3036 commit cda0e17
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions apollo-federation/src/sources/connect/json_selection/apply_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,75 @@ mod tests {
);
}

#[test]
fn test_lit_paths() {
let data = json!({
"value": {
"key": 123,
},
});

assert_eq!(
selection!("$(\"a\")->first").apply_to(&data),
(Some(json!("a")), vec![]),
);

assert_eq!(
selection!("$('asdf'->last)").apply_to(&data),
(Some(json!("f")), vec![]),
);

assert_eq!(
selection!("$(1234)->add(1111)").apply_to(&data),
(Some(json!(2345)), vec![]),
);

assert_eq!(
selection!("$(1234->add(1111))").apply_to(&data),
(Some(json!(2345)), vec![]),
);

assert_eq!(
selection!("$(value.key->mul(10))").apply_to(&data),
(Some(json!(1230)), vec![]),
);

assert_eq!(
selection!("$(value.key)->mul(10)").apply_to(&data),
(Some(json!(1230)), vec![]),
);

assert_eq!(
selection!("$(value.key->typeof)").apply_to(&data),
(Some(json!("number")), vec![]),
);

assert_eq!(
selection!("$(value.key)->typeof").apply_to(&data),
(Some(json!("number")), vec![]),
);

assert_eq!(
selection!("$([1, 2, 3])->last").apply_to(&data),
(Some(json!(3)), vec![]),
);

assert_eq!(
selection!("$([1, 2, 3]->first)").apply_to(&data),
(Some(json!(1)), vec![]),
);

assert_eq!(
selection!("$({ a: 'ay', b: 1 }).a").apply_to(&data),
(Some(json!("ay")), vec![]),
);

assert_eq!(
selection!("$({ a: 'ay', b: 2 }.a)").apply_to(&data),
(Some(json!("ay")), vec![]),
);
}

#[test]
fn test_compute_output_shape() {
assert_eq!(selection!("").shape().pretty_print(), "{}");
Expand Down

0 comments on commit cda0e17

Please sign in to comment.