diff --git a/lib/dry/inflector.rb b/lib/dry/inflector.rb index b09d23a..73398f4 100644 --- a/lib/dry/inflector.rb +++ b/lib/dry/inflector.rb @@ -298,7 +298,9 @@ def underscore(input) # @since 0.1.0 # @api private def uncountable?(input) - input.match?(/\A[[:space:]]*\z/) || inflections.uncountables.include?(input.downcase) + input.match?(/\A[[:space:]]*\z/) || + inflections.uncountables.include?(input.downcase) || + inflections.uncountables.include?(input.split(/_|\b/).last.downcase) end # @return [String] diff --git a/lib/dry/inflector/inflections/defaults.rb b/lib/dry/inflector/inflections/defaults.rb index 83bd5ed..3ea6ca0 100644 --- a/lib/dry/inflector/inflections/defaults.rb +++ b/lib/dry/inflector/inflections/defaults.rb @@ -56,7 +56,7 @@ def self.singular(inflect) inflect.singular(/s\z/i, "") inflect.singular(/(n)ews\z/i, '\1ews') inflect.singular(/([ti])a\z/i, '\1um') - inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)\z/i, + inflect.singular(/(analy|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)\z/i, '\1\2sis') inflect.singular(/(^analy)(sis|ses)\z/i, '\1sis') inflect.singular(/([^f])ves\z/i, '\1fe') @@ -75,7 +75,7 @@ def self.singular(inflect) inflect.singular(/(cris|ax|test)(is|es)\z/i, '\1is') inflect.singular(/(octop|vir)(us|i)\z/i, '\1us') inflect.singular(/(alias|status)(es)?\z/i, '\1') - inflect.singular(/^(ox)en/i, '\1') + inflect.singular(/(ox)en/i, '\1') inflect.singular(/(vert|ind)ices\z/i, '\1ex') inflect.singular(/(matr)ices\z/i, '\1ix') inflect.singular(/(quiz)zes\z/i, '\1') diff --git a/spec/unit/dry/inflector/singularize_spec.rb b/spec/unit/dry/inflector/singularize_spec.rb index 39fe771..a33c9dc 100644 --- a/spec/unit/dry/inflector/singularize_spec.rb +++ b/spec/unit/dry/inflector/singularize_spec.rb @@ -6,6 +6,18 @@ it "singularizes #{plural} => #{singular}" do expect(subject.singularize(i(plural))).to eq(singular) end + + it "singularizes test_#{plural} => test_#{singular}" do + expect(subject.singularize(i("test_#{plural}"))).to eq("test_#{singular}") + end + + it "singularizes test-#{plural} => test-#{singular}" do + expect(subject.singularize(i("test-#{plural}"))).to eq("test-#{singular}") + end + + it "singularizes 'test #{plural}' => 'test #{singular}'" do + expect(subject.singularize(i("test #{plural}"))).to eq("test #{singular}") + end end Fixtures::Singularize.pending.each do |plural, singular|