@@ -5,34 +5,38 @@ module Tests
55 module Procs
66 test "lookup: given a translation is a proc it calls the proc with the key and interpolation values" do
77 I18n . backend . store_translations ( :en , :a_lambda => lambda { |*args | I18n ::Tests ::Procs . filter_args ( *args ) } )
8- assert_equal ' [:a_lambda, { :foo=>"foo"}]' , I18n . t ( :a_lambda , :foo => 'foo' )
8+ assert_equal %| [:a_lambda, #{ { :foo => "foo" } } ]| , I18n . t ( :a_lambda , :foo => 'foo' )
99 end
1010
1111 test "lookup: given a translation is a proc it passes the interpolation values as keyword arguments" do
1212 I18n . backend . store_translations ( :en , :a_lambda => lambda { |key , foo :, **| I18n ::Tests ::Procs . filter_args ( key , foo : foo ) } )
13- assert_equal ' [:a_lambda, { :foo=>"foo"}]' , I18n . t ( :a_lambda , :foo => 'foo' )
13+ assert_equal %| [:a_lambda, #{ { :foo => "foo" } } ]| , I18n . t ( :a_lambda , :foo => 'foo' )
1414 end
1515
1616 test "defaults: given a default is a Proc it calls it with the key and interpolation values" do
1717 proc = lambda { |*args | I18n ::Tests ::Procs . filter_args ( *args ) }
18- assert_equal ' [nil, { :foo=>"foo"}]' , I18n . t ( nil , :default => proc , :foo => 'foo' )
18+ assert_equal %| [nil, #{ { :foo => "foo" } } ]| , I18n . t ( nil , :default => proc , :foo => 'foo' )
1919 end
2020
2121 test "defaults: given a default is a key that resolves to a Proc it calls it with the key and interpolation values" do
2222 the_lambda = lambda { |*args | I18n ::Tests ::Procs . filter_args ( *args ) }
2323 I18n . backend . store_translations ( :en , :a_lambda => the_lambda )
24- assert_equal ' [:a_lambda, { :foo=>"foo"}]' , I18n . t ( nil , :default => :a_lambda , :foo => 'foo' )
25- assert_equal ' [:a_lambda, { :foo=>"foo"}]' , I18n . t ( nil , :default => [ nil , :a_lambda ] , :foo => 'foo' )
24+ assert_equal %| [:a_lambda, #{ { :foo => "foo" } } ]| , I18n . t ( nil , :default => :a_lambda , :foo => 'foo' )
25+ assert_equal %| [:a_lambda, #{ { :foo => "foo" } } ]| , I18n . t ( nil , :default => [ nil , :a_lambda ] , :foo => 'foo' )
2626 end
2727
2828 test "interpolation: given an interpolation value is a lambda it calls it with key and values before interpolating it" do
2929 proc = lambda { |*args | I18n ::Tests ::Procs . filter_args ( *args ) }
30- assert_match %r(\[ \{ :foo=>#<Proc.*>\} \] ) , I18n . t ( nil , :default => '%{foo}' , :foo => proc )
30+ if RUBY_VERSION < "3.4"
31+ assert_match %r(\[ \{ :foo=>#<Proc.*>\} \] ) , I18n . t ( nil , :default => '%{foo}' , :foo => proc )
32+ else
33+ assert_match %r(\[ \{ foo: #<Proc.*>\} \] ) , I18n . t ( nil , :default => '%{foo}' , :foo => proc )
34+ end
3135 end
3236
3337 test "interpolation: given a key resolves to a Proc that returns a string then interpolation still works" do
3438 proc = lambda { |*args | "%{foo}: " + I18n ::Tests ::Procs . filter_args ( *args ) }
35- assert_equal ' foo: [nil, { :foo=>"foo"}]' , I18n . t ( nil , :default => proc , :foo => 'foo' )
39+ assert_equal %| foo: [nil, #{ { :foo => "foo" } } ]| , I18n . t ( nil , :default => proc , :foo => 'foo' )
3640 end
3741
3842 test "pluralization: given a key resolves to a Proc that returns valid data then pluralization still works" do
0 commit comments