Skip to content

Commit

Permalink
Made $$ escape a single $ in a step method (fixed #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Apr 4, 2015
1 parent 48cd87c commit 300a669
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ private String camelCaseToReadableText( String camelCase ) {
}

public void addStepMethod( Method paramMethod, List<NamedArgument> arguments, InvocationMode mode ) {
StepModel stepModel = createStepModel( paramMethod, arguments, mode );
currentStep = stepModel;
writeStep( stepModel );
}

StepModel createStepModel( Method paramMethod, List<NamedArgument> arguments, InvocationMode mode ) {
StepModel stepModel = new StepModel();

Description description = paramMethod.getAnnotation( Description.class );
Expand All @@ -112,8 +118,7 @@ public void addStepMethod( Method paramMethod, List<NamedArgument> arguments, In
}

stepModel.setStatus( mode.toStepStatus() );
currentStep = stepModel;
writeStep( stepModel );
return stepModel;
}

private List<NamedArgument> filterHiddenArguments( List<NamedArgument> arguments, Annotation[][] parameterAnnotations ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public List<Word> buildFormattedWords() {
List<String> words = Splitter.on( ' ' ).splitToList( stepDescription );
for( int i = 0; i < words.size(); i++ ) {
String word = words.get( i );
if( word.startsWith( "$" ) ) {
if( word.equals( "$$" ) ) { // $$ escapes a single $
formattedWords.add( new Word( "$" ) );
} else if( word.startsWith( "$" ) ) {
int argEnd = findArgumentEnd( i, words );
formatArgument( formattedWords, argCount, word );
if( argEnd != -1 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static Object[][] formatterTestCases() {
{ "$or should not$", asList( false ), new NotFormatter(), "", "not" },
{ "$or not$", asList( false ), new NotFormatter(), "", "not" },
{ "$", asList( true ), null, "", "true" },
{ "$$ foo", asList( true ), null, "", "\\$ foo true" },
{ "$", asList( 5d ), new PrintfFormatter(), "%.2f", "5[.,]00" },
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,5 @@ public void abstract_steps_should_appear_in_the_report_model() throws Throwable
getScenario().finished();
StepModel step = getScenario().getModel().getFirstStepModelOfLastScenario();
assertThat( step.words.get( 0 ).getFormattedValue() ).isEqualTo( "abstract step" );

}

}

0 comments on commit 300a669

Please sign in to comment.