summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorHex <hex@hex.lc>2018-07-17 16:42:30 -0600
committermd_5 <git@md-5.net>2018-07-18 09:36:16 +1000
commitd480dc74e5a6693695166ab2d53e80616ff56bb5 (patch)
tree6068454d2f14d596d2cfe0453d69d8bb69560b71 /src/test
parenta71d06a0c8426f7d1d23f9e76ea6cdf47b666db5 (diff)
downloadcraftbukkit-d480dc74e5a6693695166ab2d53e80616ff56bb5.tar
craftbukkit-d480dc74e5a6693695166ab2d53e80616ff56bb5.tar.gz
craftbukkit-d480dc74e5a6693695166ab2d53e80616ff56bb5.tar.lz
craftbukkit-d480dc74e5a6693695166ab2d53e80616ff56bb5.tar.xz
craftbukkit-d480dc74e5a6693695166ab2d53e80616ff56bb5.zip
SPIGOT-4035: Enforce case-sensitivity for chat format code matching.
This maintains case-insensitivity for URL matching, and adds a unit test to verify correct conversion via CraftChatMessage.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/bukkit/ChatTest.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/java/org/bukkit/ChatTest.java b/src/test/java/org/bukkit/ChatTest.java
index 444ce6eb..41c4b045 100644
--- a/src/test/java/org/bukkit/ChatTest.java
+++ b/src/test/java/org/bukkit/ChatTest.java
@@ -1,10 +1,13 @@
package org.bukkit;
import net.minecraft.server.EnumChatFormat;
+import net.minecraft.server.IChatBaseComponent;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class ChatTest {
@Test
@@ -19,4 +22,28 @@ public class ChatTest {
Assert.assertEquals(format, CraftChatMessage.getColor(CraftChatMessage.getColor(format)));
}
}
+
+ @Test
+ public void testColorConversion() {
+ String test = String.format("%1$sA%1$sa%1$sB%1$sb%1$sC%1$sc%1$sD%1$sd%1$sE%1$se%1$sZ%1$sz%1$s", ChatColor.COLOR_CHAR);
+ IChatBaseComponent name = CraftChatMessage.fromStringOrNull(test);
+ assertEquals(test.replace(String.valueOf(ChatColor.COLOR_CHAR), ""),
+ CraftChatMessage.fromComponent(name).replace(String.valueOf(ChatColor.COLOR_CHAR), ""));
+ }
+
+ @Test
+ public void testURLJsonConversion() {
+ IChatBaseComponent[] components;
+ components = CraftChatMessage.fromString("https://spigotmc.org/test Test Message");
+ assertEquals("TextComponent{text='', siblings=[TextComponent{text='https://spigotmc.org/test', siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=ClickEvent{action=OPEN_URL, value='https://spigotmc.org/test'}, hoverEvent=null, insertion=null}}, TextComponent{text=' Test Message', siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}",
+ components[0].toString());
+
+ components = CraftChatMessage.fromString("123 " + ChatColor.GOLD + "https://spigotmc.org " + ChatColor.BOLD + "test");
+ assertEquals("TextComponent{text='', siblings=[TextComponent{text='123 ', siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}, TextComponent{text='https://spigotmc.org', siblings=[], style=Style{hasParent=true, color=§6, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=ClickEvent{action=OPEN_URL, value='https://spigotmc.org'}, hoverEvent=null, insertion=null}}, TextComponent{text=' ', siblings=[], style=Style{hasParent=true, color=§6, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}, TextComponent{text='test', siblings=[], style=Style{hasParent=true, color=§6, bold=true, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}",
+ components[0].toString());
+
+ components = CraftChatMessage.fromString("multiCase http://SpigotMC.ORg/SpOngeBobMeEMeGoESHeRE");
+ assertEquals("TextComponent{text='', siblings=[TextComponent{text='multiCase ', siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}, TextComponent{text='http://SpigotMC.ORg/SpOngeBobMeEMeGoESHeRE', siblings=[], style=Style{hasParent=true, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=ClickEvent{action=OPEN_URL, value='http://SpigotMC.ORg/SpOngeBobMeEMeGoESHeRE'}, hoverEvent=null, insertion=null}}], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null, insertion=null}}",
+ components[0].toString());
+ }
}