Skip to content

Commit

Permalink
Add support for 4 non-positional attributes
Browse files Browse the repository at this point in the history
 - adds tests
 - fixes #1611
  • Loading branch information
iBotPeaches committed Sep 19, 2017
1 parent f0f87c8 commit bc00cce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ public static String encodeAsXmlValue(String str) {
}

public static boolean hasMultipleNonPositionalSubstitutions(String str) {
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 3);
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 4);
return ! tuple.m1.isEmpty() && tuple.m1.size() + tuple.m2.size() > 1;
}

public static String enumerateNonPositionalSubstitutionsIfRequired(String str) {
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 3);
Duo<List<Integer>, List<Integer>> tuple = findSubstitutions(str, 4);
if (tuple.m1.isEmpty() || tuple.m1.size() + tuple.m2.size() < 2) {
return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public void threePositionalArgumentsTest() {
assertEquals(" %1$s, %2$s and %3$d other", enumerateArguments(" %1$s, %2$s and %3$d other"));
}

@Test
public void fourArgumentsTest() {
assertEquals("%1$s, %2$s, and %3$d other and %4$d.", enumerateArguments("%s, %s, and %d other and %d."));
}

@Test
public void fourPositionalArgumentsTest() {
assertEquals(" %1$s, %2$s and %3$d other and %4$d.", enumerateArguments(" %1$s, %2$s and %3$d other and %4$d."));
}

private String enumerateArguments(String value) {
return ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(value);
}
Expand Down

0 comments on commit bc00cce

Please sign in to comment.