json 1.4.6 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of json might be problematic. Click here for more details.
- data/CHANGES +6 -0
- data/COPYING-json-jruby +57 -0
- data/README-json-jruby.markdown +33 -0
- data/Rakefile +224 -119
- data/VERSION +1 -1
- data/benchmarks/generator2_benchmark.rb +1 -1
- data/benchmarks/generator_benchmark.rb +1 -1
- data/ext/json/ext/generator/generator.c +20 -20
- data/ext/json/ext/generator/generator.h +7 -7
- data/ext/json/ext/parser/extconf.rb +1 -0
- data/ext/json/ext/parser/parser.c +122 -88
- data/ext/json/ext/parser/parser.h +7 -0
- data/ext/json/ext/parser/parser.rl +54 -20
- data/java/lib/bytelist-1.0.6.jar +0 -0
- data/java/lib/jcodings.jar +0 -0
- data/java/src/json/ext/ByteListTranscoder.java +167 -0
- data/java/src/json/ext/Generator.java +441 -0
- data/java/src/json/ext/GeneratorMethods.java +231 -0
- data/java/src/json/ext/GeneratorService.java +42 -0
- data/java/src/json/ext/GeneratorState.java +473 -0
- data/java/src/json/ext/OptionsReader.java +119 -0
- data/java/src/json/ext/Parser.java +2295 -0
- data/java/src/json/ext/Parser.rl +825 -0
- data/java/src/json/ext/ParserService.java +34 -0
- data/java/src/json/ext/RuntimeInfo.java +119 -0
- data/java/src/json/ext/StringDecoder.java +166 -0
- data/java/src/json/ext/StringEncoder.java +106 -0
- data/java/src/json/ext/Utils.java +89 -0
- data/json-java.gemspec +20 -0
- data/lib/json/add/core.rb +1 -2
- data/lib/json/add/rails.rb +4 -54
- data/lib/json/common.rb +36 -8
- data/lib/json/editor.rb +1 -3
- data/lib/json/ext.rb +2 -2
- data/lib/json/pure.rb +2 -64
- data/lib/json/pure/generator.rb +10 -8
- data/lib/json/pure/parser.rb +23 -12
- data/lib/json/version.rb +1 -1
- data/tests/setup_variant.rb +11 -0
- data/tests/test_json.rb +1 -5
- data/tests/test_json_addition.rb +14 -9
- data/tests/test_json_encoding.rb +9 -12
- data/tests/test_json_fixtures.rb +9 -8
- data/tests/test_json_generate.rb +3 -5
- data/tests/test_json_string_matching.rb +40 -0
- data/tests/test_json_unicode.rb +1 -5
- metadata +51 -13
- data/tests/test_json_rails.rb +0 -144
data/tests/test_json_addition.rb
CHANGED
@@ -2,12 +2,8 @@
|
|
2
2
|
# -*- coding:utf-8 -*-
|
3
3
|
|
4
4
|
require 'test/unit'
|
5
|
-
|
6
|
-
|
7
|
-
when 'ext' then require 'json/ext'
|
8
|
-
else require 'json'
|
9
|
-
end
|
10
|
-
require 'json/add/core'
|
5
|
+
require File.join(File.dirname(__FILE__), 'setup_variant')
|
6
|
+
load 'json/add/core.rb'
|
11
7
|
require 'date'
|
12
8
|
|
13
9
|
class TC_JSONAddition < Test::Unit::TestCase
|
@@ -36,6 +32,15 @@ class TC_JSONAddition < Test::Unit::TestCase
|
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
35
|
+
class A2 < A
|
36
|
+
def to_json(*args)
|
37
|
+
{
|
38
|
+
'json_class' => self.class.name,
|
39
|
+
'args' => [ @a ],
|
40
|
+
}.to_json(*args)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
39
44
|
class B
|
40
45
|
def self.json_creatable?
|
41
46
|
false
|
@@ -110,9 +115,9 @@ class TC_JSONAddition < Test::Unit::TestCase
|
|
110
115
|
json_raw_object = raw.to_json_raw_object
|
111
116
|
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
112
117
|
assert_equal hash, json_raw_object
|
113
|
-
assert_match
|
114
|
-
assert_match
|
115
|
-
assert_match
|
118
|
+
assert_match(/\A\{.*\}\Z/, json)
|
119
|
+
assert_match(/"json_class":"String"/, json)
|
120
|
+
assert_match(/"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json)
|
116
121
|
raw_again = JSON.parse(json)
|
117
122
|
assert_equal raw, raw_again
|
118
123
|
end
|
data/tests/test_json_encoding.rb
CHANGED
@@ -2,12 +2,7 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
4
|
require 'test/unit'
|
5
|
-
|
6
|
-
when 'pure' then require 'json/pure'
|
7
|
-
when 'ext' then require 'json/ext'
|
8
|
-
else require 'json'
|
9
|
-
end
|
10
|
-
require 'iconv'
|
5
|
+
require File.join(File.dirname(__FILE__), 'setup_variant')
|
11
6
|
|
12
7
|
class TC_JSONEncoding < Test::Unit::TestCase
|
13
8
|
include JSON
|
@@ -15,19 +10,21 @@ class TC_JSONEncoding < Test::Unit::TestCase
|
|
15
10
|
def setup
|
16
11
|
@utf_8 = '["© ≠ €!"]'
|
17
12
|
@parsed = [ "© ≠ €!" ]
|
18
|
-
@utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
|
19
13
|
@generated = '["\u00a9 \u2260 \u20ac!"]'
|
20
|
-
if
|
14
|
+
if String.method_defined?(:encode)
|
15
|
+
@utf_16_data = [@parsed.first.encode('utf-16be', 'utf-8')]
|
21
16
|
@utf_8_ascii_8bit = @utf_8.dup.force_encoding(Encoding::ASCII_8BIT)
|
22
|
-
@utf_16be
|
17
|
+
@utf_16be = @utf_8.encode('utf-16be', 'utf-8')
|
23
18
|
@utf_16be_ascii_8bit = @utf_16be.dup.force_encoding(Encoding::ASCII_8BIT)
|
24
|
-
@utf_16le
|
19
|
+
@utf_16le = @utf_8.encode('utf-16le', 'utf-8')
|
25
20
|
@utf_16le_ascii_8bit = @utf_16le.dup.force_encoding(Encoding::ASCII_8BIT)
|
26
|
-
@utf_32be
|
21
|
+
@utf_32be = @utf_8.encode('utf-32be', 'utf-8')
|
27
22
|
@utf_32be_ascii_8bit = @utf_32be.dup.force_encoding(Encoding::ASCII_8BIT)
|
28
|
-
@utf_32le
|
23
|
+
@utf_32le = @utf_8.encode('utf-32le', 'utf-8')
|
29
24
|
@utf_32le_ascii_8bit = @utf_32le.dup.force_encoding(Encoding::ASCII_8BIT)
|
30
25
|
else
|
26
|
+
require 'iconv'
|
27
|
+
@utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
|
31
28
|
@utf_8_ascii_8bit = @utf_8.dup
|
32
29
|
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
|
33
30
|
@utf_16be_ascii_8bit = @utf_16be.dup
|
data/tests/test_json_fixtures.rb
CHANGED
@@ -2,11 +2,7 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
4
|
require 'test/unit'
|
5
|
-
|
6
|
-
when 'pure' then require 'json/pure'
|
7
|
-
when 'ext' then require 'json/ext'
|
8
|
-
else require 'json'
|
9
|
-
end
|
5
|
+
require File.join(File.dirname(__FILE__), 'setup_variant')
|
10
6
|
|
11
7
|
class TC_JSONFixtures < Test::Unit::TestCase
|
12
8
|
def setup
|
@@ -18,15 +14,20 @@ class TC_JSONFixtures < Test::Unit::TestCase
|
|
18
14
|
|
19
15
|
def test_passing
|
20
16
|
for name, source in @passed
|
21
|
-
|
22
|
-
|
17
|
+
begin
|
18
|
+
assert JSON.parse(source),
|
19
|
+
"Did not pass for fixture '#{name}': #{source.inspect}"
|
20
|
+
rescue => e
|
21
|
+
warn "\nCaught #{e.class}(#{e}) for fixture '#{name}': #{source.inspect}\n#{e.backtrace * "\n"}"
|
22
|
+
raise e
|
23
|
+
end
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def test_failing
|
27
28
|
for name, source in @failed
|
28
29
|
assert_raises(JSON::ParserError, JSON::NestingError,
|
29
|
-
"Did not fail for fixture '#{name}'") do
|
30
|
+
"Did not fail for fixture '#{name}': #{source.inspect}") do
|
30
31
|
JSON.parse(source)
|
31
32
|
end
|
32
33
|
end
|
data/tests/test_json_generate.rb
CHANGED
@@ -2,11 +2,7 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
4
|
require 'test/unit'
|
5
|
-
|
6
|
-
when 'pure' then require 'json/pure'
|
7
|
-
when 'ext' then require 'json/ext'
|
8
|
-
else require 'json'
|
9
|
-
end
|
5
|
+
require File.join(File.dirname(__FILE__), 'setup_variant')
|
10
6
|
|
11
7
|
class TC_JSONGenerate < Test::Unit::TestCase
|
12
8
|
include JSON
|
@@ -84,6 +80,8 @@ EOT
|
|
84
80
|
assert_raise(GeneratorError) { fast_generate(666) }
|
85
81
|
end
|
86
82
|
|
83
|
+
|
84
|
+
|
87
85
|
def test_states
|
88
86
|
json = generate({1=>2}, nil)
|
89
87
|
assert_equal('{"1":2}', json)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require File.join(File.dirname(__FILE__), 'setup_variant')
|
6
|
+
require 'stringio'
|
7
|
+
require 'time'
|
8
|
+
|
9
|
+
class TestJsonStringMatching < Test::Unit::TestCase
|
10
|
+
include JSON
|
11
|
+
|
12
|
+
class TestTime < ::Time
|
13
|
+
def self.json_create(string)
|
14
|
+
Time.parse(string)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_json(*)
|
18
|
+
%{"#{strftime('%FT%T%z')}"}
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(other)
|
22
|
+
to_i == other.to_i
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_match_date
|
27
|
+
t = TestTime.new
|
28
|
+
t_json = [ t ].to_json
|
29
|
+
assert_equal [ t ],
|
30
|
+
JSON.parse(t_json,
|
31
|
+
:match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
|
32
|
+
assert_equal [ t.strftime('%FT%T%z') ],
|
33
|
+
JSON.parse(t_json,
|
34
|
+
:match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
|
35
|
+
assert_equal [ t.strftime('%FT%T%z') ],
|
36
|
+
JSON.parse(t_json,
|
37
|
+
:match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime },
|
38
|
+
:create_additions => false)
|
39
|
+
end
|
40
|
+
end
|
data/tests/test_json_unicode.rb
CHANGED
@@ -2,11 +2,7 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
4
|
require 'test/unit'
|
5
|
-
|
6
|
-
when 'pure' then require 'json/pure'
|
7
|
-
when 'ext' then require 'json/ext'
|
8
|
-
else require 'json'
|
9
|
-
end
|
5
|
+
require File.join(File.dirname(__FILE__), 'setup_variant')
|
10
6
|
|
11
7
|
class TC_JSONUnicode < Test::Unit::TestCase
|
12
8
|
include JSON
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 3
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 1.5.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Florian Frank
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-01-22 00:00:00 +01:00
|
13
19
|
default_executable: edit_json.rb
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -76,8 +82,25 @@ files:
|
|
76
82
|
- ext/json/ext/parser/parser.h
|
77
83
|
- ext/json/ext/parser/parser.c
|
78
84
|
- Rakefile
|
85
|
+
- README-json-jruby.markdown
|
79
86
|
- tools/fuzz.rb
|
80
87
|
- tools/server.rb
|
88
|
+
- java/src/json/ext/Parser.rl
|
89
|
+
- java/src/json/ext/StringDecoder.java
|
90
|
+
- java/src/json/ext/GeneratorMethods.java
|
91
|
+
- java/src/json/ext/StringEncoder.java
|
92
|
+
- java/src/json/ext/Generator.java
|
93
|
+
- java/src/json/ext/GeneratorService.java
|
94
|
+
- java/src/json/ext/Utils.java
|
95
|
+
- java/src/json/ext/ByteListTranscoder.java
|
96
|
+
- java/src/json/ext/RuntimeInfo.java
|
97
|
+
- java/src/json/ext/ParserService.java
|
98
|
+
- java/src/json/ext/OptionsReader.java
|
99
|
+
- java/src/json/ext/GeneratorState.java
|
100
|
+
- java/src/json/ext/Parser.java
|
101
|
+
- java/lib/bytelist-1.0.6.jar
|
102
|
+
- java/lib/jcodings.jar
|
103
|
+
- COPYING-json-jruby
|
81
104
|
- lib/json.rb
|
82
105
|
- lib/json/json.xpm
|
83
106
|
- lib/json/Key.xpm
|
@@ -133,13 +156,22 @@ files:
|
|
133
156
|
- tests/fixtures/fail27.json
|
134
157
|
- tests/fixtures/fail10.json
|
135
158
|
- tests/fixtures/fail23.json
|
136
|
-
- tests/test_json_rails.rb
|
137
159
|
- tests/test_json.rb
|
160
|
+
- tests/test_json_string_matching.rb
|
138
161
|
- tests/test_json_generate.rb
|
139
162
|
- tests/test_json_unicode.rb
|
163
|
+
- tests/setup_variant.rb
|
140
164
|
- tests/test_json_fixtures.rb
|
141
165
|
- COPYING
|
166
|
+
- json-java.gemspec
|
142
167
|
- install.rb
|
168
|
+
- ./tests/test_json_encoding.rb
|
169
|
+
- ./tests/test_json_addition.rb
|
170
|
+
- ./tests/test_json.rb
|
171
|
+
- ./tests/test_json_string_matching.rb
|
172
|
+
- ./tests/test_json_generate.rb
|
173
|
+
- ./tests/test_json_unicode.rb
|
174
|
+
- ./tests/test_json_fixtures.rb
|
143
175
|
has_rdoc: true
|
144
176
|
homepage: http://flori.github.com/json
|
145
177
|
licenses: []
|
@@ -155,29 +187,35 @@ require_paths:
|
|
155
187
|
- ext
|
156
188
|
- lib
|
157
189
|
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
none: false
|
158
191
|
requirements:
|
159
192
|
- - ">="
|
160
193
|
- !ruby/object:Gem::Version
|
194
|
+
hash: 3
|
195
|
+
segments:
|
196
|
+
- 0
|
161
197
|
version: "0"
|
162
|
-
version:
|
163
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
|
+
none: false
|
164
200
|
requirements:
|
165
201
|
- - ">="
|
166
202
|
- !ruby/object:Gem::Version
|
203
|
+
hash: 3
|
204
|
+
segments:
|
205
|
+
- 0
|
167
206
|
version: "0"
|
168
|
-
version:
|
169
207
|
requirements: []
|
170
208
|
|
171
209
|
rubyforge_project: json
|
172
|
-
rubygems_version: 1.3.
|
210
|
+
rubygems_version: 1.3.7
|
173
211
|
signing_key:
|
174
212
|
specification_version: 3
|
175
213
|
summary: JSON Implementation for Ruby
|
176
214
|
test_files:
|
177
|
-
- tests/test_json_encoding.rb
|
178
|
-
- tests/test_json_addition.rb
|
179
|
-
- tests/
|
180
|
-
- tests/
|
181
|
-
- tests/test_json_generate.rb
|
182
|
-
- tests/test_json_unicode.rb
|
183
|
-
- tests/test_json_fixtures.rb
|
215
|
+
- ./tests/test_json_encoding.rb
|
216
|
+
- ./tests/test_json_addition.rb
|
217
|
+
- ./tests/test_json.rb
|
218
|
+
- ./tests/test_json_string_matching.rb
|
219
|
+
- ./tests/test_json_generate.rb
|
220
|
+
- ./tests/test_json_unicode.rb
|
221
|
+
- ./tests/test_json_fixtures.rb
|
data/tests/test_json_rails.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
case ENV['JSON']
|
6
|
-
when 'pure' then require 'json/pure'
|
7
|
-
when 'ext' then require 'json/ext'
|
8
|
-
else require 'json'
|
9
|
-
end
|
10
|
-
require 'json/add/rails'
|
11
|
-
require 'date'
|
12
|
-
|
13
|
-
class TC_JSONRails < Test::Unit::TestCase
|
14
|
-
include JSON
|
15
|
-
|
16
|
-
class A
|
17
|
-
def initialize(a)
|
18
|
-
@a = a
|
19
|
-
end
|
20
|
-
|
21
|
-
attr_reader :a
|
22
|
-
|
23
|
-
def ==(other)
|
24
|
-
a == other.a
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.json_create(object)
|
28
|
-
new(*object['args'])
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_json(*args)
|
32
|
-
{
|
33
|
-
'json_class' => self.class.name,
|
34
|
-
'args' => [ @a ],
|
35
|
-
}.to_json(*args)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class B
|
40
|
-
def self.json_creatable?
|
41
|
-
false
|
42
|
-
end
|
43
|
-
|
44
|
-
def to_json(*args)
|
45
|
-
{
|
46
|
-
'json_class' => self.class.name,
|
47
|
-
}.to_json(*args)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class C
|
52
|
-
def to_json(*args)
|
53
|
-
{
|
54
|
-
'json_class' => 'TC_JSONRails::Nix',
|
55
|
-
}.to_json(*args)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class D
|
60
|
-
def initialize
|
61
|
-
@foo = 666
|
62
|
-
end
|
63
|
-
|
64
|
-
attr_reader :foo
|
65
|
-
|
66
|
-
def ==(other)
|
67
|
-
foo == other.foo
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_extended_json
|
72
|
-
a = A.new(666)
|
73
|
-
assert A.json_creatable?
|
74
|
-
assert_equal 666, a.a
|
75
|
-
json = generate(a)
|
76
|
-
a_again = JSON.parse(json)
|
77
|
-
assert_kind_of a.class, a_again
|
78
|
-
assert_equal a, a_again
|
79
|
-
assert_equal 666, a_again.a
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_extended_json_generic_object
|
83
|
-
d = D.new
|
84
|
-
assert D.json_creatable?
|
85
|
-
assert_equal 666, d.foo
|
86
|
-
json = generate(d)
|
87
|
-
d_again = JSON.parse(json)
|
88
|
-
assert_kind_of d.class, d_again
|
89
|
-
assert_equal d, d_again
|
90
|
-
assert_equal 666, d_again.foo
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_extended_json_disabled
|
94
|
-
a = A.new(666)
|
95
|
-
assert A.json_creatable?
|
96
|
-
json = generate(a)
|
97
|
-
a_again = JSON.parse(json, :create_additions => true)
|
98
|
-
assert_kind_of a.class, a_again
|
99
|
-
assert_equal a, a_again
|
100
|
-
a_hash = JSON.parse(json, :create_additions => false)
|
101
|
-
assert_kind_of Hash, a_hash
|
102
|
-
assert_equal(
|
103
|
-
{"args"=>[666], "json_class"=>"TC_JSONRails::A"}.sort_by { |k,| k },
|
104
|
-
a_hash.sort_by { |k,| k }
|
105
|
-
)
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_extended_json_fail1
|
109
|
-
b = B.new
|
110
|
-
assert !B.json_creatable?
|
111
|
-
json = generate(b)
|
112
|
-
assert_equal({ 'json_class' => B.name }, JSON.parse(json))
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_extended_json_fail2
|
116
|
-
c = C.new # with rails addition all objects are theoretically creatable
|
117
|
-
assert C.json_creatable?
|
118
|
-
json = generate(c)
|
119
|
-
assert_raises(ArgumentError, NameError) { JSON.parse(json) }
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_raw_strings
|
123
|
-
raw = ''
|
124
|
-
raw.respond_to?(:encode!) and raw.encode!(Encoding::ASCII_8BIT)
|
125
|
-
raw_array = []
|
126
|
-
for i in 0..255
|
127
|
-
raw << i
|
128
|
-
raw_array << i
|
129
|
-
end
|
130
|
-
json = raw.to_json_raw
|
131
|
-
json_raw_object = raw.to_json_raw_object
|
132
|
-
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
133
|
-
assert_equal hash, json_raw_object
|
134
|
-
assert_match /\A\{.*\}\Z/, json
|
135
|
-
assert_match /"json_class":"String"/, json
|
136
|
-
assert_match /"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json
|
137
|
-
raw_again = JSON.parse(json)
|
138
|
-
assert_equal raw, raw_again
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_symbol
|
142
|
-
assert_equal '"foo"', :foo.to_json # we don't want an object here
|
143
|
-
end
|
144
|
-
end
|