Import the error variants in the tests

This commit is contained in:
mo8it 2024-07-02 01:29:30 +02:00
parent 5217cdc5e2
commit 8ef5d10da2
2 changed files with 20 additions and 42 deletions

View file

@ -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));
}
}

View file

@ -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));
}
}