diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5089ac7b..b1899562 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -109,7 +109,7 @@ jobs: - name: Install Rust toolchain uses: artichoke/setup-rust/build-and-test@v1.9.0 with: - toolchain: "1.56.0" + toolchain: "1.58.0" - name: Compile run: cargo build --verbose diff --git a/Cargo.toml b/Cargo.toml index 437d342f..cdfc90f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "1.8.0" # remember to set `html_root_url` in `src/lib.rs`. authors = ["Ryan Lopopolo "] license = "MIT" edition = "2021" -rust-version = "1.56.0" +rust-version = "1.58.0" readme = "README.md" repository = "https://github.com/artichoke/intaglio" documentation = "https://docs.rs/intaglio" diff --git a/README.md b/README.md index d4aeba49..38522766 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ All features are enabled by default. ### Minimum Supported Rust Version -This crate requires at least Rust 1.56.0. This version can be bumped in minor +This crate requires at least Rust 1.58.0. This version can be bumped in minor releases. ## License diff --git a/src/internal.rs b/src/internal.rs index ea114cf0..6ab0041e 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -353,3 +353,201 @@ impl fmt::Debug for Slice { } } } + +#[cfg(test)] +mod tests { + use core::fmt::Write; + use std::borrow::Cow; + #[cfg(feature = "cstr")] + use std::ffi::CStr; + #[cfg(feature = "osstr")] + use std::ffi::OsStr; + #[cfg(feature = "path")] + use std::path::Path; + + use super::Interned; + + #[test] + fn test_interned_static_str_debug_format() { + let s = Interned::from(Cow::Borrowed("abc")); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "\"abc\""); + } + + #[test] + fn test_interned_owned_str_debug_format() { + let s = Interned::::from(Cow::Owned("abc".to_string())); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "\"abc\""); + } + + #[test] + #[cfg(feature = "bytes")] + fn test_interned_static_bytes_debug_format() { + let s = Interned::from(Cow::Borrowed(&b"abc"[..])); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "[97, 98, 99]"); + + let s = Interned::from(Cow::Borrowed(&b"\xFF"[..])); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "[255]"); + + let s = Interned::from(Cow::Borrowed(&b"abc"[..])); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::from(Cow::Borrowed(&b"\xFF"[..])); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"\u{FFFD}\""); + } + + #[test] + #[cfg(feature = "bytes")] + fn test_interned_owned_bytes_debug_format() { + let s = Interned::<[u8]>::from(Cow::Owned(b"abc".to_vec())); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "[97, 98, 99]"); + + let s = Interned::<[u8]>::from(Cow::Owned(b"\xFF".to_vec())); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "[255]"); + + let s = Interned::<[u8]>::from(Cow::Owned(b"abc".to_vec())); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::<[u8]>::from(Cow::Owned(b"\xFF".to_vec())); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"\u{FFFD}\""); + } + + #[test] + #[cfg(feature = "cstr")] + fn test_interned_static_cstr_debug_format() { + let s = Interned::from(Cow::Borrowed( + CStr::from_bytes_with_nul(b"abc\x00").unwrap(), + )); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::from(Cow::Borrowed( + CStr::from_bytes_with_nul(b"\xFF\x00").unwrap(), + )); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, r#""\xff""#); + + let s = Interned::from(Cow::Borrowed( + CStr::from_bytes_with_nul(b"abc\x00").unwrap(), + )); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::from(Cow::Borrowed( + CStr::from_bytes_with_nul(b"\xFF\x00").unwrap(), + )); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"\u{FFFD}\""); + } + + #[test] + #[cfg(feature = "cstr")] + fn test_interned_owned_cstring_debug_format() { + let s = Interned::::from(Cow::Owned( + CStr::from_bytes_with_nul(b"abc\x00").unwrap().to_owned(), + )); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::::from(Cow::Owned( + CStr::from_bytes_with_nul(b"\xFF\x00").unwrap().to_owned(), + )); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, r#""\xff""#); + + let s = Interned::::from(Cow::Owned( + CStr::from_bytes_with_nul(b"abc\x00").unwrap().to_owned(), + )); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::::from(Cow::Owned( + CStr::from_bytes_with_nul(b"\xFF\x00").unwrap().to_owned(), + )); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"\u{FFFD}\""); + } + + #[test] + #[cfg(feature = "osstr")] + fn test_interned_static_osstr_debug_format() { + let s = Interned::from(Cow::Borrowed(OsStr::new("abc"))); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::from(Cow::Borrowed(OsStr::new("abc"))); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"abc\""); + } + + #[test] + #[cfg(feature = "osstr")] + fn test_interned_owned_osstring_debug_format() { + let s = Interned::::from(Cow::Owned(OsStr::new("abc").to_owned())); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::::from(Cow::Owned(OsStr::new("abc").to_owned())); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"abc\""); + } + + #[test] + #[cfg(feature = "path")] + fn test_interned_static_path_debug_format() { + let s = Interned::from(Cow::Borrowed(Path::new("abc"))); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::from(Cow::Borrowed(Path::new("abc"))); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"abc\""); + } + + #[test] + #[cfg(feature = "path")] + fn test_interned_owned_pathbuf_debug_format() { + let s = Interned::::from(Cow::Owned(Path::new("abc").to_owned())); + let mut buf = String::new(); + write!(&mut buf, "{s:?}").unwrap(); + assert_eq!(buf, "\"abc\""); + + let s = Interned::::from(Cow::Owned(Path::new("abc").to_owned())); + let mut buf = String::new(); + write!(&mut buf, "{s:#?}").unwrap(); + assert_eq!(buf, "\"abc\""); + } +} diff --git a/src/lib.rs b/src/lib.rs index 1f5a25ce..e002a973 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -296,7 +296,7 @@ mod tests { fn error_display_is_not_empty() { let tc = SymbolOverflowError::new(); let mut buf = String::new(); - write!(&mut buf, "{}", tc).unwrap(); + write!(&mut buf, "{tc}").unwrap(); assert!(!buf.is_empty()); } @@ -304,7 +304,7 @@ mod tests { fn error_debug_is_not_empty() { let tc = SymbolOverflowError::new(); let mut buf = String::new(); - write!(&mut buf, "{:?}", tc).unwrap(); + write!(&mut buf, "{tc:?}").unwrap(); assert!(!buf.is_empty()); }