mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_transcode.rb: added tests from Martin Duerst <duerst
AT it.aoyama.ac.jp>. [ruby-dev:32532] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a153fdb6ed
commit
3609358aac
2 changed files with 63 additions and 29 deletions
|
@ -1,10 +1,13 @@
|
|||
Tue Dec 11 13:57:25 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Tue Dec 11 14:27:50 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* transcode.c (transcode_loop): get rid of SEGV at sequence can not be
|
||||
converted.
|
||||
|
||||
* transcode.c (rb_str_transcode_bang): copy encoding. [ruby-dev:32532]
|
||||
|
||||
* test/ruby/test_transcode.rb: added tests from Martin Duerst <duerst
|
||||
AT it.aoyama.ac.jp>. [ruby-dev:32532]
|
||||
|
||||
Tue Dec 11 12:05:51 2007 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* encoding.c (rb_enc_get_ascii): add an argument to provide the
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
# -*- encoding: US-ASCII -*- # make sure this runs in binary mode
|
||||
|
||||
class String
|
||||
# different name, because we should be able to remove this later
|
||||
def fix_encoding (encoding)
|
||||
force_encoding(encoding)
|
||||
end
|
||||
end
|
||||
|
||||
require 'test/unit'
|
||||
class TestConvert < Test::Unit::TestCase
|
||||
def test_can_call
|
||||
def test_basic
|
||||
# we don't have semantics for conversion without attribute yet
|
||||
# maybe 'convert to UTF-8' would be nice :-)
|
||||
assert_raise(ArgumentError) { 'abc'.encode }
|
||||
|
@ -20,25 +13,63 @@ class TestConvert < Test::Unit::TestCase
|
|||
assert_raise(ArgumentError) { 'abc'.encode!('foo', 'bar') }
|
||||
assert_raise(ArgumentError) { 'abc'.force_encoding('utf-8').encode('foo') }
|
||||
assert_raise(ArgumentError) { 'abc'.force_encoding('utf-8').encode!('foo') }
|
||||
assert_equal('abc'.force_encoding('utf-8').encode('iso-8859-1'), 'abc') # temporary, fix encoding
|
||||
assert_equal("D\xFCrst".force_encoding('iso-8859-1').encode('utf-8').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-1').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-2').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-3').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-4').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-9').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-10').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-13').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-14').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-15').fix_encoding('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-1'), "D\xFCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-2'), "D\xFCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-3'), "D\xFCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-4'), "D\xFCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-9'), "D\xFCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-10'), "D\xFCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-13'), "D\xFCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-14'), "D\xFCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-15'), "D\xFCrst")
|
||||
assert_equal('abc'.force_encoding('utf-8').encode('iso-8859-1'), 'abc')
|
||||
# check that encoding is kept when no conversion is done
|
||||
assert_equal('abc'.force_encoding('Shift_JIS').encode('Shift_JIS'), 'abc'.force_encoding('Shift_JIS'))
|
||||
assert_equal('abc'.force_encoding('Shift_JIS').encode!('Shift_JIS'), 'abc'.force_encoding('Shift_JIS'))
|
||||
# assert that encoding is correctly set
|
||||
assert_equal("D\xFCrst".force_encoding('iso-8859-1').encode('utf-8').encoding, "D\u00FCrst".encoding)
|
||||
# check that Encoding can be used as parameter
|
||||
assert_equal("D\xFCrst".encode('utf-8', Encoding.find('ISO-8859-1')), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode(Encoding.find('utf-8'), 'ISO-8859-1'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode(Encoding.find('utf-8'), Encoding.find('ISO-8859-1')), "D\u00FCrst")
|
||||
|
||||
# temporary, fix encoding
|
||||
assert_equal("D\xFCrst".force_encoding('iso-8859-1').encode('utf-8'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-1'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-2'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-3'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-4'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-9'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-10'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-13'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-14'), "D\u00FCrst")
|
||||
assert_equal("D\xFCrst".encode('utf-8', 'iso-8859-15'), "D\u00FCrst")
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-1'), "D\xFCrst".force_encoding('iso-8859-1'))
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-2'), "D\xFCrst".force_encoding('iso-8859-2'))
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-3'), "D\xFCrst".force_encoding('iso-8859-3'))
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-4'), "D\xFCrst".force_encoding('iso-8859-4'))
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-9'), "D\xFCrst".force_encoding('iso-8859-9'))
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-10'), "D\xFCrst".force_encoding('iso-8859-10'))
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-13'), "D\xFCrst".force_encoding('iso-8859-13'))
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-14'), "D\xFCrst".force_encoding('iso-8859-14'))
|
||||
assert_equal("D\u00FCrst".encode('iso-8859-15'), "D\xFCrst".force_encoding('iso-8859-15'))
|
||||
# test length extension
|
||||
assert_equal(("\xA4"*20).encode('utf-8', 'iso-8859-15'), "\u20AC"*20)
|
||||
assert_equal(("\xA4"*20).encode!('utf-8', 'iso-8859-15'), "\u20AC"*20)
|
||||
|
||||
end
|
||||
|
||||
def test_all_bytes
|
||||
encodings_8859 = [
|
||||
'ISO-8859-1', 'ISO-8859-2',
|
||||
#'ISO-8859-3', # not all bytes used
|
||||
'ISO-8859-4', 'ISO-8859-5',
|
||||
#'ISO-8859-6', # not all bytes used
|
||||
#'ISO-8859-7', # not all bytes used
|
||||
#'ISO-8859-8', # not all bytes used
|
||||
'ISO-8859-9', 'ISO-8859-10',
|
||||
#'ISO-8859-11', # not all bytes used
|
||||
#'ISO-8859-12', # not available
|
||||
'ISO-8859-13','ISO-8859-14','ISO-8859-15',
|
||||
#'ISO-8859-16', # not available
|
||||
]
|
||||
all_bytes = (0..255).collect {|x| x}.pack 'C*'
|
||||
test_start = all_bytes
|
||||
test_start.encode('UTF-8','ISO-8859-1').encode('ISO-8859-1')
|
||||
encodings_8859.each do |enc|
|
||||
test_start = all_bytes
|
||||
assert_equal(test_start.encode('UTF-8',enc).encode(enc).force_encoding('ASCII-8BIT'), test_start)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue