1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/ruby/test_encoding.rb
shugo 1f828497d1 * safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4.  $SAFE=4 is now obsolete.
  [ruby-core:55222] [Feature #8468]

* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
  Kernel#untrusted?, untrust, and trust are now deprecated.
  Their behavior is same as tainted?, taint, and untaint,
  respectively.

* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
  and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
  respectively.

* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
  ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
  ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
  ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
  ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
  ext/socket/socket.c, ext/socket/udpsocket.c,
  ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
  ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
  load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
  safe.c, string.c, thread.c, transcode.c, variable.c,
  vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
  $SAFE=4.

* test/dl/test_dl2.rb, test/erb/test_erb.rb,
  test/readline/test_readline.rb,
  test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
  test/ruby/test_array.rb, test/ruby/test_dir.rb,
  test/ruby/test_encoding.rb, test/ruby/test_env.rb,
  test/ruby/test_eval.rb, test/ruby/test_exception.rb,
  test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
  test/ruby/test_io.rb, test/ruby/test_method.rb,
  test/ruby/test_module.rb, test/ruby/test_object.rb,
  test/ruby/test_pack.rb, test/ruby/test_rand.rb,
  test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
  test/ruby/test_struct.rb, test/ruby/test_thread.rb,
  test/ruby/test_time.rb: remove tests for $SAFE=4.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 14:20:51 +00:00

111 lines
3.4 KiB
Ruby

require 'test/unit'
require_relative 'envutil'
class TestEncoding < Test::Unit::TestCase
# Test basic encoding methods: list, find, name
def test_encoding
encodings = Encoding.list
assert_equal(encodings.empty?, false)
encodings.each do |e|
assert_equal(e, Encoding.find(e.name))
assert_equal(e, Encoding.find(e.name.upcase))
assert_equal(e, Encoding.find(e.name.capitalize))
assert_equal(e, Encoding.find(e.name.downcase))
assert_equal(e, Encoding.find(e))
end
end
def test_enc_names
aliases = Encoding.aliases
aliases.each do |a, en|
e = Encoding.find(a)
assert_equal(e.name, en)
assert(e.names.include?(a))
end
end
# Test that Encoding objects can't be copied
# And that they can be compared by object_id
def test_singleton
encodings = Encoding.list
encodings.each do |e|
assert_raise(TypeError) { e.dup }
assert_raise(TypeError) { e.clone }
assert_equal(e.object_id, Marshal.load(Marshal.dump(e)).object_id)
end
end
def test_find
assert_raise(ArgumentError) { Encoding.find("foobarbazqux") }
assert_nothing_raised{Encoding.find("locale")}
assert_nothing_raised{Encoding.find("filesystem")}
if /(?:ms|dar)win|mingw/ !~ RUBY_PLATFORM
# Unix's filesystem encoding is default_external
assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS')
exit Encoding.find("filesystem") == Encoding::UTF_8
Encoding.default_external = Encoding::EUC_JP
exit Encoding.find("filesystem") == Encoding::EUC_JP
EOS
end
bug5150 = '[ruby-dev:44327]'
assert_raise(TypeError, bug5150) {Encoding.find(1)}
end
def test_replicate
assert_instance_of(Encoding, Encoding::UTF_8.replicate('UTF-8-ANOTHER'))
assert_instance_of(Encoding, Encoding::ISO_2022_JP.replicate('ISO-2022-JP-ANOTHER'))
bug3127 = '[ruby-dev:40954]'
assert_raise(TypeError, bug3127) {Encoding::UTF_8.replicate(0)}
assert_raise(ArgumentError, bug3127) {Encoding::UTF_8.replicate("\0")}
end
def test_dummy_p
assert_equal(true, Encoding::ISO_2022_JP.dummy?)
assert_equal(false, Encoding::UTF_8.dummy?)
end
def test_ascii_compatible_p
assert_equal(true, Encoding::ASCII_8BIT.ascii_compatible?)
assert_equal(true, Encoding::UTF_8.ascii_compatible?)
assert_equal(false, Encoding::UTF_16BE.ascii_compatible?)
assert_equal(false, Encoding::ISO_2022_JP.ascii_compatible?)
end
def test_name_list
assert_instance_of(Array, Encoding.name_list)
Encoding.name_list.each do |x|
assert_instance_of(String, x)
end
end
def test_aliases
assert_instance_of(Hash, Encoding.aliases)
Encoding.aliases.each do |k, v|
assert(Encoding.name_list.include?(k))
assert(Encoding.name_list.include?(v))
assert_instance_of(String, k)
assert_instance_of(String, v)
end
end
def test_marshal
str = "".force_encoding("EUC-JP")
str2 = Marshal.load(Marshal.dump(str))
assert_equal(str, str2)
str2 = Marshal.load(Marshal.dump(str2))
assert_equal(str, str2, '[ruby-dev:38596]')
end
def test_compatible_p
ua = "abc".force_encoding(Encoding::UTF_8)
assert_equal(Encoding::UTF_8, Encoding.compatible?(ua, :abc))
assert_equal(nil, Encoding.compatible?(ua, 1))
bin = "a".force_encoding(Encoding::ASCII_8BIT)
asc = "b".force_encoding(Encoding::US_ASCII)
assert_equal(Encoding::ASCII_8BIT, Encoding.compatible?(bin, asc))
end
end