mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Update tests
This commit is contained in:
parent
c25f25f7f1
commit
6d293ede9f
@ -250,24 +250,11 @@ fn test_result_as_deref() {
|
||||
let expected_result = Result::Ok::<&[i32], &u32>([1, 2, 3, 4, 5].as_slice());
|
||||
assert_eq!(ref_ok.as_deref(), expected_result);
|
||||
|
||||
// &Result<T, E: Deref>::Err(T).as_deref_err() ->
|
||||
// Result<&T, &E::Deref::Target>::Err(&*E)
|
||||
let ref_err = &Result::Err::<u8, &i32>(&41);
|
||||
let expected_result = Result::Err::<&u8, &i32>(&41);
|
||||
assert_eq!(ref_err.as_deref_err(), expected_result);
|
||||
|
||||
let ref_err = &Result::Err::<u32, String>(String::from("an error"));
|
||||
let expected_result = Result::Err::<&u32, &str>("an error");
|
||||
assert_eq!(ref_err.as_deref_err(), expected_result);
|
||||
|
||||
let ref_err = &Result::Err::<u32, Vec<i32>>(vec![5, 4, 3, 2, 1]);
|
||||
let expected_result = Result::Err::<&u32, &[i32]>([5, 4, 3, 2, 1].as_slice());
|
||||
assert_eq!(ref_err.as_deref_err(), expected_result);
|
||||
|
||||
// &Result<T: Deref, E: Deref>::Err(T).as_deref_err() ->
|
||||
// Result<&T, &E::Deref::Target>::Err(&*E)
|
||||
let ref_err = &Result::Err::<&u8, &i32>(&41);
|
||||
let expected_result = Result::Err::<&u8, &&i32>(&&41);
|
||||
// &Result<T: Deref, E>::Err(T).as_deref() ->
|
||||
// Result<&T::Deref::Target, &E>::Err(&*E)
|
||||
let val = 41;
|
||||
let ref_err = &Result::Err::<&u8, i32>(val);
|
||||
let expected_result = Result::Err::<&u8, &i32>(&val);
|
||||
assert_eq!(ref_err.as_deref(), expected_result);
|
||||
|
||||
let s = String::from("an error");
|
||||
@ -279,46 +266,12 @@ fn test_result_as_deref() {
|
||||
let ref_err = &Result::Err::<&u32, Vec<i32>>(v.clone());
|
||||
let expected_result = Result::Err::<&u32, &Vec<i32>>(&v);
|
||||
assert_eq!(ref_err.as_deref(), expected_result);
|
||||
|
||||
// The following cases test calling `as_deref_*` with the wrong variant (i.e.
|
||||
// `as_deref()` with a `Result::Err()`, or `as_deref_err()` with a `Result::Ok()`.
|
||||
// While uncommon, these cases are supported to ensure that an `as_deref_*`
|
||||
// call can still be made even when one of the Result types does not implement
|
||||
// `Deref` (for example, std::io::Error).
|
||||
|
||||
// &Result<T, E: Deref>::Ok(T).as_deref_err() ->
|
||||
// Result<&T, &E::Deref::Target>::Ok(&T)
|
||||
let ref_ok = &Result::Ok::<i32, &u8>(42);
|
||||
let expected_result = Result::Ok::<&i32, &u8>(&42);
|
||||
assert_eq!(ref_ok.as_deref_err(), expected_result);
|
||||
|
||||
let ref_ok = &Result::Ok::<&str, &u32>("a result");
|
||||
let expected_result = Result::Ok::<&&str, &u32>(&"a result");
|
||||
assert_eq!(ref_ok.as_deref_err(), expected_result);
|
||||
|
||||
let ref_ok = &Result::Ok::<[i32; 5], &u32>([1, 2, 3, 4, 5]);
|
||||
let expected_result = Result::Ok::<&[i32; 5], &u32>(&[1, 2, 3, 4, 5]);
|
||||
assert_eq!(ref_ok.as_deref_err(), expected_result);
|
||||
|
||||
// &Result<T: Deref, E>::Err(E).as_deref() ->
|
||||
// Result<&T::Deref::Target, &E>::Err(&E)
|
||||
let ref_err = &Result::Err::<&u8, i32>(41);
|
||||
let expected_result = Result::Err::<&u8, &i32>(&41);
|
||||
assert_eq!(ref_err.as_deref(), expected_result);
|
||||
|
||||
let ref_err = &Result::Err::<&u32, &str>("an error");
|
||||
let expected_result = Result::Err::<&u32, &&str>(&"an error");
|
||||
assert_eq!(ref_err.as_deref(), expected_result);
|
||||
|
||||
let ref_err = &Result::Err::<&u32, [i32; 5]>([5, 4, 3, 2, 1]);
|
||||
let expected_result = Result::Err::<&u32, &[i32; 5]>(&[5, 4, 3, 2, 1]);
|
||||
assert_eq!(ref_err.as_deref(), expected_result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_result_as_deref_mut() {
|
||||
// &mut Result<T: Deref, E>::Ok(T).as_deref_mut() ->
|
||||
// Result<&mut T::Deref::Target, &mut E>::Ok(&mut *T)
|
||||
// &mut Result<T: DerefMut, E>::Ok(T).as_deref_mut() ->
|
||||
// Result<&mut T::DerefMut::Target, &mut E>::Ok(&mut *T)
|
||||
let mut val = 42;
|
||||
let mut expected_val = 42;
|
||||
let mut_ok = &mut Result::Ok::<&mut i32, u8>(&mut val);
|
||||
@ -335,26 +288,8 @@ fn test_result_as_deref_mut() {
|
||||
let expected_result = Result::Ok::<&mut [i32], &mut u32>(expected_vec.as_mut_slice());
|
||||
assert_eq!(mut_ok.as_deref_mut(), expected_result);
|
||||
|
||||
// &mut Result<T, E: Deref>::Err(T).as_deref_mut_err() ->
|
||||
// Result<&mut T, &mut E::Deref::Target>::Err(&mut *E)
|
||||
let mut val = 41;
|
||||
let mut expected_val = 41;
|
||||
let mut_err = &mut Result::Err::<u8, &mut i32>(&mut val);
|
||||
let expected_result = Result::Err::<&mut u8, &mut i32>(&mut expected_val);
|
||||
assert_eq!(mut_err.as_deref_mut_err(), expected_result);
|
||||
|
||||
let mut expected_string = String::from("an error");
|
||||
let mut_err = &mut Result::Err::<u32, String>(expected_string.clone());
|
||||
let expected_result = Result::Err::<&mut u32, &mut str>(expected_string.deref_mut());
|
||||
assert_eq!(mut_err.as_deref_mut_err(), expected_result);
|
||||
|
||||
let mut expected_vec = vec![5, 4, 3, 2, 1];
|
||||
let mut_err = &mut Result::Err::<u32, Vec<i32>>(expected_vec.clone());
|
||||
let expected_result = Result::Err::<&mut u32, &mut [i32]>(expected_vec.as_mut_slice());
|
||||
assert_eq!(mut_err.as_deref_mut_err(), expected_result);
|
||||
|
||||
// &mut Result<T: Deref, E: Deref>::Err(T).as_deref_mut_err() ->
|
||||
// Result<&mut T, &mut E::Deref::Target>::Err(&mut *E)
|
||||
// &mut Result<T: DerefMut, E>::Err(T).as_deref_mut() ->
|
||||
// Result<&mut T, &mut E>::Err(&mut *E)
|
||||
let mut val = 41;
|
||||
let mut_err = &mut Result::Err::<&mut u8, i32>(val);
|
||||
let expected_result = Result::Err::<&mut u8, &mut i32>(&mut val);
|
||||
@ -369,48 +304,4 @@ fn test_result_as_deref_mut() {
|
||||
let mut_err = &mut Result::Err::<&mut u32, Vec<i32>>(expected_vec.clone());
|
||||
let expected_result = Result::Err::<&mut u32, &mut Vec<i32>>(&mut expected_vec);
|
||||
assert_eq!(mut_err.as_deref_mut(), expected_result);
|
||||
|
||||
// The following cases test calling `as_deref_mut_*` with the wrong variant (i.e.
|
||||
// `as_deref_mut()` with a `Result::Err()`, or `as_deref_mut_err()` with a `Result::Ok()`.
|
||||
// While uncommon, these cases are supported to ensure that an `as_deref_mut_*`
|
||||
// call can still be made even when one of the Result types does not implement
|
||||
// `Deref` (for example, std::io::Error).
|
||||
|
||||
// &mut Result<T, E: Deref>::Ok(T).as_deref_mut_err() ->
|
||||
// Result<&mut T, &mut E::Deref::Target>::Ok(&mut T)
|
||||
let mut expected_val = 42;
|
||||
let mut_ok = &mut Result::Ok::<i32, &mut u8>(expected_val.clone());
|
||||
let expected_result = Result::Ok::<&mut i32, &mut u8>(&mut expected_val);
|
||||
assert_eq!(mut_ok.as_deref_mut_err(), expected_result);
|
||||
|
||||
let string = String::from("a result");
|
||||
let expected_string = string.clone();
|
||||
let mut ref_str = expected_string.as_ref();
|
||||
let mut_ok = &mut Result::Ok::<&str, &mut u32>(string.as_str());
|
||||
let expected_result = Result::Ok::<&mut &str, &mut u32>(&mut ref_str);
|
||||
assert_eq!(mut_ok.as_deref_mut_err(), expected_result);
|
||||
|
||||
let mut expected_arr = [1, 2, 3, 4, 5];
|
||||
let mut_ok = &mut Result::Ok::<[i32; 5], &mut u32>(expected_arr.clone());
|
||||
let expected_result = Result::Ok::<&mut [i32; 5], &mut u32>(&mut expected_arr);
|
||||
assert_eq!(mut_ok.as_deref_mut_err(), expected_result);
|
||||
|
||||
// &mut Result<T: Deref, E>::Err(E).as_deref_mut() ->
|
||||
// Result<&mut T::Deref::Target, &mut E>::Err(&mut E)
|
||||
let mut expected_val = 41;
|
||||
let mut_err = &mut Result::Err::<&mut u8, i32>(expected_val.clone());
|
||||
let expected_result = Result::Err::<&mut u8, &mut i32>(&mut expected_val);
|
||||
assert_eq!(mut_err.as_deref_mut(), expected_result);
|
||||
|
||||
let string = String::from("an error");
|
||||
let expected_string = string.clone();
|
||||
let mut ref_str = expected_string.as_ref();
|
||||
let mut_err = &mut Result::Err::<&mut u32, &str>(string.as_str());
|
||||
let expected_result = Result::Err::<&mut u32, &mut &str>(&mut ref_str);
|
||||
assert_eq!(mut_err.as_deref_mut(), expected_result);
|
||||
|
||||
let mut expected_arr = [5, 4, 3, 2, 1];
|
||||
let mut_err = &mut Result::Err::<&mut u32, [i32; 5]>(expected_arr.clone());
|
||||
let expected_result = Result::Err::<&mut u32, &mut [i32; 5]>(&mut expected_arr);
|
||||
assert_eq!(mut_err.as_deref_mut(), expected_result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user