chore: fix clippy error in ci (#803)

* chore: fix clippy error in ci

* chore: fix fmt
This commit is contained in:
Y Togami 2023-02-18 03:24:50 +09:00 committed by GitHub
parent 4955863bdf
commit b31ede7733
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 371 additions and 444 deletions

View file

@ -2435,7 +2435,7 @@ fn parse_create_or_replace_table() {
#[test]
fn parse_create_table_with_on_delete_on_update_2in_any_order() -> Result<(), ParserError> {
let sql = |options: &str| -> String {
format!("create table X (y_id int references Y (id) {})", options)
format!("create table X (y_id int references Y (id) {options})")
};
parse_sql_statements(&sql("on update cascade on delete no action"))?;
@ -2777,7 +2777,7 @@ fn parse_alter_table_constraints() {
check_one("CHECK (end_date > start_date OR end_date IS NULL)");
fn check_one(constraint_text: &str) {
match verified_stmt(&format!("ALTER TABLE tab ADD {}", constraint_text)) {
match verified_stmt(&format!("ALTER TABLE tab ADD {constraint_text}")) {
Statement::AlterTable {
name,
operation: AlterTableOperation::AddConstraint(constraint),
@ -2787,7 +2787,7 @@ fn parse_alter_table_constraints() {
}
_ => unreachable!(),
}
verified_stmt(&format!("CREATE TABLE foo (id INT, {})", constraint_text));
verified_stmt(&format!("CREATE TABLE foo (id INT, {constraint_text})"));
}
}
@ -2804,7 +2804,7 @@ fn parse_alter_table_drop_column() {
);
fn check_one(constraint_text: &str) {
match verified_stmt(&format!("ALTER TABLE tab {}", constraint_text)) {
match verified_stmt(&format!("ALTER TABLE tab {constraint_text}")) {
Statement::AlterTable {
name,
operation:
@ -2827,10 +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 COLUMN is_active SET NOT NULL",
alter_stmt
)) {
match verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active SET NOT NULL")) {
Statement::AlterTable {
name,
operation: AlterTableOperation::AlterColumn { column_name, op },
@ -2848,8 +2845,7 @@ fn parse_alter_table_alter_column() {
);
match verified_stmt(&format!(
"{} ALTER COLUMN is_active SET DEFAULT false",
alter_stmt
"{alter_stmt} ALTER COLUMN is_active SET DEFAULT false"
)) {
Statement::AlterTable {
name,
@ -2867,10 +2863,7 @@ fn parse_alter_table_alter_column() {
_ => unreachable!(),
}
match verified_stmt(&format!(
"{} ALTER COLUMN is_active DROP DEFAULT",
alter_stmt
)) {
match verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active DROP DEFAULT")) {
Statement::AlterTable {
name,
operation: AlterTableOperation::AlterColumn { column_name, op },
@ -2906,7 +2899,7 @@ fn parse_alter_table_alter_column_type() {
let res = Parser::parse_sql(
&GenericDialect {},
&format!("{} ALTER COLUMN is_active TYPE TEXT", alter_stmt),
&format!("{alter_stmt} ALTER COLUMN is_active TYPE TEXT"),
);
assert_eq!(
ParserError::ParserError("Expected SET/DROP NOT NULL, SET DEFAULT, SET DATA TYPE after ALTER COLUMN, found: TYPE".to_string()),
@ -2915,10 +2908,7 @@ fn parse_alter_table_alter_column_type() {
let res = Parser::parse_sql(
&GenericDialect {},
&format!(
"{} ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'",
alter_stmt
),
&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()),
@ -2966,7 +2956,7 @@ fn parse_alter_table_drop_constraint() {
let res = Parser::parse_sql(
&GenericDialect {},
&format!("{} DROP CONSTRAINT is_active TEXT", alter_stmt),
&format!("{alter_stmt} DROP CONSTRAINT is_active TEXT"),
);
assert_eq!(
ParserError::ParserError("Expected end of statement, found: TEXT".to_string()),
@ -2997,7 +2987,7 @@ fn parse_scalar_function_in_projection() {
for function_name in names {
// like SELECT sqrt(id) FROM foo
let sql = dbg!(format!("SELECT {}(id) FROM foo", function_name));
let sql = dbg!(format!("SELECT {function_name}(id) FROM foo"));
let select = verified_only_select(&sql);
assert_eq!(
&Expr::Function(Function {
@ -4221,7 +4211,7 @@ fn parse_ctes() {
// Top-level CTE
assert_ctes_in_select(&cte_sqls, &verified_query(with));
// CTE in a subquery
let sql = &format!("SELECT ({})", with);
let sql = &format!("SELECT ({with})");
let select = verified_only_select(sql);
match expr_from_projection(only(&select.projection)) {
Expr::Subquery(ref subquery) => {
@ -4230,7 +4220,7 @@ fn parse_ctes() {
_ => panic!("Expected subquery"),
}
// CTE in a derived table
let sql = &format!("SELECT * FROM ({})", with);
let sql = &format!("SELECT * FROM ({with})");
let select = verified_only_select(sql);
match only(select.from).relation {
TableFactor::Derived { subquery, .. } => {
@ -4239,13 +4229,13 @@ fn parse_ctes() {
_ => panic!("Expected derived table"),
}
// CTE in a view
let sql = &format!("CREATE VIEW v AS {}", with);
let sql = &format!("CREATE VIEW v AS {with}");
match verified_stmt(sql) {
Statement::CreateView { query, .. } => assert_ctes_in_select(&cte_sqls, &query),
_ => panic!("Expected CREATE VIEW"),
}
// CTE in a CTE...
let sql = &format!("WITH outer_cte AS ({}) SELECT * FROM outer_cte", with);
let sql = &format!("WITH outer_cte AS ({with}) SELECT * FROM outer_cte");
let select = verified_query(sql);
assert_ctes_in_select(&cte_sqls, &only(&select.with.unwrap().cte_tables).query);
}
@ -4270,10 +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 ({}) SELECT * FROM nums",
cte_query
);
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);
@ -5029,9 +5016,8 @@ fn lateral_derived() {
fn chk(lateral_in: bool) {
let lateral_str = if lateral_in { "LATERAL " } else { "" };
let sql = format!(
"SELECT * FROM customer LEFT JOIN {}\
(SELECT * FROM order WHERE order.customer = customer.id LIMIT 3) AS order ON true",
lateral_str
"SELECT * FROM customer LEFT JOIN {lateral_str}\
(SELECT * FROM order WHERE order.customer = customer.id LIMIT 3) AS order ON true"
);
let select = verified_only_select(&sql);
let from = only(select.from);
@ -6286,9 +6272,7 @@ fn parse_cache_table() {
let query = all_dialects().verified_query(sql);
assert_eq!(
verified_stmt(
format!("CACHE TABLE '{table_name}'", table_name = 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)]),
@ -6299,14 +6283,7 @@ fn parse_cache_table() {
);
assert_eq!(
verified_stmt(
format!(
"CACHE {flag} TABLE '{table_name}'",
flag = table_flag,
table_name = 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)]),
@ -6319,9 +6296,7 @@ fn parse_cache_table() {
assert_eq!(
verified_stmt(
format!(
"CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88)",
flag = table_flag,
table_name = cache_table_name,
"CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88)",
)
.as_str()
),
@ -6346,10 +6321,7 @@ fn parse_cache_table() {
assert_eq!(
verified_stmt(
format!(
"CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) {sql}",
flag = table_flag,
table_name = cache_table_name,
sql = sql,
"CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) {sql}",
)
.as_str()
),
@ -6374,10 +6346,7 @@ fn parse_cache_table() {
assert_eq!(
verified_stmt(
format!(
"CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) AS {sql}",
flag = table_flag,
table_name = cache_table_name,
sql = sql,
"CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) AS {sql}",
)
.as_str()
),
@ -6400,15 +6369,7 @@ fn parse_cache_table() {
);
assert_eq!(
verified_stmt(
format!(
"CACHE {flag} TABLE '{table_name}' {sql}",
flag = table_flag,
table_name = cache_table_name,
sql = 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)]),
@ -6419,14 +6380,7 @@ fn parse_cache_table() {
);
assert_eq!(
verified_stmt(
format!(
"CACHE {flag} TABLE '{table_name}' AS {sql}",
flag = table_flag,
table_name = cache_table_name
)
.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)]),
@ -6574,7 +6528,7 @@ fn parse_with_recursion_limit() {
.expect("tokenize to work")
.parse_statements();
assert!(matches!(res, Ok(_)), "{:?}", res);
assert!(matches!(res, Ok(_)), "{res:?}");
// limit recursion to something smaller, expect parsing to fail
let res = Parser::new(&dialect)
@ -6592,7 +6546,7 @@ fn parse_with_recursion_limit() {
.with_recursion_limit(50)
.parse_statements();
assert!(matches!(res, Ok(_)), "{:?}", res);
assert!(matches!(res, Ok(_)), "{res:?}");
}
/// Makes a predicate that looks like ((user_id = $id) OR user_id = $2...)
@ -6604,7 +6558,7 @@ fn make_where_clause(num: usize) -> String {
if i > 0 {
write!(&mut output, " OR ").unwrap();
}
write!(&mut output, "user_id = {}", i).unwrap();
write!(&mut output, "user_id = {i}").unwrap();
if i < num - 1 {
write!(&mut output, ")").unwrap();
}