Browse Source

More tests for load_data

index-subcmd
Vincent Prouillet 5 years ago
parent
commit
97e796a724
2 changed files with 45 additions and 0 deletions
  1. +44
    -0
      components/templates/src/global_fns/load_data.rs
  2. +1
    -0
      components/utils/test-files/test.css

+ 44
- 0
components/templates/src/global_fns/load_data.rs View File

@@ -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"));


+ 1
- 0
components/utils/test-files/test.css View File

@@ -0,0 +1 @@
.hello {}

Loading…
Cancel
Save