diff --git a/gherkin-checks-testkit/src/main/java/org/sonar/gherkin/checks/verifier/GherkinCheckVerifier.java b/gherkin-checks-testkit/src/main/java/org/sonar/gherkin/checks/verifier/GherkinCheckVerifier.java index 543df9e..01c9a12 100644 --- a/gherkin-checks-testkit/src/main/java/org/sonar/gherkin/checks/verifier/GherkinCheckVerifier.java +++ b/gherkin-checks-testkit/src/main/java/org/sonar/gherkin/checks/verifier/GherkinCheckVerifier.java @@ -56,18 +56,17 @@ public class GherkinCheckVerifier extends SubscriptionVisitorCheck { /** * Check issues + * Example: + *
+ * GherkinCheckVerifier.issues(new MyCheck(), myFile) + * .next().atLine(2).withMessage("This is message for line 2.") + * .next().atLine(3).withMessage("This is message for line 3.").withCost(2.) + * .next().atLine(8) + * .noMore(); + ** * @param check Check to test * @param file File to test - *
- * Example: - *
- * GherkinCheckVerifier.issues(new MyCheck(), myFile) - * .next().atLine(2).withMessage("This is message for line 2.") - * .next().atLine(3).withMessage("This is message for line 3.").withCost(2.) - * .next().atLine(8) - * .noMore(); - **/ public static CheckMessagesVerifier issues(GherkinCheck check, File file) { return issues(check, file, Charsets.UTF_8); @@ -123,7 +122,7 @@ public static void verify(GherkinCheck check, File file) { * @param charset Charset of the file to test. */ public static void verify(GherkinCheck check, File file, Charset charset) { - GherkinDocumentTree propertiesTree = (GherkinDocumentTree) GherkinParserBuilder.createParser(charset).parse(file); + GherkinDocumentTree propertiesTree = (GherkinDocumentTree) GherkinParserBuilder.createTestParser(charset).parse(file); GherkinVisitorContext context = new GherkinVisitorContext(propertiesTree, file); GherkinCheckVerifier checkVerifier = new GherkinCheckVerifier(); diff --git a/gherkin-checks-testkit/src/main/java/org/sonar/gherkin/checks/verifier/TreeCheckTest.java b/gherkin-checks-testkit/src/main/java/org/sonar/gherkin/checks/verifier/TreeCheckTest.java index 9f98f42..b7a2fe0 100644 --- a/gherkin-checks-testkit/src/main/java/org/sonar/gherkin/checks/verifier/TreeCheckTest.java +++ b/gherkin-checks-testkit/src/main/java/org/sonar/gherkin/checks/verifier/TreeCheckTest.java @@ -43,7 +43,7 @@ private TreeCheckTest() { public static Collection
For readability reasons, code should be properly indented
+For readability reasons, code should be properly indented.
Feature: my feature... Scenario: my scenario... diff --git a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/AllStepTypesInScenarioCheckTest.java b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/AllSemanticStepTypesInScenarioCheckTest.java similarity index 96% rename from gherkin-checks/src/test/java/org/sonar/gherkin/checks/AllStepTypesInScenarioCheckTest.java rename to gherkin-checks/src/test/java/org/sonar/gherkin/checks/AllSemanticStepTypesInScenarioCheckTest.java index 5715934..aabdfbd 100644 --- a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/AllStepTypesInScenarioCheckTest.java +++ b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/AllSemanticStepTypesInScenarioCheckTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.sonar.gherkin.checks.verifier.GherkinCheckVerifier; -public class AllStepTypesInScenarioCheckTest { +public class AllSemanticStepTypesInScenarioCheckTest { @Test public void test_without_background() { diff --git a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/DuplicatedFeatureNamesCheckTest.java b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/DuplicatedFeatureNamesCheckTest.java index 43b48e8..9a3d624 100644 --- a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/DuplicatedFeatureNamesCheckTest.java +++ b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/DuplicatedFeatureNamesCheckTest.java @@ -90,7 +90,7 @@ public void analyze_several_files() { private void scanFile(GherkinCheck check, String fileName) { GherkinDocumentTree gherkinDocument = (GherkinDocumentTree) GherkinParserBuilder - .createParser(Charsets.UTF_8) + .createTestParser(Charsets.UTF_8) .parse(getTestFile(fileName)); GherkinVisitorContext context = new GherkinVisitorContext(gherkinDocument, getTestFile(fileName)); diff --git a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/DuplicatedScenarioNamesCheckTest.java b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/DuplicatedScenarioNamesCheckTest.java index 5d259da..5ae2537 100644 --- a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/DuplicatedScenarioNamesCheckTest.java +++ b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/DuplicatedScenarioNamesCheckTest.java @@ -112,7 +112,7 @@ public void analyze_several_files() { private void scanFile(GherkinCheck check, String fileName) { GherkinDocumentTree gherkinDocument = (GherkinDocumentTree) GherkinParserBuilder - .createParser(Charsets.UTF_8) + .createTestParser(Charsets.UTF_8) .parse(getTestFile(fileName)); GherkinVisitorContext context = new GherkinVisitorContext(gherkinDocument, getTestFile(fileName)); diff --git a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/IndentationCheckTest.java b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/IndentationCheckTest.java index d390828..5e0044e 100644 --- a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/IndentationCheckTest.java +++ b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/IndentationCheckTest.java @@ -48,4 +48,10 @@ public void should_raise_some_issues_with_custom_parameter_value() { GherkinCheckVerifier.verify(check, CheckTestUtils.getTestFile("indentation/indentation-custom-ko.feature")); } + @Test + public void should_raise_some_issues_about_single_whitespace() { + IndentationCheck check = new IndentationCheck(); + GherkinCheckVerifier.verify(check, CheckTestUtils.getTestFile("indentation/indentation-single-whitespace.feature")); + } + } diff --git a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/SpellingCheckTest.java b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/SpellingCheckTest.java index e0079f1..d2c6529 100644 --- a/gherkin-checks/src/test/java/org/sonar/gherkin/checks/SpellingCheckTest.java +++ b/gherkin-checks/src/test/java/org/sonar/gherkin/checks/SpellingCheckTest.java @@ -27,12 +27,20 @@ public class SpellingCheckTest { @Test - public void should_find_some_spelling_mistakes_and_raise_some_issues() { + public void should_find_some_spelling_mistakes_and_raise_some_issues_default_en_US_language() { SpellingCheck check = new SpellingCheck(); check.setWordsToIgnore("blabla,toto"); GherkinCheckVerifier.verify(check, CheckTestUtils.getTestFile("spelling/spelling.feature")); } + @Test + public void should_find_some_spelling_mistakes_and_raise_some_issues_french() { + SpellingCheck check = new SpellingCheck(); + check.setWordsToIgnore("blabla,toto"); + check.setLanguage("fr"); + GherkinCheckVerifier.verify(check, CheckTestUtils.getTestFile("spelling/spelling-fr.feature")); + } + @Test public void should_not_find_any_spelling_mistake_because_some_spelling_rules_are_exclude() { SpellingCheck check = new SpellingCheck(); @@ -45,13 +53,16 @@ public void should_not_find_any_spelling_mistake_because_some_spelling_rules_are public void should_throw_an_illegal_state_exception_as_the_language_parameter_is_not_valid() { try { SpellingCheck check = new SpellingCheck(); - check.setLanguage("en_NZ"); + check.setLanguage("abc"); GherkinCheckVerifier.issues(check, CheckTestUtils.getTestFile("spelling/spelling.feature")).noMore(); } catch (IllegalStateException e) { assertThat(e.getMessage()).isEqualTo("Check gherkin:spelling (Spelling mistakes should be fixed): " - + "language parameter \"en_NZ\" is not valid. Allowed values are 'en_US' and 'en_GB'."); + + "language parameter \"abc\" is not valid. Allowed values are: ast-ES, be-BY, br-FR, ca-ES, ca-ES-valencia, " + + "da-DK, de, de-AT, de-CH, de-DE, de-DE-x-simple-language, el-GR, en, en-AU, en-CA, en-GB, en-NZ, en-US, " + + "en-ZA, eo, es, fa, fr, gl-ES, is-IS, it, ja-JP, km-KH, lt-LT, ml-IN, nl, pl-PL, pt, pt-BR, pt-PT, " + + "ro-RO, ru-RU, sk-SK, sl-SI, sv, ta-IN, tl-PH, uk-UA, zh-CN"); } } diff --git a/gherkin-checks/src/test/resources/checks/french.feature b/gherkin-checks/src/test/resources/checks/french.feature new file mode 100644 index 0000000..283cefd --- /dev/null +++ b/gherkin-checks/src/test/resources/checks/french.feature @@ -0,0 +1,16 @@ +# language: fr +Fonctionnalité: My feature french + Blabla... + + Scénario: My scenario 1 french + # Noncompliant [[sc=5;ec=7]] {{Replace this star prefix with one of the Given/When/Then prefixes.}} + * Blabla... + Lorsque Blabla when... + Alors Blabla then... + + Scénario: My scenario 2 french + Soit Blabla given... + # Noncompliant [[sc=5;ec=10]] {{Replace this redundant Given prefix with And or But.}} + Soit Blabla given... + Lorsque Blabla when... + Alors Blabla then... diff --git a/gherkin-checks/src/test/resources/checks/indentation/indentation-custom-ko.feature b/gherkin-checks/src/test/resources/checks/indentation/indentation-custom-ko.feature index bb70162..ca7c037 100644 --- a/gherkin-checks/src/test/resources/checks/indentation/indentation-custom-ko.feature +++ b/gherkin-checks/src/test/resources/checks/indentation/indentation-custom-ko.feature @@ -60,22 +60,19 @@ | 2 | - # Noncompliant [[sc=16;ec=50]] {{Indent this token at column 15 (currently indented at column 16).}} - Scenario: Scenario 3 - indentation custom KO + Scenario: Scenario 3 - indentation custom KO Blabla... Given Blabla given... When Blabla when Then Blabla then... - # Noncompliant [[sc=25;ec=59]] {{Indent this token at column 23 (currently indented at column 25).}} - Scenario Outline: Scenario 4 - indentation custom KO + Scenario Outline: Scenario 4 - indentation custom KO Blabla... Given Blabla given... When Blabla when... Then Blabla then... - # Noncompliant [[sc=20;ec=57]] {{Indent this token at column 19 (currently indented at column 20).}} - Examples: Blabla examples indentation custom KO + Examples: Blabla examples indentation custom KO | data | | 1 | | 2 | diff --git a/gherkin-checks/src/test/resources/checks/indentation/indentation-default-ko.feature b/gherkin-checks/src/test/resources/checks/indentation/indentation-default-ko.feature index 85dd1f5..3f9a296 100644 --- a/gherkin-checks/src/test/resources/checks/indentation/indentation-default-ko.feature +++ b/gherkin-checks/src/test/resources/checks/indentation/indentation-default-ko.feature @@ -2,7 +2,7 @@ @tag @abc # Noncompliant [[sc=3;ec=10]] {{Indent this token at column 1 (currently indented at column 3).}} - Feature: My feature indentation default KO + Feature: My feature indentation default KO # Noncompliant [[sc=5;ec=14]] {{Indent this token at column 3 (currently indented at column 5).}} Blabla... Blabla... @@ -12,7 +12,7 @@ # Noncompliant [[sc=3;ec=12]] {{Indent this token at column 5 (currently indented at column 3).}} Blabla... Blabla... - # Noncompliant [[sc=6;ec=11]] {{Indent this token at column 5 (currently indented at column 6).}} + # Noncompliant [[sc=6;ec=12]] {{Indent this token at column 5 (currently indented at column 6).}} Given Blabla given1... # Noncompliant [[sc=5;ec=6]] {{Indent this token at column 3 (currently indented at column 5).}} @@ -60,22 +60,19 @@ | 1 | | 2 | - # Noncompliant [[sc=14;ec=49]] {{Indent this token at column 13 (currently indented at column 14).}} - Scenario: Scenario 3 - indentation default KO + Scenario: Scenario 3 - indentation default KO Blabla... Given Blabla given... When Blabla when Then Blabla then... - # Noncompliant [[sc=23;ec=58]] {{Indent this token at column 21 (currently indented at column 23).}} - Scenario Outline: Scenario 4 - indentation default KO + Scenario Outline: Scenario 4 - indentation default KO Blabla... Given Blabla given... When Blabla when... Then Blabla then... - # Noncompliant [[sc=16;ec=54]] {{Indent this token at column 15 (currently indented at column 16).}} - Examples: Blabla examples indentation default KO + Examples: Blabla examples indentation default KO | data | | 1 | | 2 | diff --git a/gherkin-checks/src/test/resources/checks/indentation/indentation-single-whitespace.feature b/gherkin-checks/src/test/resources/checks/indentation/indentation-single-whitespace.feature new file mode 100644 index 0000000..ed7de2b --- /dev/null +++ b/gherkin-checks/src/test/resources/checks/indentation/indentation-single-whitespace.feature @@ -0,0 +1,40 @@ +# Noncompliant [[sc=11;ec=44;secondary=+0]] {{Leave one single whitespace between the name and the column.}} +Feature: My feature indentation default WS + Blabla... + Blabla... + + # Noncompliant [[sc=16;ec=56;secondary=+0]] {{Leave one single whitespace between the name and the column.}} + Background: Blabla background indentation default WS + Blabla... + Blabla... + Given Blabla given blabla... + + # Noncompliant [[sc=15;ec=48;secondary=+0]] {{Leave one single whitespace between the name and the column.}} + Scenario: Scenario 1 indentation default WS + Blabla... + Blabla... + Given Blabla given... + When Blabla when... + Then Blabla then... + + # Noncompliant [[sc=22;ec=55;secondary=+0]] {{Leave one single whitespace between the name and the column.}} + Scenario Outline: Scenario 2 indentation default WS + Blabla... + Blabla... + Given Blabla given... + When Blabla when... + | data | + | 2 | + Then Blabla then... + """string + Blabla... + Blabla... + """ + + # Noncompliant [[sc=16;ec=54;secondary=+0]] {{Leave one single whitespace between the name and the column.}} + Examples: Blabla examples indentation default WS + Blabla... + Blabla... + | data | + | 1 | + | 2 | diff --git a/gherkin-checks/src/test/resources/checks/spelling/spelling-fr.feature b/gherkin-checks/src/test/resources/checks/spelling/spelling-fr.feature new file mode 100644 index 0000000..8eded51 --- /dev/null +++ b/gherkin-checks/src/test/resources/checks/spelling/spelling-fr.feature @@ -0,0 +1,7 @@ +# Noncompliant [[sc=27;ec=32]] {{[HUNSPELL_NO_SUGGEST_RULE] Faute de frappe possible trouvée.}} +Feature: J'achète un joli veelo + + Scenario: Blabla est le nom de mon scénario + Given Je suis sur le catalogue + When J'ajoute un joli vélo dans mon panier + Then Je devrais voir un joli vélo dans mon panier diff --git a/gherkin-checks/src/test/resources/checks/star-step-prefix.feature b/gherkin-checks/src/test/resources/checks/star-step-prefix.feature index 698a3a1..345bfc6 100644 --- a/gherkin-checks/src/test/resources/checks/star-step-prefix.feature +++ b/gherkin-checks/src/test/resources/checks/star-step-prefix.feature @@ -2,7 +2,7 @@ Feature: My feature Star step prefix Blabla... Scenario: My scenario 1 - Star step prefix - # Noncompliant [[sc=5;ec=6]] {{Replace this star prefix with one of the Given/When/Then prefixes.}} + # Noncompliant [[sc=5;ec=7]] {{Replace this star prefix with one of the Given/When/Then prefixes.}} * Blabla... When Blabla when... Then Blabla then... diff --git a/gherkin-checks/src/test/resources/checks/step-of-unknown-type.feature b/gherkin-checks/src/test/resources/checks/step-of-unknown-type.feature index 07702d1..47db042 100644 --- a/gherkin-checks/src/test/resources/checks/step-of-unknown-type.feature +++ b/gherkin-checks/src/test/resources/checks/step-of-unknown-type.feature @@ -2,7 +2,7 @@ Feature: My feature Step of unknown type Blabla... Scenario: Scenario 1 Step of unknown type - # Noncompliant [[sc=5;ec=8]] {{Update the prefix of this unknown type step.}} + # Noncompliant [[sc=5;ec=9]] {{Update the prefix of this unknown type step.}} And I am a customer When I add a product to my cart Then I should see the product in my cart diff --git a/gherkin-checks/src/test/resources/checks/steps-right-order.feature b/gherkin-checks/src/test/resources/checks/steps-right-order.feature index 05af2a5..1519869 100644 --- a/gherkin-checks/src/test/resources/checks/steps-right-order.feature +++ b/gherkin-checks/src/test/resources/checks/steps-right-order.feature @@ -5,13 +5,13 @@ Feature: My feature Steps right order Given I am a customer When I add a product to my cart Then I should see the product in my cart - # Noncompliant [[sc=5;ec=9]] {{Unexpected When step. Reorder the steps of this scenario.}} + # Noncompliant [[sc=5;ec=10]] {{Unexpected When step. Reorder the steps of this scenario.}} When I proceed to the order payment Then I should see the order total amount Scenario Outline: Scenario 2 Steps right order Given I am a customer - # Noncompliant [[sc=5;ec=9]] {{Unexpected Then step. Reorder the steps of this scenario.}} + # Noncompliant [[sc=5;ec=10]] {{Unexpected Then step. Reorder the steps of this scenario.}} Then I should see the product in my cart And I should see the order total amount Examples: diff --git a/gherkin-checks/src/test/resources/checks/use-and-but.feature b/gherkin-checks/src/test/resources/checks/use-and-but.feature index 8cf9263..bb1ad99 100644 --- a/gherkin-checks/src/test/resources/checks/use-and-but.feature +++ b/gherkin-checks/src/test/resources/checks/use-and-but.feature @@ -3,14 +3,14 @@ Feature: My feature Use And But Scenario: Scenario 1 Use And But Given Blabla given1... - # Noncompliant [[sc=5;ec=10]] {{Replace this redundant Given prefix with And or But.}} + # Noncompliant [[sc=5;ec=11]] {{Replace this redundant Given prefix with And or But prefix.}} Given Blabla given2... When Blabla when... Then Blabla then... Scenario Outline: Scenario 2 Use And But Given Blabla given1... - # Noncompliant [[sc=5;ec=10]] {{Replace this redundant Given prefix with And or But.}} + # Noncompliant [[sc=5;ec=11]] {{Replace this redundant Given prefix with And or But prefix.}} Given Blabla given2... When Blabla when... Then Blabla then...@@ -23,7 +23,7 @@ Feature: My feature Use And But Given Blabla given... And Blabla... When Blabla when... - # Noncompliant [[sc=5;ec=9]] {{Replace this redundant When prefix with And or But.}} + # Noncompliant [[sc=5;ec=10]] {{Replace this redundant When prefix with And or But prefix.}} When Blabla when1... Then Blabla then... diff --git a/gherkin-frontend/pom.xml b/gherkin-frontend/pom.xml index d805fa9..5419b45 100644 --- a/gherkin-frontend/pom.xml +++ b/gherkin-frontend/pom.xml @@ -34,6 +34,10 @@ com.google.guava guava