Skip to content

Commit f9ae6f9

Browse files
committed
Simplify some assertions
1 parent 42aede0 commit f9ae6f9

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

arrow-cast/src/cast/mod.rs

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11760,17 +11760,11 @@ mod tests {
1176011760
let result: Result<Arc<dyn Array + 'static>, ArrowError> =
1176111761
cast_with_options(&array_ref, &target_type, &cast_options);
1176211762

11763-
match result {
11764-
Err(e) => {
11765-
assert!(
11766-
e.to_string()
11767-
.contains("Cast error: Can't cast value 100000 to type Int16")
11768-
);
11769-
}
11770-
Ok(_array_ref) => {
11771-
panic!("This should not happen");
11772-
}
11773-
}
11763+
let e = result.err().expect("Cast should have failed but succeeded");
11764+
assert!(
11765+
e.to_string()
11766+
.contains("Cast error: Can't cast value 100000 to type Int16")
11767+
);
1177411768
}
1177511769

1177611770
#[test]
@@ -11801,25 +11795,19 @@ mod tests {
1180111795
let result: Result<Arc<dyn Array + 'static>, ArrowError> =
1180211796
cast_with_options(&array_ref, &target_type, &cast_options);
1180311797

11804-
match result {
11805-
Ok(array_ref) => {
11806-
// Downcast to RunArray<Int64Type>
11807-
let run_array = array_ref
11808-
.as_any()
11809-
.downcast_ref::<RunArray<Int64Type>>()
11810-
.unwrap();
11798+
let array_ref = result.expect("Cast should have succeeded but failed");
11799+
// Downcast to RunArray<Int64Type>
11800+
let run_array = array_ref
11801+
.as_any()
11802+
.downcast_ref::<RunArray<Int64Type>>()
11803+
.unwrap();
1181111804

11812-
// Verify the cast worked correctly
11813-
// Assert the values were cast correctly
11814-
assert_eq!(run_array.run_ends().values(), &[2i64, 5i64, 8i64]);
11815-
assert_eq!(run_array.values().as_string::<i32>().value(0), "a");
11816-
assert_eq!(run_array.values().as_string::<i32>().value(1), "b");
11817-
assert_eq!(run_array.values().as_string::<i32>().value(2), "c");
11818-
}
11819-
Err(e) => {
11820-
panic!("Cast should have succeeded but failed: {}", e);
11821-
}
11822-
}
11805+
// Verify the cast worked correctly
11806+
// Assert the values were cast correctly
11807+
assert_eq!(run_array.run_ends().values(), &[2i64, 5i64, 8i64]);
11808+
assert_eq!(run_array.values().as_string::<i32>().value(0), "a");
11809+
assert_eq!(run_array.values().as_string::<i32>().value(1), "b");
11810+
assert_eq!(run_array.values().as_string::<i32>().value(2), "c");
1182311811
}
1182411812

1182511813
#[test]
@@ -11850,14 +11838,10 @@ mod tests {
1185011838
let result: Result<Arc<dyn Array + 'static>, ArrowError> =
1185111839
cast_with_options(&array_ref, &target_type, &cast_options);
1185211840

11853-
match result {
11854-
Ok(_) => {
11855-
panic!("Cast should have failed due to overflow but succeeded");
11856-
}
11857-
Err(e) => {
11858-
// Verify the error is about overflow/out of range
11859-
assert!(e.to_string().contains("Can't cast value"));
11860-
}
11861-
}
11841+
// Verify the error is about overflow/out of range
11842+
let e = result
11843+
.err()
11844+
.expect("Cast should have failed due to overflow but succeeded");
11845+
assert!(e.to_string().contains("Can't cast value"));
1186211846
}
1186311847
}

0 commit comments

Comments
 (0)