Skip to content

Commit 8065379

Browse files
committed
codewide: ditch assert!(matches!(...))
As assert_matches!(...) provide superior experience (providing helpful debugging messages with how the mismatched type looked like), all assert!(matches!(...)) occurences across the code were changed to assert_matches!(...).
1 parent 165e8a8 commit 8065379

File tree

5 files changed

+99
-101
lines changed

5 files changed

+99
-101
lines changed

scylla-cql/src/frame/value_tests.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use super::value::{
1010
CqlDate, CqlDuration, CqlTime, CqlTimestamp, LegacyBatchValues, LegacySerializedValues,
1111
MaybeUnset, SerializeValuesError, Unset, Value, ValueList, ValueTooBig,
1212
};
13+
#[cfg(test)]
14+
use assert_matches::assert_matches;
1315
use bytes::BufMut;
1416
use std::collections::hash_map::DefaultHasher;
1517
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
@@ -1262,7 +1264,7 @@ fn serialized_values_value_list() {
12621264
ser_values.add_value(&"qwertyuiop").unwrap();
12631265

12641266
let ser_ser_values: Cow<LegacySerializedValues> = ser_values.serialized().unwrap();
1265-
assert!(matches!(ser_ser_values, Cow::Borrowed(_)));
1267+
assert_matches!(ser_ser_values, Cow::Borrowed(_));
12661268

12671269
assert_eq!(&ser_values, ser_ser_values.as_ref());
12681270
}
@@ -1272,7 +1274,7 @@ fn cow_serialized_values_value_list() {
12721274
let cow_ser_values: Cow<LegacySerializedValues> = Cow::Owned(LegacySerializedValues::new());
12731275

12741276
let serialized: Cow<LegacySerializedValues> = cow_ser_values.serialized().unwrap();
1275-
assert!(matches!(serialized, Cow::Borrowed(_)));
1277+
assert_matches!(serialized, Cow::Borrowed(_));
12761278

12771279
assert_eq!(cow_ser_values.as_ref(), serialized.as_ref());
12781280
}

scylla-cql/src/types/serialize/row.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ mod tests {
865865
};
866866

867867
use super::SerializedValues;
868+
use assert_matches::assert_matches;
868869
use scylla_macros::SerializeRow;
869870

