diff options
Diffstat (limited to 'src/bindings.rs')
-rw-r--r-- | src/bindings.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/bindings.rs b/src/bindings.rs index 4233528..ea35f57 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -294,20 +294,17 @@ impl Bindings { /// Find the binding matching a given scenario step, if there is /// exactly one. - pub fn find(&self, step: &ScenarioStep) -> Option<MatchedStep> { + pub fn find(&self, step: &ScenarioStep) -> Result<MatchedStep> { let mut matches = self .bindings() .iter() - .map(|b| b.match_with_step(step)) - .filter(|o| o.is_some()); - if let Some(m) = matches.next() { - if matches.count() == 0 { - m - } else { - None - } - } else { - None + .filter_map(|b| b.match_with_step(step)); + match matches.next() { + None => Err(SubplotError::BindingUnknown(step.to_string())), + Some(matched) => match matches.next() { + None => Ok(matched), + Some(_) => Err(SubplotError::BindingNotUnique(step.to_string())), + }, } } @@ -441,7 +438,7 @@ mod test_bindings { let binding = Binding::new(StepKind::When, r"I am Tomjon", "set_foo", None).unwrap(); let mut bindings = Bindings::new(); bindings.add(&binding); - assert!(bindings.find(&step).is_none()); + assert!(bindings.find(&step).is_err()); } #[test] @@ -451,7 +448,7 @@ mod test_bindings { Binding::new(StepKind::Given, r"I am Tomjon of Lancre", "set_foo", None).unwrap(); let mut bindings = Bindings::new(); bindings.add(&binding); - assert!(bindings.find(&step).is_none()); + assert!(bindings.find(&step).is_err()); } #[test] |