summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-15 07:28:50 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-15 07:28:50 +0000
commitef18be23664d105954a2685a28e5deb868fa6a8e (patch)
tree8d8c33b2e6d179cc2b061a25a84fe56cf5497f2e /test
parent4c5171bb17198984de8424d3e1b5f2652f3256a9 (diff)
* object.c (rb_inspect): raise the result is not compatible with
the default external encoding. [ruby-core:42095] [Bug #5848] If the default external encoding is ASCII compatible, the encoding of inspected result must be compatible with it. If the default external encoding is ASCII incomapatible, the result must be ASCII only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_m17n.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 7c261138ba..3bfb540b13 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -271,6 +271,34 @@ class TestM17N < Test::Unit::TestCase
Encoding.default_external = orig_ext
end
+ def test_object_inspect_external
+ orig_v, $VERBOSE = $VERBOSE, false
+ orig_int, Encoding.default_internal = Encoding.default_internal, nil
+ orig_ext = Encoding.default_external
+ o = Object.new
+
+ Encoding.default_external = Encoding::UTF_16BE
+ def o.inspect
+ "abc"
+ end
+ assert_nothing_raised(Encoding::CompatibilityError) { [o].inspect }
+
+ def o.inspect
+ "abc".encode(Encoding.default_external)
+ end
+ assert_raise(Encoding::CompatibilityError) { [o].inspect }
+
+ Encoding.default_external = Encoding::US_ASCII
+ def o.inspect
+ "\u3042"
+ end
+ assert_raise(Encoding::CompatibilityError) { [o].inspect }
+ ensure
+ Encoding.default_internal = orig_int
+ Encoding.default_external = orig_ext
+ $VERBOSE = orig_v
+ end
+
def test_str_dump
[
e("\xfe"),