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 /src | |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/error.rs | 4 | ||||
-rw-r--r-- | src/steps.rs | 6 |
2 files changed, 9 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"); } |