@@ -14,7 +14,9 @@ class TC_JSONEncoding < Test::Unit::TestCase
1414
1515 def setup
1616 @utf_8 = '["© ≠ €!"]'
17- @decoded = [ "© ≠ €!" ]
17+ @parsed = [ "© ≠ €!" ]
18+ @utf_16_data = Iconv . iconv ( 'utf-16be' , 'utf-8' , @parsed . first )
19+ @generated = '["\u00a9 \u2260 \u20ac!"]'
1820 if defined? ( ::Encoding )
1921 @utf_8_ascii_8bit = @utf_8 . dup . force_encoding ( Encoding ::ASCII_8BIT )
2022 @utf_16be , = Iconv . iconv ( 'utf-16be' , 'utf-8' , @utf_8 )
@@ -38,20 +40,28 @@ def setup
3840 end
3941 end
4042
41- def test_decode
42- assert @decoded , JSON . parse ( @utf_8 )
43- assert @decoded , JSON . parse ( @utf_16be )
44- assert @decoded , JSON . parse ( @utf_16le )
45- assert @decoded , JSON . parse ( @utf_32be )
46- assert @decoded , JSON . parse ( @utf_32le )
43+ def test_parse
44+ assert_equal @parsed , JSON . parse ( @utf_8 )
45+ assert_equal @parsed , JSON . parse ( @utf_16be )
46+ assert_equal @parsed , JSON . parse ( @utf_16le )
47+ assert_equal @parsed , JSON . parse ( @utf_32be )
48+ assert_equal @parsed , JSON . parse ( @utf_32le )
4749 end
4850
49- def test_decode_ascii_8bit
50- assert @decoded , JSON . parse ( @utf_8_ascii_8bit )
51- assert @decoded , JSON . parse ( @utf_16be_ascii_8bit )
52- assert @decoded , JSON . parse ( @utf_16le_ascii_8bit )
53- assert @decoded , JSON . parse ( @utf_32be_ascii_8bit )
54- assert @decoded , JSON . parse ( @utf_32le_ascii_8bit )
51+ def test_parse_ascii_8bit
52+ assert_equal @parsed , JSON . parse ( @utf_8_ascii_8bit )
53+ assert_equal @parsed , JSON . parse ( @utf_16be_ascii_8bit )
54+ assert_equal @parsed , JSON . parse ( @utf_16le_ascii_8bit )
55+ assert_equal @parsed , JSON . parse ( @utf_32be_ascii_8bit )
56+ assert_equal @parsed , JSON . parse ( @utf_32le_ascii_8bit )
5557 end
5658
59+ def test_generate
60+ assert_equal @generated , JSON . generate ( @parsed )
61+ if defined? ( ::Encoding )
62+ assert_equal @generated , JSON . generate ( @utf_16_data )
63+ else
64+ assert_raises ( JSON ::GeneratorError ) { JSON . generate ( @utf_16_data ) }
65+ end
66+ end
5767end
0 commit comments