mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add Inflection test (and fixes) to ensure singularizing a singular actually give you the correct singular in more cases
This commit is contained in:
parent
faaf694e0f
commit
532cd49530
2 changed files with 15 additions and 6 deletions
|
@ -23,10 +23,11 @@ module ActiveSupport
|
||||||
inflect.plural(/(quiz)$/i, '\1zes')
|
inflect.plural(/(quiz)$/i, '\1zes')
|
||||||
|
|
||||||
inflect.singular(/s$/i, '')
|
inflect.singular(/s$/i, '')
|
||||||
|
inflect.singular(/(ss)$/i, '\1')
|
||||||
inflect.singular(/(n)ews$/i, '\1ews')
|
inflect.singular(/(n)ews$/i, '\1ews')
|
||||||
inflect.singular(/([ti])a$/i, '\1um')
|
inflect.singular(/([ti])a$/i, '\1um')
|
||||||
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
|
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '\1\2sis')
|
||||||
inflect.singular(/(^analy)ses$/i, '\1sis')
|
inflect.singular(/(^analy)(sis|ses)$/i, '\1sis')
|
||||||
inflect.singular(/([^f])ves$/i, '\1fe')
|
inflect.singular(/([^f])ves$/i, '\1fe')
|
||||||
inflect.singular(/(hive)s$/i, '\1')
|
inflect.singular(/(hive)s$/i, '\1')
|
||||||
inflect.singular(/(tive)s$/i, '\1')
|
inflect.singular(/(tive)s$/i, '\1')
|
||||||
|
@ -36,12 +37,12 @@ module ActiveSupport
|
||||||
inflect.singular(/(m)ovies$/i, '\1ovie')
|
inflect.singular(/(m)ovies$/i, '\1ovie')
|
||||||
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
|
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
|
||||||
inflect.singular(/(m|l)ice$/i, '\1ouse')
|
inflect.singular(/(m|l)ice$/i, '\1ouse')
|
||||||
inflect.singular(/(bus)es$/i, '\1')
|
inflect.singular(/(bus)(es)?$/i, '\1')
|
||||||
inflect.singular(/(o)es$/i, '\1')
|
inflect.singular(/(o)es$/i, '\1')
|
||||||
inflect.singular(/(shoe)s$/i, '\1')
|
inflect.singular(/(shoe)s$/i, '\1')
|
||||||
inflect.singular(/(cris|ax|test)es$/i, '\1is')
|
inflect.singular(/(cris|ax|test)(is|es)$/i, '\1is')
|
||||||
inflect.singular(/(octop|vir)i$/i, '\1us')
|
inflect.singular(/(octop|vir)(us|i)$/i, '\1us')
|
||||||
inflect.singular(/(alias|status)es$/i, '\1')
|
inflect.singular(/(alias|status)(es)?$/i, '\1')
|
||||||
inflect.singular(/^(ox)en/i, '\1')
|
inflect.singular(/^(ox)en/i, '\1')
|
||||||
inflect.singular(/(vert|ind)ices$/i, '\1ex')
|
inflect.singular(/(vert|ind)ices$/i, '\1ex')
|
||||||
inflect.singular(/(matr)ices$/i, '\1ix')
|
inflect.singular(/(matr)ices$/i, '\1ix')
|
||||||
|
|
|
@ -65,6 +65,14 @@ class InflectorTest < ActiveSupport::TestCase
|
||||||
assert_equal(plural.capitalize, ActiveSupport::Inflector.pluralize(plural.capitalize))
|
assert_equal(plural.capitalize, ActiveSupport::Inflector.pluralize(plural.capitalize))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
SingularToPlural.each do |singular, plural|
|
||||||
|
define_method "test_singularize_singular_#{singular}" do
|
||||||
|
assert_equal(singular, ActiveSupport::Inflector.singularize(singular))
|
||||||
|
assert_equal(singular.capitalize, ActiveSupport::Inflector.singularize(singular.capitalize))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_overwrite_previous_inflectors
|
def test_overwrite_previous_inflectors
|
||||||
assert_equal("series", ActiveSupport::Inflector.singularize("series"))
|
assert_equal("series", ActiveSupport::Inflector.singularize("series"))
|
||||||
|
|
Loading…
Reference in a new issue