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