Skip to content

Commit

Permalink
chore: fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
togami2864 committed Feb 3, 2023
1 parent cee5ac8 commit b6a8af1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 59 deletions.
2 changes: 1 addition & 1 deletion examples/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $ cargo run --feature json_example --example cli FILENAME.sql [--dialectname]
#[cfg(feature = "json_example")]
{
let serialized = serde_json::to_string_pretty(&statements).unwrap();
println!("Serialized as JSON:\n{}", serialized);
println!("Serialized as JSON:\n{serialized}");
}
} else {
println!("Parse results:\n{statements:#?}");
Expand Down
5 changes: 1 addition & 4 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,7 @@ impl fmt::Display for AlterTableOperation {
AlterTableOperation::RenameColumn {
old_column_name,
new_column_name,
} => write!(
f,
"RENAME COLUMN {old_column_name} TO {new_column_name}"
),
} => write!(f, "RENAME COLUMN {old_column_name} TO {new_column_name}"),
AlterTableOperation::RenameTable { table_name } => {
write!(f, "RENAME TO {table_name}")
}
Expand Down
15 changes: 3 additions & 12 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2454,10 +2454,7 @@ impl fmt::Display for Statement {
Ok(())
}
Statement::ShowCreate { obj_type, obj_name } => {
write!(
f,
"SHOW CREATE {obj_type} {obj_name}",
)?;
write!(f, "SHOW CREATE {obj_type} {obj_name}",)?;
Ok(())
}
Statement::ShowColumns {
Expand Down Expand Up @@ -2690,10 +2687,7 @@ impl fmt::Display for Statement {
if_exists,
} => {
if *if_exists {
write!(
f,
"UNCACHE TABLE IF EXISTS {table_name}"
)
write!(f, "UNCACHE TABLE IF EXISTS {table_name}")
} else {
write!(f, "UNCACHE TABLE {table_name}")
}
Expand Down Expand Up @@ -4178,10 +4172,7 @@ mod tests {
Expr::Identifier(Ident::new("d")),
],
]);
assert_eq!(
"GROUPING SETS ((a, b), (c, d))",
format!("{grouping_sets}")
);
assert_eq!("GROUPING SETS ((a, b), (c, d))", format!("{grouping_sets}"));
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ impl fmt::Display for SetExpr {
} => {
write!(f, "{left} {op}")?;
match set_quantifier {
SetQuantifier::All | SetQuantifier::Distinct => {
write!(f, " {set_quantifier}")?
}
SetQuantifier::All | SetQuantifier::Distinct => write!(f, " {set_quantifier}")?,
SetQuantifier::None => write!(f, "{set_quantifier}")?,
}
write!(f, " {right}")?;
Expand Down
12 changes: 6 additions & 6 deletions src/ast/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,32 +600,32 @@ mod tests {
type Break = ();

fn pre_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow<Self::Break> {
self.visited.push(format!("PRE: RELATION: {}", relation));
self.visited.push(format!("PRE: RELATION: {relation}"));
ControlFlow::Continue(())
}

fn post_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow<Self::Break> {
self.visited.push(format!("POST: RELATION: {}", relation));
self.visited.push(format!("POST: RELATION: {relation}"));
ControlFlow::Continue(())
}

fn pre_visit_expr(&mut self, expr: &Expr) -> ControlFlow<Self::Break> {
self.visited.push(format!("PRE: EXPR: {}", expr));
self.visited.push(format!("PRE: EXPR: {expr}"));
ControlFlow::Continue(())
}

fn post_visit_expr(&mut self, expr: &Expr) -> ControlFlow<Self::Break> {
self.visited.push(format!("POST: EXPR: {}", expr));
self.visited.push(format!("POST: EXPR: {expr}"));
ControlFlow::Continue(())
}

fn pre_visit_statement(&mut self, statement: &Statement) -> ControlFlow<Self::Break> {
self.visited.push(format!("PRE: STATEMENT: {}", statement));
self.visited.push(format!("PRE: STATEMENT: {statement}"));
ControlFlow::Continue(())
}

fn post_visit_statement(&mut self, statement: &Statement) -> ControlFlow<Self::Break> {
self.visited.push(format!("POST: STATEMENT: {}", statement));
self.visited.push(format!("POST: STATEMENT: {statement}"));
ControlFlow::Continue(())
}
}
Expand Down
41 changes: 8 additions & 33 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2827,9 +2827,7 @@ fn parse_alter_table_drop_column() {
#[test]
fn parse_alter_table_alter_column() {
let alter_stmt = "ALTER TABLE tab";
match verified_stmt(&format!(
"{alter_stmt} ALTER COLUMN is_active SET NOT NULL"
)) {
match verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active SET NOT NULL")) {
Statement::AlterTable {
name,
operation: AlterTableOperation::AlterColumn { column_name, op },
Expand Down Expand Up @@ -2865,9 +2863,7 @@ fn parse_alter_table_alter_column() {
_ => unreachable!(),
}

match verified_stmt(&format!(
"{alter_stmt} ALTER COLUMN is_active DROP DEFAULT"
)) {
match verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active DROP DEFAULT")) {
Statement::AlterTable {
name,
operation: AlterTableOperation::AlterColumn { column_name, op },
Expand Down Expand Up @@ -2912,9 +2908,7 @@ fn parse_alter_table_alter_column_type() {

let res = Parser::parse_sql(
&GenericDialect {},
&format!(
"{alter_stmt} ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'"
),
&format!("{alter_stmt} ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'"),
);
assert_eq!(
ParserError::ParserError("Expected end of statement, found: USING".to_string()),
Expand Down Expand Up @@ -4266,9 +4260,7 @@ fn parse_cte_renamed_columns() {
#[test]
fn parse_recursive_cte() {
let cte_query = "SELECT 1 UNION ALL SELECT val + 1 FROM nums WHERE val < 10".to_owned();
let sql = &format!(
"WITH RECURSIVE nums (val) AS ({cte_query}) SELECT * FROM nums"
);
let sql = &format!("WITH RECURSIVE nums (val) AS ({cte_query}) SELECT * FROM nums");

let cte_query = verified_query(&cte_query);
let query = verified_query(sql);
Expand Down Expand Up @@ -6280,9 +6272,7 @@ fn parse_cache_table() {
let query = all_dialects().verified_query(sql);

assert_eq!(
verified_stmt(
format!("CACHE TABLE '{cache_table_name}'").as_str()
),
verified_stmt(format!("CACHE TABLE '{cache_table_name}'").as_str()),
Statement::Cache {
table_flag: None,
table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]),
Expand All @@ -6293,12 +6283,7 @@ fn parse_cache_table() {
);

assert_eq!(
verified_stmt(
format!(
"CACHE {table_flag} TABLE '{cache_table_name}'"
)
.as_str()
),
verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}'").as_str()),
Statement::Cache {
table_flag: Some(ObjectName(vec![Ident::new(table_flag)])),
table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]),
Expand Down Expand Up @@ -6384,12 +6369,7 @@ fn parse_cache_table() {
);

assert_eq!(
verified_stmt(
format!(
"CACHE {table_flag} TABLE '{cache_table_name}' {sql}"
)
.as_str()
),
verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}' {sql}").as_str()),
Statement::Cache {
table_flag: Some(ObjectName(vec![Ident::new(table_flag)])),
table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]),
Expand All @@ -6400,12 +6380,7 @@ fn parse_cache_table() {
);

assert_eq!(
verified_stmt(
format!(
"CACHE {table_flag} TABLE '{cache_table_name}' AS {sql}"
)
.as_str()
),
verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}' AS {sql}").as_str()),
Statement::Cache {
table_flag: Some(ObjectName(vec![Ident::new(table_flag)])),
table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]),
Expand Down

0 comments on commit b6a8af1

Please sign in to comment.