test(feel-pg): add descendant operator test coverage
public
test(feel-pg): add descendant operator test coverage Adds PostgreSQL integration tests for the `e ... name` descendant operator (DMN §10.3.2.7) covering: - Specification example validation - List-of-contexts traversal - Empty result handling - Nested JSONB descent BREAKING CHANGE: None
| Changeset | c738b142f5649beb82a082731799fa64cdc0a284 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@gmail.com>, |
| Parents | fea1d27abd0f |
| Children | |
| Pushlog | by timo via ssh |
modified crates/feel-pg/src/lib.rs +40 −0
| @@ -570,6 +570,46 @@ | ||
| 570 | 570 | ) |
| 571 | 571 | .expect("DDL should raise before this unwrap"); |
| 572 | 572 | } |
| 573 | + | |
| 574 | + // Descendant `e ... name` (DMN 10.3.2.7, grammar rule 68). jsonb is a serialized | |
| 575 | + // value tree, so the reachable JsonbForeign sub-graph is definitionally acyclic | |
| 576 | + // — feel-pg is EXEMPT from the cycle-guard question (no identity() override and | |
| 577 | + // no cycle test, because a cycle cannot be constructed in jsonb). | |
| 578 | + #[pg_test] | |
| 579 | + fn descendant_spec_example() { | |
| 580 | + let matched = Spi::get_one::<bool>( | |
| 581 | + r#"SELECT feel_eval('{a: {b: {b: 1}}} ... b') = '[{"b": 1}, 1]'::jsonb"#, | |
| 582 | + ) | |
| 583 | + .expect("SPI query failed"); | |
| 584 | + assert_eq!(matched, Some(true)); | |
| 585 | + } | |
| 586 | + | |
| 587 | + #[pg_test] | |
| 588 | + fn descendant_collects_across_a_list_of_contexts() { | |
| 589 | + let matched = Spi::get_one::<bool>( | |
| 590 | + r#"SELECT feel_eval('[{x:1},{x:2}] ... x') = '[1, 2]'::jsonb"#, | |
| 591 | + ) | |
| 592 | + .expect("SPI query failed"); | |
| 593 | + assert_eq!(matched, Some(true)); | |
| 594 | + } | |
| 595 | + | |
| 596 | + #[pg_test] | |
| 597 | + fn descendant_no_match_is_empty_list() { | |
| 598 | + let matched = | |
| 599 | + Spi::get_one::<bool>(r#"SELECT feel_eval('{a:1} ... z') = '[]'::jsonb"#) | |
| 600 | + .expect("SPI query failed"); | |
| 601 | + assert_eq!(matched, Some(true)); | |
| 602 | + } | |
| 603 | + | |
| 604 | + #[pg_test] | |
| 605 | + fn descendant_descends_into_nested_jsonb() { | |
| 606 | + let matched = Spi::get_one::<bool>( | |
| 607 | + r#"SELECT feel_eval('o ... name', '{"o": {"customer": {"name": "Ada"}}}'::jsonb) | |
| 608 | + = '["Ada"]'::jsonb"#, | |
| 609 | + ) | |
| 610 | + .expect("SPI query failed"); | |
| 611 | + assert_eq!(matched, Some(true)); | |
| 612 | + } | |
| 573 | 613 | } |
| 574 | 614 | |
| 575 | 615 | /// Required pgrx test harness hooks. |