@@ -1186,3 +1186,63 @@ fn test_dollar_sign_in_identifier() {
11861186 . parse_sql_statements ( "SELECT a$ FROM t" )
11871187 . unwrap_err ( ) ;
11881188}
1189+
1190+ #[ test]
1191+ fn parse_bitwise_and_or_share_precedence ( ) {
1192+ fn num ( n : & str ) -> Expr {
1193+ Expr :: value ( number ( n) )
1194+ }
1195+ fn bin ( left : Expr , op : BinaryOperator , right : Expr ) -> Expr {
1196+ Expr :: BinaryOp {
1197+ left : Box :: new ( left) ,
1198+ op,
1199+ right : Box :: new ( right) ,
1200+ }
1201+ }
1202+ use BinaryOperator :: { BitwiseAnd , BitwiseOr , Eq , Multiply , Plus } ;
1203+
1204+ for ( sql, expected) in [
1205+ (
1206+ "6 | 1 & 3" ,
1207+ bin ( bin ( num ( "6" ) , BitwiseOr , num ( "1" ) ) , BitwiseAnd , num ( "3" ) ) ,
1208+ ) ,
1209+ (
1210+ "6 & 3 | 8" ,
1211+ bin ( bin ( num ( "6" ) , BitwiseAnd , num ( "3" ) ) , BitwiseOr , num ( "8" ) ) ,
1212+ ) ,
1213+ (
1214+ "1 & 2 & 3" ,
1215+ bin ( bin ( num ( "1" ) , BitwiseAnd , num ( "2" ) ) , BitwiseAnd , num ( "3" ) ) ,
1216+ ) ,
1217+ (
1218+ "1 | 2 | 3" ,
1219+ bin ( bin ( num ( "1" ) , BitwiseOr , num ( "2" ) ) , BitwiseOr , num ( "3" ) ) ,
1220+ ) ,
1221+ (
1222+ "1 | 2 + 3 & 4 * 5" ,
1223+ bin (
1224+ bin ( num ( "1" ) , BitwiseOr , bin ( num ( "2" ) , Plus , num ( "3" ) ) ) ,
1225+ BitwiseAnd ,
1226+ bin ( num ( "4" ) , Multiply , num ( "5" ) ) ,
1227+ ) ,
1228+ ) ,
1229+ (
1230+ "6 | (1 & 3)" ,
1231+ bin (
1232+ num ( "6" ) ,
1233+ BitwiseOr ,
1234+ Expr :: Nested ( Box :: new ( bin ( num ( "1" ) , BitwiseAnd , num ( "3" ) ) ) ) ,
1235+ ) ,
1236+ ) ,
1237+ (
1238+ "1 | 2 = 3 & 4" ,
1239+ bin (
1240+ bin ( num ( "1" ) , BitwiseOr , num ( "2" ) ) ,
1241+ Eq ,
1242+ bin ( num ( "3" ) , BitwiseAnd , num ( "4" ) ) ,
1243+ ) ,
1244+ ) ,
1245+ ] {
1246+ assert_eq ! ( sqlite( ) . verified_expr( sql) , expected, "{sql}" ) ;
1247+ }
1248+ }
0 commit comments