diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-06-07 18:24:54 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-06-07 18:24:54 +0300 |
commit | 21beb119ed2a8a1dcf1dfc8b6bd91d3ba46b10af (patch) | |
tree | 99cdb46451ea07079f279488f11783a794306055 | |
parent | ff61617ca720750cda810d16275485e973068af5 (diff) | |
download | subplot-21beb119ed2a8a1dcf1dfc8b6bd91d3ba46b10af.tar.gz |
feat! don't allow indented scenario steps
Some day we will have syntax for continuing a step to the next line.
This change makes it easier to introduce that syntax, without a
breaking change.
Sponsored-by: author
-rw-r--r-- | src/error.rs | 4 | ||||
-rw-r--r-- | src/steps.rs | 6 | ||||
-rw-r--r-- | subplot.md | 36 |
3 files changed, 45 insertions, 1 deletions
diff --git a/src/error.rs b/src/error.rs index db85e83..93a828a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,6 +10,10 @@ use thiserror::Error; /// Define all the kinds of errors any part of this crate can return. #[derive(Debug, Error)] pub enum SubplotError { + /// Scenario step does not start at the beginning of the line. + #[error("Scenario step is indented: {0}")] + NotAtBoln(String), + /// Document has non-fatal errors. #[error("Document has {0} warnings.")] Warnings(usize), diff --git a/src/steps.rs b/src/steps.rs index b0a15e9..1005ad8 100644 --- a/src/steps.rs +++ b/src/steps.rs @@ -51,6 +51,10 @@ impl ScenarioStep { text: &str, default: Option<StepKind>, ) -> Result<ScenarioStep, SubplotError> { + if text.trim_start() != text { + return Err(SubplotError::NotAtBoln(text.into())); + } + let mut words = text.split_whitespace(); let keyword = match words.next() { @@ -126,7 +130,7 @@ mod test { #[test] fn parses_given_with_extra_spaces() { - let step = ScenarioStep::new_from_str(" given I am Tomjon ", None).unwrap(); + let step = ScenarioStep::new_from_str("given I am Tomjon ", None).unwrap(); assert_eq!(step.kind(), StepKind::Given); assert_eq!(step.text(), "I am Tomjon"); } @@ -1059,6 +1059,42 @@ and step "then bar was done" was run and command is successful ~~~ +## Indented scenario steps are not allowed + +_Requirement: A scenario step starts at the beginning of the line._ + +Justification: We may want to allow continuing a step to the next +line, but as of June, 2023, we haven't settled on a syntax for this. +However, whatever syntax we do eventually choose, it will be easier +to add that if scenario steps start at the beginning of a line, +without making a breaking change. + +~~~scenario +given file indented-step.subplot +given file indented-step.md +given file b.yaml +given an installed subplot +when I try to run subplot docgen indented-step.subplot -o foo.html +then command fails +and stderr contains "indented" +~~~ + +~~~{#indented-step.subplot .file .yaml .numberLines} +title: Indented scenario step +markdowns: + - indented-step.md +bindings: + - b.yaml +~~~ + +~~~~~~{#indented-step.md .file .markdown .numberLines} +# This is a title + +~~~scenario + given precondition +~~~ +~~~~~~ + ## No scenarios means codegen fails If you attempt to `subplot codegen` on a document which contains no scenarios, the |