Skip to content

Commit

Permalink
Fix #64 FP on rule unused-variable: Variable in doc string not recogn…
Browse files Browse the repository at this point in the history
…ized
  • Loading branch information
racodond committed Dec 12, 2017
1 parent 3e52f73 commit 5cbdfff
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private void checkUnusedDataTableColumn(ExamplesTree examples, Set<String> allVa
"Remove the following unused variable" + (unusedVariables.size() > 1 ? "s" : "") + ": "
+ unusedVariables.stream().sorted().collect(Collectors.joining(", ")));
}

}

}
23 changes: 23 additions & 0 deletions gherkin-checks/src/test/resources/checks/unused-variable.feature
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,26 @@ Feature: My feature Unused variable
| number |
| 1 |
| 2 |

Scenario Outline: Scenario 6 Unused variable
Given Blabla given...
"""
Blabla...
Blabla... <number> blabla...
"""
When Blabla when...
Then Blabla then...
# Noncompliant [[sc=5;ec=13]] {{Remove the following unused variable: type}}
Examples:
| number | type |
| 1 | bike |
| 2 | book |
# Noncompliant [[sc=5;ec=13]] {{Remove the following unused variable: bbbb}}
Examples:
| number | bbbb |
| 1 | bike |
| 2 | book |
Examples:
| number |
| 1 |
| 2 |
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ private void initVariables() {
if (table != null) {
table.rows().stream().map(SyntaxToken::text).forEach(this::addVariablesFromText);
}

if (docString != null) {
docString.data().stream().map(SyntaxToken::text).forEach(this::addVariablesFromText);
}
}

private void addVariablesFromText(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public void step() throws Exception {
assertThat(tree.variables().contains("ghi")).isTrue();
assertThat(tree.variables().contains("zzz")).isFalse();

tree = checkParsed("Given blabla...\n" +
" \"\"\"\n" +
" {\n" +
" \"code\":\"79365\",\n" +
" \"price\":<value>\n" +
" }\n" +
" \"\"\"",
"Given ", "blabla...");
assertThat(tree.variables()).hasSize(1);
assertThat(tree.variables().contains("value")).isTrue();

checkParsed("Given I am a customer", "Given ", " I am a customer");
}

Expand Down
23 changes: 23 additions & 0 deletions its/ruling/projects/custom/unused-variable.feature
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,26 @@ Feature: My feature Unused variable
| number |
| 1 |
| 2 |

Scenario Outline: Scenario 6 Unused variable
Given Blabla given...
"""
Blabla...
Blabla... <number> blabla...
"""
When Blabla when...
Then Blabla then...
# Noncompliant [[sc=5;ec=13]] {{Remove the following unused variable: type}}
Examples:
| number | type |
| 1 | bike |
| 2 | book |
# Noncompliant [[sc=5;ec=13]] {{Remove the following unused variable: bbbb}}
Examples:
| number | bbbb |
| 1 | bike |
| 2 | book |
Examples:
| number |
| 1 |
| 2 |
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
49,
83,
88,
106,
111,
],
}

0 comments on commit 5cbdfff

Please sign in to comment.