1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Ruby 1.9 compat: no Unicode normalization support yet

This commit is contained in:
Jeremy Kemper 2008-11-26 17:59:35 -08:00
parent 51e15a60b0
commit 2c43a6429e
3 changed files with 27 additions and 3 deletions

View file

@ -275,9 +275,16 @@ module ActiveSupport
Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s
end
if RUBY_VERSION >= '1.9'
undef_method :transliterate
def transliterate(string)
warn "Ruby 1.9 doesn't support Unicode normalization yet"
string.dup
end
# The iconv transliteration code doesn't function correctly
# on some platforms, but it's very fast where it does function.
if "foo" != Inflector.transliterate("föö")
elsif "foo" != Inflector.transliterate("föö")
undef_method :transliterate
def transliterate(string)
string.mb_chars.normalize(:kd). # Decompose accented characters

View file

@ -104,6 +104,12 @@ class InflectorTest < Test::Unit::TestCase
end
end
def test_parameterize_and_normalize
StringToParameterizedAndNormalized.each do |some_string, parameterized_string|
assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string))
end
end
def test_parameterize_with_custom_separator
StringToParameterized.each do |some_string, parameterized_string|
assert_equal(parameterized_string.gsub('-', '_'), ActiveSupport::Inflector.parameterize(some_string, '_'))

View file

@ -147,14 +147,25 @@ module InflectorTestCases
StringToParameterized = {
"Donald E. Knuth" => "donald-e-knuth",
"Random text with *(bad)* characters" => "random-text-with-bad-characters",
"Malmö" => "malmo",
"Garçons" => "garcons",
"Allow_Under_Scores" => "allow_under_scores",
"Trailing bad characters!@#" => "trailing-bad-characters",
"!@#Leading bad characters" => "leading-bad-characters",
"Squeeze separators" => "squeeze-separators"
}
# Ruby 1.9 doesn't do Unicode normalization yet.
if RUBY_VERSION >= '1.9'
StringToParameterizedAndNormalized = {
"Malmö" => "malm",
"Garçons" => "gar-ons"
}
else
StringToParameterizedAndNormalized = {
"Malmö" => "malmo",
"Garçons" => "garcons"
}
end
UnderscoreToHuman = {
"employee_salary" => "Employee salary",
"employee_id" => "Employee",