diff --git a/tests/net/addr.rs b/tests/net/addr.rs index 4abe2a4dd..8961221b8 100644 --- a/tests/net/addr.rs +++ b/tests/net/addr.rs @@ -28,22 +28,23 @@ fn encode_decode() { fn test_unix_addr() { use rustix::cstr; use rustix::net::SocketAddrUnix; + use std::borrow::Cow; assert_eq!( SocketAddrUnix::new("/").unwrap().path().unwrap(), - cstr!("/").into() + Cow::from(cstr!("/")) ); assert_eq!( SocketAddrUnix::new("//").unwrap().path().unwrap(), - cstr!("//").into() + Cow::from(cstr!("//")) ); assert_eq!( SocketAddrUnix::new("/foo/bar").unwrap().path().unwrap(), - cstr!("/foo/bar").into() + Cow::from(cstr!("/foo/bar")) ); assert_eq!( SocketAddrUnix::new("foo").unwrap().path().unwrap(), - cstr!("foo").into() + Cow::from(cstr!("foo")) ); SocketAddrUnix::new("/foo\0/bar").unwrap_err(); assert!(SocketAddrUnix::new("").unwrap().path().is_none()); diff --git a/tests/path/arg.rs b/tests/path/arg.rs index f1bfd7536..8222e2612 100644 --- a/tests/path/arg.rs +++ b/tests/path/arg.rs @@ -16,126 +16,243 @@ fn test_arg() { let t: &str = "hello"; assert_eq!("hello", Arg::as_str(&t).unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: String = "hello".to_owned(); assert_eq!("hello", Arg::as_str(&t).unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: &OsStr = OsStr::new("hello"); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: OsString = OsString::from("hello".to_owned()); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: &Path = Path::new("hello"); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: PathBuf = PathBuf::from("hello".to_owned()); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: &CStr = cstr!("hello"); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: CString = cstr!("hello").to_owned(); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); assert_eq!( cstr!("hello"), - Borrow::borrow(&Arg::as_cow_c_str(&t).unwrap()) + Borrow::::borrow(&Arg::as_cow_c_str(&t).unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) ); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); let t: Components<'_> = Path::new("hello").components(); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Component<'_> = Path::new("hello").components().next().unwrap(); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Iter<'_> = Path::new("hello").iter(); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Cow<'_, str> = Cow::Borrowed("hello"); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Cow<'_, str> = Cow::Owned("hello".to_owned()); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Cow<'_, OsStr> = Cow::Borrowed(OsStr::new("hello")); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Cow<'_, OsStr> = Cow::Owned(OsString::from("hello".to_owned())); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Cow<'_, CStr> = Cow::Borrowed(cstr!("hello")); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Cow<'_, CStr> = Cow::Owned(cstr!("hello").to_owned()); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: &[u8] = b"hello"; assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: Vec = b"hello".to_vec(); assert_eq!("hello", t.as_str().unwrap()); assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); - assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); + assert_eq!( + cstr!("hello"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); let t: DecInt = DecInt::new(43110); assert_eq!("43110", t.as_str()); assert_eq!("43110".to_owned(), Arg::to_string_lossy(&t)); - assert_eq!(cstr!("43110"), Borrow::borrow(&t.as_cow_c_str().unwrap())); + assert_eq!( + cstr!("43110"), + Borrow::::borrow(&t.as_cow_c_str().unwrap()) + ); assert_eq!(cstr!("43110"), t.as_c_str()); - assert_eq!(cstr!("43110"), Borrow::borrow(&t.into_c_str().unwrap())); + assert_eq!( + cstr!("43110"), + Borrow::::borrow(&t.into_c_str().unwrap()) + ); } #[test]