From 97e796a724dbbdbac48969a8e469dd7c7744dcdb Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Fri, 22 Mar 2019 20:44:06 +0100 Subject: [PATCH] More tests for load_data --- .../templates/src/global_fns/load_data.rs | 44 +++++++++++++++++++ components/utils/test-files/test.css | 1 + 2 files changed, 45 insertions(+) create mode 100644 components/utils/test-files/test.css diff --git a/components/templates/src/global_fns/load_data.rs b/components/templates/src/global_fns/load_data.rs index e7b0dbf2..b8f053c4 100644 --- a/components/templates/src/global_fns/load_data.rs +++ b/components/templates/src/global_fns/load_data.rs @@ -155,6 +155,9 @@ fn get_output_format_from_args( ); if let Some(format) = format_arg { + if format == "plain" { + return Ok(OutputFormat::Plain); + } return OutputFormat::from_str(&format); } @@ -434,6 +437,47 @@ mod tests { ); } + #[test] + fn unknown_extension_defaults_to_plain() { + let static_fn = LoadData::new(PathBuf::from("../utils/test-files")); + let mut args = HashMap::new(); + args.insert("path".to_string(), to_value("test.css").unwrap()); + let result = static_fn.call(&args.clone()).unwrap(); + + assert_eq!( + result, + ".hello {}\n", + ); + } + + #[test] + fn can_override_known_extension_with_format() { + let static_fn = LoadData::new(PathBuf::from("../utils/test-files")); + let mut args = HashMap::new(); + args.insert("path".to_string(), to_value("test.csv").unwrap()); + args.insert("format".to_string(), to_value("plain").unwrap()); + let result = static_fn.call(&args.clone()).unwrap(); + + assert_eq!( + result, + "Number,Title\n1,Gutenberg\n2,Printing", + ); + } + + #[test] + fn will_use_format_on_unknown_extension() { + let static_fn = LoadData::new(PathBuf::from("../utils/test-files")); + let mut args = HashMap::new(); + args.insert("path".to_string(), to_value("test.css").unwrap()); + args.insert("format".to_string(), to_value("plain").unwrap()); + let result = static_fn.call(&args.clone()).unwrap(); + + assert_eq!( + result, + ".hello {}\n", + ); + } + #[test] fn can_load_csv() { let static_fn = LoadData::new(PathBuf::from("../utils/test-files")); diff --git a/components/utils/test-files/test.css b/components/utils/test-files/test.css new file mode 100644 index 00000000..3a461fe2 --- /dev/null +++ b/components/utils/test-files/test.css @@ -0,0 +1 @@ +.hello {}