Acceptance criteria are only useful if they are well-formed. Validate one scenario written in Given/When/Then style.
Read lines until the end of input. Ignore empty lines and a first line starting with Scenario:. Every other line (after trimming) must start with one of the keywords Given, When, Then, And, But followed by a space. The rules:
- The steps must follow the order Given* → When+ → Then+ (zero or more Given, then at least one When, then at least one Then).
And/Butcontinue the previous keyword (they are not allowed as the first step). - After a
Then, a newGivenorWhenis not allowed.
Report problems with the (1-based) line number counted over all input lines, in this form, stopping at the first problem:
Line k: unknown keyword— the line does not start with a valid keywordLine k: And/But cannot start a scenarioLine k: Given after When/Line k: Given after Then/Line k: When after ThenLine k: Then before When
If no line is wrong, check the end: no When → Missing When; no Then → Missing Then. If everything is fine print VALID (g Given, w When, t Then, a And/But).
Input:
Scenario: matching
Given Ana is in CPS 4301
And Ben is in CPS 4301
When Ana opens Find partners
Then Ben is listed
Output:
VALID (1 Given, 1 When, 1 Then, 1 And/But)