@@ -2425,6 +2425,37 @@ fn parse_ilike() {
24252425 chk(true);
24262426}
24272427
2428+ #[test]
2429+ fn parse_tilde_like_match_operators() {
2430+ let like_match = all_dialects_where(|d| d.supports_tilde_like_match_operator());
2431+ for (op, expected) in [
2432+ ("~~", BinaryOperator::PGLikeMatch),
2433+ ("~~*", BinaryOperator::PGILikeMatch),
2434+ ("!~~", BinaryOperator::PGNotLikeMatch),
2435+ ("!~~*", BinaryOperator::PGNotILikeMatch),
2436+ ] {
2437+ let select = like_match.verified_only_select(&format!("SELECT a {op} b"));
2438+ assert_eq!(
2439+ select.projection[0],
2440+ SelectItem::UnnamedExpr(Expr::BinaryOp {
2441+ left: Box::new(Expr::Identifier(Ident::new("a"))),
2442+ op: expected,
2443+ right: Box::new(Expr::Identifier(Ident::new("b"))),
2444+ })
2445+ );
2446+ }
2447+ assert_eq!(
2448+ like_match.parse_sql_statements("SELECT ~~a"),
2449+ Err(ParserError::ParserError(
2450+ "Expected: an expression, found: ~~".to_string()
2451+ ))
2452+ );
2453+
2454+ let bitwise_not = all_dialects_where(|d| !d.supports_tilde_like_match_operator());
2455+ bitwise_not.one_statement_parses_to("SELECT ~~a", "SELECT ~ ~ a");
2456+ bitwise_not.one_statement_parses_to("SELECT ~~~a", "SELECT ~ ~ ~ a");
2457+ }
2458+
24282459#[test]
24292460fn parse_like() {
24302461 fn chk(negated: bool) {
@@ -21254,34 +21285,3 @@ fn parse_qualified_literal_prefix_requires_adjacent_period() {
2125421285 dialects.tokenizes_to(sql, vec![token]);
2125521286 }
2125621287}
21257-
21258- #[test]
21259- fn parse_tilde_like_match_operators() {
21260- let like_match = all_dialects_where(|d| d.supports_tilde_like_match_operator());
21261- for (op, expected) in [
21262- ("~~", BinaryOperator::PGLikeMatch),
21263- ("~~*", BinaryOperator::PGILikeMatch),
21264- ("!~~", BinaryOperator::PGNotLikeMatch),
21265- ("!~~*", BinaryOperator::PGNotILikeMatch),
21266- ] {
21267- let select = like_match.verified_only_select(&format!("SELECT a {op} b"));
21268- assert_eq!(
21269- select.projection[0],
21270- SelectItem::UnnamedExpr(Expr::BinaryOp {
21271- left: Box::new(Expr::Identifier(Ident::new("a"))),
21272- op: expected,
21273- right: Box::new(Expr::Identifier(Ident::new("b"))),
21274- })
21275- );
21276- }
21277- assert_eq!(
21278- like_match.parse_sql_statements("SELECT ~~a"),
21279- Err(ParserError::ParserError(
21280- "Expected: an expression, found: ~~".to_string()
21281- ))
21282- );
21283-
21284- let bitwise_not = all_dialects_where(|d| !d.supports_tilde_like_match_operator());
21285- bitwise_not.one_statement_parses_to("SELECT ~~a", "SELECT ~ ~ a");
21286- bitwise_not.one_statement_parses_to("SELECT ~~~a", "SELECT ~ ~ ~ a");
21287- }
0 commit comments