summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-23 21:14:31 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-23 21:14:31 +0000
commitd3e0fe6b2f9ea2644137c1032fb579424ce3eac3 (patch)
tree70984be00dea8a599d806d9c94de125893ee45aa
parenta7208d2a8196e83131d0354aba2b9244b75f76d1 (diff)
Added a test for CoW strings.
by John Shahid <jvshahid@gmail.com> https://github.com/ruby/ruby/pull/148 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_transcode.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb
index 9cb42c61d2..8052c82194 100644
--- a/test/ruby/test_transcode.rb
+++ b/test/ruby/test_transcode.rb
@@ -60,6 +60,32 @@ class TestTranscode < Test::Unit::TestCase
assert_equal(str2.force_encoding(enc2), str1.encode(enc2, enc1))
end
+ def test_encoding_of_ascii_originating_from_binary
+ binary_string = [0x82, 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
+ 0x61, 0x20, 0x76, 0x65, 0x72, 0x79, 0x20, 0x6c, 0x6f,
+ 0x6e, 0x67, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67]
+ class << binary_string
+ # create a copy on write substring that contains
+ # just the ascii characters (i.e. this is...), in JRuby
+ # the underlying string have the same buffer backing
+ # it up, but the offset of the string will be 1 instead
+ # of 0.
+ def make_cow_substring
+ pack('C27').slice(1, 26)
+ end
+ end
+
+ ascii_string = binary_string.make_cow_substring
+ assert_equal("this is a very long string", ascii_string)
+ assert_equal(Encoding::ASCII_8BIT, ascii_string.encoding)
+ utf8_string = nil
+ assert_nothing_raised("JRUBY-6764") do
+ utf8_string = ascii_string.encode(Encoding::UTF_8)
+ end
+ assert_equal("this is a very long string", utf8_string)
+ assert_equal(Encoding::UTF_8, utf8_string.encoding)
+ end
+
def test_encodings
check_both_ways("\u307E\u3064\u3082\u3068 \u3086\u304D\u3072\u308D",
"\x82\xdc\x82\xc2\x82\xe0\x82\xc6 \x82\xe4\x82\xab\x82\xd0\x82\xeb", 'shift_jis') # まつもと ゆきひろ