Skip to content

Commit 76dd8c2

Browse files
author
Oleg Michailov
committed
Handling some words mentioned in #4
1 parent e1f9882 commit 76dd8c2

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

library/src/main/kotlin/com/cesarferreira/pluralize/Pluralize.kt

+7-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private fun String.pluralizer(): String {
5050
var found = Pattern.compile(rule.component1(), Pattern.CASE_INSENSITIVE).matcher(this).replaceAll(rule.component2())
5151
val endsWith = exceptions().firstOrNull { this.endsWith(it.component1()) }
5252
if (endsWith != null) found = this.replace(endsWith.component1(), endsWith.component2())
53-
val exception = exceptions().firstOrNull() { this.equals(it.component1()) }
53+
val exception = exceptions().firstOrNull() { this.equals(it.component1(), true) }
5454
if (exception != null) found = exception.component2()
5555
return found
5656
}
@@ -59,7 +59,7 @@ private fun String.singularizer(): String {
5959
if (unCountable().contains(this.toLowerCase())) {
6060
return this
6161
}
62-
val exceptions = exceptions().firstOrNull() { this.equals(it.component2()) }
62+
val exceptions = exceptions().firstOrNull() { this.equals(it.component2(), true) }
6363

6464
if (exceptions != null) {
6565
return exceptions.component1()
@@ -147,7 +147,8 @@ fun exceptions(): List<Pair<String, String>> {
147147
"noumenon" to "noumena",
148148
"organon" to "organa",
149149
"asyndeton" to "asyndeta",
150-
"hyperbaton" to "hyperbata")
150+
"hyperbaton" to "hyperbata",
151+
"foot" to "feet")
151152
}
152153

153154
fun pluralizeRules(): List<Pair<String, String>> {
@@ -176,7 +177,9 @@ fun pluralizeRules(): List<Pair<String, String>> {
176177
"f$" to "ves",
177178
"fe$" to "ves",
178179
"um$" to "a",
179-
"on$" to "a")
180+
"on$" to "a",
181+
"tion" to "tions",
182+
"sion" to "sions")
180183
}
181184

182185
fun singularizeRules(): List<Pair<String, String>> {

library/src/test/kotlin/com/cesarferreira/pluralize/PluralizationTest.kt

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class PluralizationTest {
88
@Test
99
fun `Should add default "s" suffix`() {
1010
assertEquals("posts", "post".pluralize())
11+
assertEquals("descriptions", "description".pluralize())
12+
assertEquals("colections", "colection".pluralize())
13+
assertEquals("versions", "version".pluralize())
1114
}
1215

1316
@Test
@@ -18,6 +21,12 @@ class PluralizationTest {
1821
@Test
1922
fun `Should handle exception words`() {
2023
assertEquals("men", "man".pluralize())
24+
assertEquals("feet", "foot".pluralize())
25+
}
26+
27+
@Test
28+
fun `Should handle in case insensitive manner`() {
29+
assertEquals("people", "Person".pluralize())
2130
}
2231

2332
}

library/src/test/kotlin/com/cesarferreira/pluralize/SingularizationTest.kt

+5
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ class SingularizationTest {
2020
assertEquals("person", "people".singularize())
2121
}
2222

23+
@Test
24+
fun `Should handle in case insensitive manner`() {
25+
assertEquals("goy", "Goyim".singularize())
26+
}
27+
2328
}

0 commit comments

Comments
 (0)