Introduce slugs in arenas and classes.
Whitespace and punctuation in identifiers is a fairly big source of issues in areas like permissions and commands where whitespace isn't directly supported (or at least makes things needlessly difficult). This commit introduces the concept of a "slug" in arenas and classes, giving them a _consistent_ `kebab-case` name for use in such places, but it does not implement their use anywhere. Slugs are expected to be the solution to problems like the one posed in issue #647. At the time of writing, we're only concerned with simple stuff like removing periods, commas, parentheses and replacing underscores and spaces with dashes. If it turns out that people have unanticipatedly problematic arena and class names, we may have to expand the slug definition rules or allow for custom slugs.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.garbagemule.MobArena.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class SlugsTest {
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{"castle", "castle"},
|
||||
{"Castle", "castle"},
|
||||
{"CaStLe", "castle"},
|
||||
{"Castle of Kebab", "castle-of-kebab"},
|
||||
{"Area 52", "area-52"},
|
||||
{"Project: Nuclear", "project-nuclear"},
|
||||
{"Mr. Kebal Bab's Mansion", "mr-kebal-babs-mansion"},
|
||||
{"Unnamed Arena (3)", "unnamed-arena-3"},
|
||||
{"The Wolf Master", "the-wolf-master"},
|
||||
{"already-a-slug", "already-a-slug"},
|
||||
});
|
||||
}
|
||||
|
||||
@Parameter
|
||||
public String input;
|
||||
|
||||
@Parameter(1)
|
||||
public String expected;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String actual = Slugs.create(input);
|
||||
|
||||
assertEquals("Wrong slug for '" + input + "'", expected, actual);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user