aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/multibyte_utils_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/multibyte_utils_test.rb')
-rw-r--r--activesupport/test/multibyte_utils_test.rb75
1 files changed, 15 insertions, 60 deletions
diff --git a/activesupport/test/multibyte_utils_test.rb b/activesupport/test/multibyte_utils_test.rb
index 1dff944922..f807492be0 100644
--- a/activesupport/test/multibyte_utils_test.rb
+++ b/activesupport/test/multibyte_utils_test.rb
@@ -2,7 +2,6 @@
require 'abstract_unit'
require 'multibyte_test_helpers'
-require 'active_support/core_ext/kernel/reporting'
class MultibyteUtilsTest < ActiveSupport::TestCase
include MultibyteTestHelpers
@@ -57,37 +56,9 @@ class MultibyteUtilsTest < ActiveSupport::TestCase
end
end
- if RUBY_VERSION < '1.9'
- test "clean leaves ASCII strings intact" do
- with_encoding('None') do
- [
- 'word', "\270\236\010\210\245"
- ].each do |string|
- assert_equal string, ActiveSupport::Multibyte.clean(string)
- end
- end
- end
-
- test "clean cleans invalid characters from UTF-8 encoded strings" do
- with_encoding('UTF8') do
- cleaned_utf8 = [8].pack('C*')
- assert_equal example('valid UTF-8'), ActiveSupport::Multibyte.clean(example('valid UTF-8'))
- assert_equal cleaned_utf8, ActiveSupport::Multibyte.clean(example('invalid UTF-8'))
- end
- end
-
- test "clean cleans invalid characters from Shift-JIS encoded strings" do
- with_encoding('SJIS') do
- cleaned_sjis = [184, 0, 136, 165].pack('C*')
- assert_equal example('valid Shift-JIS'), ActiveSupport::Multibyte.clean(example('valid Shift-JIS'))
- assert_equal cleaned_sjis, ActiveSupport::Multibyte.clean(example('invalid Shift-JIS'))
- end
- end
- else
- test "clean is a no-op" do
- with_encoding('UTF8') do
- assert_equal example('invalid Shift-JIS'), ActiveSupport::Multibyte.clean(example('invalid Shift-JIS'))
- end
+ test "clean is a no-op" do
+ with_encoding('UTF8') do
+ assert_equal example('invalid Shift-JIS'), ActiveSupport::Multibyte.clean(example('invalid Shift-JIS'))
end
end
@@ -102,37 +73,21 @@ class MultibyteUtilsTest < ActiveSupport::TestCase
'invalid Shift-JIS' => [184, 158, 8, 0, 255, 136, 165].pack('C*')
}
- if Kernel.const_defined?(:Encoding)
- def example(key)
- STRINGS[key].force_encoding(Encoding.default_external)
- end
-
- def examples
- STRINGS.values.map { |s| s.force_encoding(Encoding.default_external) }
- end
- else
- def example(key)
- STRINGS[key]
- end
-
- def examples
- STRINGS.values
- end
+ def example(key)
+ STRINGS[key].force_encoding(Encoding.default_external)
end
- if 'string'.respond_to?(:encoding)
- KCODE_TO_ENCODING = Hash.new(Encoding::BINARY).
- update('UTF8' => Encoding::UTF_8, 'SJIS' => Encoding::Shift_JIS)
-
- def with_encoding(enc)
- before = Encoding.default_external
- silence_warnings { Encoding.default_external = KCODE_TO_ENCODING[enc] }
+ def examples
+ STRINGS.values.map { |s| s.force_encoding(Encoding.default_external) }
+ end
- yield
+ KCODE_TO_ENCODING = Hash.new(Encoding::BINARY).
+ update('UTF8' => Encoding::UTF_8, 'SJIS' => Encoding::Shift_JIS)
- silence_warnings { Encoding.default_external = before }
- end
- else
- alias with_encoding with_kcode
+ def with_encoding(enc)
+ before = Encoding.default_external
+ silence_warnings { Encoding.default_external = KCODE_TO_ENCODING[enc] }
+ yield
+ silence_warnings { Encoding.default_external = before }
end
end