Skip to content

Commit

Permalink
Feature-gate applicable doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Oct 29, 2023
1 parent c5e29da commit d53c274
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,17 @@ impl Format {
/// File extensions are matched case-insensitively and may optionally start
/// with a period. If the given file extension does not correspond to a
/// known file format, `None` is returned.
///
/// # Example
///
/// ```
/// use cfgurate::Format;
///
/// assert_eq!(Format::from_extension(".json"), Some(Format::Json));
/// assert_eq!(Format::from_extension("YML"), Some(Format::Yaml));
/// assert_eq!(Format::from_extension("cfg"), None);
/// ```
#[cfg_attr(all(feature = "json", feature = "yaml"), doc = concat!(
"# Example\n",
"\n",
"```\n",
"use cfgurate::Format;\n",
"\n",
"assert_eq!(Format::from_extension(\".json\"), Some(Format::Json));\n",
"assert_eq!(Format::from_extension(\"YML\"), Some(Format::Yaml));\n",
"assert_eq!(Format::from_extension(\"cfg\"), None);\n",
"```\n",
))]
pub fn from_extension(ext: &str) -> Option<Format> {
let ext = ext.strip_prefix('.').unwrap_or(ext).to_ascii_lowercase();
let ext = &*ext;
Expand All @@ -209,18 +210,18 @@ impl Format {
///
/// Only [enabled][Format::is_enabled] formats are supported by this
/// method.
///
/// # Example
///
/// ```
/// use cfgurate::Format;
///
/// assert_eq!(Format::identify("path/to/file.json").unwrap(), Format::Json);
/// assert_eq!(Format::identify("path/to/file.RON").unwrap(), Format::Ron);
/// assert!(Format::identify("path/to/file.cfg").is_err());
/// assert!(Format::identify("path/to/file").is_err());
/// ```
///
#[cfg_attr(all(feature = "json", feature = "ron"), doc = concat!(
"# Example\n",
"\n",
"```\n",
"use cfgurate::Format;\n",
"\n",
"assert_eq!(Format::identify(\"path/to/file.json\").unwrap(), Format::Json);\n",
"assert_eq!(Format::identify(\"path/to/file.RON\").unwrap(), Format::Ron);\n",
"assert!(Format::identify(\"path/to/file.cfg\").is_err());\n",
"assert!(Format::identify(\"path/to/file\").is_err());\n",
"```\n",
))]
/// # Errors
///
/// Returns an error if the given file path does not have an extension, the
Expand Down

0 comments on commit d53c274

Please sign in to comment.