Files
rdbms-playground/tests/typing_surface/drop_relationship.rs
T
claude@clouddev1 41b7e9a049 style: format the whole tree with cargo fmt (stock defaults, #35)
One-time, mechanical reformat — no functional changes. The tree was not
rustfmt-clean (~1800 hunks across ~100 files); this brings it to stock
`cargo fmt` defaults so a `cargo fmt --check` CI gate can follow.
Behaviour-preserving: 2509 pass / 0 fail / 1 ignored (unchanged baseline),
clippy clean. A .git-blame-ignore-revs entry follows so `git blame`
skips this commit.
2026-06-17 21:39:19 +00:00

100 lines
3.5 KiB
Rust

//! Matrix coverage for `drop relationship (endpoints | name)`
//! (ADR-0013).
//!
//! Two selector forms:
//! - by endpoints: `drop relationship from P.c to C.c`
//! - by name: `drop relationship <name>`
//!
//! Handoff-12 §2.2 noted the qualified-column slots
//! (`from T.col`) don't narrow to T's columns. The fix lands
//! alongside the matrix where the test asserts narrowing.
use crate::typing_surface::*;
use rdbms_playground::completion::SchemaCache;
use rdbms_playground::input_render::InputState;
/// schema_multi_table + a named relationship in the cache so
/// the by-name selector has a candidate.
fn schema_with_relationship() -> SchemaCache {
let mut cache = schema_multi_table();
cache
.relationships
.push("Orders_CustId_to_Customers".to_string());
cache
}
#[test]
fn after_relationship_keyword_offers_from_and_names() {
let schema = schema_with_relationship();
let a = assess_at_end("drop relationship ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
// Both selector forms discoverable: `from` for endpoints,
// the relationship name for the by-name form.
assert_candidate_present(&a, &["from", "Orders_CustId_to_Customers"]);
crate::snap!("after_relationship_keyword", a);
}
#[test]
fn after_from_offers_table_names() {
let schema = schema_with_relationship();
let a = assess_at_end("drop relationship from ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
assert_candidate_present(&a, &["Customers", "Orders"]);
crate::snap!("after_from", a);
}
#[test]
fn after_parent_table_dot_narrows_to_parent_columns() {
// §2.2 follow-up: `from Orders.` should narrow the
// column slot to Orders's columns.
let schema = schema_with_relationship();
let a = assess_at_end("drop relationship from Orders.", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
assert_candidate_present(&a, &["OrderId", "CustId", "Total"]);
assert_no_candidate_named(&a, &["Name"]);
crate::snap!("after_parent_dot", a);
}
#[test]
fn after_to_offers_table_names() {
let schema = schema_with_relationship();
let a = assess_at_end("drop relationship from Orders.CustId to ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
assert_candidate_present(&a, &["Customers", "Orders"]);
crate::snap!("after_to", a);
}
#[test]
fn after_child_table_dot_narrows_to_child_columns() {
let schema = schema_with_relationship();
let a = assess_at_end(
"drop relationship from Orders.CustId to Customers.",
&schema,
);
assert!(matches!(a.state, InputState::IncompleteAtEof));
assert_candidate_present(&a, &["id", "Name"]);
assert_no_candidate_named(&a, &["OrderId", "CustId", "Total"]);
crate::snap!("after_child_dot", a);
}
#[test]
fn complete_drop_relationship_by_endpoints_parses() {
let schema = schema_with_relationship();
let a = assess_at_end(
"drop relationship from Orders.CustId to Customers.id",
&schema,
);
assert!(matches!(a.state, InputState::Valid));
assert_eq!(a.parse_result.as_deref(), Ok("DropRelationship"));
crate::snap!("complete_by_endpoints", a);
}
#[test]
fn complete_drop_relationship_by_name_parses() {
let schema = schema_with_relationship();
let a = assess_at_end("drop relationship Orders_CustId_to_Customers", &schema);
assert!(matches!(a.state, InputState::Valid));
assert_eq!(a.parse_result.as_deref(), Ok("DropRelationship"));
crate::snap!("complete_by_name", a);
}