870871
fn col_spec(name: &str, typ: ColumnType) -> ColumnSpec {
@@ -1044,13 +1045,13 @@ mod tests {
10441045
let err = do_serialize_err(v, &spec);
10451046
let err = get_typeck_err(&err);
10461047
assert_eq!(err.rust_name, std::any::type_name::<()>());
1047-
assert!(matches!(
1048+
assert_matches!(
10481049
err.kind,
10491050
BuiltinTypeCheckErrorKind::WrongColumnCount {
10501051
actual: 0,
10511052
asked_for: 1,
10521053
}
1053-
));
1054+
);
10541055

10551056
// Non-unit tuple
10561057
// Count mismatch
@@ -1059,13 +1060,13 @@ mod tests {
10591060
let err = do_serialize_err(v, &spec);
10601061
let err = get_typeck_err(&err);
10611062
assert_eq!(err.rust_name, std::any::type_name::<(&str,)>());
1062-
assert!(matches!(
1063+
assert_matches!(
10631064
err.kind,
10641065
BuiltinTypeCheckErrorKind::WrongColumnCount {
10651066
actual: 1,
10661067
asked_for: 2,
10671068
}
1068-
));
1069+
);
10691070

10701071
// Serialization of one of the element fails
10711072
let v = ("Ala ma kota", 123_i32);
@@ -1086,13 +1087,13 @@ mod tests {
10861087
let err = do_serialize_err(v, &spec);
10871088
let err = get_typeck_err(&err);
10881089
assert_eq!(err.rust_name, std::any::type_name::<Vec<&str>>());
1089-
assert!(matches!(
1090+
assert_matches!(
10901091
err.kind,
10911092
BuiltinTypeCheckErrorKind::WrongColumnCount {
10921093
actual: 1,
10931094
asked_for: 2,
10941095
}
1095-
));
1096+
);
10961097

10971098
// Serialization of one of the element fails
10981099
let v = vec!["Ala ma kota", "Kot ma pchły"];
@@ -1214,10 +1215,10 @@ mod tests {
12141215
};
12151216
let err = <_ as SerializeRow>::serialize(&row, &ctx, &mut row_writer).unwrap_err();
12161217
let err = err.0.downcast_ref::<BuiltinTypeCheckError>().unwrap();
1217-
assert!(matches!(
1218+
assert_matches!(
12181219
err.kind,
12191220
BuiltinTypeCheckErrorKind::ValueMissingForColumn { .. }
1220-
));
1221+
);
12211222

12221223
let spec_duplicate_column = [
12231224
col("a", ColumnType::Text),
@@ -1232,10 +1233,7 @@ mod tests {
12321233
};
12331234
let err = <_ as SerializeRow>::serialize(&row, &ctx, &mut row_writer).unwrap_err();
12341235
let err = err.0.downcast_ref::<BuiltinTypeCheckError>().unwrap();
1235-
assert!(matches!(
1236-
err.kind,
1237-
BuiltinTypeCheckErrorKind::NoColumnWithName { .. }
1238-
));
1236+
assert_matches!(err.kind, BuiltinTypeCheckErrorKind::NoColumnWithName { .. });
12391237

12401238
let spec_wrong_type = [
12411239
col("a", ColumnType::Text),
@@ -1248,10 +1246,10 @@ mod tests {
12481246
};
12491247
let err = <_ as SerializeRow>::serialize(&row, &ctx, &mut row_writer).unwrap_err();
12501248
let err = err.0.downcast_ref::<BuiltinSerializationError>().unwrap();
1251-
assert!(matches!(
1249+
assert_matches!(
12521250
err.kind,
12531251
BuiltinSerializationErrorKind::ColumnSerializationFailed { .. }
1254-
));
1252+
);
12551253
}
12561254

12571255
#[derive(SerializeRow)]
@@ -1325,10 +1323,10 @@ mod tests {
13251323
let ctx = RowSerializationContext { columns: &spec };
13261324
let err = <_ as SerializeRow>::serialize(&row, &ctx, &mut writer).unwrap_err();
13271325
let err = err.0.downcast_ref::<BuiltinTypeCheckError>().unwrap();
1328-
assert!(matches!(
1326+
assert_matches!(
13291327
err.kind,
13301328
BuiltinTypeCheckErrorKind::ColumnNameMismatch { .. }
1331-
));
1329+
);
13321330

13331331
let spec_without_c = [
13341332
col("a", ColumnType::Text),
@@ -1341,10 +1339,10 @@ mod tests {
13411339
};
13421340
let err = <_ as SerializeRow>::serialize(&row, &ctx, &mut writer).unwrap_err();
13431341
let err = err.0.downcast_ref::<BuiltinTypeCheckError>().unwrap();
1344-
assert!(matches!(
1342+
assert_matches!(
13451343
err.kind,
13461344
BuiltinTypeCheckErrorKind::ValueMissingForColumn { .. }
1347-
));
1345+
);
13481346

13491347
let spec_duplicate_column = [
13501348
col("a", ColumnType::Text),
@@ -1359,10 +1357,7 @@ mod tests {
13591357
};
13601358
let err = <_ as SerializeRow>::serialize(&row, &ctx, &mut writer).unwrap_err();
13611359
let err = err.0.downcast_ref::<BuiltinTypeCheckError>().unwrap();
1362-
assert!(matches!(
1363-
err.kind,
1364-
BuiltinTypeCheckErrorKind::NoColumnWithName { .. }
1365-
));
1360+
assert_matches!(err.kind, BuiltinTypeCheckErrorKind::NoColumnWithName { .. });
13661361

13671362
let spec_wrong_type = [
13681363
col("a", ColumnType::Text),
@@ -1375,10 +1370,10 @@ mod tests {
13751370
};
13761371
let err = <_ as SerializeRow>::serialize(&row, &ctx, &mut writer).unwrap_err();
13771372
let err = err.0.downcast_ref::<BuiltinSerializationError>().unwrap();
1378-
assert!(matches!(
1373+
assert_matches!(
13791374
err.kind,
13801375
BuiltinSerializationErrorKind::ColumnSerializationFailed { .. }
1381-
));
1376+
);
13821377
}
13831378

13841379
#[test]

0 commit comments

Comments
 (0)