@@ -1070,33 +1070,22 @@ mod test {
1070
1070
fn not_op ( ) {
1071
1071
use AssocOp :: { Add , Equal , Greater , GreaterEqual , LAnd , LOr , Less , LessEqual , NotEqual } ;
1072
1072
1073
- // Invert the comparison operator.
1074
- let sugg = Sugg :: BinOp ( Equal , "1" . into ( ) , "1" . into ( ) ) ;
1075
- assert_eq ! ( "1 != 1" , ( !sugg) . to_string( ) ) ;
1076
-
1077
- let sugg = Sugg :: BinOp ( NotEqual , "1" . into ( ) , "1" . into ( ) ) ;
1078
- assert_eq ! ( "1 == 1" , ( !sugg) . to_string( ) ) ;
1079
-
1080
- let sugg = Sugg :: BinOp ( Less , "1" . into ( ) , "1" . into ( ) ) ;
1081
- assert_eq ! ( "1 >= 1" , ( !sugg) . to_string( ) ) ;
1082
-
1083
- let sugg = Sugg :: BinOp ( LessEqual , "1" . into ( ) , "1" . into ( ) ) ;
1084
- assert_eq ! ( "1 > 1" , ( !sugg) . to_string( ) ) ;
1085
-
1086
- let sugg = Sugg :: BinOp ( Greater , "1" . into ( ) , "1" . into ( ) ) ;
1087
- assert_eq ! ( "1 <= 1" , ( !sugg) . to_string( ) ) ;
1073
+ fn test_not ( op : AssocOp , correct : & str ) {
1074
+ let sugg = Sugg :: BinOp ( op, "x" . into ( ) , "y" . into ( ) ) ;
1075
+ assert_eq ! ( ( !sugg) . to_string( ) , correct) ;
1076
+ }
1088
1077
1089
- let sugg = Sugg :: BinOp ( GreaterEqual , "1" . into ( ) , "1" . into ( ) ) ;
1090
- assert_eq ! ( "1 < 1" , ( !sugg) . to_string( ) ) ;
1078
+ // Invert the comparison operator.
1079
+ test_not ( Equal , "x != y" ) ;
1080
+ test_not ( NotEqual , "x == y" ) ;
1081
+ test_not ( Less , "x >= y" ) ;
1082
+ test_not ( LessEqual , "x > y" ) ;
1083
+ test_not ( Greater , "x <= y" ) ;
1084
+ test_not ( GreaterEqual , "x < y" ) ;
1091
1085
1092
1086
// Other operators are inverted like !(..).
1093
- let sugg = Sugg :: BinOp ( Add , "1" . into ( ) , "1" . into ( ) ) ;
1094
- assert_eq ! ( "!(1 + 1)" , ( !sugg) . to_string( ) ) ;
1095
-
1096
- let sugg = Sugg :: BinOp ( LAnd , "1" . into ( ) , "1" . into ( ) ) ;
1097
- assert_eq ! ( "!(1 && 1)" , ( !sugg) . to_string( ) ) ;
1098
-
1099
- let sugg = Sugg :: BinOp ( LOr , "1" . into ( ) , "1" . into ( ) ) ;
1100
- assert_eq ! ( "!(1 || 1)" , ( !sugg) . to_string( ) ) ;
1087
+ test_not ( Add , "!(x + y)" ) ;
1088
+ test_not ( LAnd , "!(x && y)" ) ;
1089
+ test_not ( LOr , "!(x || y)" ) ;
1101
1090
}
1102
1091
}
0 commit comments