Files
rdbms-playground/tests/typing_surface/where_expression.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

103 lines
3.7 KiB
Rust

//! Matrix coverage for the complex WHERE-expression surface
//! and `show data` `where` / `limit` (ADR-0026).
//!
//! The simple `where col = val` cells live in
//! `delete_with_where` / `update_with_where`; this file covers
//! the expression grammar's wider surface — operators, the
//! AND / OR connectives, the negatable predicates, and the
//! `show data` filter / limit clauses.
use crate::typing_surface::*;
use rdbms_playground::input_render::InputState;
#[test]
fn after_where_column_offers_predicate_operators() {
let schema = schema_serial_pk();
let a = assess_at_end("delete from Customers where Email ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
// After an operand the grammar expects a predicate tail —
// the negatable keywords surface as candidates.
assert_candidate_present(&a, &["like", "between", "in", "is"]);
crate::snap!("after_column", a);
}
#[test]
fn after_complete_predicate_offers_and_or() {
let schema = schema_serial_pk();
let a = assess_at_end("delete from Customers where id=1 ", &schema);
assert!(matches!(a.state, InputState::Valid));
// A complete predicate can be extended with a connective.
assert_candidate_present(&a, &["and", "or"]);
crate::snap!("after_predicate", a);
}
#[test]
fn after_not_keyword_expects_a_predicate() {
let schema = schema_serial_pk();
let a = assess_at_end("delete from Customers where not ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
// `not` is followed by another predicate — the column
// operands of the active table are offered.
assert_candidate_present(&a, &["Email", "Name"]);
crate::snap!("after_not", a);
}
#[test]
fn between_expects_a_low_bound() {
let schema = schema_every_type();
let a = assess_at_end("delete from Things where k between ", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
crate::snap!("between_low", a);
}
#[test]
fn in_list_open_paren_expects_an_item() {
let schema = schema_every_type();
let a = assess_at_end("delete from Things where k in (", &schema);
assert!(matches!(a.state, InputState::IncompleteAtEof));
crate::snap!("in_open_paren", a);
}
#[test]
fn complex_and_or_expression_parses() {
let schema = schema_every_type();
// `note` is the text column — `t` is not a column of
// `Things`, and the schema-existence diagnostic (ADR-0027)
// would now correctly flag it; this cell tests a *valid*
// complex expression, so it uses a real column.
let a = assess_at_end(
"delete from Things where k > 1 and note like 'a%' or k = 9",
&schema,
);
assert!(matches!(a.state, InputState::Valid));
assert_eq!(a.parse_result.as_deref(), Ok("Delete"));
crate::snap!("complex_and_or", a);
}
#[test]
fn show_data_after_table_offers_where_and_limit() {
let schema = schema_serial_pk();
let a = assess_at_end("show data Customers ", &schema);
assert!(matches!(a.state, InputState::Valid));
assert_candidate_present(&a, &["where", "limit"]);
crate::snap!("show_after_table", a);
}
#[test]
fn show_data_after_where_predicate_offers_limit() {
let schema = schema_serial_pk();
let a = assess_at_end("show data Customers where id=1 ", &schema);
assert!(matches!(a.state, InputState::Valid));
assert_candidate_present(&a, &["limit", "and", "or"]);
crate::snap!("show_after_where", a);
}
#[test]
fn complete_show_data_with_where_and_limit_parses() {
let schema = schema_serial_pk();
let a = assess_at_end("show data Customers where id=1 limit 10", &schema);
assert!(matches!(a.state, InputState::Valid));
assert_eq!(a.parse_result.as_deref(), Ok("ShowData"));
crate::snap!("complete_show_where_limit", a);
}