Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / scripts / maps / osm_ingest / tests / extract_part4.rs
extract_part4.rs72 lines · 2.2 KiBRaw
| 1 | #[cfg(test)] |
| 2 | mod tests_part4 { |
| 3 | use osm_ingest::extract::{parse_args, Args, Layer}; use std::path::PathBuf; |
| 4 | |
| 5 | #[test] |
| 6 | fn args_need_a_layer_and_an_out() { |
| 7 | let ok = parse_args(&[ |
| 8 | "in.pbf".into(), |
| 9 | "--layer".into(), |
| 10 | "safety".into(), |
| 11 | "--out".into(), |
| 12 | "s.geojsonseq".into(), |
| 13 | "--bbox".into(), |
| 14 | "-122.6,37.2,-121.7,37.9".into(), |
| 15 | ]) |
| 16 | .unwrap(); |
| 17 | assert_eq!(ok.input, PathBuf::from("in.pbf")); |
| 18 | assert_eq!(ok.layer, Layer::Safety); |
| 19 | assert!(ok.bbox.is_some()); |
| 20 | |
| 21 | assert!(parse_args(&["in.pbf".into()]).is_err()); |
| 22 | assert!(parse_args(&["in.pbf".into(), "--layer".into(), "safety".into()]).is_err()); |
| 23 | assert!(parse_args(&["--layer".into(), "safety".into(), "--out".into(), "o".into()]).is_err()); |
| 24 | // A bad layer name names the ones that do exist. |
| 25 | let err = parse_args(&[ |
| 26 | "in.pbf".into(), |
| 27 | "--layer".into(), |
| 28 | "nope".into(), |
| 29 | "--out".into(), |
| 30 | "o".into(), |
| 31 | ]) |
| 32 | .map(|_| ()) |
| 33 | .unwrap_err(); |
| 34 | assert!(err.contains("safety"), "{err}"); |
| 35 | // A malformed bbox is rejected here, not silently ignored. |
| 36 | assert!(parse_args(&[ |
| 37 | "in.pbf".into(), |
| 38 | "--layer".into(), |
| 39 | "safety".into(), |
| 40 | "--out".into(), |
| 41 | "o".into(), |
| 42 | "--bbox".into(), |
| 43 | "1,2,3".into(), |
| 44 | ]) |
| 45 | .is_err()); |
| 46 | } |
| 47 | |
| 48 | #[test] |
| 49 | fn threads_is_optional_and_must_be_positive() { |
| 50 | let base: Vec<String> = vec![ |
| 51 | "in.pbf".into(), |
| 52 | "--layer".into(), |
| 53 | "safety".into(), |
| 54 | "--out".into(), |
| 55 | "o".into(), |
| 56 | ]; |
| 57 | assert_eq!(parse_args(&base).unwrap().threads, None); |
| 58 | |
| 59 | let mut with = base.clone(); |
| 60 | with.extend(["--threads".to_string(), "6".to_string()]); |
| 61 | assert_eq!(parse_args(&with).unwrap().threads, Some(6)); |
| 62 | |
| 63 | let mut zero = base.clone(); |
| 64 | zero.extend(["--threads".to_string(), "0".to_string()]); |
| 65 | assert!(parse_args(&zero).is_err()); |
| 66 | |
| 67 | let mut bare = base; |
| 68 | bare.push("--threads".into()); |
| 69 | assert!(parse_args(&bare).is_err()); |
| 70 | } |
| 71 | } |
| 72 |