mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/json: Update to JSON 1.4.1.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9372cdb80a
commit
54592ad627
26 changed files with 2434 additions and 1814 deletions
68
test/json/test_json_encoding.rb
Normal file
68
test/json/test_json_encoding.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
require 'test/unit'
|
||||
case ENV['JSON']
|
||||
when 'pure' then require 'json/pure'
|
||||
when 'ext' then require 'json/ext'
|
||||
else require 'json'
|
||||
end
|
||||
require 'iconv'
|
||||
|
||||
class TC_JSONEncoding < Test::Unit::TestCase
|
||||
include JSON
|
||||
|
||||
def setup
|
||||
@utf_8 = '["© ≠ €!"]'
|
||||
@parsed = [ "© ≠ €!" ]
|
||||
@utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
|
||||
@generated = '["\u00a9 \u2260 \u20ac!"]'
|
||||
if defined?(::Encoding)
|
||||
@utf_8_ascii_8bit = @utf_8.dup.force_encoding(Encoding::ASCII_8BIT)
|
||||
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
|
||||
@utf_16be_ascii_8bit = @utf_16be.dup.force_encoding(Encoding::ASCII_8BIT)
|
||||
@utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
|
||||
@utf_16le_ascii_8bit = @utf_16le.dup.force_encoding(Encoding::ASCII_8BIT)
|
||||
@utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
|
||||
@utf_32be_ascii_8bit = @utf_32be.dup.force_encoding(Encoding::ASCII_8BIT)
|
||||
@utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
|
||||
@utf_32le_ascii_8bit = @utf_32le.dup.force_encoding(Encoding::ASCII_8BIT)
|
||||
else
|
||||
@utf_8_ascii_8bit = @utf_8.dup
|
||||
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
|
||||
@utf_16be_ascii_8bit = @utf_16be.dup
|
||||
@utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
|
||||
@utf_16le_ascii_8bit = @utf_16le.dup
|
||||
@utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
|
||||
@utf_32be_ascii_8bit = @utf_32be.dup
|
||||
@utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
|
||||
@utf_32le_ascii_8bit = @utf_32le.dup
|
||||
end
|
||||
end
|
||||
|
||||
def test_parse
|
||||
assert_equal @parsed, JSON.parse(@utf_8)
|
||||
assert_equal @parsed, JSON.parse(@utf_16be)
|
||||
assert_equal @parsed, JSON.parse(@utf_16le)
|
||||
assert_equal @parsed, JSON.parse(@utf_32be)
|
||||
assert_equal @parsed, JSON.parse(@utf_32le)
|
||||
end
|
||||
|
||||
def test_parse_ascii_8bit
|
||||
assert_equal @parsed, JSON.parse(@utf_8_ascii_8bit)
|
||||
assert_equal @parsed, JSON.parse(@utf_16be_ascii_8bit)
|
||||
assert_equal @parsed, JSON.parse(@utf_16le_ascii_8bit)
|
||||
assert_equal @parsed, JSON.parse(@utf_32be_ascii_8bit)
|
||||
assert_equal @parsed, JSON.parse(@utf_32le_ascii_8bit)
|
||||
end
|
||||
|
||||
def test_generate
|
||||
assert_equal @generated, JSON.generate(@parsed, :ascii_only => true)
|
||||
if defined?(::Encoding)
|
||||
assert_equal @generated, JSON.generate(@utf_16_data, :ascii_only => true)
|
||||
else
|
||||
# XXX checking of correct utf8 data is not as strict (yet?) without :ascii_only
|
||||
assert_raises(JSON::GeneratorError) { JSON.generate(@utf_16_data, :ascii_only => true) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue