Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static String resolveName(String typed, Set<String> names) {
* @return the normalized form
*/
private static String normalize(String s) {
return Util.stripColor(s).toLowerCase(Locale.ENGLISH).replaceAll("\\s+", " ").trim();
return Util.stripColor(s).toLowerCase(Locale.ENGLISH).replace('_', ' ').replaceAll("\\s+", " ").trim();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ void testResolveNameCaseAndSpaceInsensitive() {
assertEquals("My Home", IslandGoCommand.resolveName("my HOME", Set.of("My Home", "Hut")));
}

/**
* Underscores and spaces are interchangeable when resolving destination names.
*/
@Test
void testResolveNameUnderscoreAndSpaceEquivalent() {
assertEquals("Happy Place", IslandGoCommand.resolveName("happy_place", Set.of("Happy Place", "Hut")));
}

/**
* Underscore normalization must not choose arbitrarily between equivalent names.
*/
@Test
void testResolveNameAmbiguousUnderscoreAndSpaceEquivalentReturnsNull() {
assertNull(IslandGoCommand.resolveName("HAPPY PLACE", Set.of("Happy Place", "Happy_Place")));
}

/**
* Test method for {@link IslandGoCommand#resolveName(String, Set)}
*/
Expand Down