1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
# encoding: UTF-8
require_relative "./test_helper"
class HTMLEntities::StringEncodingsTest < Test::Unit::TestCase
def test_should_encode_ascii_to_ascii
s = "<elan>".encode(Encoding::US_ASCII)
assert_equal Encoding::US_ASCII, s.encoding
t = HTMLEntities.new.encode(s)
assert_equal "<elan>", t
assert_equal Encoding::US_ASCII, t.encoding
end
def test_should_encode_utf8_to_utf8_if_needed
s = "<élan>"
assert_equal Encoding::UTF_8, s.encoding
t = HTMLEntities.new.encode(s)
assert_equal "<élan>", t
assert_equal Encoding::UTF_8, t.encoding
end
def test_should_encode_utf8_to_ascii_if_possible
s = "<elan>"
assert_equal Encoding::UTF_8, s.encoding
t = HTMLEntities.new.encode(s)
assert_equal "<elan>", t
assert_equal Encoding::US_ASCII, t.encoding
end
def test_should_encode_other_encoding_to_utf8
s = "<élan>".encode(Encoding::ISO_8859_1)
assert_equal Encoding::ISO_8859_1, s.encoding
t = HTMLEntities.new.encode(s)
assert_equal "<élan>", t
assert_equal Encoding::UTF_8, t.encoding
end
def test_should_decode_ascii_to_utf8
s = "<élan>".encode(Encoding::US_ASCII)
assert_equal Encoding::US_ASCII, s.encoding
t = HTMLEntities.new.decode(s)
assert_equal "<élan>", t
assert_equal Encoding::UTF_8, t.encoding
end
def test_should_decode_utf8_to_utf8
s = "<élan>".encode(Encoding::UTF_8)
assert_equal Encoding::UTF_8, s.encoding
t = HTMLEntities.new.decode(s)
assert_equal "<élan>", t
assert_equal Encoding::UTF_8, t.encoding
end
def test_should_decode_other_encoding_to_utf8
s = "<élan>".encode(Encoding::ISO_8859_1)
assert_equal Encoding::ISO_8859_1, s.encoding
t = HTMLEntities.new.decode(s)
assert_equal "<élan>", t
assert_equal Encoding::UTF_8, t.encoding
end
end
|