diff --git a/docs/stages.adoc b/docs/stages.adoc index 4270c209536..17af7b300a5 100644 --- a/docs/stages.adoc +++ b/docs/stages.adoc @@ -161,7 +161,7 @@ include::{sourcedir}/userguide/ExtendedVocabularyTest.java[tags=givenPunctuation This would generate the following report: ---- -Given a clean worksurface, a bowl and the ingredients +Given a clean worksurface, a bowl and the ingredients: an egg some milk the ingredient flour diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/impl/ScenarioModelBuilder.java b/jgiven-core/src/main/java/com/tngtech/jgiven/impl/ScenarioModelBuilder.java index fb60be0878f..274d4ddc0e0 100644 --- a/jgiven-core/src/main/java/com/tngtech/jgiven/impl/ScenarioModelBuilder.java +++ b/jgiven-core/src/main/java/com/tngtech/jgiven/impl/ScenarioModelBuilder.java @@ -171,10 +171,12 @@ private void addToFillerWords( String value ) { } private void addPunctuation( String value ) { - if ( fillerWords.isEmpty() ) { - addToFillerWords( value ); - } else { + if ( !fillerWords.isEmpty() ) { Iterables.getLast( fillerWords ).appendPunctuation( value ); + } else if ( currentStep != null ) { + currentStep.getLastWord().appendPunctuation( value ); + } else { + addToFillerWords( value ); } } diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/GivenTestStep.java b/jgiven-core/src/test/java/com/tngtech/jgiven/GivenTestStep.java index bd0468145d1..8ed1de1f0cc 100644 --- a/jgiven-core/src/test/java/com/tngtech/jgiven/GivenTestStep.java +++ b/jgiven-core/src/test/java/com/tngtech/jgiven/GivenTestStep.java @@ -190,9 +190,15 @@ public GivenTestStep comma() { return self(); } - @As("-") + @As(":") @FillerWord(punctuation = true) - public GivenTestStep hyphen() { + public GivenTestStep colon() { + return self(); + } + + @As(".") + @FillerWord(punctuation = true) + public GivenTestStep full_stop() { return self(); } diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/impl/ScenarioModelBuilderTest.java b/jgiven-core/src/test/java/com/tngtech/jgiven/impl/ScenarioModelBuilderTest.java index bd432edf89d..933787dedba 100644 --- a/jgiven-core/src/test/java/com/tngtech/jgiven/impl/ScenarioModelBuilderTest.java +++ b/jgiven-core/src/test/java/com/tngtech/jgiven/impl/ScenarioModelBuilderTest.java @@ -427,13 +427,14 @@ public void filler_words_can_be_used_for_punctuation() throws Throwable { } @Test - public void punctuation_can_be_used_at_the_start_of_a_sentence() throws Throwable { - startScenario( "Scenario with punctuation prefixing a sentence" ); - given().something() - .hyphen().something_else(); + public void punctuation_can_be_used_at_the_end_of_a_sentence() throws Throwable { + startScenario( "Scenario with punctuation at the end of a a sentence" ); + given().something().colon().and().something_else().full_stop(); getScenario().finished(); - StepModel step = getScenario().getScenarioCaseModel().getStep(1); - assertThat( step.getCompleteSentence() ).isEqualTo( "- something else" ); + StepModel firstStep = getScenario().getScenarioCaseModel().getFirstStep(); + StepModel secondStep = getScenario().getScenarioCaseModel().getStep( 1 ); + assertThat( firstStep.getCompleteSentence() ).isEqualTo( "Given something:" ); + assertThat( secondStep.getCompleteSentence() ).isEqualTo( "and something else." ); } @Test diff --git a/jgiven-examples/src/test/java/com/tngtech/jgiven/examples/userguide/ExtendedVocabularyTest.java b/jgiven-examples/src/test/java/com/tngtech/jgiven/examples/userguide/ExtendedVocabularyTest.java index c88e11596e2..a73029851e4 100644 --- a/jgiven-examples/src/test/java/com/tngtech/jgiven/examples/userguide/ExtendedVocabularyTest.java +++ b/jgiven-examples/src/test/java/com/tngtech/jgiven/examples/userguide/ExtendedVocabularyTest.java @@ -29,7 +29,7 @@ public void with_punctuation() { // tag::givenPunctuation[] - given().a().clean_worksurface().comma().a().bowl().and().the().ingredients() + given().a().clean_worksurface().comma().a().bowl().and().the().ingredients().colon() .an().egg() .some().milk() .the().ingredient( "flour" ); @@ -79,6 +79,12 @@ public SELF comma() { return self(); } + @As(":") + @FillerWord(punctuation = true) + public SELF colon() { + return self(); + } + // end::punctuation[] }