From 9f2fd0f331cf2a4e58eb37dde078f3ba1ab3e154 Mon Sep 17 00:00:00 2001 From: Ry Biesemeyer Date: Wed, 6 Mar 2019 20:04:10 +0000 Subject: [PATCH] add tests for UTF-16 and UTF-32 encodings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > 8.1. Character Encoding > > JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32. The default > encoding is UTF-8, and JSON texts that are encoded in UTF-8 are > interoperable in the sense that they will be read successfully by the > maximum number of implementations; there are many implementations > that cannot successfully read texts in other encodings (such as > UTF-16 and UTF-32). > > -- [RFC7159 §8.1](https://tools.ietf.org/html/rfc7159) --- test/jrjackson_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/jrjackson_test.rb b/test/jrjackson_test.rb index 1f0e608..94eac4f 100755 --- a/test/jrjackson_test.rb +++ b/test/jrjackson_test.rb @@ -468,6 +468,24 @@ def test_can_parse_big_decimals end + def test_can_parse_utf_16 + expected = { "key" => "value👍" } + json_utf_16 = '{"key": "value👍"}'.encode('UTF-16') + + actual = JrJackson::Json.load(json_utf_16) + + assert_equal(expected, actual) + end + + def test_can_parse_utf_32 + expected = { "key" => "value👍" } + json_utf_32 = '{"key": "value👍"}'.encode('UTF-32') + + actual = JrJackson::Json.load(json_utf_32) + + assert_equal(expected, actual) + end + def test_can_serialize_object obj = Object.new actual = JrJackson::Json.dump({"foo" => obj})