Skip to content

Commit 75bb588

Browse files
authored
Update inflections (mattt#6)
* Update inflection rules from latest Active Support rails/rails@589dd0f * Add test coverage for new inflection rules
1 parent b3e7a98 commit 75bb588

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sources/InflectorKit/TTTStringInflector.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ @implementation TTTStringInflector (Localization)
180180

181181
/**
182182
Inflection rules adapted from Active Support
183-
Copyright (c) 2005-2012 David Heinemeier Hansson
183+
Copyright (c) 2005-2020 David Heinemeier Hansson
184184
185185
Permission is hereby granted, free of charge, to any person obtaining
186186
a copy of this software and associated documentation files (the
@@ -228,6 +228,8 @@ - (void)addPluralizationRulesForEnUSLocale {
228228
[self addSingularRule:@"(ss)$" withReplacement:@"$1"];
229229
[self addSingularRule:@"(n)ews$" withReplacement:@"$1ews"];
230230
[self addSingularRule:@"([ti])a$" withReplacement:@"$1um"];
231+
[self addSingularRule:@"((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$" withReplacement:@"$1sis"];
232+
[self addSingularRule:@"(^analy)(sis|ses)$$" withReplacement:@"$1sis"];
231233
[self addSingularRule:@"([^f])ves$" withReplacement:@"$1fe"];
232234
[self addSingularRule:@"(hive)s$" withReplacement:@"$1"];
233235
[self addSingularRule:@"(tive)s$" withReplacement:@"$1"];
@@ -255,7 +257,6 @@ - (void)addPluralizationRulesForEnUSLocale {
255257
[self addIrregularWithSingular:@"child" plural:@"children"];
256258
[self addIrregularWithSingular:@"sex" plural:@"sexes"];
257259
[self addIrregularWithSingular:@"move" plural:@"moves"];
258-
[self addIrregularWithSingular:@"cow" plural:@"cattle"];
259260
[self addIrregularWithSingular:@"zombie" plural:@"zombies"];
260261

261262
[self addUncountable:@"equipment"];
@@ -267,6 +268,7 @@ - (void)addPluralizationRulesForEnUSLocale {
267268
[self addUncountable:@"fish"];
268269
[self addUncountable:@"sheep"];
269270
[self addUncountable:@"jeans"];
271+
[self addUncountable:@"police"];
270272
}
271273

272274
@end

Tests/InflectorKitTests/InflectorKitTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ final class InflectorKitTests: XCTestCase {
66
XCTAssertEqual("people".singularized, "person")
77
XCTAssertEqual("tomatoes".singularized, "tomato")
88
XCTAssertEqual("matrices".singularized, "matrix")
9+
XCTAssertEqual("analyses".singularized, "analysis")
910
XCTAssertEqual("octopi".singularized, "octopus")
1011
XCTAssertEqual("fish".singularized, "fish")
12+
XCTAssertEqual("police".singularized, "police")
1113
}
1214

1315
func testPluralization() {
@@ -16,6 +18,8 @@ final class InflectorKitTests: XCTestCase {
1618
XCTAssertEqual("matrix".pluralized, "matrices")
1719
XCTAssertEqual("octopus".pluralized, "octopi")
1820
XCTAssertEqual("fish".pluralized, "fish")
21+
XCTAssertEqual("police".pluralized, "police")
22+
XCTAssertEqual("cow".pluralized, "cows")
1923
}
2024

2125
func testStringInflector() {

0 commit comments

Comments
 (0)