summaryrefslogtreecommitdiff
path: root/src/matches.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/matches.rs')
-rw-r--r--src/matches.rs44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/matches.rs b/src/matches.rs
index 472b475..88d2c55 100644
--- a/src/matches.rs
+++ b/src/matches.rs
@@ -1,3 +1,4 @@
+use crate::Binding;
use crate::Result;
use crate::Scenario;
use crate::StepKind;
@@ -34,6 +35,30 @@ impl MatchedScenario {
}
}
+/// A list of matched steps.
+#[derive(Debug)]
+pub struct MatchedSteps {
+ matches: Vec<MatchedStep>,
+}
+
+impl MatchedSteps {
+ /// Create new set of steps that match a scenario step.
+ pub fn new(matches: Vec<MatchedStep>) -> Self {
+ Self { matches }
+ }
+}
+
+impl std::fmt::Display for MatchedSteps {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
+ let matches: Vec<String> = self
+ .matches
+ .iter()
+ .map(|m| format!("{}", m.pattern()))
+ .collect();
+ write!(f, "{}", matches.join("\n"))
+ }
+}
+
/// A matched binding and scenario step, with captured parts.
///
/// A MatchedStep is a sequence of partial steps, each representing
@@ -41,6 +66,7 @@ impl MatchedScenario {
#[derive(Debug, Serialize, Deserialize)]
pub struct MatchedStep {
kind: StepKind,
+ pattern: String,
text: String,
parts: Vec<PartialStep>,
function: String,
@@ -50,18 +76,14 @@ pub struct MatchedStep {
impl MatchedStep {
/// Return a new empty match. Empty means it has no step parts.
- pub fn new(
- kind: StepKind,
- function: &str,
- cleanup: Option<&str>,
- types: &HashMap<String, CaptureType>,
- ) -> MatchedStep {
+ pub fn new(binding: &Binding, types: &HashMap<String, CaptureType>) -> MatchedStep {
MatchedStep {
- kind,
+ kind: binding.kind(),
+ pattern: binding.pattern().to_string(),
text: "".to_string(),
parts: vec![],
- function: function.to_string(),
- cleanup: cleanup.map(String::from),
+ function: binding.function().to_string(),
+ cleanup: binding.cleanup().map(String::from),
types: types.clone(),
}
}
@@ -87,6 +109,10 @@ impl MatchedStep {
self.parts.iter()
}
+ fn pattern(&self) -> String {
+ self.pattern.to_string()
+ }
+
fn text(&self) -> String {
let mut t = String::new();
for part in self.parts() {