summaryrefslogtreecommitdiff
path: root/src/map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.rs')
-rw-r--r--src/map.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/map.rs b/src/map.rs
index 874e537..b592fbd 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -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.
@@ -135,10 +139,7 @@ impl Roadmap {
1 => (),
_ => {
let names: Vec<String> = goals.iter().map(|s| s.name().into()).collect();
- return Err(RoadmapError::ManyGoals {
- count: n,
- names,
- });
+ return Err(RoadmapError::ManyGoals { count: n, names });
}
}
@@ -146,11 +147,12 @@ impl Roadmap {
for step in self.iter() {
for depname in step.dependencies() {
match self.get_step(depname) {
- None =>
+ None => {
return Err(RoadmapError::MissingDep {
name: step.name().into(),
missing: depname.into(),
- }),
+ })
+ }
Some(_) => (),
}
}
@@ -222,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();
@@ -237,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();
@@ -281,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"),
@@ -290,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", "");