Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for hex color codes in locale
- Loading branch information
Showing
11 changed files
with
176 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/test/java/com/gmail/nossr50/locale/LocaleLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.gmail.nossr50.locale; | ||
|
||
import org.bukkit.ChatColor; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class LocaleLoaderTest { | ||
|
||
@BeforeEach | ||
void setUp() { | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"§cTest", "[[RED]]Test"}) | ||
void addColorsShouldAddColorRed(String testString) { | ||
// When | ||
final String result = LocaleLoader.addColors(testString); | ||
|
||
// Then | ||
assertThat(result).isEqualTo(ChatColor.RED + "Test"); | ||
} | ||
|
||
// hex colors test | ||
@Test | ||
void translateHexColorCodesShouldAddRed() { | ||
// Given | ||
final String testString = "&#FF0000Test"; | ||
|
||
// When | ||
final String result = LocaleLoader.translateHexColorCodes(testString); | ||
|
||
// Then | ||
final String expectedResult = "§x§F§F§0§0§0§0Test"; | ||
assertThat(result).isEqualTo(expectedResult); | ||
} | ||
|
||
@Test | ||
void reverseTranslateHexColorCodesShouldRemoveRed() { | ||
// Given | ||
final String testString = "§x§F§F§0§0§0§0Test"; | ||
|
||
// When | ||
final String result = LocaleLoader.reverseTranslateHexColorCodes(testString); | ||
|
||
// Then | ||
final String expectedResult = "&#FF0000Test"; | ||
assertThat(result).isEqualTo(expectedResult); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"&#FF0000Te�FFst", "&#FF0000Te[[RED]]st", "[[BLUE]]Te[[RED]]st", "§9Te§cst"}) | ||
void addColorsShouldAddRedAndBlue(String testString) { | ||
// When | ||
final String result = LocaleLoader.addColors(testString); | ||
|
||
// TODO: Hacky, clean this up sometime in the future | ||
// Then | ||
// All legal representations of the same string | ||
final List<String> expectedResults = List.of("§x§F§F§0§0§0§0Te§x§0§0§0§0§F§Fst", | ||
"§x§F§F§0§0§0§0Te§x§0§0§0§0§F§Fst", | ||
"§x§F§F§0§0§0§0Te§cst", | ||
"§9Te§cst"); | ||
assertThat(expectedResults).contains(result); | ||
} | ||
} |