diff --git a/pkg/core/src/parser.ts b/pkg/core/src/parser.ts index e4314b32..f9aa2dbc 100644 --- a/pkg/core/src/parser.ts +++ b/pkg/core/src/parser.ts @@ -220,12 +220,17 @@ export const parse = (p: PluginMap, t: Token[], lineNo: number): Cst => { errors: [], }; let givenThen: 'given' | 'then' | undefined; + let openConnect: 'open' | 'connect' | undefined; if (t[0]) { if (t[0].name != 'given' && t[0].name != 'then') cst.errors.push({ message: ParseError.wrong(t[0], 'given', 'then'), lineNo, start: t[0].start, end: t[0].end }); else givenThen = t[0].name; if (t[1]) { if (t[1].raw !== 'I') cst.errors.push({message: ParseError.wrong(t[1], 'I'), lineNo, start: t[1].start, end: t[1].end}); + if (t[2]) { + if (t[2].raw == 'open') openConnect = 'open'; + else if (t[2].raw == 'connect') openConnect = 'connect'; + } } else cst.errors.push({ message: ParseError.missing(t[0], 'I'), lineNo, start: t[0].start, end: t[0].end}); } else { cst.errors.push({ message: ParseError.missing(lineNo, 'Given I', 'Then I'), lineNo}); @@ -246,6 +251,9 @@ export const parse = (p: PluginMap, t: Token[], lineNo: number): Cst => { if (curErrLen !== undefined && m.err.length > curErrLen) throw lemmeout; }; try { + // check open and connect statement only against the correct statements + if(openConnect && (openConnect !== k.openconnect)) throw lemmeout; + // Open 'ident' and|Connect to 'ident' and if (k.openconnect === 'open') { if (t[++i]?.name !== 'open') newErr(i, 'open'); diff --git a/pkg/core/test/parser.ts b/pkg/core/test/parser.ts index 53fed4cd..b90dc5ef 100644 --- a/pkg/core/test/parser.ts +++ b/pkg/core/test/parser.ts @@ -601,6 +601,33 @@ test('parser works', (t) => { }, ], }, + "Given I connect to": { + givenThen: 'given', + errors: [], + matches: [ + { + key: { + openconnect: 'connect', + phrase: 'send http request', + params: ['object'], + }, + bindings: new Map(), + err: [ + {message: ParseError.missing(new Token('to', 1, 16, 17), '\'\''), lineNo: 1}, + {message: ParseError.missing(1, 'and'), lineNo: 1}, + {message: ParseError.missing(1, 'send'), lineNo: 1}, + {message: ParseError.missing(1, 'object'), lineNo: 1}, + {message: ParseError.missing(1, '\'\''), lineNo: 1}, + {message: ParseError.missing(1, 'and'), lineNo: 1}, + {message: ParseError.missing(1, 'send'), lineNo: 1}, + {message: ParseError.missing(1, 'http'), lineNo: 1}, + {message: ParseError.missing(1, 'request'), lineNo: 1}, + + ], + lineNo: 1, + }, + ], + }, }).forEach(([give, want], index) => { const lexed = lex(give, 1); if (!lexed.ok) throw new Error(lexed.error.message.message);