From 73854a5cecb92237ff1522bcc32b9bd05e078e25 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 22 Jul 2023 08:06:58 +0200 Subject: [PATCH] Use new API in `test_parse_only_timezone_offset_permissive_no_panic` --- src/format/strftime.rs | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/format/strftime.rs b/src/format/strftime.rs index 3134277dcd..230d8ac3f7 100644 --- a/src/format/strftime.rs +++ b/src/format/strftime.rs @@ -696,10 +696,11 @@ mod tests { #[cfg(feature = "unstable-locales")] use crate::format::Locale; use crate::format::{ - fixed, internal_fixed, num, num0, nums, Fixed, InternalInternal, Numeric::*, + fixed, internal_fixed, num, num0, nums, Fixed, FormattingSpec, InternalInternal, Numeric::*, }; + use crate::{DateTime, Utc}; #[cfg(any(feature = "alloc", feature = "std"))] - use crate::{DateTime, FixedOffset, NaiveDate, ParseError, TimeZone, Timelike, Utc}; + use crate::{FixedOffset, NaiveDate, ParseError, TimeZone, Timelike}; #[test] fn test_strftime_items() { @@ -971,6 +972,15 @@ mod tests { Ok(()) } + /// Ensure parsing a timestamp with the parse-only stftime formatter "%#z" does + /// not cause a panic. + /// + /// See . + #[test] + fn test_parse_only_timezone_offset_permissive_no_panic() { + assert!(FormattingSpec::, _>::from_items(StrftimeItems::new("%#z")).is_err()); + } + #[test] #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] fn test_strftime_docs_localized() -> Result<(), ParseError> { @@ -1021,31 +1031,6 @@ mod tests { Ok(()) } - /// Ensure parsing a timestamp with the parse-only stftime formatter "%#z" does - /// not cause a panic. - /// - /// See . - #[test] - #[cfg(any(feature = "alloc", feature = "std"))] - fn test_parse_only_timezone_offset_permissive_no_panic() { - use crate::NaiveDate; - use crate::{FixedOffset, TimeZone}; - use std::fmt::Write; - - let dt = FixedOffset::east_opt(34200) - .unwrap() - .from_local_datetime( - &NaiveDate::from_ymd_opt(2001, 7, 8) - .unwrap() - .and_hms_nano_opt(0, 34, 59, 1_026_490_708) - .unwrap(), - ) - .unwrap(); - - let mut buf = String::new(); - let _ = write!(buf, "{}", dt.format("%#z")).expect_err("parse-only formatter should fail"); - } - #[test] #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] fn test_strftime_localized_korean() -> Result<(), ParseError> {