From 534ee25b901aaedf9d99cd381fc2ac1b2c905131 Mon Sep 17 00:00:00 2001 From: James Prestwich Date: Thu, 12 Aug 2021 09:32:23 -0700 Subject: [PATCH] test: de minimis test for style deser --- rust/optics-base/src/settings/trace/fmt.rs | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/rust/optics-base/src/settings/trace/fmt.rs b/rust/optics-base/src/settings/trace/fmt.rs index a4d15cb31..e18feaa03 100644 --- a/rust/optics-base/src/settings/trace/fmt.rs +++ b/rust/optics-base/src/settings/trace/fmt.rs @@ -11,7 +11,7 @@ use tracing_subscriber::{ }; /// Basic tracing configuration -#[derive(Debug, Clone, Copy, serde::Deserialize)] +#[derive(Debug, Clone, Copy, serde::Deserialize, Eq, PartialEq)] #[serde(rename_all = "camelCase")] pub enum Style { /// Pretty print @@ -203,3 +203,47 @@ where } } } + +#[cfg(test)] +mod test { + + use super::*; + + #[derive(serde::Deserialize)] + struct TestStyle { + style: Style, + } + + #[test] + fn it_deserializes_formatting_strings() { + let case = r#"{"style": "pretty"}"#; + assert_eq!( + serde_json::from_str::(case).unwrap().style, + Style::Pretty + ); + + let case = r#"{"style": "compact"}"#; + assert_eq!( + serde_json::from_str::(case).unwrap().style, + Style::Compact + ); + + let case = r#"{"style": "full"}"#; + assert_eq!( + serde_json::from_str::(case).unwrap().style, + Style::Full + ); + + let case = r#"{"style": "json"}"#; + assert_eq!( + serde_json::from_str::(case).unwrap().style, + Style::Json + ); + + let case = r#"{"style": "toast"}"#; + assert_eq!( + serde_json::from_str::(case).unwrap().style, + Style::Full + ); + } +}