@@ -955,6 +955,47 @@ fn test_drop_trigger() {
955955 }
956956}
957957
958+ #[ test]
959+ fn parse_between_low_bound_precedence ( ) {
960+ match sqlite ( ) . verified_expr ( "a BETWEEN b > 1 AND c" ) {
961+ Expr :: Between { low, .. } => assert ! (
962+ matches!(
963+ * low,
964+ Expr :: BinaryOp {
965+ op: BinaryOperator :: Gt ,
966+ ..
967+ }
968+ ) ,
969+ "{low:?}"
970+ ) ,
971+ other => panic ! ( "expected BETWEEN, got {other:?}" ) ,
972+ }
973+ sqlite ( ) . verified_expr ( "a BETWEEN b LIKE 'x' AND c" ) ;
974+ sqlite ( ) . verified_expr ( "a BETWEEN b IS NOT NULL AND c" ) ;
975+ sqlite ( ) . expr_parses_to ( "a BETWEEN b NOTNULL AND c" , "a BETWEEN b IS NOT NULL AND c" ) ;
976+ sqlite ( ) . verified_expr ( "a BETWEEN b BETWEEN 1 AND 2 AND c" ) ;
977+
978+ // Operators after the high bound apply to the whole BETWEEN.
979+ sqlite ( ) . verified_expr ( "5 BETWEEN 1 AND NULL IS NULL" ) ;
980+ sqlite ( ) . verified_expr ( "5 BETWEEN 1 AND 10 = 1" ) ;
981+
982+ // The inner AND belongs to the bound expression, so the missing `)` is reported at FROM.
983+ assert_eq ! (
984+ sqlite( ) . parse_sql_statements( "SELECT a BETWEEN (1 AND 2 FROM t" ) ,
985+ Err ( ParserError :: ParserError (
986+ "Expected: ), found: FROM" . to_string( )
987+ ) )
988+ ) ;
989+
990+ assert_eq ! (
991+ TestedDialects :: new( vec![ Box :: new( GenericDialect { } ) ] )
992+ . parse_sql_statements( "SELECT a BETWEEN b > 1 AND c FROM t" ) ,
993+ Err ( ParserError :: ParserError (
994+ "Expected: AND, found: >" . to_string( )
995+ ) )
996+ ) ;
997+ }
998+
958999#[ test]
9591000fn parse_pattern_operators_bind_at_like_precedence ( ) {
9601001 fn where_operator ( sql : & str ) -> BinaryOperator {
@@ -1362,47 +1403,6 @@ fn parse_over_as_column_alias_after_function() {
13621403 ) ;
13631404}
13641405
1365- #[ test]
1366- fn parse_between_low_bound_precedence ( ) {
1367- match sqlite ( ) . verified_expr ( "a BETWEEN b > 1 AND c" ) {
1368- Expr :: Between { low, .. } => assert ! (
1369- matches!(
1370- * low,
1371- Expr :: BinaryOp {
1372- op: BinaryOperator :: Gt ,
1373- ..
1374- }
1375- ) ,
1376- "{low:?}"
1377- ) ,
1378- other => panic ! ( "expected BETWEEN, got {other:?}" ) ,
1379- }
1380- sqlite ( ) . verified_expr ( "a BETWEEN b LIKE 'x' AND c" ) ;
1381- sqlite ( ) . verified_expr ( "a BETWEEN b IS NOT NULL AND c" ) ;
1382- sqlite ( ) . expr_parses_to ( "a BETWEEN b NOTNULL AND c" , "a BETWEEN b IS NOT NULL AND c" ) ;
1383- sqlite ( ) . verified_expr ( "a BETWEEN b BETWEEN 1 AND 2 AND c" ) ;
1384-
1385- // Operators after the high bound apply to the whole BETWEEN.
1386- sqlite ( ) . verified_expr ( "5 BETWEEN 1 AND NULL IS NULL" ) ;
1387- sqlite ( ) . verified_expr ( "5 BETWEEN 1 AND 10 = 1" ) ;
1388-
1389- // The inner AND belongs to the bound expression, so the missing `)` is reported at FROM.
1390- assert_eq ! (
1391- sqlite( ) . parse_sql_statements( "SELECT a BETWEEN (1 AND 2 FROM t" ) ,
1392- Err ( ParserError :: ParserError (
1393- "Expected: ), found: FROM" . to_string( )
1394- ) )
1395- ) ;
1396-
1397- assert_eq ! (
1398- TestedDialects :: new( vec![ Box :: new( GenericDialect { } ) ] )
1399- . parse_sql_statements( "SELECT a BETWEEN b > 1 AND c FROM t" ) ,
1400- Err ( ParserError :: ParserError (
1401- "Expected: AND, found: >" . to_string( )
1402- ) )
1403- ) ;
1404- }
1405-
14061406fn sqlite ( ) -> TestedDialects {
14071407 TestedDialects :: new ( vec ! [ Box :: new( SQLiteDialect { } ) ] )
14081408}
0 commit comments