diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-01-21 09:34:47 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-01-21 10:09:41 +0200 |
commit | f49a7c9eaa14ce1aaf342d862ec292b84fa2e7bc (patch) | |
tree | e81eb68c3626715c541644e9055c2bd8c709fee9 /src/map.rs | |
parent | 82073da80b0f38d605204e96bf4b430c2b785813 (diff) | |
download | roadmap-f49a7c9eaa14ce1aaf342d862ec292b84fa2e7bc.tar.gz |
refactor: parse with serde directly to data structure
Use serde to parse directly to a hashmap of steps, instead of generic
YAML values. This gives us better error messages.
Sponsored-by: author
Diffstat (limited to 'src/map.rs')
-rw-r--r-- | src/map.rs | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -1,3 +1,5 @@ +use std::collections::HashMap; + use textwrap::fill; pub use crate::from_yaml; @@ -21,8 +23,10 @@ impl Roadmap { /// Create a new, empty roadmap. /// /// You probably want the `from_yaml` function instead. - pub fn new() -> Self { - Self::default() + pub fn new(map: HashMap<String, Step>) -> Self { + Self { + steps: map.values().cloned().collect(), + } } // Find steps that nothing depends on. @@ -220,13 +224,13 @@ mod tests { #[test] fn new_roadmap() { - let roadmap = Roadmap::new(); + let roadmap = Roadmap::default(); assert_eq!(roadmap.step_names().count(), 0); } #[test] fn add_step_to_roadmap() { - let mut roadmap = Roadmap::new(); + let mut roadmap = Roadmap::default(); let first = Step::new("first", "the first step"); roadmap.add_step(first); let names: Vec<&str> = roadmap.step_names().collect(); @@ -235,7 +239,7 @@ mod tests { #[test] fn get_step_from_roadmap() { - let mut roadmap = Roadmap::new(); + let mut roadmap = Roadmap::default(); let first = Step::new("first", "the first step"); roadmap.add_step(first); let gotit = roadmap.get_step("first").unwrap(); @@ -279,7 +283,7 @@ blocked: #[test] fn empty_dot() { - let roadmap = Roadmap::new(); + let roadmap = Roadmap::default(); match roadmap.format_as_dot(999) { Err(_) => (), _ => panic!("expected error for empty roadmap"), @@ -288,7 +292,7 @@ blocked: #[test] fn simple_dot() { - let mut roadmap = Roadmap::new(); + let mut roadmap = Roadmap::default(); let mut first = Step::new("first", ""); first.set_status(Status::Ready); let mut second = Step::new("second", ""); |