Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move the test to test/ruby/test_transcode.rb and change the test to l…
…ook like what @tenderlove and @nobu suggested.
  • Loading branch information
jvshahid committed Jul 29, 2012
commit 32c63d97add4d403d158b27de413bb4b0c51a681
11 changes: 0 additions & 11 deletions test/ruby/test_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ def test_encoding
end
end

def test_encoding_of_ascii_originating_from_binary
binary_string = "\x82foo"
ascii_string = binary_string.bytes.to_a.pack('c*')[1..-1]
assert_equal "foo", ascii_string
assert_equal "ASCII-8BIT", ascii_string.encoding.name
utf8_string = ascii_string.encode("UTF-8")
assert_equal "foo", utf8_string
assert_equal "UTF-8", utf8_string.encoding.name
puts "End"
end

def test_enc_names
aliases = Encoding.aliases
aliases.each do |a, en|
Expand Down
24 changes: 24 additions & 0 deletions test/ruby/test_transcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ def check_both_ways2(str1, enc1, str2, enc2)
assert_equal(str2.force_encoding(enc2), str1.encode(enc2, enc1))
end

def test_encoding_of_ascii_originating_from_binary
binary_string = [0x82, 0x66, 0x6f, 0x6f]
class << binary_string
# create a copy on write substring that contains
# just the ascii characters (i.e. foo), 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('C4').slice(1, 3)
end
end

ascii_string = binary_string.make_cow_substring
assert_equal("foo", 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("foo", 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') # まつもと ゆきひろ
Expand Down