Place regression tests beside related syntax cases
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 9718d21..6c047d1 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs
@@ -2426,6 +2426,37 @@ } #[test] +fn parse_tilde_like_match_operators() { + let like_match = all_dialects_where(|d| d.supports_tilde_like_match_operator()); + for (op, expected) in [ + ("~~", BinaryOperator::PGLikeMatch), + ("~~*", BinaryOperator::PGILikeMatch), + ("!~~", BinaryOperator::PGNotLikeMatch), + ("!~~*", BinaryOperator::PGNotILikeMatch), + ] { + let select = like_match.verified_only_select(&format!("SELECT a {op} b")); + assert_eq!( + select.projection[0], + SelectItem::UnnamedExpr(Expr::BinaryOp { + left: Box::new(Expr::Identifier(Ident::new("a"))), + op: expected, + right: Box::new(Expr::Identifier(Ident::new("b"))), + }) + ); + } + assert_eq!( + like_match.parse_sql_statements("SELECT ~~a"), + Err(ParserError::ParserError( + "Expected: an expression, found: ~~".to_string() + )) + ); + + let bitwise_not = all_dialects_where(|d| !d.supports_tilde_like_match_operator()); + bitwise_not.one_statement_parses_to("SELECT ~~a", "SELECT ~ ~ a"); + bitwise_not.one_statement_parses_to("SELECT ~~~a", "SELECT ~ ~ ~ a"); +} + +#[test] fn parse_like() { fn chk(negated: bool) { let sql = &format!( @@ -21305,34 +21336,3 @@ dialects.tokenizes_to(sql, vec![token]); } } - -#[test] -fn parse_tilde_like_match_operators() { - let like_match = all_dialects_where(|d| d.supports_tilde_like_match_operator()); - for (op, expected) in [ - ("~~", BinaryOperator::PGLikeMatch), - ("~~*", BinaryOperator::PGILikeMatch), - ("!~~", BinaryOperator::PGNotLikeMatch), - ("!~~*", BinaryOperator::PGNotILikeMatch), - ] { - let select = like_match.verified_only_select(&format!("SELECT a {op} b")); - assert_eq!( - select.projection[0], - SelectItem::UnnamedExpr(Expr::BinaryOp { - left: Box::new(Expr::Identifier(Ident::new("a"))), - op: expected, - right: Box::new(Expr::Identifier(Ident::new("b"))), - }) - ); - } - assert_eq!( - like_match.parse_sql_statements("SELECT ~~a"), - Err(ParserError::ParserError( - "Expected: an expression, found: ~~".to_string() - )) - ); - - let bitwise_not = all_dialects_where(|d| !d.supports_tilde_like_match_operator()); - bitwise_not.one_statement_parses_to("SELECT ~~a", "SELECT ~ ~ a"); - bitwise_not.one_statement_parses_to("SELECT ~~~a", "SELECT ~ ~ ~ a"); -}