Skip to content

Commit

Permalink
Complete implementation of feature #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Lindgren committed Apr 13, 2017
1 parent 3837f43 commit db8666d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ private boolean isDefaultDelimiter(String numbers) {
}

private String getDelimiter(String numbers) {
Pattern pattern = Pattern.compile("//(.)");
Pattern pattern = Pattern.compile("//\\[?(.*?)\\]?\n");
Matcher matcher = pattern.matcher(numbers);

if(matcher.find()) {
return matcher.group(1);
return "\\Q" +matcher.group(1) +"\\E";
}

return DEFAULT_DELIMITER;
Expand Down
13 changes: 7 additions & 6 deletions src/test/groovy/StringCalculatorTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class StringCalculatorTest extends Specification {
stringCalculator.add(NUMBERS) == SUM

where:
NUMBERS | SUM
'' | 0
'1' | 1
'1,2' | 3
'1\n2,3' | 6
'//;\n1;2' | 3
NUMBERS | SUM
'' | 0
'1' | 1
'1,2' | 3
'1\n2,3' | 6
'//;\n1;2' | 3
'//[***]\n1***2***3' | 6
}

def "should throw exception for negative numbers"() {
Expand Down

0 comments on commit db8666d

Please sign in to comment.