Fix non-replaced placeholders and add test case

This commit is contained in:
filoghost 2021-04-28 23:42:10 +02:00
parent ff77738a51
commit 92bcda8f2d
2 changed files with 9 additions and 2 deletions

View File

@ -51,12 +51,11 @@ public class StringWithPlaceholders {
if (replacement != null) {
// Append placeholder replacement
output.append(replacement);
lastAppendIndex = match.endIndex;
} else {
// If no replacement is provided, do not replace the occurrence
output.append(match.unparsedString);
}
lastAppendIndex = match.endIndex;
}
// Append trailing text (if any)

View File

@ -5,6 +5,7 @@
*/
package me.filoghost.holographicdisplays.placeholder.parsing;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ -33,6 +34,13 @@ class StringWithPlaceholdersTest {
Arguments.of("abc p}", "abc p}") // Placeholder without opening tag
);
}
@Test
void skipReplacing() {
String input = "{p} a {p} b {p}";
StringWithPlaceholders s = new StringWithPlaceholders(input);
assertThat(s.replacePlaceholders(occurrence -> null)).isEqualTo(input);
}
@ParameterizedTest(name = "[{index}] {0} -> {1}, {2}, {3}")
@MethodSource("parsingTestArguments")