Skip to content

Commit

Permalink
Added scenarios outline basic support
Browse files Browse the repository at this point in the history
  • Loading branch information
silversonicaxel committed Mar 26, 2019
1 parent ef7646e commit 39b1689
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
56 changes: 55 additions & 1 deletion src/class/analyzer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ describe('#Analyzer', () => {
'Scenario Outline: Scenario Outline Feature with <a> and <b>',
'Given an initial state is set',
'When an action is taken',
'Then an outcome happens'
'Then an outcome happens',
'Examples',
'| a | b |',
'| 1 | 2 |',
'| 4 | 3 |'
],
features: [
'Extension Feature'
Expand Down Expand Up @@ -77,6 +81,8 @@ describe('#Analyzer', () => {
const getValidStateStub = sandboxSet.stub(analyzer, 'getValidState');
const getValidActionStub = sandboxSet.stub(analyzer, 'getValidAction');
const getValidOutcomeStub = sandboxSet.stub(analyzer, 'getValidOutcome');
const getValidExampleTitleStub = sandboxSet.stub(analyzer, 'getValidExampleTitle');
const getValidExampleDataStub = sandboxSet.stub(analyzer, 'getValidExampleData');

analyzer.getGherkins(gherkin);

Expand All @@ -86,6 +92,8 @@ describe('#Analyzer', () => {
assert.calledWith(getValidStateStub);
assert.calledWith(getValidActionStub);
assert.calledWith(getValidOutcomeStub);
assert.calledWith(getValidExampleTitleStub);
assert.calledWith(getValidExampleDataStub);
});
});

Expand Down Expand Up @@ -268,4 +276,50 @@ describe('#Analyzer', () => {
expect(expectedOutcome).to.be.deep.equal(null);
});
});

describe('#getValidExampleTitle', () => {
it('should return a valid example title', () => {
const validExampleTitle = 'Examples';

const expectedValidExampleTitle = analyzer['getValidExampleTitle'](validExampleTitle);

expect(expectedValidExampleTitle).to.be.not.equal('');
expect(expectedValidExampleTitle).to.be.deep.equal(validExampleTitle);
});

it('should return nothing', () => {
const invalidExampleTitle = 'Wrong';

const expectedValidExampleTitle = analyzer['getValidExampleTitle'](invalidExampleTitle);

expect(expectedValidExampleTitle).to.be.deep.equal(null);
});
});

describe('#getValidExampleData', () => {
it('should return a valid example data', () => {
const validExampleData = `|A|B|`;

const expectedValidExampleData = analyzer['getValidExampleData'](validExampleData, 'example');

expect(expectedValidExampleData).to.be.not.equal('');
expect(expectedValidExampleData).to.be.deep.equal(validExampleData);
});

it('should return nothing due to invalid example data', () => {
const invalidExampleData = 'Wrong';

const expectedValidExampleData = analyzer['getValidExampleData'](invalidExampleData, 'example');

expect(expectedValidExampleData).to.be.deep.equal(null);
});

it('should return nothing due to invalid previous read line', () => {
const validExampleData = `|A|B|`;

const expectedValidExampleData = analyzer['getValidExampleData'](validExampleData, 'state');

expect(expectedValidExampleData).to.be.deep.equal(null);
});
});
});
19 changes: 19 additions & 0 deletions src/class/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export class Analyzer {
private actionRegExp = new RegExp('^(when)+[:]?', 'i');
private outcomeRegExp = new RegExp('^(then)+[:]?', 'i');
private glueRegExp = new RegExp('^(and|but)+[:]?', 'i');
private examplesTitleRegExp = new RegExp('^(examples|example)', 'i');
private examplesDataRegExp = new RegExp('^[|]', 'i');

getGherkins(listRows: string[]): any {
const features: string[] = [];
Expand Down Expand Up @@ -36,6 +38,10 @@ export class Analyzer {
} else if (rowAnalyzed = this.getValidOutcome(listRow, currentReadRow)) {
outcomes.push(rowAnalyzed);
currentReadRow = 'outcome';
} else if (rowAnalyzed = this.getValidExampleTitle(listRow)) {
currentReadRow = 'example';
} else if (rowAnalyzed = this.getValidExampleData(listRow, currentReadRow)) {
currentReadRow = 'example';
} else {
continue;
}
Expand Down Expand Up @@ -75,4 +81,17 @@ export class Analyzer {
const listRowToAnalyze = previousRow === 'outcome' ? this.glueRegExp.exec(listRow) : this.outcomeRegExp.exec(listRow);
return listRowToAnalyze ? listRow.replace(listRowToAnalyze[0], '').trim() : null;
}

private getValidExampleTitle(listRow: string): string | null {
const listRowToAnalyze = this.examplesTitleRegExp.exec(listRow);
return listRowToAnalyze ? listRowToAnalyze[0].trim() : null;
}

private getValidExampleData(listRow: string, previousRow: string): string | null {
if (previousRow === 'example') {
const listRowToAnalyze = this.examplesDataRegExp.exec(listRow);
return listRowToAnalyze ? listRow.trim() : null;
}
return null;
}
}

0 comments on commit 39b1689

Please sign in to comment.