2007-10-14 04:31:51 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
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))
|
|
|
|
end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2008-10-09 03:33:55 -04:00
|
|
|
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
|
2007-10-14 04:31:51 -04:00
|
|
|
|
|
|
|
# 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)
|
2009-03-05 22:56:38 -05:00
|
|
|
end
|
2007-10-14 04:31:51 -04:00
|
|
|
end
|
2008-06-03 09:34:48 -04:00
|
|
|
|
|
|
|
def test_find
|
|
|
|
assert_raise(ArgumentError) { Encoding.find("foobarbazqux") }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dummy_p
|
|
|
|
assert_equal(true, Encoding::ISO_2022_JP.dummy?)
|
|
|
|
assert_equal(false, Encoding::UTF_8.dummy?)
|
|
|
|
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
|
2007-10-14 04:31:51 -04:00
|
|
|
end
|