diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-01 07:02:08 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-01 07:02:08 +0000 |
commit | 6016591e1cc54e48d58662180cc548c03334e1c5 (patch) | |
tree | ccca4b39098ccc785c863cb9115e5ef60d6cfe7d /test/ruby/test_string.rb | |
parent | f83651ac30c7c776dee8a6a401c654757cb8d1c2 (diff) | |
download | ruby-6016591e1cc54e48d58662180cc548c03334e1c5.tar.gz |
* string.c (rb_str_byteslice): the resulted encoding should keep
original encoding. this also fixes the encoding when the result
shares internal string. [ruby-core:35376]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_string.rb')
-rw-r--r-- | test/ruby/test_string.rb | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index f18c8148e4..0b632ab1a8 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1945,32 +1945,34 @@ class TestString < Test::Unit::TestCase assert_equal(S("hello "), b) end - def b(str) - str.force_encoding(Encoding::ASCII_8BIT) + def u(str) + str.force_encoding(Encoding::UTF_8) end def test_byteslice - assert_equal(b("h"), "hello".byteslice(0)) + assert_equal("h", "hello".byteslice(0)) assert_equal(nil, "hello".byteslice(5)) - assert_equal(b("o"), "hello".byteslice(-1)) + assert_equal("o", "hello".byteslice(-1)) assert_equal(nil, "hello".byteslice(-6)) - assert_equal(b(""), "hello".byteslice(0, 0)) - assert_equal(b("hello"), "hello".byteslice(0, 6)) - assert_equal(b("hello"), "hello".byteslice(0, 6)) - assert_equal(b(""), "hello".byteslice(5, 1)) - assert_equal(b("o"), "hello".byteslice(-1, 6)) + assert_equal("", "hello".byteslice(0, 0)) + assert_equal("hello", "hello".byteslice(0, 6)) + assert_equal("hello", "hello".byteslice(0, 6)) + assert_equal("", "hello".byteslice(5, 1)) + assert_equal("o", "hello".byteslice(-1, 6)) assert_equal(nil, "hello".byteslice(-6, 1)) - assert_equal(b("h"), "hello".byteslice(0..0)) - assert_equal(b(""), "hello".byteslice(5..0)) - assert_equal(b("o"), "hello".byteslice(4..5)) + assert_equal("h", "hello".byteslice(0..0)) + assert_equal("", "hello".byteslice(5..0)) + assert_equal("o", "hello".byteslice(4..5)) assert_equal(nil, "hello".byteslice(6..0)) - assert_equal(b(""), "hello".byteslice(-1..0)) - assert_equal(b("llo"), "hello".byteslice(-3..5)) + assert_equal("", "hello".byteslice(-1..0)) + assert_equal("llo", "hello".byteslice(-3..5)) - assert_equal(b("\x81"), "\u3042".byteslice(1)) - assert_equal(b("\x81\x82"), "\u3042".byteslice(1, 2)) - assert_equal(b("\x81\x82"), "\u3042".byteslice(1..2)) + assert_equal(u("\x81"), "\u3042".byteslice(1)) + assert_equal(u("\x81\x82"), "\u3042".byteslice(1, 2)) + assert_equal(u("\x81\x82"), "\u3042".byteslice(1..2)) + + assert_equal(u("\x82")+("\u3042"*9), ("\u3042"*10).byteslice(2, 28)) end end |