Skip to content

Commit 75ba821

Browse files
committed
fixup: simplify tests
1 parent ab5c571 commit 75ba821

File tree

1 file changed

+6
-102
lines changed

1 file changed

+6
-102
lines changed

tests/sqlparser_common.rs

Lines changed: 6 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -15992,129 +15992,33 @@ fn parse_create_procedure_with_parameter_modes() {
1599215992
#[test]
1599315993
fn parse_not_null_unsupported() {
1599415994
// Only DuckDB and SQLite support `x NOT NULL` as an expression
15995-
// All other dialects fail to parse.
15996-
let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOT NULL FROM t"#;
15995+
// All other dialects fail to parse the `NOT NULL` portion
1599715996
let dialects =
1599815997
all_dialects_except(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotSpaceNull));
15999-
let res = dialects.parse_sql_statements(sql);
16000-
assert_eq!(
16001-
ParserError::ParserError("Expected: end of statement, found: NULL".to_string()),
16002-
res.unwrap_err()
16003-
);
15998+
let _ = dialects.expr_parses_to("x NOT NULL", "x");
1600415999
}
1600516000

1600616001
#[test]
1600716002
fn parse_not_null_supported() {
1600816003
// DuckDB and SQLite support `x NOT NULL` as an alias for `x IS NOT NULL`
16009-
let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOT NULL FROM t"#;
16010-
let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x IS NOT NULL FROM t"#;
1601116004
let dialects =
1601216005
all_dialects_where(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotSpaceNull));
16013-
let stmt = dialects.one_statement_parses_to(sql, canonical);
16014-
match stmt {
16015-
Statement::Query(qry) => match *qry.body {
16016-
SetExpr::Select(select) => {
16017-
assert_eq!(select.projection.len(), 1);
16018-
match select.projection.first().unwrap() {
16019-
UnnamedExpr(expr) => {
16020-
let fake_span = Span {
16021-
start: Location { line: 0, column: 0 },
16022-
end: Location { line: 0, column: 0 },
16023-
};
16024-
assert_eq!(
16025-
*expr,
16026-
Expr::IsNotNull(Box::new(Identifier(Ident {
16027-
value: "x".to_string(),
16028-
quote_style: None,
16029-
span: fake_span,
16030-
})),),
16031-
);
16032-
}
16033-
_ => unreachable!(),
16034-
}
16035-
}
16036-
_ => unreachable!(),
16037-
},
16038-
_ => unreachable!(),
16039-
}
16006+
let _ = dialects.expr_parses_to("x NOT NULL", "x IS NOT NULL");
1604016007
}
1604116008

1604216009
#[test]
1604316010
fn parse_notnull_unsupported() {
1604416011
// Only Postgres, DuckDB, and SQLite support `x NOTNULL` as an expression
1604516012
// All other dialects consider `x NOTNULL` like `x AS NOTNULL` and thus
1604616013
// consider `NOTNULL` an alias for x.
16047-
let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOTNULL FROM t"#;
16048-
let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x AS NOTNULL FROM t"#;
1604916014
let dialects = all_dialects_except(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotNull));
16050-
let stmt = dialects.one_statement_parses_to(sql, canonical);
16051-
match stmt {
16052-
Statement::Query(qry) => match *qry.body {
16053-
SetExpr::Select(select) => {
16054-
assert_eq!(select.projection.len(), 1);
16055-
match select.projection.first().unwrap() {
16056-
SelectItem::ExprWithAlias { expr, alias } => {
16057-
let fake_span = Span {
16058-
start: Location { line: 0, column: 0 },
16059-
end: Location { line: 0, column: 0 },
16060-
};
16061-
assert_eq!(
16062-
*expr,
16063-
Identifier(Ident {
16064-
value: "x".to_string(),
16065-
quote_style: None,
16066-
span: fake_span,
16067-
})
16068-
);
16069-
assert_eq!(
16070-
*alias,
16071-
Ident {
16072-
value: "NOTNULL".to_string(),
16073-
quote_style: None,
16074-
span: fake_span,
16075-
}
16076-
);
16077-
}
16078-
_ => unreachable!(),
16079-
}
16080-
}
16081-
_ => unreachable!(),
16082-
},
16083-
_ => unreachable!(),
16084-
}
16015+
let _ = dialects
16016+
.verified_only_select_with_canonical("SELECT NULL NOTNULL", "SELECT NULL AS NOTNULL");
1608516017
}
1608616018

1608716019
#[test]
1608816020
fn parse_notnull_supported() {
1608916021
// Postgres, DuckDB and SQLite support `x NOTNULL` as an alias for `x IS NOT NULL`
16090-
let sql = r#"WITH t AS (SELECT NULL AS x) SELECT x NOTNULL FROM t"#;
16091-
let canonical = r#"WITH t AS (SELECT NULL AS x) SELECT x IS NOT NULL FROM t"#;
1609216022
let dialects = all_dialects_where(|d| d.supports_is_not_null_alias(IsNotNullAlias::NotNull));
16093-
let stmt = dialects.one_statement_parses_to(sql, canonical);
16094-
match stmt {
16095-
Statement::Query(qry) => match *qry.body {
16096-
SetExpr::Select(select) => {
16097-
assert_eq!(select.projection.len(), 1);
16098-
match select.projection.first().unwrap() {
16099-
UnnamedExpr(expr) => {
16100-
let fake_span = Span {
16101-
start: Location { line: 0, column: 0 },
16102-
end: Location { line: 0, column: 0 },
16103-
};
16104-
assert_eq!(
16105-
*expr,
16106-
Expr::IsNotNull(Box::new(Identifier(Ident {
16107-
value: "x".to_string(),
16108-
quote_style: None,
16109-
span: fake_span,
16110-
})),),
16111-
);
16112-
}
16113-
_ => unreachable!(),
16114-
}
16115-
}
16116-
_ => unreachable!(),
16117-
},
16118-
_ => unreachable!(),
16119-
}
16023+
let _ = dialects.expr_parses_to("x NOTNULL", "x IS NOT NULL");
1612016024
}

0 commit comments

Comments
 (0)