result-exos #1
@ -22,3 +22,18 @@ exercises:
|
||||
- "get_or_default_some_diff"
|
||||
- "get_or_panic_none"
|
||||
- "get_or_panic_some"
|
||||
result:
|
||||
required_files:
|
||||
- "src/errors.rs"
|
||||
- "src/errors/option.rs"
|
||||
tests:
|
||||
- "is_err_err"
|
||||
- "is_ok_err"
|
||||
- "is_err_ok"
|
||||
- "is_ok_ok"
|
||||
- "get_err_or_panic_err"
|
||||
- "get_err_or_panic_ok"
|
||||
- "get_val_or_panic_err"
|
||||
- "get_val_or_panic_ok"
|
||||
- "discard_err_ok"
|
||||
- "discard_err_err"
|
||||
|
||||
@ -1,22 +1,53 @@
|
||||
use subject_source::errors::result;
|
||||
|
||||
|
||||
#[test]
|
||||
pub fn is_err_err() {
|
||||
assert!(is_err(Err("oh no")));
|
||||
assert!(result::is_err(&Err("oh no")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn is_err_ok() {
|
||||
assert!(!is_err(Ok(420)));
|
||||
assert!(!result::is_err(&Ok(420)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn is_ok_err() {
|
||||
assert!(!is_ok(Err("oh no")));
|
||||
assert!(!result::is_ok(&Err("oh no")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn is_ok_ok() {
|
||||
assert!(is_ok(Ok(420)));
|
||||
assert!(result::is_ok(&Ok(420)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn get_err_or_panic_err() {
|
||||
assert_eq!(result::get_err_or_panic(Err("ayaya")), "ayaya");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn get_err_or_panic_ok() {
|
||||
let _ = std::hint::black_box(result::get_err_or_panic(Ok(10)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn get_val_or_panic_ok() {
|
||||
assert_eq!(result::get_val_or_panic(Ok(10)), 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
pub fn get_val_or_panic_err() {
|
||||
let _ = std::hint::black_box(result::get_val_or_panic(Err("oaizjd")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn discard_err_err() {
|
||||
assert_eq!(result::discard_err(Err("hello")), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn discard_err_ok() {
|
||||
assert_eq!(result::discard_err(Ok(128)), Some(128));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user