From 3f895ec06b4bf2d4e9cbf06a6cee5134adeeeb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=ADdac=20Sement=C3=A9=20Fern=C3=A1ndez?= Date: Sun, 27 Dec 2020 13:14:16 +0100 Subject: [PATCH] * Adjusted doctest for unstable-locales --- README.md | 6 +++--- src/lib.rs | 52 ++++++++++++++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 5a5a74b4..48af06cf 100644 --- a/README.md +++ b/README.md @@ -238,8 +238,8 @@ Chrono now also provides date formatting in almost any language without the help of an additional C library. This functionality is under the feature `unstable-locales`: -```text -chrono { version = "0.4", features = ["unstable-locales"] +```toml +chrono = { version = "0.4", features = ["unstable-locales"] } ``` The `unstable-locales` feature requires and implies at least the `alloc` feature. @@ -251,8 +251,8 @@ let dt = Utc.ymd(2014, 11, 28).and_hms(12, 0, 9); assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2014-11-28 12:00:09"); assert_eq!(dt.format("%a %b %e %T %Y").to_string(), "Fri Nov 28 12:00:09 2014"); assert_eq!(dt.format_localized("%A %e %B %Y, %T", Locale::fr_BE).to_string(), "vendredi 28 novembre 2014, 12:00:09"); -assert_eq!(dt.format("%a %b %e %T %Y").to_string(), dt.format("%c").to_string()); +assert_eq!(dt.format("%a %b %e %T %Y").to_string(), dt.format("%c").to_string()); assert_eq!(dt.to_string(), "2014-11-28 12:00:09 UTC"); assert_eq!(dt.to_rfc2822(), "Fri, 28 Nov 2014 12:00:09 +0000"); assert_eq!(dt.to_rfc3339(), "2014-11-28T12:00:09+00:00"); diff --git a/src/lib.rs b/src/lib.rs index f2e642da..23c94e69 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -230,34 +230,38 @@ //! help of an additional C library. This functionality is under the feature //! `unstable-locales`: //! -//! ```text +//! ```toml //! chrono = { version = "0.4", features = ["unstable-locales"] } //! ``` -#![cfg_attr( - feature = "unstable-locales", - doc = r##" -The `unstable-locales` feature requires and implies at least the `alloc` feature. - -```rust -use chrono::prelude::*; - -let dt = Utc.ymd(2014, 11, 28).and_hms(12, 0, 9); -assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2014-11-28 12:00:09"); -assert_eq!(dt.format("%a %b %e %T %Y").to_string(), "Fri Nov 28 12:00:09 2014"); -assert_eq!(dt.format_localized("%A %e %B %Y, %T", Locale::fr_BE).to_string(), "vendredi 28 novembre 2014, 12:00:09"); -assert_eq!(dt.format("%a %b %e %T %Y").to_string(), dt.format("%c").to_string()); //! -assert_eq!(dt.to_string(), "2014-11-28 12:00:09 UTC"); -assert_eq!(dt.to_rfc2822(), "Fri, 28 Nov 2014 12:00:09 +0000"); -assert_eq!(dt.to_rfc3339(), "2014-11-28T12:00:09+00:00"); -assert_eq!(format!("{:?}", dt), "2014-11-28T12:00:09Z"); +//! The `unstable-locales` feature requires and implies at least the `alloc` feature. //! -// Note that milli/nanoseconds are only printed if they are non-zero -let dt_nano = Utc.ymd(2014, 11, 28).and_hms_nano(12, 0, 9, 1); -assert_eq!(format!("{:?}", dt_nano), "2014-11-28T12:00:09.000000001Z"); -``` -"## -)] +//! ```rust +//! use chrono::prelude::*; +//! +//! # #[cfg(feature = "unstable-locales")] +//! # fn test() { +//! let dt = Utc.ymd(2014, 11, 28).and_hms(12, 0, 9); +//! assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2014-11-28 12:00:09"); +//! assert_eq!(dt.format("%a %b %e %T %Y").to_string(), "Fri Nov 28 12:00:09 2014"); +//! assert_eq!(dt.format_localized("%A %e %B %Y, %T", Locale::fr_BE).to_string(), "vendredi 28 novembre 2014, 12:00:09"); +//! +//! assert_eq!(dt.format("%a %b %e %T %Y").to_string(), dt.format("%c").to_string()); +//! assert_eq!(dt.to_string(), "2014-11-28 12:00:09 UTC"); +//! assert_eq!(dt.to_rfc2822(), "Fri, 28 Nov 2014 12:00:09 +0000"); +//! assert_eq!(dt.to_rfc3339(), "2014-11-28T12:00:09+00:00"); +//! assert_eq!(format!("{:?}", dt), "2014-11-28T12:00:09Z"); +//! +//! // Note that milli/nanoseconds are only printed if they are non-zero +//! let dt_nano = Utc.ymd(2014, 11, 28).and_hms_nano(12, 0, 9, 1); +//! assert_eq!(format!("{:?}", dt_nano), "2014-11-28T12:00:09.000000001Z"); +//! # } +//! # #[cfg(not(feature = "unstable-locales"))] +//! # fn test() {} +//! # if cfg!(feature = "unstable-locales") { +//! # test(); +//! # } +//! ``` //! //! Parsing can be done with three methods: //!