mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-19 07:17:37 +01:00
Fix non-replaced placeholders and add test case
This commit is contained in:
parent
ff77738a51
commit
92bcda8f2d
@ -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)
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user