WHERE expressions: matrix cells + predicate_tail grammar fix (ADR-0026 step 6)
Adds tests/typing_surface/where_expression.rs — 9 matrix cells for the complex WHERE / show-data limit typing surface: operator candidates after an operand, AND / OR after a predicate, NOT, BETWEEN / IN bounds, and `show data` where / limit. Writing the cells surfaced a grammar bug. `predicate_tail`'s `[NOT] negatable` branch started with `Optional(not)`, and an Optional-first `Seq` always "commits" — so on an incomplete input the walker's `Choice` returned that branch's `Incomplete` early and discarded every sibling branch's expected set, dropping `is` and the comparison operators from completion after a column. Fixed by splitting it into explicit `NOT negatable` and bare `negatable` branches — no `predicate_tail` branch starts with an `Optional` now. The matched terminal sequence is unchanged, so `build_expr` is untouched. Docs: ADR-0026 gains an "As-built notes" section recording the option-1 builder realization, its two deviations from the §3 sketch, and the deferral of §7 diagnostic flagging to ADR-0027. requirements.md C5a -> [x] (steps 1-4) with the test baseline refreshed to 1079; CLAUDE.md's deferred list reconciled (C5a implemented; the QA1/QA2 note now points at ADR-0028).
This commit is contained in:
@@ -27,6 +27,7 @@ pub mod insert_form_c;
|
||||
pub mod update_with_where;
|
||||
pub mod update_all_rows;
|
||||
pub mod delete_with_where;
|
||||
pub mod where_expression;
|
||||
pub mod delete_all_rows;
|
||||
pub mod create_table;
|
||||
pub mod drop_column;
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"delete from Customers where id=1 \" cursor=33"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "delete from Customers where id=1 ",
|
||||
cursor: 33,
|
||||
state: Valid,
|
||||
hint: Some(
|
||||
Candidates {
|
||||
items: [
|
||||
Candidate {
|
||||
text: "and",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "or",
|
||||
kind: Keyword,
|
||||
},
|
||||
],
|
||||
selected: None,
|
||||
},
|
||||
),
|
||||
completion: Some(
|
||||
Completion {
|
||||
replaced_range: (
|
||||
33,
|
||||
33,
|
||||
),
|
||||
partial_prefix: "",
|
||||
candidates: [
|
||||
Candidate {
|
||||
text: "and",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "or",
|
||||
kind: Keyword,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
parse_result: Ok(
|
||||
"Delete",
|
||||
),
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"delete from Customers where not \" cursor=32"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "delete from Customers where not ",
|
||||
cursor: 32,
|
||||
state: IncompleteAtEof,
|
||||
hint: Some(
|
||||
Candidates {
|
||||
items: [
|
||||
Candidate {
|
||||
text: "not",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "null",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "true",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "false",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "(",
|
||||
kind: Punct,
|
||||
},
|
||||
Candidate {
|
||||
text: "Email",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "Name",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "id",
|
||||
kind: Identifier,
|
||||
},
|
||||
],
|
||||
selected: None,
|
||||
},
|
||||
),
|
||||
completion: Some(
|
||||
Completion {
|
||||
replaced_range: (
|
||||
32,
|
||||
32,
|
||||
),
|
||||
partial_prefix: "",
|
||||
candidates: [
|
||||
Candidate {
|
||||
text: "not",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "null",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "true",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "false",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "(",
|
||||
kind: Punct,
|
||||
},
|
||||
Candidate {
|
||||
text: "Email",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "Name",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "id",
|
||||
kind: Identifier,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
parse_result: Err(
|
||||
"Invalid(at_eof)",
|
||||
),
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"delete from Customers where Email \" cursor=34"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "delete from Customers where Email ",
|
||||
cursor: 34,
|
||||
state: IncompleteAtEof,
|
||||
hint: Some(
|
||||
Candidates {
|
||||
items: [
|
||||
Candidate {
|
||||
text: "is",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "not",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "like",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "between",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "in",
|
||||
kind: Keyword,
|
||||
},
|
||||
],
|
||||
selected: None,
|
||||
},
|
||||
),
|
||||
completion: Some(
|
||||
Completion {
|
||||
replaced_range: (
|
||||
34,
|
||||
34,
|
||||
),
|
||||
partial_prefix: "",
|
||||
candidates: [
|
||||
Candidate {
|
||||
text: "is",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "not",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "like",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "between",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "in",
|
||||
kind: Keyword,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
parse_result: Err(
|
||||
"Invalid(at_eof)",
|
||||
),
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"delete from Things where k between \" cursor=35"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "delete from Things where k between ",
|
||||
cursor: 35,
|
||||
state: IncompleteAtEof,
|
||||
hint: Some(
|
||||
Prose(
|
||||
"for `k`: Type an integer (e.g. 42, -7) or null",
|
||||
),
|
||||
),
|
||||
completion: Some(
|
||||
Completion {
|
||||
replaced_range: (
|
||||
35,
|
||||
35,
|
||||
),
|
||||
partial_prefix: "",
|
||||
candidates: [
|
||||
Candidate {
|
||||
text: "null",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "true",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "false",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "auto",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "b",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "d",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "data",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "dt",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "k",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "note",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "r",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "sid",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "ts",
|
||||
kind: Identifier,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
parse_result: Err(
|
||||
"Invalid(at_eof)",
|
||||
),
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"show data Customers where id=1 limit 10\" cursor=39"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "show data Customers where id=1 limit 10",
|
||||
cursor: 39,
|
||||
state: Valid,
|
||||
hint: Some(
|
||||
Prose(
|
||||
"Submit with Enter",
|
||||
),
|
||||
),
|
||||
completion: None,
|
||||
parse_result: Ok(
|
||||
"ShowData",
|
||||
),
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"delete from Things where k > 1 and t like 'a%' or k = 9\" cursor=55"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "delete from Things where k > 1 and t like 'a%' or k = 9",
|
||||
cursor: 55,
|
||||
state: Valid,
|
||||
hint: Some(
|
||||
Prose(
|
||||
"Submit with Enter",
|
||||
),
|
||||
),
|
||||
completion: None,
|
||||
parse_result: Ok(
|
||||
"Delete",
|
||||
),
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"delete from Things where k in (\" cursor=31"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "delete from Things where k in (",
|
||||
cursor: 31,
|
||||
state: IncompleteAtEof,
|
||||
hint: Some(
|
||||
Prose(
|
||||
"for `k`: Type an integer (e.g. 42, -7) or null",
|
||||
),
|
||||
),
|
||||
completion: Some(
|
||||
Completion {
|
||||
replaced_range: (
|
||||
31,
|
||||
31,
|
||||
),
|
||||
partial_prefix: "",
|
||||
candidates: [
|
||||
Candidate {
|
||||
text: "null",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "true",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "false",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "auto",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "b",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "d",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "data",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "dt",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "k",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "note",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "r",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "sid",
|
||||
kind: Identifier,
|
||||
},
|
||||
Candidate {
|
||||
text: "ts",
|
||||
kind: Identifier,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
parse_result: Err(
|
||||
"Invalid(at_eof)",
|
||||
),
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"show data Customers \" cursor=20"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "show data Customers ",
|
||||
cursor: 20,
|
||||
state: Valid,
|
||||
hint: Some(
|
||||
Candidates {
|
||||
items: [
|
||||
Candidate {
|
||||
text: "where",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "limit",
|
||||
kind: Keyword,
|
||||
},
|
||||
],
|
||||
selected: None,
|
||||
},
|
||||
),
|
||||
completion: Some(
|
||||
Completion {
|
||||
replaced_range: (
|
||||
20,
|
||||
20,
|
||||
),
|
||||
partial_prefix: "",
|
||||
candidates: [
|
||||
Candidate {
|
||||
text: "where",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "limit",
|
||||
kind: Keyword,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
parse_result: Ok(
|
||||
"ShowData",
|
||||
),
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
---
|
||||
source: tests/typing_surface/where_expression.rs
|
||||
description: "input=\"show data Customers where id=1 \" cursor=31"
|
||||
expression: "& a"
|
||||
---
|
||||
Assessment {
|
||||
input: "show data Customers where id=1 ",
|
||||
cursor: 31,
|
||||
state: Valid,
|
||||
hint: Some(
|
||||
Candidates {
|
||||
items: [
|
||||
Candidate {
|
||||
text: "and",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "or",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "limit",
|
||||
kind: Keyword,
|
||||
},
|
||||
],
|
||||
selected: None,
|
||||
},
|
||||
),
|
||||
completion: Some(
|
||||
Completion {
|
||||
replaced_range: (
|
||||
31,
|
||||
31,
|
||||
),
|
||||
partial_prefix: "",
|
||||
candidates: [
|
||||
Candidate {
|
||||
text: "and",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "or",
|
||||
kind: Keyword,
|
||||
},
|
||||
Candidate {
|
||||
text: "limit",
|
||||
kind: Keyword,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
parse_result: Ok(
|
||||
"ShowData",
|
||||
),
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
//! 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();
|
||||
let a = assess_at_end(
|
||||
"delete from Things where k > 1 and t 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);
|
||||
}
|
||||
Reference in New Issue
Block a user