Skip to content

Commit

Permalink
fix: handling of irregulars in singularize / pluralize
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Jul 21, 2021
1 parent aa2e4b8 commit 51dcf95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/io/sundr/functions/Pluralize.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public enum Pluralize implements Function<String, String> {

private static final List<Function<String, String>> PLURALS = Arrays.<Function<String, String>> asList(
//Irregulars
new StringReplace("(p)eople$", "$1erson"),
new StringReplace("(m)en$", "$1an"),
new StringReplace("(c)hildren$", "$1hild"),
new StringReplace("(s)exes$", "$1ex"),
new StringReplace("(m)oves$", "$1ove"),
new StringReplace("(s)tadiums$", "$1tadium"),
new StringReplace("(p)erson$", "$1eople"),
new StringReplace("(m)an$", "$1en"),
new StringReplace("(c)hild$", "$1hildren"),
new StringReplace("(s)ex$", "$1exes"),
new StringReplace("(m)ove$", "$1oves"),
new StringReplace("(s)tadium$", "$1tadiums"),

//Rules
new StringReplace("(quiz)$", "$1zes"),
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/io/sundr/functions/Singularize.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public enum Singularize implements Function<String, String> {

private static final List<Function<String, String>> SINGULARS = Arrays.<Function<String, String>> asList(
//Irregulars
new StringReplace("(p)erson$", "$1eople"),
new StringReplace("(m)an$", "$1en"),
new StringReplace("(c)hild$", "$1hildren"),
new StringReplace("(s)ex$", "$1exes"),
new StringReplace("(m)ove$", "$1oves"),
new StringReplace("(s)tadium$", "$1tadiums"),
new StringReplace("(p)eople$", "$1erson"),
new StringReplace("(m)en$", "$1an"),
new StringReplace("(c)hildren$", "$1hild"),
new StringReplace("(s)exes$", "$1ex"),
new StringReplace("(m)oves$", "$1ove"),
new StringReplace("(s)tadiums$", "$1tadium"),

//Rules
new StringReplace("(quiz)zes$", "$1"),
Expand Down
8 changes: 5 additions & 3 deletions core/src/test/java/io/sundr/functions/SingularizeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ public class SingularizeTest {
public void testSingularize() {

assertEquals("address", Singularize.FUNCTION.apply("addresses"));
assertEquals("ADDRESS", Singularize.FUNCTION.apply("ADDRESSES"));
assertEquals("Address", Singularize.FUNCTION.apply("Addresses"));

assertEquals("number", Singularize.FUNCTION.apply("numbers"));
assertEquals("NUMBER", Singularize.FUNCTION.apply("NUMBERS"));
}
assertEquals("Number", Singularize.FUNCTION.apply("Numbers"));

assertEquals("child", Singularize.FUNCTION.apply("children"));
assertEquals("Child", Singularize.FUNCTION.apply("Children"));
}
}

0 comments on commit 51dcf95

Please sign in to comment.