mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-25 23:10:30 +00:00
Import the error variants in the tests
This commit is contained in:
parent
5217cdc5e2
commit
8ef5d10da2
2 changed files with 20 additions and 42 deletions
|
@ -52,10 +52,11 @@ fn main() {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ParsePersonError::*;
|
||||
|
||||
#[test]
|
||||
fn empty_input() {
|
||||
assert_eq!("".parse::<Person>(), Err(ParsePersonError::BadLen));
|
||||
assert_eq!("".parse::<Person>(), Err(BadLen));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -69,56 +70,44 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn missing_age() {
|
||||
assert!(matches!(
|
||||
"John,".parse::<Person>(),
|
||||
Err(ParsePersonError::ParseInt(_)),
|
||||
));
|
||||
assert!(matches!("John,".parse::<Person>(), Err(ParseInt(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_age() {
|
||||
assert!(matches!(
|
||||
"John,twenty".parse::<Person>(),
|
||||
Err(ParsePersonError::ParseInt(_)),
|
||||
));
|
||||
assert!(matches!("John,twenty".parse::<Person>(), Err(ParseInt(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_comma_and_age() {
|
||||
assert_eq!("John".parse::<Person>(), Err(ParsePersonError::BadLen));
|
||||
assert_eq!("John".parse::<Person>(), Err(BadLen));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_name() {
|
||||
assert_eq!(",1".parse::<Person>(), Err(ParsePersonError::NoName));
|
||||
assert_eq!(",1".parse::<Person>(), Err(NoName));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_name_and_age() {
|
||||
assert!(matches!(
|
||||
",".parse::<Person>(),
|
||||
Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)),
|
||||
));
|
||||
assert!(matches!(",".parse::<Person>(), Err(NoName | ParseInt(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_name_and_invalid_age() {
|
||||
assert!(matches!(
|
||||
",one".parse::<Person>(),
|
||||
Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)),
|
||||
Err(NoName | ParseInt(_)),
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_comma() {
|
||||
assert_eq!("John,32,".parse::<Person>(), Err(ParsePersonError::BadLen));
|
||||
assert_eq!("John,32,".parse::<Person>(), Err(BadLen));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_comma_and_some_string() {
|
||||
assert_eq!(
|
||||
"John,32,man".parse::<Person>(),
|
||||
Err(ParsePersonError::BadLen),
|
||||
);
|
||||
assert_eq!("John,32,man".parse::<Person>(), Err(BadLen));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,10 +56,11 @@ fn main() {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ParsePersonError::*;
|
||||
|
||||
#[test]
|
||||
fn empty_input() {
|
||||
assert_eq!("".parse::<Person>(), Err(ParsePersonError::BadLen));
|
||||
assert_eq!("".parse::<Person>(), Err(BadLen));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -73,56 +74,44 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn missing_age() {
|
||||
assert!(matches!(
|
||||
"John,".parse::<Person>(),
|
||||
Err(ParsePersonError::ParseInt(_)),
|
||||
));
|
||||
assert!(matches!("John,".parse::<Person>(), Err(ParseInt(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_age() {
|
||||
assert!(matches!(
|
||||
"John,twenty".parse::<Person>(),
|
||||
Err(ParsePersonError::ParseInt(_)),
|
||||
));
|
||||
assert!(matches!("John,twenty".parse::<Person>(), Err(ParseInt(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_comma_and_age() {
|
||||
assert_eq!("John".parse::<Person>(), Err(ParsePersonError::BadLen));
|
||||
assert_eq!("John".parse::<Person>(), Err(BadLen));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_name() {
|
||||
assert_eq!(",1".parse::<Person>(), Err(ParsePersonError::NoName));
|
||||
assert_eq!(",1".parse::<Person>(), Err(NoName));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_name_and_age() {
|
||||
assert!(matches!(
|
||||
",".parse::<Person>(),
|
||||
Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)),
|
||||
));
|
||||
assert!(matches!(",".parse::<Person>(), Err(NoName | ParseInt(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_name_and_invalid_age() {
|
||||
assert!(matches!(
|
||||
",one".parse::<Person>(),
|
||||
Err(ParsePersonError::NoName | ParsePersonError::ParseInt(_)),
|
||||
Err(NoName | ParseInt(_)),
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_comma() {
|
||||
assert_eq!("John,32,".parse::<Person>(), Err(ParsePersonError::BadLen));
|
||||
assert_eq!("John,32,".parse::<Person>(), Err(BadLen));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trailing_comma_and_some_string() {
|
||||
assert_eq!(
|
||||
"John,32,man".parse::<Person>(),
|
||||
Err(ParsePersonError::BadLen),
|
||||
);
|
||||
assert_eq!("John,32,man".parse::<Person>(), Err(BadLen));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue