diff --git a/tests/lexicographic_file_walker.rs b/tests/common/lexicographic_file_walker.rs similarity index 97% rename from tests/lexicographic_file_walker.rs rename to tests/common/lexicographic_file_walker.rs index c311b2456..dc953e39a 100644 --- a/tests/lexicographic_file_walker.rs +++ b/tests/common/lexicographic_file_walker.rs @@ -46,6 +46,6 @@ impl Iterator for LexicographicFileWalker { temp_dirs.sort(); self.dirs.extend(temp_dirs.into_iter()); } - return self.files.pop_front(); + self.files.pop_front() } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs new file mode 100644 index 000000000..8e72731eb --- /dev/null +++ b/tests/common/mod.rs @@ -0,0 +1,2 @@ +pub mod lexicographic_file_walker; +pub mod osm; \ No newline at end of file diff --git a/tests/osm.rs b/tests/common/osm.rs similarity index 67% rename from tests/osm.rs rename to tests/common/osm.rs index 7814694c1..a6d7b4bd4 100644 --- a/tests/osm.rs +++ b/tests/common/osm.rs @@ -7,7 +7,7 @@ use std::collections::HashMap; use xml_builder::{XMLBuilder, XMLElement, XMLVersion}; static OSM_USER: &str = "osrm"; -static OSM_TIMESTAMP :&str = "2000-01-01T00:00:00Z"; +static OSM_TIMESTAMP: &str = "2000-01-01T00:00:00Z"; static OSM_UID: &str = "1"; #[derive(Clone, Debug, Default)] @@ -19,25 +19,25 @@ pub struct OSMNode { } impl OSMNode { - pub fn add_tag(&mut self, key: &str, value: &str) { - self.tags.insert(key.into(), value.into()); - } + // pub fn add_tag(&mut self, key: &str, value: &str) { + // self.tags.insert(key.into(), value.into()); + // } - pub fn set_id_(&mut self, id: u64) { - self.id = id; - } + // pub fn set_id_(&mut self, id: u64) { + // self.id = id; + // } - pub fn set_tags(&mut self, tags: HashMap) { - self.tags = tags - } + // pub fn set_tags(&mut self, tags: HashMap) { + // self.tags = tags + // } pub fn to_xml(&self) -> XMLElement { let mut node = XMLElement::new("node"); node.add_attribute("id", &self.id.to_string()); node.add_attribute("version", "1"); - node.add_attribute("uid", &OSM_UID); - node.add_attribute("user", &OSM_USER); - node.add_attribute("timestamp", &OSM_TIMESTAMP); + node.add_attribute("uid", OSM_UID); + node.add_attribute("user", OSM_USER); + node.add_attribute("timestamp", OSM_TIMESTAMP); node.add_attribute("lon", &format!("{:?}", self.lon)); node.add_attribute("lat", &format!("{:?}", self.lat)); @@ -67,17 +67,17 @@ impl OSMWay { self.nodes.push(node); } - pub fn set_tags(&mut self, tags: HashMap) { - self.tags = tags; - } + // pub fn set_tags(&mut self, tags: HashMap) { + // self.tags = tags; + // } pub fn to_xml(&self) -> XMLElement { let mut way = XMLElement::new("way"); way.add_attribute("id", &self.id.to_string()); way.add_attribute("version", "1"); - way.add_attribute("uid", &OSM_UID); - way.add_attribute("user", &OSM_USER); - way.add_attribute("timestamp", &OSM_TIMESTAMP); + way.add_attribute("uid", OSM_UID); + way.add_attribute("user", OSM_USER); + way.add_attribute("timestamp", OSM_TIMESTAMP); assert!(self.nodes.len() >= 2); @@ -104,71 +104,72 @@ impl OSMWay { } } -#[derive(Clone, Debug)] -struct Member { - id: u64, - member_type: String, - member_role: String, -} +// #[derive(Clone, Debug)] +// struct Member { +// id: u64, +// member_type: String, +// member_role: String, +// } -#[derive(Clone, Debug)] -struct OSMRelation { - id: u64, - osm_user: String, - osm_time_stamp: String, - osm_uid: String, - members: Vec, - tags: HashMap, -} +// #[derive(Clone, Debug)] +// struct OSMRelation { +// id: u64, +// osm_user: String, +// osm_time_stamp: String, +// osm_uid: String, +// members: Vec, +// tags: HashMap, +// } -impl OSMRelation { - fn add_member(&mut self, member_type: String, id: u64, member_role: String) { - self.members.push(Member { - id, - member_type, - member_role, - }); - } +// impl OSMRelation { +// fn add_member(&mut self, member_type: String, id: u64, member_role: String) { +// self.members.push(Member { +// id, +// member_type, +// member_role, +// }); +// } - pub fn add_tag(&mut self, key: &str, value: &str) { - self.tags.insert(key.into(), value.into()); - } -} +// pub fn add_tag(&mut self, key: &str, value: &str) { +// self.tags.insert(key.into(), value.into()); +// } +// } #[derive(Debug, Default)] pub struct OSMDb { nodes: Vec<(char, OSMNode)>, ways: Vec, - relations: Vec, + // relations: Vec, } impl OSMDb { pub fn add_node(&mut self, node: OSMNode) { let name = node.tags.get("name").unwrap(); - assert!(name.len() == 1, "name needs to be of length 1, but was \"{name}\""); - self.nodes.push((name.chars().next().unwrap() as char, node)); + assert!( + name.len() == 1, + "name needs to be of length 1, but was \"{name}\"" + ); + self.nodes.push((name.chars().next().unwrap(), node)); } pub fn find_node(&self, search_name: char) -> Option<&(char, OSMNode)> { // TODO: this is a linear search. - self.nodes.iter().find(|(name, _node)| { - search_name == *name - }) + self.nodes.iter().find(|(name, _node)| search_name == *name) } pub fn add_way(&mut self, way: OSMWay) { self.ways.push(way); } - pub fn add_relation(&mut self, relation: OSMRelation) { - self.relations.push(relation); - } + // pub fn add_relation(&mut self, relation: OSMRelation) { + // self.relations.push(relation); + // } - pub fn clear(&mut self) { - self.nodes.clear(); - self.ways.clear(); - self.relations.clear(); - } + // pub fn clear(&mut self) { + // self.nodes.clear(); + // self.ways.clear(); + // // self.relations.clear(); + // } pub fn to_xml(&self) -> String { let mut xml = XMLBuilder::new() @@ -195,32 +196,33 @@ impl OSMDb { String::from_utf8(writer).unwrap() } - pub fn node_len(&self) -> usize { - self.nodes.len() - } - pub fn way_len(&self) -> usize { - self.ways.len() - } - pub fn relation_len(&self) -> usize { - self.relations.len() - } + // pub fn node_len(&self) -> usize { + // self.nodes.len() + // } + // pub fn way_len(&self) -> usize { + // self.ways.len() + // } + // pub fn relation_len(&self) -> usize { + // self.relations.len() + // } } #[cfg(test)] -mod test { - use super::{OSMNode, OSMWay}; +mod tests { #[test] fn empty_db_by_default() { - let osm_db = crate::OSMDb::default(); + use super::*; + let osm_db = OSMDb::default(); assert_eq!(0, osm_db.node_len()); assert_eq!(0, osm_db.way_len()); - assert_eq!(0, osm_db.relation_len()); + // assert_eq!(0, osm_db.relation_len()); } #[test] fn osm_db_with_single_node() { - let mut osm_db = crate::OSMDb::default(); + use super::*; + let mut osm_db = OSMDb::default(); let mut node1 = OSMNode { id: 123, diff --git a/tests/cucumber.rs b/tests/cucumber.rs index b6921b55c..006ec6b66 100644 --- a/tests/cucumber.rs +++ b/tests/cucumber.rs @@ -1,7 +1,6 @@ extern crate clap; -mod lexicographic_file_walker; -mod osm; +mod common; use core::panic; use std::collections::{HashMap, HashSet}; @@ -12,11 +11,11 @@ use std::{env, fs}; use cheap_ruler::CheapRuler; use clap::Parser; +use common::lexicographic_file_walker::LexicographicFileWalker; +use common::osm::{OSMDb, OSMNode, OSMWay}; use cucumber::{self, gherkin::Step, given, when, World}; use futures::{future, FutureExt}; use geo_types::{point, Point}; -use lexicographic_file_walker::LexicographicFileWalker; -use osm::{OSMDb, OSMNode, OSMWay}; #[derive(Debug, Default, World)] struct OSRMWorld { @@ -35,10 +34,10 @@ struct OSRMWorld { impl OSRMWorld { fn set_scenario_specific_paths_and_digests(&mut self, path: Option) { - self.feature_path = path.clone(); + self.feature_path.clone_from(&path); let file = File::open(path.clone().unwrap()) - .expect(&format!("filesystem broken? can't open file {:?}", path)); + .unwrap_or_else(|_| panic!("filesystem broken? can't open file {:?}", path)); self.feature_digest = chksum_md5::chksum(file) .expect("md5 could not be computed") .to_hex_lowercase(); @@ -227,8 +226,8 @@ fn request_nearest(world: &mut OSRMWorld, step: &Step) { // TODO: move to different file fn get_file_as_byte_vec(path: &PathBuf) -> Vec { println!("opening {path:?}"); - let mut f = File::open(&path).expect("no file found"); - let metadata = fs::metadata(&path).expect("unable to read metadata"); + let mut f = File::open(path).expect("no file found"); + let metadata = fs::metadata(path).expect("unable to read metadata"); let mut buffer = vec![0; metadata.len() as usize]; f.read(&mut buffer).expect("buffer overflow"); @@ -306,9 +305,8 @@ fn main() { "osrm_partition", ]; - let files: Vec = fs::read_dir(&build_path) + let files: Vec = fs::read_dir(build_path) .unwrap() - .into_iter() .filter_map(|e| e.ok()) .map(|dir_entry| dir_entry.path()) .collect(); @@ -323,8 +321,7 @@ fn main() { .to_str() .unwrap() .contains(name) - }) - .map(|e| e.clone()) + }).cloned() .expect("file exists and is usable") }); @@ -346,7 +343,7 @@ fn main() { for path_buf in dependencies { let data = get_file_as_byte_vec(&path_buf); - if data.len() == 0 { + if data.is_empty() { continue; } md5.update(data); @@ -374,7 +371,7 @@ fn main() { _ => x, }) .collect::() - .replace(r"\", "_") + .replace('\\', "_") .replace("__", "_") .replace("..", "."); s.truncate(64);