400fb71460
ambient_hint now reads the walker's schema-aware diagnostics. input_diagnostics is non-empty only for a command that structurally parses — so a non-empty result means "complete and submittable, but wrong or dubious". That is checked early (right after the Tab-cycle memo), ahead of slot hints and completions: a command that parses but is flawed no longer gets the misleading "Submit with Enter" prose, it gets the diagnostic's why. pick_hint_diagnostic prefers the diagnostic under the cursor, else the most severe. The cursor-local invalid-ident hint is kept for genuinely incomplete commands (no Match → no diagnostics). 5 ambient_hint tests (unknown table, type-mismatch over submit-prose, LIKE-numeric, clean command still submittable, cursor-following). The complex_and_or matrix cell referenced a non-existent column `t`; fixed to a real column so it tests a valid expression as intended. 1118 passing, clippy clean.
106 lines
3.7 KiB
Rust
106 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);
|
|
}
|