1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/test/multibyte_proxy_test.rb
Michael Grosser 203998c916
allow running each test with pure ruby path/to/test.rb
also:
 - makes test dependencies obvious
 - makes tests runnable from within subfolders
2019-12-18 08:49:19 -06:00

34 lines
817 B
Ruby

# frozen_string_literal: true
require_relative "abstract_unit"
class MultibyteProxyText < ActiveSupport::TestCase
class AsciiOnlyEncoder
attr_reader :wrapped_string
alias to_s wrapped_string
def initialize(string)
@wrapped_string = string.gsub(/[^\u0000-\u007F]/, "?")
end
end
def with_custom_encoder(encoder)
original_proxy_class = ActiveSupport::Multibyte.proxy_class
begin
ActiveSupport::Multibyte.proxy_class = encoder
yield
ensure
ActiveSupport::Multibyte.proxy_class = original_proxy_class
end
end
test "custom multibyte encoder" do
with_custom_encoder(AsciiOnlyEncoder) do
assert_equal "s?me string 123", "søme string 123".mb_chars.to_s
end
assert_equal "søme string 123", "søme string 123".mb_chars.to_s
end
end