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:
@@ -405,8 +405,14 @@ const TABLE_FK_NAMED: Node = Node::Seq(TABLE_FK_NAMED_NODES);
|
||||
// / `foreign`) that disambiguates it from a column name. (A column
|
||||
// literally named with one of those keywords is therefore unavailable,
|
||||
// the same trade real SQL makes with its reserved words.)
|
||||
static ELEMENT_CHOICES: &[Node] =
|
||||
&[TABLE_PK, TABLE_UNIQUE, TABLE_CHECK, TABLE_FK_NAMED, TABLE_FK, COLUMN_DEF];
|
||||
static ELEMENT_CHOICES: &[Node] = &[
|
||||
TABLE_PK,
|
||||
TABLE_UNIQUE,
|
||||
TABLE_CHECK,
|
||||
TABLE_FK_NAMED,
|
||||
TABLE_FK,
|
||||
COLUMN_DEF,
|
||||
];
|
||||
const ELEMENT_INNER: Node = Node::Choice(ELEMENT_CHOICES);
|
||||
// Issue #4: wrap the element slot in `IntroProse` so a fresh element
|
||||
// position (`create table T (` and after every `,`) surfaces a prose
|
||||
@@ -495,18 +501,31 @@ mod tests {
|
||||
let mut ctx = WalkContext::new();
|
||||
let mut path = MatchedPath::new();
|
||||
let mut per_byte = Vec::new();
|
||||
match walk_node(input, 0, &SQL_CREATE_TABLE_SHAPE, &mut ctx, &mut path, &mut per_byte) {
|
||||
match walk_node(
|
||||
input,
|
||||
0,
|
||||
&SQL_CREATE_TABLE_SHAPE,
|
||||
&mut ctx,
|
||||
&mut path,
|
||||
&mut per_byte,
|
||||
) {
|
||||
NodeWalkResult::Matched { end, .. } => input[end..].trim().is_empty(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn good(input: &str) {
|
||||
assert!(walks(input), "{input:?} should be a valid CREATE TABLE tail");
|
||||
assert!(
|
||||
walks(input),
|
||||
"{input:?} should be a valid CREATE TABLE tail"
|
||||
);
|
||||
}
|
||||
|
||||
fn bad(input: &str) {
|
||||
assert!(!walks(input), "{input:?} should NOT walk as a complete CREATE TABLE tail");
|
||||
assert!(
|
||||
!walks(input),
|
||||
"{input:?} should NOT walk as a complete CREATE TABLE tail"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -638,7 +657,9 @@ mod tests {
|
||||
good("table t (id int, ref int references other(id))");
|
||||
good("table t (id int, ref int references other)"); // bare ref
|
||||
good("table t (id int, ref int references other(id) on delete cascade)");
|
||||
good("table t (id int, ref int references other(id) on update set null on delete restrict)");
|
||||
good(
|
||||
"table t (id int, ref int references other(id) on update set null on delete restrict)",
|
||||
);
|
||||
good("table t (id int, ref int, foreign key (ref) references other(id))");
|
||||
good("table t (id int, ref int, constraint fk_x foreign key (ref) references other(id))");
|
||||
good(
|
||||
@@ -691,7 +712,10 @@ mod builder_tests {
|
||||
assert_eq!(name, "t");
|
||||
assert_eq!(
|
||||
cols,
|
||||
vec![("id".to_string(), Type::Int), ("name".to_string(), Type::Text)]
|
||||
vec![
|
||||
("id".to_string(), Type::Int),
|
||||
("name".to_string(), Type::Text)
|
||||
]
|
||||
);
|
||||
assert!(pk.is_empty(), "no PK declared");
|
||||
assert!(!ine);
|
||||
@@ -740,7 +764,10 @@ mod builder_tests {
|
||||
let (_, cols, _, _) = sct("create table t (a varchar(255), b numeric(10, 2))");
|
||||
assert_eq!(
|
||||
cols,
|
||||
vec![("a".to_string(), Type::Text), ("b".to_string(), Type::Decimal)]
|
||||
vec![
|
||||
("a".to_string(), Type::Text),
|
||||
("b".to_string(), Type::Decimal)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -780,8 +807,7 @@ mod builder_tests {
|
||||
fn redundant_constraints_deduped_off_sole_pk_column() {
|
||||
// ADR-0035 §6.5: advanced mode accepts the redundant spelling
|
||||
// and silently drops the flags off the sole PK column.
|
||||
match parse_command("create table t (id int primary key not null unique)")
|
||||
.expect("parses")
|
||||
match parse_command("create table t (id int primary key not null unique)").expect("parses")
|
||||
{
|
||||
Command::SqlCreateTable {
|
||||
columns,
|
||||
@@ -944,8 +970,7 @@ mod builder_tests {
|
||||
// depth 2, not an element boundary, so the following `check`
|
||||
// is still column-level. A naive "reset on any comma" would
|
||||
// misclassify it as table-level (the §4.2 probe).
|
||||
let (cols, checks) =
|
||||
parse_sct_checks("create table t (n numeric(10, 2) check (n > 0))");
|
||||
let (cols, checks) = parse_sct_checks("create table t (n numeric(10, 2) check (n > 0))");
|
||||
assert_eq!(col(&cols, "n").check_sql.as_deref(), Some("n > 0"));
|
||||
assert!(checks.is_empty(), "no table-level CHECK was produced");
|
||||
}
|
||||
@@ -977,8 +1002,7 @@ mod builder_tests {
|
||||
fn table_check_before_a_later_column_is_table_level() {
|
||||
// A CHECK element that appears between columns (not after a
|
||||
// column's type) is table-level even though more columns follow.
|
||||
let (cols, checks) =
|
||||
parse_sct_checks("create table t (a int, check (a > 0), b int)");
|
||||
let (cols, checks) = parse_sct_checks("create table t (a int, check (a > 0), b int)");
|
||||
assert_eq!(checks, vec!["a > 0".to_string()]);
|
||||
assert!(col(&cols, "a").check_sql.is_none() && col(&cols, "b").check_sql.is_none());
|
||||
}
|
||||
@@ -1004,7 +1028,10 @@ mod builder_tests {
|
||||
assert_eq!(fk.parent_columns, Some(vec!["id".to_string()]));
|
||||
assert_eq!(fk.on_delete, ReferentialAction::NoAction);
|
||||
assert_eq!(fk.on_update, ReferentialAction::NoAction);
|
||||
assert!(fk.inline, "a column-level `references` is an inline FK (ADR-0043 D4)");
|
||||
assert!(
|
||||
fk.inline,
|
||||
"a column-level `references` is an inline FK (ADR-0043 D4)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1012,14 +1039,19 @@ mod builder_tests {
|
||||
// The table-level `FOREIGN KEY (...)` form is not inline, so it can
|
||||
// carry a multi-column reference and never triggers the inline
|
||||
// "use the table-level form" hint (ADR-0043 D4).
|
||||
let fks = parse_sct_fks("create table t (id int, pid int, foreign key (pid) references parent(id))");
|
||||
let fks = parse_sct_fks(
|
||||
"create table t (id int, pid int, foreign key (pid) references parent(id))",
|
||||
);
|
||||
assert!(!fks[0].inline, "table-level FOREIGN KEY is not inline");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bare_inline_reference_has_no_parent_column() {
|
||||
let fks = parse_sct_fks("create table t (id int, pid int references parent)");
|
||||
assert_eq!(fks[0].parent_columns, None, "bare REFERENCES — resolved at execution");
|
||||
assert_eq!(
|
||||
fks[0].parent_columns, None,
|
||||
"bare REFERENCES — resolved at execution"
|
||||
);
|
||||
assert_eq!(fks[0].parent_table, "parent");
|
||||
assert_eq!(fks[0].child_columns, vec!["pid".to_string()]);
|
||||
}
|
||||
@@ -1047,8 +1079,9 @@ mod builder_tests {
|
||||
|
||||
#[test]
|
||||
fn table_level_foreign_key_captured() {
|
||||
let fks =
|
||||
parse_sct_fks("create table t (id int, pid int, foreign key (pid) references parent(id))");
|
||||
let fks = parse_sct_fks(
|
||||
"create table t (id int, pid int, foreign key (pid) references parent(id))",
|
||||
);
|
||||
assert_eq!(fks.len(), 1);
|
||||
assert_eq!(fks[0].name, None);
|
||||
assert_eq!(fks[0].child_columns, vec!["pid".to_string()]);
|
||||
@@ -1073,8 +1106,20 @@ mod builder_tests {
|
||||
foreign key (a) references p(id), foreign key (b) references q(id))",
|
||||
);
|
||||
assert_eq!(fks.len(), 2);
|
||||
assert_eq!((fks[0].child_columns[0].as_str(), fks[0].parent_table.as_str()), ("a", "p"));
|
||||
assert_eq!((fks[1].child_columns[0].as_str(), fks[1].parent_table.as_str()), ("b", "q"));
|
||||
assert_eq!(
|
||||
(
|
||||
fks[0].child_columns[0].as_str(),
|
||||
fks[0].parent_table.as_str()
|
||||
),
|
||||
("a", "p")
|
||||
);
|
||||
assert_eq!(
|
||||
(
|
||||
fks[1].child_columns[0].as_str(),
|
||||
fks[1].parent_table.as_str()
|
||||
),
|
||||
("b", "q")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1108,7 +1153,12 @@ mod builder_tests {
|
||||
assert_eq!(foreign_keys[0].child_columns, vec!["pid".to_string()]);
|
||||
// the column-level CHECK still attaches to `pid`
|
||||
assert_eq!(
|
||||
columns.iter().find(|c| c.name == "pid").unwrap().check_sql.as_deref(),
|
||||
columns
|
||||
.iter()
|
||||
.find(|c| c.name == "pid")
|
||||
.unwrap()
|
||||
.check_sql
|
||||
.as_deref(),
|
||||
Some("pid > 0")
|
||||
);
|
||||
// the table-level CHECK is captured separately
|
||||
|
||||
Reference in New Issue
Block a user