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.
This commit is contained in:
+119
-179
@@ -28,12 +28,10 @@ use crate::completion::TableColumn;
|
||||
use crate::dsl::grammar::{HighlightClass, Node, ValidationError};
|
||||
use crate::dsl::walker::context::WalkContext;
|
||||
use crate::dsl::walker::lex_helpers::{
|
||||
consume_bare_path, consume_flag, consume_ident, consume_number_literal,
|
||||
consume_string_literal, skip_whitespace,
|
||||
};
|
||||
use crate::dsl::walker::outcome::{
|
||||
ByteClass, Expectation, MatchedItem, MatchedKind, MatchedPath,
|
||||
consume_bare_path, consume_flag, consume_ident, consume_number_literal, consume_string_literal,
|
||||
skip_whitespace,
|
||||
};
|
||||
use crate::dsl::walker::outcome::{ByteClass, Expectation, MatchedItem, MatchedKind, MatchedPath};
|
||||
|
||||
/// Maximum nesting of `Node::Subgrammar` frames (ADR-0026 §1).
|
||||
///
|
||||
@@ -77,10 +75,7 @@ static DYNAMIC_CACHE: LazyLock<Mutex<HashMap<DynamicKey, &'static Node>>> =
|
||||
/// Resolve a `DynamicSubgrammar` factory to a `&'static Node`,
|
||||
/// reusing a previously-leaked Node when the factory's inputs
|
||||
/// match a cached entry.
|
||||
fn resolve_dynamic(
|
||||
factory: fn(&WalkContext) -> Node,
|
||||
ctx: &WalkContext,
|
||||
) -> &'static Node {
|
||||
fn resolve_dynamic(factory: fn(&WalkContext) -> Node, ctx: &WalkContext) -> &'static Node {
|
||||
let key = DynamicKey {
|
||||
factory: factory as usize,
|
||||
current_table_columns: ctx.current_table_columns.clone(),
|
||||
@@ -123,10 +118,7 @@ pub enum NodeWalkResult {
|
||||
expected: Vec<Expectation>,
|
||||
},
|
||||
/// Committed and hit a hard mismatch or validator failure.
|
||||
Failed {
|
||||
position: usize,
|
||||
kind: FailureKind,
|
||||
},
|
||||
Failed { position: usize, kind: FailureKind },
|
||||
}
|
||||
|
||||
const fn matched(end: usize) -> NodeWalkResult {
|
||||
@@ -218,9 +210,7 @@ fn walk_node_inner(
|
||||
kind: FailureKind::Mismatch { expected: vec![] },
|
||||
}
|
||||
}
|
||||
Node::Subgrammar(inner) => {
|
||||
walk_subgrammar(source, pos, inner, ctx, path, per_byte)
|
||||
}
|
||||
Node::Subgrammar(inner) => walk_subgrammar(source, pos, inner, ctx, path, per_byte),
|
||||
Node::ScopedSubgrammar(inner) => {
|
||||
walk_scoped_subgrammar(source, pos, inner, ctx, path, per_byte)
|
||||
}
|
||||
@@ -247,8 +237,7 @@ fn walk_node_inner(
|
||||
// DynamicSubgrammar wrapper that delegates to the
|
||||
// memoized `column_value_list`), so the per-walk
|
||||
// leak is a few bytes, not a whole typed tree.
|
||||
let resolved: &'static Node =
|
||||
Box::leak(Box::new(factory(ctx, source, pos)));
|
||||
let resolved: &'static Node = Box::leak(Box::new(factory(ctx, source, pos)));
|
||||
walk_node(source, pos, resolved, ctx, path, per_byte)
|
||||
}
|
||||
Node::SetColumn(col) => {
|
||||
@@ -262,7 +251,10 @@ fn walk_node_inner(
|
||||
let col: &crate::completion::TableColumn = col;
|
||||
ctx.current_column = Some(col.clone());
|
||||
ctx.pending_value_column = Some(col.name.clone());
|
||||
NodeWalkResult::Matched { end: pos, skipped: Vec::new() }
|
||||
NodeWalkResult::Matched {
|
||||
end: pos,
|
||||
skipped: Vec::new(),
|
||||
}
|
||||
}
|
||||
Node::TypedValueSlot {
|
||||
ty,
|
||||
@@ -342,7 +334,10 @@ fn walk_word(
|
||||
// Amendment 4). Plain keywords leave it `None`.
|
||||
class: word.highlight_override.unwrap_or(HighlightClass::Keyword),
|
||||
});
|
||||
NodeWalkResult::Matched { end, skipped: Vec::new() }
|
||||
NodeWalkResult::Matched {
|
||||
end,
|
||||
skipped: Vec::new(),
|
||||
}
|
||||
} else {
|
||||
NodeWalkResult::NoMatch {
|
||||
position,
|
||||
@@ -477,9 +472,7 @@ fn walk_ident(
|
||||
// ScopedSubgrammar (which is structurally guaranteed to be
|
||||
// the CTE body — no intervening scoped subgrammar in CTE
|
||||
// syntax) runs the harvest at body-frame exit.
|
||||
if writes_cte_name
|
||||
&& let Some(frame) = ctx.from_scope_stack.last_mut()
|
||||
{
|
||||
if writes_cte_name && let Some(frame) = ctx.from_scope_stack.last_mut() {
|
||||
frame
|
||||
.cte_bindings
|
||||
.push(crate::dsl::walker::context::CteBinding {
|
||||
@@ -487,13 +480,12 @@ fn walk_ident(
|
||||
columns: Vec::new(),
|
||||
});
|
||||
let placeholder_index = frame.cte_bindings.len() - 1;
|
||||
ctx.pending_cte_harvest =
|
||||
Some(crate::dsl::walker::context::PendingCteHarvest {
|
||||
placeholder_index,
|
||||
col_list: Vec::new(),
|
||||
cte_name: text.clone(),
|
||||
cte_name_span: (start, end),
|
||||
});
|
||||
ctx.pending_cte_harvest = Some(crate::dsl::walker::context::PendingCteHarvest {
|
||||
placeholder_index,
|
||||
col_list: Vec::new(),
|
||||
cte_name: text.clone(),
|
||||
cte_name_span: (start, end),
|
||||
});
|
||||
}
|
||||
// ADR-0032 §10.3: the optional `(c1, c2, …)` rename list
|
||||
// between the cte name and `AS`. Each `cte_column` ident
|
||||
@@ -507,9 +499,7 @@ fn walk_ident(
|
||||
}
|
||||
// ADR-0032 §10.4: projection-list alias accumulator for
|
||||
// ORDER BY completion candidates.
|
||||
if writes_projection_alias
|
||||
&& let Some(frame) = ctx.from_scope_stack.last_mut()
|
||||
{
|
||||
if writes_projection_alias && let Some(frame) = ctx.from_scope_stack.last_mut() {
|
||||
frame.projection_aliases.push(text.clone());
|
||||
}
|
||||
if writes_column && matches!(src, crate::dsl::grammar::IdentSource::Columns) {
|
||||
@@ -529,9 +519,7 @@ fn walk_ident(
|
||||
.map(|c| c.name.clone())
|
||||
.or_else(|| Some(text.clone()));
|
||||
}
|
||||
if writes_user_listed_column
|
||||
&& matches!(src, crate::dsl::grammar::IdentSource::Columns)
|
||||
{
|
||||
if writes_user_listed_column && matches!(src, crate::dsl::grammar::IdentSource::Columns) {
|
||||
// Form A: `insert into <T> (col1, col2, …)`. Append the
|
||||
// matched column name to user_listed_columns so the
|
||||
// inner `values (…)` slot list mirrors the user's
|
||||
@@ -564,7 +552,10 @@ fn walk_ident(
|
||||
// (issue #8 / ADR-0022 Amendment 4).
|
||||
class: highlight_override.unwrap_or(HighlightClass::Identifier),
|
||||
});
|
||||
NodeWalkResult::Matched { end, skipped: Vec::new() }
|
||||
NodeWalkResult::Matched {
|
||||
end,
|
||||
skipped: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn walk_string_lit(
|
||||
@@ -648,7 +639,10 @@ fn walk_literal(
|
||||
end,
|
||||
class,
|
||||
});
|
||||
NodeWalkResult::Matched { end, skipped: Vec::new() }
|
||||
NodeWalkResult::Matched {
|
||||
end,
|
||||
skipped: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn walk_number_lit(
|
||||
@@ -683,7 +677,10 @@ fn walk_number_lit(
|
||||
end,
|
||||
class: HighlightClass::Number,
|
||||
});
|
||||
NodeWalkResult::Matched { end, skipped: Vec::new() }
|
||||
NodeWalkResult::Matched {
|
||||
end,
|
||||
skipped: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn walk_flag(
|
||||
@@ -717,7 +714,10 @@ fn walk_flag(
|
||||
end,
|
||||
class: HighlightClass::Flag,
|
||||
});
|
||||
NodeWalkResult::Matched { end, skipped: Vec::new() }
|
||||
NodeWalkResult::Matched {
|
||||
end,
|
||||
skipped: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -784,7 +784,10 @@ fn walk_repeated(
|
||||
count += 1;
|
||||
last_item_skipped = skipped;
|
||||
}
|
||||
NodeWalkResult::NoMatch { expected, position: inner_pos } => {
|
||||
NodeWalkResult::NoMatch {
|
||||
expected,
|
||||
position: inner_pos,
|
||||
} => {
|
||||
// Mid-typing-the-next-item recovery: if the
|
||||
// separator just consumed and the inner failed
|
||||
// at EOF, the user is partway through typing the
|
||||
@@ -860,7 +863,10 @@ fn walk_bare_path(
|
||||
end,
|
||||
class: HighlightClass::String,
|
||||
});
|
||||
NodeWalkResult::Matched { end, skipped: Vec::new() }
|
||||
NodeWalkResult::Matched {
|
||||
end,
|
||||
skipped: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn walk_choice(
|
||||
@@ -1031,7 +1037,10 @@ fn walk_optional(
|
||||
skipped: expected,
|
||||
}
|
||||
}
|
||||
NodeWalkResult::Incomplete { position: p, expected } if !inner_committed => {
|
||||
NodeWalkResult::Incomplete {
|
||||
position: p,
|
||||
expected,
|
||||
} if !inner_committed => {
|
||||
// Inner reported Incomplete without consuming
|
||||
// anything — same as NoMatch from the user's
|
||||
// perspective. Roll back and skip.
|
||||
@@ -1156,9 +1165,7 @@ fn walk_scoped_subgrammar(
|
||||
// walks that NoMatch / Incomplete / Fail leave the placeholder
|
||||
// empty (the outer-frame state is also discarded in the
|
||||
// speculative path, so this is correct).
|
||||
if let (Some(req), NodeWalkResult::Matched { end, .. }) =
|
||||
(pending_cte, &result)
|
||||
{
|
||||
if let (Some(req), NodeWalkResult::Matched { end, .. }) = (pending_cte, &result) {
|
||||
run_cte_harvest(ctx, path, source, pos, *end, &req);
|
||||
}
|
||||
|
||||
@@ -1240,9 +1247,8 @@ fn run_cte_harvest(
|
||||
select_idx = Some(i + 1); // start of projection list
|
||||
}
|
||||
MatchedKind::Word(
|
||||
"from" | "where" | "group" | "having" | "order"
|
||||
| "limit" | "offset" | "union" | "intersect"
|
||||
| "except",
|
||||
"from" | "where" | "group" | "having" | "order" | "limit" | "offset" | "union"
|
||||
| "intersect" | "except",
|
||||
) if select_idx.is_some() => {
|
||||
end_idx = i;
|
||||
break;
|
||||
@@ -1281,12 +1287,7 @@ fn run_cte_harvest(
|
||||
// Classify each projection item per ADR-0032 §10.3.
|
||||
let mut derived: Vec<CteColumn> = Vec::new();
|
||||
for slice in item_slices {
|
||||
classify_projection_item(
|
||||
slice,
|
||||
body_frame,
|
||||
&ctx.from_scope_stack,
|
||||
&mut derived,
|
||||
);
|
||||
classify_projection_item(slice, body_frame, &ctx.from_scope_stack, &mut derived);
|
||||
}
|
||||
|
||||
// Apply (c1, c2, …) positional rename if provided. Types
|
||||
@@ -1339,8 +1340,7 @@ fn run_cte_harvest(
|
||||
let stack_len = ctx.from_scope_stack.len();
|
||||
if stack_len >= 2
|
||||
&& let Some(outer) = ctx.from_scope_stack.get_mut(stack_len - 2)
|
||||
&& let Some(placeholder) =
|
||||
outer.cte_bindings.get_mut(req.placeholder_index)
|
||||
&& let Some(placeholder) = outer.cte_bindings.get_mut(req.placeholder_index)
|
||||
{
|
||||
placeholder.columns = derived;
|
||||
}
|
||||
@@ -1368,9 +1368,7 @@ fn classify_projection_item(
|
||||
// empty because it wasn't a base-table lookup), resolve
|
||||
// through to the in-scope CteBinding so nested CTEs project
|
||||
// correctly.
|
||||
if expr_slice.len() == 1
|
||||
&& matches!(expr_slice[0].kind, MatchedKind::Punct('*'))
|
||||
{
|
||||
if expr_slice.len() == 1 && matches!(expr_slice[0].kind, MatchedKind::Punct('*')) {
|
||||
for binding in &body_frame.from_scope {
|
||||
for col in expand_binding(binding, scope_stack) {
|
||||
out.push(col);
|
||||
@@ -1383,7 +1381,10 @@ fn classify_projection_item(
|
||||
if expr_slice.len() == 3
|
||||
&& matches!(
|
||||
expr_slice[0].kind,
|
||||
MatchedKind::Ident { role: "qualified_star_qualifier", .. }
|
||||
MatchedKind::Ident {
|
||||
role: "qualified_star_qualifier",
|
||||
..
|
||||
}
|
||||
)
|
||||
&& matches!(expr_slice[1].kind, MatchedKind::Punct('.'))
|
||||
&& matches!(expr_slice[2].kind, MatchedKind::Punct('*'))
|
||||
@@ -1413,11 +1414,7 @@ fn classify_projection_item(
|
||||
)
|
||||
{
|
||||
let col_text = &expr_slice[0].text;
|
||||
let resolved_type = resolve_bare_column_type_in_frame(
|
||||
body_frame,
|
||||
scope_stack,
|
||||
col_text,
|
||||
);
|
||||
let resolved_type = resolve_bare_column_type_in_frame(body_frame, scope_stack, col_text);
|
||||
let name = alias.unwrap_or_else(|| col_text.clone());
|
||||
out.push(CteColumn {
|
||||
name: Some(name),
|
||||
@@ -1447,12 +1444,7 @@ fn classify_projection_item(
|
||||
{
|
||||
let qual = &expr_slice[0].text;
|
||||
let col_text = &expr_slice[2].text;
|
||||
let resolved_type = resolve_qualified_column_type(
|
||||
body_frame,
|
||||
scope_stack,
|
||||
qual,
|
||||
col_text,
|
||||
);
|
||||
let resolved_type = resolve_qualified_column_type(body_frame, scope_stack, qual, col_text);
|
||||
let name = alias.unwrap_or_else(|| col_text.clone());
|
||||
out.push(CteColumn {
|
||||
name: Some(name),
|
||||
@@ -1493,16 +1485,8 @@ fn strip_trailing_alias<'a>(
|
||||
}
|
||||
) {
|
||||
// Optional preceding `AS` keyword.
|
||||
if slice.len() >= 2
|
||||
&& matches!(
|
||||
slice[slice.len() - 2].kind,
|
||||
MatchedKind::Word("as")
|
||||
)
|
||||
{
|
||||
return (
|
||||
&slice[..slice.len() - 2],
|
||||
Some(last.text.clone()),
|
||||
);
|
||||
if slice.len() >= 2 && matches!(slice[slice.len() - 2].kind, MatchedKind::Word("as")) {
|
||||
return (&slice[..slice.len() - 2], Some(last.text.clone()));
|
||||
}
|
||||
return (&slice[..slice.len() - 1], Some(last.text.clone()));
|
||||
}
|
||||
@@ -1613,8 +1597,8 @@ fn merge_expected(dst: &mut Vec<Expectation>, src: Vec<Expectation>) {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
DYNAMIC_CACHE, FailureKind, MAX_SUBGRAMMAR_DEPTH, NodeWalkResult,
|
||||
resolve_dynamic, walk_node,
|
||||
DYNAMIC_CACHE, FailureKind, MAX_SUBGRAMMAR_DEPTH, NodeWalkResult, resolve_dynamic,
|
||||
walk_node,
|
||||
};
|
||||
use crate::dsl::grammar::{Node, Word};
|
||||
use crate::dsl::walker::context::WalkContext;
|
||||
@@ -1629,18 +1613,14 @@ mod tests {
|
||||
Node::Subgrammar(&NESTED),
|
||||
Node::Punct(')'),
|
||||
];
|
||||
static NESTED_CHOICES: &[Node] = &[
|
||||
Node::Seq(NESTED_GROUP),
|
||||
Node::Word(Word::keyword("x")),
|
||||
];
|
||||
static NESTED_CHOICES: &[Node] = &[Node::Seq(NESTED_GROUP), Node::Word(Word::keyword("x"))];
|
||||
static NESTED: Node = Node::Choice(NESTED_CHOICES);
|
||||
|
||||
fn walk_nested(input: &str) -> NodeWalkResult {
|
||||
let mut ctx = WalkContext::new();
|
||||
let mut path = MatchedPath::new();
|
||||
let mut per_byte = Vec::new();
|
||||
let result =
|
||||
walk_node(input, 0, &NESTED, &mut ctx, &mut path, &mut per_byte);
|
||||
let result = walk_node(input, 0, &NESTED, &mut ctx, &mut path, &mut per_byte);
|
||||
assert_eq!(
|
||||
ctx.subgrammar_depth, 0,
|
||||
"subgrammar_depth must be restored to 0 after the walk",
|
||||
@@ -1726,14 +1706,8 @@ mod tests {
|
||||
fn resolve_dynamic_cache_is_populated() {
|
||||
let ctx = WalkContext::new();
|
||||
let _ = resolve_dynamic(const_factory, &ctx);
|
||||
let populated = !DYNAMIC_CACHE
|
||||
.lock()
|
||||
.expect("cache lock")
|
||||
.is_empty();
|
||||
assert!(
|
||||
populated,
|
||||
"resolve_dynamic should populate the memo cache",
|
||||
);
|
||||
let populated = !DYNAMIC_CACHE.lock().expect("cache lock").is_empty();
|
||||
assert!(populated, "resolve_dynamic should populate the memo cache",);
|
||||
}
|
||||
|
||||
// ---- ScopedSubgrammar (ADR-0032 §10.2) -----------------------
|
||||
@@ -1758,14 +1732,7 @@ mod tests {
|
||||
let mut path = MatchedPath::new();
|
||||
let mut per_byte = Vec::new();
|
||||
let baseline_frames = ctx.from_scope_stack.len();
|
||||
let result = walk_node(
|
||||
input,
|
||||
0,
|
||||
&SCOPED_NESTED,
|
||||
&mut ctx,
|
||||
&mut path,
|
||||
&mut per_byte,
|
||||
);
|
||||
let result = walk_node(input, 0, &SCOPED_NESTED, &mut ctx, &mut path, &mut per_byte);
|
||||
assert_eq!(
|
||||
ctx.subgrammar_depth, 0,
|
||||
"subgrammar_depth must be restored to 0 after the walk",
|
||||
@@ -1801,9 +1768,9 @@ mod tests {
|
||||
kind: FailureKind::Validation(err),
|
||||
..
|
||||
} => assert_eq!(err.message_key, "parse.custom.expression_too_deep"),
|
||||
other => panic!(
|
||||
"expected expression_too_deep on pathological scoped nesting, got {other:?}",
|
||||
),
|
||||
other => {
|
||||
panic!("expected expression_too_deep on pathological scoped nesting, got {other:?}",)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1822,9 +1789,7 @@ mod tests {
|
||||
/// Walk a top-level SQL SELECT and return the bottom frame's
|
||||
/// `from_scope` after the walk completes. Used to verify that
|
||||
/// `writes_table` / `writes_table_alias` populate bindings.
|
||||
fn from_scope_after_walk(
|
||||
input: &str,
|
||||
) -> Vec<crate::dsl::walker::context::TableBinding> {
|
||||
fn from_scope_after_walk(input: &str) -> Vec<crate::dsl::walker::context::TableBinding> {
|
||||
let mut ctx = WalkContext::new();
|
||||
let mut path = MatchedPath::new();
|
||||
let mut per_byte = Vec::new();
|
||||
@@ -1871,9 +1836,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn join_pushes_a_second_binding() {
|
||||
let bindings = from_scope_after_walk(
|
||||
"select * from a join b on x = y",
|
||||
);
|
||||
let bindings = from_scope_after_walk("select * from a join b on x = y");
|
||||
assert_eq!(bindings.len(), 2);
|
||||
assert_eq!(bindings[0].table, "a");
|
||||
assert_eq!(bindings[1].table, "b");
|
||||
@@ -1881,9 +1844,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn join_with_aliases() {
|
||||
let bindings = from_scope_after_walk(
|
||||
"select * from a as x join b as y on x.id = y.id",
|
||||
);
|
||||
let bindings = from_scope_after_walk("select * from a as x join b as y on x.id = y.id");
|
||||
assert_eq!(bindings.len(), 2);
|
||||
assert_eq!(bindings[0].table, "a");
|
||||
assert_eq!(bindings[0].alias, Some("x".to_string()));
|
||||
@@ -1893,9 +1854,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn three_way_join_pushes_three_bindings() {
|
||||
let bindings = from_scope_after_walk(
|
||||
"select * from a join b on x = y left join c on y = z",
|
||||
);
|
||||
let bindings =
|
||||
from_scope_after_walk("select * from a join b on x = y left join c on y = z");
|
||||
assert_eq!(bindings.len(), 3);
|
||||
assert_eq!(bindings[0].table, "a");
|
||||
assert_eq!(bindings[1].table, "b");
|
||||
@@ -1908,9 +1868,8 @@ mod tests {
|
||||
// binding into the inner scope frame; on exit, the frame
|
||||
// pops and the inner binding is gone. The outer scope's
|
||||
// from_scope still contains only `outer_t`.
|
||||
let bindings = from_scope_after_walk(
|
||||
"select * from outer_t where id in (select id from inner_t)",
|
||||
);
|
||||
let bindings =
|
||||
from_scope_after_walk("select * from outer_t where id in (select id from inner_t)");
|
||||
assert_eq!(bindings.len(), 1);
|
||||
assert_eq!(bindings[0].table, "outer_t");
|
||||
}
|
||||
@@ -1921,9 +1880,8 @@ mod tests {
|
||||
// body's scope frame; on body-frame exit, the inner
|
||||
// binding goes away. The outer scope contains only
|
||||
// the CTE-name reference `cte_x`.
|
||||
let bindings = from_scope_after_walk(
|
||||
"with cte_x as (select * from base_table) select * from cte_x",
|
||||
);
|
||||
let bindings =
|
||||
from_scope_after_walk("with cte_x as (select * from base_table) select * from cte_x");
|
||||
assert_eq!(bindings.len(), 1);
|
||||
assert_eq!(bindings[0].table, "cte_x");
|
||||
}
|
||||
@@ -1940,10 +1898,7 @@ mod tests {
|
||||
/// `cte_bindings` and `projection_aliases` after the walk.
|
||||
fn frame_state_after_walk(
|
||||
input: &str,
|
||||
) -> (
|
||||
Vec<crate::dsl::walker::context::CteBinding>,
|
||||
Vec<String>,
|
||||
) {
|
||||
) -> (Vec<crate::dsl::walker::context::CteBinding>, Vec<String>) {
|
||||
let mut ctx = WalkContext::new();
|
||||
let mut path = MatchedPath::new();
|
||||
let mut per_byte = Vec::new();
|
||||
@@ -1968,9 +1923,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn cte_name_pushes_placeholder_binding() {
|
||||
let (ctes, _) = frame_state_after_walk(
|
||||
"with cte_x as (select 1) select * from cte_x",
|
||||
);
|
||||
let (ctes, _) = frame_state_after_walk("with cte_x as (select 1) select * from cte_x");
|
||||
assert_eq!(ctes.len(), 1);
|
||||
assert_eq!(ctes[0].name, "cte_x");
|
||||
// §10.3 stage-2 harvest produces one CteColumn per
|
||||
@@ -1984,9 +1937,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn multiple_ctes_push_in_order() {
|
||||
let (ctes, _) = frame_state_after_walk(
|
||||
"with a as (select 1), b as (select 2) select * from b",
|
||||
);
|
||||
let (ctes, _) =
|
||||
frame_state_after_walk("with a as (select 1), b as (select 2) select * from b");
|
||||
assert_eq!(ctes.len(), 2);
|
||||
assert_eq!(ctes[0].name, "a");
|
||||
assert_eq!(ctes[1].name, "b");
|
||||
@@ -2006,25 +1958,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn projection_aliases_captured_via_as_form() {
|
||||
let (_, aliases) = frame_state_after_walk(
|
||||
"select a as alpha, b as beta from t",
|
||||
);
|
||||
let (_, aliases) = frame_state_after_walk("select a as alpha, b as beta from t");
|
||||
assert_eq!(aliases, vec!["alpha".to_string(), "beta".to_string()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn projection_aliases_captured_via_bare_form() {
|
||||
let (_, aliases) = frame_state_after_walk(
|
||||
"select a alpha, b beta from t",
|
||||
);
|
||||
let (_, aliases) = frame_state_after_walk("select a alpha, b beta from t");
|
||||
assert_eq!(aliases, vec!["alpha".to_string(), "beta".to_string()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn projection_aliases_mixed_forms() {
|
||||
let (_, aliases) = frame_state_after_walk(
|
||||
"select a as alpha, b beta, c, d as delta from t",
|
||||
);
|
||||
let (_, aliases) =
|
||||
frame_state_after_walk("select a as alpha, b beta, c, d as delta from t");
|
||||
assert_eq!(
|
||||
aliases,
|
||||
vec!["alpha".to_string(), "beta".to_string(), "delta".to_string()]
|
||||
@@ -2033,8 +1980,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn projection_aliases_empty_when_no_aliases() {
|
||||
let (_, aliases) =
|
||||
frame_state_after_walk("select a, b from t");
|
||||
let (_, aliases) = frame_state_after_walk("select a, b from t");
|
||||
assert!(aliases.is_empty());
|
||||
}
|
||||
|
||||
@@ -2088,9 +2034,24 @@ mod tests {
|
||||
s.table_columns.insert(
|
||||
"users".to_string(),
|
||||
vec![
|
||||
TableColumn { name: "id".to_string(), user_type: Type::Int, not_null: false, has_default: false },
|
||||
TableColumn { name: "name".to_string(), user_type: Type::Text, not_null: false, has_default: false },
|
||||
TableColumn { name: "age".to_string(), user_type: Type::Int, not_null: false, has_default: false },
|
||||
TableColumn {
|
||||
name: "id".to_string(),
|
||||
user_type: Type::Int,
|
||||
not_null: false,
|
||||
has_default: false,
|
||||
},
|
||||
TableColumn {
|
||||
name: "name".to_string(),
|
||||
user_type: Type::Text,
|
||||
not_null: false,
|
||||
has_default: false,
|
||||
},
|
||||
TableColumn {
|
||||
name: "age".to_string(),
|
||||
user_type: Type::Int,
|
||||
not_null: false,
|
||||
has_default: false,
|
||||
},
|
||||
],
|
||||
);
|
||||
s
|
||||
@@ -2108,10 +2069,7 @@ mod tests {
|
||||
assert_eq!(ctes.len(), 1);
|
||||
assert_eq!(ctes[0].columns.len(), 3);
|
||||
assert_eq!(ctes[0].columns[0].name.as_deref(), Some("id"));
|
||||
assert_eq!(
|
||||
ctes[0].columns[0].type_,
|
||||
Some(crate::dsl::types::Type::Int),
|
||||
);
|
||||
assert_eq!(ctes[0].columns[0].type_, Some(crate::dsl::types::Type::Int),);
|
||||
assert_eq!(ctes[0].columns[1].name.as_deref(), Some("name"));
|
||||
assert_eq!(
|
||||
ctes[0].columns[1].type_,
|
||||
@@ -2161,10 +2119,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(ctes[0].columns.len(), 1);
|
||||
assert_eq!(ctes[0].columns[0].name.as_deref(), Some("age"));
|
||||
assert_eq!(
|
||||
ctes[0].columns[0].type_,
|
||||
Some(crate::dsl::types::Type::Int),
|
||||
);
|
||||
assert_eq!(ctes[0].columns[0].type_, Some(crate::dsl::types::Type::Int),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2259,15 +2214,9 @@ mod tests {
|
||||
.expect("outer_cte binding");
|
||||
assert_eq!(outer.columns.len(), 2);
|
||||
assert_eq!(outer.columns[0].name.as_deref(), Some("id"));
|
||||
assert_eq!(
|
||||
outer.columns[0].type_,
|
||||
Some(crate::dsl::types::Type::Int),
|
||||
);
|
||||
assert_eq!(outer.columns[0].type_, Some(crate::dsl::types::Type::Int),);
|
||||
assert_eq!(outer.columns[1].name.as_deref(), Some("name"));
|
||||
assert_eq!(
|
||||
outer.columns[1].type_,
|
||||
Some(crate::dsl::types::Type::Text),
|
||||
);
|
||||
assert_eq!(outer.columns[1].type_, Some(crate::dsl::types::Type::Text),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2287,15 +2236,9 @@ mod tests {
|
||||
let b = ctes.iter().find(|c| c.name == "b").expect("b binding");
|
||||
assert_eq!(b.columns.len(), 2);
|
||||
assert_eq!(b.columns[0].name.as_deref(), Some("id"));
|
||||
assert_eq!(
|
||||
b.columns[0].type_,
|
||||
Some(crate::dsl::types::Type::Int),
|
||||
);
|
||||
assert_eq!(b.columns[0].type_, Some(crate::dsl::types::Type::Int),);
|
||||
assert_eq!(b.columns[1].name.as_deref(), Some("name"));
|
||||
assert_eq!(
|
||||
b.columns[1].type_,
|
||||
Some(crate::dsl::types::Type::Text),
|
||||
);
|
||||
assert_eq!(b.columns[1].type_, Some(crate::dsl::types::Type::Text),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2310,10 +2253,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(ctes[0].columns.len(), 3);
|
||||
assert_eq!(ctes[0].columns[0].name.as_deref(), Some("a"));
|
||||
assert_eq!(
|
||||
ctes[0].columns[0].type_,
|
||||
Some(crate::dsl::types::Type::Int),
|
||||
);
|
||||
assert_eq!(ctes[0].columns[0].type_, Some(crate::dsl::types::Type::Int),);
|
||||
assert_eq!(ctes[0].columns[1].name.as_deref(), Some("b"));
|
||||
assert_eq!(
|
||||
ctes[0].columns[1].type_,
|
||||
|
||||
Reference in New Issue
Block a user