From 1044c8d46890dcf4f8d50f8c7d4b69bafd7b080d Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 7 Oct 2022 11:50:20 +0100 Subject: [PATCH] Update path tests --- src/ty/path.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/ty/path.rs b/src/ty/path.rs index c993bc9f..1153074b 100644 --- a/src/ty/path.rs +++ b/src/ty/path.rs @@ -109,17 +109,14 @@ impl Path { /// - If no segments are supplied /// - If any of the segments are invalid Rust identifiers pub fn from_segments(segments: I) -> Result - where - I: IntoIterator::String>, + where + I: IntoIterator::String>, { let segments = segments.into_iter().collect::>(); if segments.is_empty() { return Err(PathError::MissingSegments) } - if let Some(err_at) = segments - .iter() - .position(|seg| !is_rust_identifier(seg)) - { + if let Some(err_at) = segments.iter().position(|seg| !is_rust_identifier(seg)) { return Err(PathError::InvalidIdentifier { segment: err_at }) } Ok(Path { segments }) @@ -200,19 +197,19 @@ mod tests { #[test] fn path_ok() { assert_eq!( - Path::::from_segments(vec!["hello"]), + Path::from_segments(vec!["hello"]), Ok(Path { segments: vec!["hello"] }) ); assert_eq!( - Path::::from_segments(vec!["Hello", "World"]), + Path::from_segments(vec!["Hello", "World"]), Ok(Path { segments: vec!["Hello", "World"] }) ); assert_eq!( - Path::::from_segments(vec!["_"]), + Path::from_segments(vec!["_"]), Ok(Path { segments: vec!["_"] }) @@ -222,7 +219,7 @@ mod tests { #[test] fn path_with_raw_identifers_ok() { assert_eq!( - Path::::from_segments(vec!["r#mod", "r#Struct"]), + Path::from_segments(vec!["r#mod", "r#Struct"]), Ok(Path { segments: vec!["r#mod", "r#Struct"] }) @@ -232,19 +229,19 @@ mod tests { #[test] fn path_err() { assert_eq!( - Path::::from_segments(Vec::new()), + Path::from_segments(Vec::new()), Err(PathError::MissingSegments) ); assert_eq!( - Path::::from_segments(vec![""]), + Path::from_segments(vec![""]), Err(PathError::InvalidIdentifier { segment: 0 }) ); assert_eq!( - Path::::from_segments(vec!["1"]), + Path::from_segments(vec!["1"]), Err(PathError::InvalidIdentifier { segment: 0 }) ); assert_eq!( - Path::::from_segments(vec!["Hello", ", World!"]), + Path::from_segments(vec!["Hello", ", World!"]), Err(PathError::InvalidIdentifier { segment: 1 }) ); } @@ -258,7 +255,7 @@ mod tests { } ); assert_eq!( - Path::::from_segments(vec!["Earth", "::world"]), + Path::from_segments(vec!["Earth", "::world"]), Err(PathError::InvalidIdentifier { segment: 1 }) ); }