summaryrefslogtreecommitdiff
path: root/src/matches.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/matches.rs')
-rw-r--r--src/matches.rs37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/matches.rs b/src/matches.rs
index f8de59a..18c9832 100644
--- a/src/matches.rs
+++ b/src/matches.rs
@@ -1,4 +1,4 @@
-use crate::html::Location;
+use crate::html::{Attribute, Content, Element, ElementTag, Location};
use crate::Binding;
use crate::Scenario;
use crate::StepKind;
@@ -141,6 +141,14 @@ impl MatchedStep {
pub fn types(&self) -> &HashMap<String, CaptureType> {
&self.types
}
+
+ /// Render the step as HTML.
+ pub fn to_html(&self) -> Element {
+ let mut e = Element::new(ElementTag::Span);
+ e.push_attribute(Attribute::new("class", "scenario_step"));
+ e.push_child(Content::Text(self.text().into()));
+ e
+ }
}
/// Part of a scenario step, possibly captured by a pattern.
@@ -156,6 +164,8 @@ pub enum PartialStep {
name: String,
/// Text of the capture.
text: String,
+ /// Type of capture.
+ kind: CaptureType,
},
}
@@ -166,10 +176,11 @@ impl PartialStep {
}
/// Construct a textual captured part of a scenario step.
- pub fn text(name: &str, text: &str) -> PartialStep {
+ pub fn text(name: &str, text: &str, kind: CaptureType) -> PartialStep {
PartialStep::CapturedText {
name: name.to_string(),
text: text.to_string(),
+ kind,
}
}
@@ -184,6 +195,7 @@ impl PartialStep {
#[cfg(test)]
mod test_partial_steps {
use super::PartialStep;
+ use crate::bindings::CaptureType;
#[test]
fn identical_uncaptured_texts_match() {
@@ -201,29 +213,29 @@ mod test_partial_steps {
#[test]
fn identical_captured_texts_match() {
- let p1 = PartialStep::text("xxx", "foo");
- let p2 = PartialStep::text("xxx", "foo");
+ let p1 = PartialStep::text("xxx", "foo", CaptureType::Text);
+ let p2 = PartialStep::text("xxx", "foo", CaptureType::Text);
assert_eq!(p1, p2);
}
#[test]
fn different_captured_texts_dont_match() {
- let p1 = PartialStep::text("xxx", "foo");
- let p2 = PartialStep::text("xxx", "bar");
+ let p1 = PartialStep::text("xxx", "foo", CaptureType::Text);
+ let p2 = PartialStep::text("xxx", "bar", CaptureType::Text);
assert_ne!(p1, p2);
}
#[test]
fn differently_named_captured_texts_dont_match() {
- let p1 = PartialStep::text("xxx", "foo");
- let p2 = PartialStep::text("yyy", "foo");
+ let p1 = PartialStep::text("xxx", "foo", CaptureType::Text);
+ let p2 = PartialStep::text("yyy", "foo", CaptureType::Text);
assert_ne!(p1, p2);
}
#[test]
fn differently_captured_texts_dont_match() {
let p1 = PartialStep::uncaptured("foo");
- let p2 = PartialStep::text("xxx", "foo");
+ let p2 = PartialStep::text("xxx", "foo", CaptureType::Text);
assert_ne!(p1, p2);
}
}
@@ -254,6 +266,8 @@ impl StepSnippet {
#[cfg(test)]
mod test {
+ use crate::bindings::CaptureType;
+
use super::PartialStep;
#[test]
@@ -267,11 +281,12 @@ mod test {
#[test]
fn returns_text() {
- let p = PartialStep::text("xxx", "foo");
+ let p = PartialStep::text("xxx", "foo", crate::bindings::CaptureType::Text);
match p {
- PartialStep::CapturedText { name, text } => {
+ PartialStep::CapturedText { name, text, kind } => {
assert_eq!(name, "xxx");
assert_eq!(text, "foo");
+ assert_eq!(kind, CaptureType::Text);
}
_ => panic!("expected CapturedText: {:?}", p),
}