summaryrefslogtreecommitdiff
path: root/src/steps.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-02-15 10:40:55 +0000
committerLars Wirzenius <liw@liw.fi>2020-02-15 10:40:55 +0000
commitf997af392d33f557d779af8b71fc782c2f105b23 (patch)
treefa86fc7f920f991de5d9cf7698ca20790aef8ae5 /src/steps.rs
parent62df0717e7087a051ec697b59b21feefaa27ece7 (diff)
parent3383d2689be3ddbe4ff7609d0f5e655f4d82745b (diff)
downloadsubplot-f997af392d33f557d779af8b71fc782c2f105b23.tar.gz
Merge branch 'liw/andbut' into 'master'
Add: add support for "and" and "but" keywords See merge request larswirzenius/subplot!3
Diffstat (limited to 'src/steps.rs')
-rw-r--r--src/steps.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/steps.rs b/src/steps.rs
index 66ab453..ccf7694 100644
--- a/src/steps.rs
+++ b/src/steps.rs
@@ -37,13 +37,18 @@ impl ScenarioStep {
}
/// Construct a step from a line in a scenario.
- pub fn new_from_str(text: &str) -> Result<ScenarioStep> {
+ ///
+ /// If the step uses the "and" or "but" keyword, use the default
+ /// step kind instead.
+ pub fn new_from_str(text: &str, default: StepKind) -> Result<ScenarioStep> {
let mut words = text.split_whitespace();
let kind = match words.next() {
Some("given") => StepKind::Given,
Some("when") => StepKind::When,
Some("then") => StepKind::Then,
+ Some("and") => default,
+ Some("but") => default,
_ => return Err(Error::UnknownStepKind),
};
@@ -99,28 +104,37 @@ mod test {
#[test]
fn parses_given() {
- let step = ScenarioStep::new_from_str("given I am Tomjon").unwrap();
+ let step = ScenarioStep::new_from_str("given I am Tomjon", StepKind::Then).unwrap();
assert_eq!(step.kind(), StepKind::Given);
assert_eq!(step.text(), "I am Tomjon");
}
#[test]
fn parses_given_with_extra_spaces() {
- let step = ScenarioStep::new_from_str(" given I am Tomjon ").unwrap();
+ let step =
+ ScenarioStep::new_from_str(" given I am Tomjon ", StepKind::When).unwrap();
assert_eq!(step.kind(), StepKind::Given);
assert_eq!(step.text(), "I am Tomjon");
}
#[test]
fn parses_when() {
- let step = ScenarioStep::new_from_str("when I declare myself king").unwrap();
+ let step =
+ ScenarioStep::new_from_str("when I declare myself king", StepKind::Given).unwrap();
assert_eq!(step.kind(), StepKind::When);
assert_eq!(step.text(), "I declare myself king");
}
#[test]
fn parses_then() {
- let step = ScenarioStep::new_from_str("then everyone accepts it").unwrap();
+ let step = ScenarioStep::new_from_str("then everyone accepts it", StepKind::Given).unwrap();
+ assert_eq!(step.kind(), StepKind::Then);
+ assert_eq!(step.text(), "everyone accepts it");
+ }
+
+ #[test]
+ fn parses_and() {
+ let step = ScenarioStep::new_from_str("and everyone accepts it", StepKind::Then).unwrap();
assert_eq!(step.kind(), StepKind::Then);
assert_eq!(step.text(), "everyone accepts it");
}