Skip to content

Commit

Permalink
Move encoding tests to interpolation, add Gemfile.all.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 29, 2010
1 parent 593e473 commit ccecff2
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 28 deletions.
11 changes: 11 additions & 0 deletions ci/Gemfile.all
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
source :rubygems

gem 'activerecord', '~> 3.0.0'
gem 'activesupport', '~> 3.0.0'
gem 'sqlite3-ruby'
gem 'mocha'
gem 'rufus-tokyo'
gem 'ffi'
gem 'ruby-cldr'
gem 'ruby2ruby'
gem 'ParseTree'
57 changes: 57 additions & 0 deletions ci/Gemfile.all.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
GEM
remote: http://rubygems.org/
specs:
ParseTree (3.0.5)
RubyInline (>= 3.7.0)
sexp_processor (>= 3.0.0)
RubyInline (3.7.0)
hoe (>= 1.5.3)
activemodel (3.0.1)
activesupport (= 3.0.1)
builder (~> 2.1.2)
i18n (~> 0.4.1)
activerecord (3.0.1)
activemodel (= 3.0.1)
activesupport (= 3.0.1)
arel (~> 1.0.0)
tzinfo (~> 0.3.23)
activesupport (3.0.1)
arel (1.0.1)
activesupport (~> 3.0.0)
builder (2.1.2)
ffi (0.6.3)
rake (>= 0.8.7)
hoe (2.6.1)
rake (>= 0.8.7)
rubyforge (>= 2.0.4)
i18n (0.4.2)
json_pure (1.4.6)
mocha (0.9.8)
rake
rake (0.8.7)
ruby-cldr (0.0.1)
ruby2ruby (1.2.5)
ruby_parser (~> 2.0)
sexp_processor (~> 3.0)
ruby_parser (2.0.5)
sexp_processor (~> 3.0)
rubyforge (2.0.4)
json_pure (>= 1.1.7)
rufus-tokyo (1.0.7)
sexp_processor (3.0.5)
sqlite3-ruby (1.3.1)
tzinfo (0.3.23)

PLATFORMS
ruby

DEPENDENCIES
ParseTree
activerecord (~> 3.0.0)
activesupport (~> 3.0.0)
ffi
mocha
ruby-cldr
ruby2ruby
rufus-tokyo
sqlite3-ruby
25 changes: 19 additions & 6 deletions test/api/tests/interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,30 @@ def interpolate(*args)
interpolate(:default => euc_jp('こんにちは、%{name}さん!'), :name => 'ゆきひろ')
end
end

# define_method "test interpolation: given a utf-8 translation and a euc-jp value it returns a translation in euc-jp" do
# assert_equal euc_jp('Hi ゆきひろ!'), interpolate(:default => 'Hi %{name}!', :name => euc_jp('ゆきひろ'))
# end
#
# TODO should better explain how this relates to the test above with the simpler utf-8 default string

define_method "test interpolation: given a utf-8 translation and a euc-jp value it raises Encoding::CompatibilityError" do
assert_raise(Encoding::CompatibilityError) do
interpolate(:default => 'こんにちは、%{name}さん!', :name => euc_jp('ゆきひろ'))
end
end

define_method "test interpolation: ASCII strings in the backend should be encoded to UTF8 if interpolation options are in UTF8" do
I18n.backend.store_translations 'en', 'encoding' => ('%{who} let me go'.force_encoding("ASCII"))
result = I18n.t 'encoding', :who => "måmmå miå"
assert_equal Encoding::UTF_8, result.encoding
end

define_method "test interpolation: UTF8 strings in the backend are still returned as UTF8 with ASCII interpolation" do
I18n.backend.store_translations 'en', 'encoding' => 'måmmå miå %{what}'
result = I18n.t 'encoding', :what => 'let me go'.force_encoding("ASCII")
assert_equal Encoding::UTF_8, result.encoding
end

define_method "test interpolation: UTF8 strings in the backend are still returned as UTF8 even with numbers interpolation" do
I18n.backend.store_translations 'en', 'encoding' => '%{count} times: måmmå miå'
result = I18n.t 'encoding', :count => 3
assert_equal Encoding::UTF_8, result.encoding
end
end

define_method "test interpolation: given a translations containing a reserved key it raises I18n::ReservedInterpolationKey" do
Expand Down
21 changes: 0 additions & 21 deletions test/backend/simple_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,4 @@ def setup
I18n.backend.reload!
assert_equal I18n.backend.initialized?, false
end

# Encoding
if "string".respond_to?(:force_encoding)
test "ASCII strings in the backend should be encoded to UTF8 if interpolation options are in UTF8" do
I18n.backend.store_translations 'en', 'encoding' => ('%{who} let me go'.force_encoding("ASCII"))
result = I18n.t 'encoding', :who => "måmmå miå"
assert_equal Encoding::UTF_8, result.encoding
end

test "UTF8 strings in the backend are still returned as UTF8" do
I18n.backend.store_translations 'en', 'encoding' => 'måmmå miå %{what}'
result = I18n.t 'encoding', :what => 'let me go'.force_encoding("ASCII")
assert_equal Encoding::UTF_8, result.encoding
end

test "UTF8 strings in the backend are still returned as UTF8 even with numbers" do
I18n.backend.store_translations 'en', 'encoding' => '%{count} times: måmmå miå'
result = I18n.t 'encoding', :count => 3
assert_equal Encoding::UTF_8, result.encoding
end
end
end
4 changes: 3 additions & 1 deletion test/test_setup/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ def parse_options!
@options[:adapter] = dep
when :r23, :'rails-2.3.x'
ENV['BUNDLE_GEMFILE'] = 'ci/Gemfile.rails-2.3.x'
when :r3, :'rails-3.0.x'
ENV['BUNDLE_GEMFILE'] = 'ci/Gemfile.rails-3.x'
when :'no-rails'
ENV['BUNDLE_GEMFILE'] = 'ci/Gemfile.no-rails'
end
end

ENV['BUNDLE_GEMFILE'] ||= 'ci/Gemfile.rails-3.x'
ENV['BUNDLE_GEMFILE'] ||= 'ci/Gemfile.all'
end
end
end
Expand Down

0 comments on commit ccecff2

Please sign in to comment.