Add UTF-8 roundtrip tests #46

Closed
wants to merge 2 commits into
from
View
9 test/psych/test_hash.rb
@@ -21,6 +21,15 @@ def test_map
assert_equal X, x.class
end
+ def test_hash_roundtrip_with_utf8_key_and_value
+ string = [1055, 1086, 1079, 1086, 1088, 1080, 1097, 1077].pack("U*")
+ string.force_encoding 'utf-8'
+ hash = {string => string}
+ yml = Psych.dump hash
+ assert_equal "---\n#{string}: #{string}\n", yml
+ assert_equal hash, Psych.load(yml)
+ end
+
def test_self_referential
@hash['self'] = @hash
assert_cycle(@hash)
View
8 test/psych/test_string.rb
@@ -55,6 +55,14 @@ def test_binary_string
assert_equal string, Psych.load(yml)
end
+ def test_utf8_string
+ string = [1055, 1086, 1079, 1086, 1088, 1080, 1097, 1077].pack("U*")
+ string.force_encoding 'utf-8'
+ yml = Psych.dump string
+ assert_equal "--- #{string}\n...\n", yml
+ assert_equal string, Psych.load(yml)
+ end
+
def test_non_binary_string
string = binary_string(0.29)
yml = Psych.dump string