Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the feature keyword issue #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/regex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
globalMatch: {
feature: /(?<!\S)Feature:/g,
feature: /(?<!\S)(?:^| )Feature:/gm,
Copy link
Member

@saw-jan saw-jan Jul 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the regex will match with the following:

   some text Feature: description

Also add a test for this case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SagarGi Also, add test for the tabs

<tab><tab>Feature: description

beginningStep:
/(?<=(Background:|Scenario( (Outline|Template))?:|Example:)(.*)[\n\r](\s)*)(Given|When|Then|And|But)(?= )/g,
docString: /"""[\s\S]*?"""/g,
Expand Down
19 changes: 6 additions & 13 deletions server/tests/unit/rules/only_one_feature.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ const testCases = [
['Feature: - Feature:', 'Feature: Feature name\nFeature:', [buildLintInfo(22, 30)]],
['Feature: - Feature Description', 'Feature: Feature name\n Feature Description', []],
['Feature: - feature: Description', 'Feature: Feature name\n feature: Description', []],
['Feature: - Feature: Description', 'Feature: Feature name\n Feature: Description', [buildLintInfo(26, 34)]],
['Feature: - Feature: Description', 'Feature: Feature name\n Feature: Description', [buildLintInfo(25, 34)]],
['Tag - Feature:', '@tag\nFeature: Feature name', []],
['MultipleTags - Feature:', '@tag1\n@tag2 @tag3 @tag4\nFeature: Feature name', []],
['Feature: - Background: - Feature:', 'Feature: Feature name\n Feature Description\n\n Background: Background name\n Given a step\n\nFeature:\n', [buildLintInfo(101, 109)]],
['Feature: - Scenario: - Feature:', 'Feature: Feature name\n Feature Description\n\n Scenario: Scenario name\n Given a step\n\nFeature:\n', [buildLintInfo(97, 105)]],
['Feature: - Scenario Outline: - Feature:', 'Feature: Feature name\n Feature Description\n\n Scenario Outline: Scenario Outline name\n\nFeature:\n', [buildLintInfo(96, 104)]],
['Feature: - Background: - Scenario: - Scenario Outline: - Feature:', 'Feature: Feature name\n Feature Description\n Background: Background name\n Scenario: Scenario name\n Scenario Outline: Scenario Outline name \nFeature:\n', [buildLintInfo(152, 160)]],

['Feature: - Feature: as text', 'Feature: Feature name\n This is Feature: description\n', []],
['Comment with Feature: - Feature:', '# comment Feature: section\nFeature: Feature name\n', []],
['Multiple Feature: - Feature: as text', 'Feature: Feature 1 Description\nFeature: Feature 2 Description\nFeature: Feature 3 Description\n This is a Feature: description\n', [buildLintInfo(31, 39),buildLintInfo(62, 70)]],
['Multiple Feature: - Multiple Feature: as text', '# There should be only one Feature: keyword \nFeature: Feature 1 Description\nFeature: Feature 2 Description\nFeature: Feature 3 Description\n This is a Feature: description1\n This is a Feature: description2\n', [buildLintInfo(76, 84),buildLintInfo(107, 115)]],
['Feature: - Whitespace Feature: - Feature: as text', 'Feature: Feature 1 Description\n Feature: Feature 2 Description\n This is a Feature: description\n', [buildLintInfo(34, 43)]],
];

describe('Rule: Feature file must have only one feature keyword ', function () {
Expand All @@ -25,17 +29,6 @@ describe('Rule: Feature file must have only one feature keyword ', function () {
});
});

// This test needs to be passed but is failing while linting
// This test case can be added to above testscases after the following issue has been solved
// https://github.com/gherlint/gherlint-vscode/issues/16
describe('Tests expected to pass but failing ', function () {
test.failing('Feature: as a text but not keyword', () => {
const problems = Rule.run('Feature: Feature name\n This Feature: is not a keyword');
const expected = []
assert.deepEqual(problems, expected);
});
});

function buildLintInfo(startIndex, endIndex) {
return {
startIndex,
Expand Down