Skip to content

Commit

Permalink
Fix pluralize and singularize for nouns with endings of f or fe (n…
Browse files Browse the repository at this point in the history
  • Loading branch information
styd authored and nurugger07 committed Oct 2, 2017
1 parent 23e379b commit 9cb513f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/inflex/pluralize.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ defmodule Inflex.Pluralize do
{ ~r/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, "\\1sis" },
{ ~r/(analy)(sis|ses)$/i, "\\1sis" },
{ ~r/(octop|vir)i$/i, "\\1us" },
{ ~r/([^f])ves$/i, "\\1fe" },
{ ~r/(hive)s$/i, "\\1" },
{ ~r/(tive)s$/i, '\\1' },
{ ~r/([lr])ves$/i, "\\1f" },
{ ~r/([lora])ves$/i, "\\1f" },
{ ~r/([^f])ves$/i, "\\1fe" },
{ ~r/([^aeiouy]|qu)ies$/i, "\\1y" },
{ ~r/(m)ovies$/i, "\\1ovie" },
{ ~r/(x|ch|ss|sh)es$/i, "\\1" },
Expand All @@ -95,7 +95,8 @@ defmodule Inflex.Pluralize do
{ ~r/(x|ch|ss|sh)$/i, "\\1es" },
{ ~r/([^aeiouy]|qu)y$/i, "\\1ies" },
{ ~r/(hive)$/i, "\\1s" },
{ ~r/(?:([^f])fe|([lr])f)$/i, "\\1\\1ves" },
{ ~r/(sc[au]rf)$/i, "\\1s" },
{ ~r/(?:([^f])fe|((hoo)|([lra]))f)$/i, "\\2\\1ves" },
{ ~r/sis$/i, "ses" },
{ ~r/([ti])um$/i, "\\1a" },
{ ~r/(buffal|tomat)o$/i, "\\1oes" },
Expand Down
28 changes: 28 additions & 0 deletions test/inflex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ defmodule InflexTest do
assert "buses" == pluralize(:bus)
end

test :special_case_nouns_ending_in_f_or_fe do
assert "life" == singularize("lives")
assert "knife" == singularize("knives")
assert "hoof" == singularize("hooves")
assert "roof" == singularize("roofs")
assert "loof" == singularize("loofs")
assert "wolf" == singularize("wolves")
assert "calf" == singularize("calves")
assert "scarf" == singularize("scarfs")
assert "scurf" == singularize("scurfs")
assert "wharf" == singularize("wharves")
assert "loaf" == singularize("loaves")
assert "leaf" == singularize("leaves")

assert "lives" == pluralize("life")
assert "knives" == pluralize("knife")
assert "hooves" == pluralize("hoof")
assert "roofs" == pluralize("roof")
assert "loofs" == pluralize("loof")
assert "wolves" == pluralize("wolf")
assert "calves" == pluralize("calf")
assert "scarfs" == pluralize("scarf")
assert "scurfs" == pluralize("scurf")
assert "wharves" == pluralize("wharf")
assert "loaves" == pluralize("loaf")
assert "leaves" == pluralize("leaf")
end

test :special_case_nouns_ending_in_o do
assert "echo" == singularize("echoes")
assert "hero" == singularize("heroes")
Expand Down

0 comments on commit 9cb513f

Please sign in to comment.