Place regression tests beside related syntax cases
diff --git a/tests/sqlparser_sqlite.rs b/tests/sqlparser_sqlite.rs index 8b1e6db..b5552ef 100644 --- a/tests/sqlparser_sqlite.rs +++ b/tests/sqlparser_sqlite.rs
@@ -1225,6 +1225,36 @@ ); } +fn sqlite() -> TestedDialects { + TestedDialects::new(vec![Box::new(SQLiteDialect {})]) +} + +fn sqlite_with_options(options: ParserOptions) -> TestedDialects { + TestedDialects::new_with_options(vec![Box::new(SQLiteDialect {})], options) +} + +fn sqlite_and_generic() -> TestedDialects { + TestedDialects::new(vec![ + Box::new(SQLiteDialect {}), + Box::new(GenericDialect {}), + ]) +} + +#[test] +fn test_dollar_sign_in_identifier() { + // SQLite allows $ anywhere after the first character of an identifier + sqlite().verified_stmt("SELECT a$ FROM t"); + sqlite().verified_stmt("SELECT 1 AS a$"); + sqlite().one_statement_parses_to("CREATE TABLE t(a$ INT)", "CREATE TABLE t (a$ INT)"); + sqlite().verified_stmt("INSERT INTO t$ VALUES (1)"); + // AS$ is parsed as the alias name + sqlite().one_statement_parses_to("SELECT a AS$", "SELECT a AS AS$"); + // Dialects without $ as an identifier character still reject these identifiers + TestedDialects::new(vec![Box::new(AnsiDialect {})]) + .parse_sql_statements("SELECT a$ FROM t") + .unwrap_err(); +} + #[test] fn parse_comparison_binds_tighter_than_equality() { let id = |name: &str| Expr::Identifier(Ident::new(name)); @@ -1297,36 +1327,6 @@ ); } -fn sqlite() -> TestedDialects { - TestedDialects::new(vec![Box::new(SQLiteDialect {})]) -} - -fn sqlite_with_options(options: ParserOptions) -> TestedDialects { - TestedDialects::new_with_options(vec![Box::new(SQLiteDialect {})], options) -} - -fn sqlite_and_generic() -> TestedDialects { - TestedDialects::new(vec![ - Box::new(SQLiteDialect {}), - Box::new(GenericDialect {}), - ]) -} - -#[test] -fn test_dollar_sign_in_identifier() { - // SQLite allows $ anywhere after the first character of an identifier - sqlite().verified_stmt("SELECT a$ FROM t"); - sqlite().verified_stmt("SELECT 1 AS a$"); - sqlite().one_statement_parses_to("CREATE TABLE t(a$ INT)", "CREATE TABLE t (a$ INT)"); - sqlite().verified_stmt("INSERT INTO t$ VALUES (1)"); - // AS$ is parsed as the alias name - sqlite().one_statement_parses_to("SELECT a AS$", "SELECT a AS AS$"); - // Dialects without $ as an identifier character still reject these identifiers - TestedDialects::new(vec![Box::new(AnsiDialect {})]) - .parse_sql_statements("SELECT a$ FROM t") - .unwrap_err(); -} - #[test] fn parse_bitwise_and_or_share_precedence() { fn num(n: &str) -> Expr {