aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorManfred Stienstra <manfred@fngtps.com>2008-09-21 17:22:55 +0200
committerManfred Stienstra <manfred@fngtps.com>2008-09-21 17:22:55 +0200
commit021172208885be0c137a9d5f352f862479044e7a (patch)
tree124106443ceade8c49721806abb800ddd87d1c70 /activesupport/test/core_ext
parent042fd971271791659c90e065e761cf90d3117b74 (diff)
downloadrails-021172208885be0c137a9d5f352f862479044e7a.tar.gz
rails-021172208885be0c137a9d5f352f862479044e7a.tar.bz2
rails-021172208885be0c137a9d5f352f862479044e7a.zip
Move with_kcode helper to abstract_unit. Add tests for multibyte string extensions.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/string_ext_test.rb53
1 files changed, 47 insertions, 6 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb
index c0decf2c3f..fe5ce276c5 100644
--- a/activesupport/test/core_ext/string_ext_test.rb
+++ b/activesupport/test/core_ext/string_ext_test.rb
@@ -191,13 +191,12 @@ class StringInflectionsTest < Test::Unit::TestCase
if RUBY_VERSION < '1.9'
def test_each_char_with_utf8_string_when_kcode_is_utf8
- old_kcode, $KCODE = $KCODE, 'UTF8'
- '€2.99'.each_char do |char|
- assert_not_equal 1, char.length
- break
+ with_kcode('UTF8') do
+ '€2.99'.each_char do |char|
+ assert_not_equal 1, char.length
+ break
+ end
end
- ensure
- $KCODE = old_kcode
end
end
end
@@ -206,4 +205,46 @@ class StringBehaviourTest < Test::Unit::TestCase
def test_acts_like_string
assert 'Bambi'.acts_like_string?
end
+end
+
+class CoreExtStringMultibyteTest < Test::Unit::TestCase
+ UNICODE_STRING = 'こにちわ'
+ ASCII_STRING = 'ohayo'
+ BYTE_STRING = "\270\236\010\210\245"
+
+ def test_core_ext_adds_mb_chars
+ assert UNICODE_STRING.respond_to?(:mb_chars)
+ end
+
+ def test_string_should_recognize_utf8_strings
+ assert UNICODE_STRING.is_utf8?
+ assert ASCII_STRING.is_utf8?
+ assert !BYTE_STRING.is_utf8?
+ end
+
+ if RUBY_VERSION < '1.8.7'
+ def test_core_ext_adds_chars
+ assert UNICODE_STRING.respond_to?(:chars)
+ end
+ end
+
+ if RUBY_VERSION < '1.9'
+ def test_mb_chars_returns_self_when_kcode_not_set
+ with_kcode('none') do
+ assert UNICODE_STRING.mb_chars.kind_of?(String)
+ end
+ end
+
+ def test_mb_chars_returns_an_instance_of_the_chars_proxy_when_kcode_utf8
+ with_kcode('UTF8') do
+ assert UNICODE_STRING.mb_chars.kind_of?(ActiveSupport::Multibyte.proxy_class)
+ end
+ end
+ end
+
+ if RUBY_VERSION >= '1.9'
+ def test_mb_chars_returns_string
+ assert UNICODE_STRING.mb_chars.kind_of?(String)
+ end
+ end
end \ No newline at end of file