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) { if (replacement != null) {
// Append placeholder replacement // Append placeholder replacement
output.append(replacement); output.append(replacement);
lastAppendIndex = match.endIndex;
} else { } else {
// If no replacement is provided, do not replace the occurrence // If no replacement is provided, do not replace the occurrence
output.append(match.unparsedString); output.append(match.unparsedString);
} }
lastAppendIndex = match.endIndex;
} }
// Append trailing text (if any) // Append trailing text (if any)

View File

@ -5,6 +5,7 @@
*/ */
package me.filoghost.holographicdisplays.placeholder.parsing; package me.filoghost.holographicdisplays.placeholder.parsing;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
@ -34,6 +35,13 @@ class StringWithPlaceholdersTest {
); );
} }
@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}") @ParameterizedTest(name = "[{index}] {0} -> {1}, {2}, {3}")
@MethodSource("parsingTestArguments") @MethodSource("parsingTestArguments")
void parsing(String input, String expectedPluginName, String expectedIdentifier, String expectedArgument) { void parsing(String input, String expectedPluginName, String expectedIdentifier, String expectedArgument) {