diff options
author | Florian Frank <flori@ping.de> | 2009-10-15 21:02:49 +0200 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2009-10-16 21:51:09 +0200 |
commit | 03b157516fa22ac135496a3831963f8305f7a0bb (patch) | |
tree | cd16481453ac694256e8177caf0f7b9047670aa0 /tests | |
parent | d9f9557594840b0381007d2dad769d473adc59f3 (diff) | |
download | json-03b157516fa22ac135496a3831963f8305f7a0bb.tar.gz |
implemented utf sniffing, transcoding in parser
improved documentation
added to changes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_json_encoding.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_json_encoding.rb b/tests/test_json_encoding.rb new file mode 100644 index 0000000..f46b476 --- /dev/null +++ b/tests/test_json_encoding.rb @@ -0,0 +1,57 @@ +#!/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 = '["© ≠ €!"]' + @decoded = [ "© ≠ €!" ] + 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_decode + assert @decoded, JSON.parse(@utf_8) + assert @decoded, JSON.parse(@utf_16be) + assert @decoded, JSON.parse(@utf_16le) + assert @decoded, JSON.parse(@utf_32be) + assert @decoded, JSON.parse(@utf_32le) + end + + def test_decode_ascii_8bit + assert @decoded, JSON.parse(@utf_8_ascii_8bit) + assert @decoded, JSON.parse(@utf_16be_ascii_8bit) + assert @decoded, JSON.parse(@utf_16le_ascii_8bit) + assert @decoded, JSON.parse(@utf_32be_ascii_8bit) + assert @decoded, JSON.parse(@utf_32le_ascii_8bit) + end + +end |