Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add UTF-8 roundtrip tests #46

Closed
wants to merge 2 commits into from

2 participants

@julik

Knowing that Unicode is that little something-something which gets broken every now and then I thought it might be useful to have a couple of roundtrip tests for a clean UTF-8 string, for two most common cases (string and hash).

@tenderlove
Owner

These tests are tightly coupled with the YAML format. Can you change them to do roundtrip testing? Thanks.

@tenderlove tenderlove closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 10, 2012
  1. @julik

    Add a UTF-8 roundtrip test

    julik authored
  2. @julik
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 0 deletions.
  1. +9 −0 test/psych/test_hash.rb
  2. +8 −0 test/psych/test_string.rb
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
Something went wrong with that request. Please try again.