From 92bcda8f2dcdb6454f71a74c529c13b148835c1f Mon Sep 17 00:00:00 2001 From: filoghost Date: Wed, 28 Apr 2021 23:42:10 +0200 Subject: [PATCH] Fix non-replaced placeholders and add test case --- .../placeholder/parsing/StringWithPlaceholders.java | 3 +-- .../placeholder/parsing/StringWithPlaceholdersTest.java | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/parsing/StringWithPlaceholders.java b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/parsing/StringWithPlaceholders.java index 37c1570b..24ea06ad 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/parsing/StringWithPlaceholders.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/placeholder/parsing/StringWithPlaceholders.java @@ -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) diff --git a/plugin/src/test/java/me/filoghost/holographicdisplays/placeholder/parsing/StringWithPlaceholdersTest.java b/plugin/src/test/java/me/filoghost/holographicdisplays/placeholder/parsing/StringWithPlaceholdersTest.java index d4029f51..9d089aa4 100644 --- a/plugin/src/test/java/me/filoghost/holographicdisplays/placeholder/parsing/StringWithPlaceholdersTest.java +++ b/plugin/src/test/java/me/filoghost/holographicdisplays/placeholder/parsing/StringWithPlaceholdersTest.java @@ -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")