Skip to content

Commit

Permalink
Punctuation can now be added to the end of a sentence
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Stowe committed Jun 18, 2020
1 parent d0f5029 commit 0275d20
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/stages.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down
10 changes: 8 additions & 2 deletions jgiven-core/src/test/java/com/tngtech/jgiven/GivenTestStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -79,6 +79,12 @@ public SELF comma() {
return self();
}

@As(":")
@FillerWord(punctuation = true)
public SELF colon() {
return self();
}

// end::punctuation[]

}
Expand Down

0 comments on commit 0275d20

Please sign in to comment.