oj 3.16.9 → 3.16.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/oj/fast.c +3 -6
- data/ext/oj/mimic_json.c +3 -6
- data/ext/oj/oj.c +2 -4
- data/ext/oj/parse.c +15 -5
- data/ext/oj/parser.c +1 -1
- data/ext/oj/parser.h +2 -0
- data/ext/oj/rails.c +1 -2
- data/ext/oj/saj.c +3 -6
- data/ext/oj/scp.c +3 -6
- data/ext/oj/stream_writer.c +1 -7
- data/ext/oj/strict.c +2 -4
- data/ext/oj/string_writer.c +1 -3
- data/lib/oj/version.rb +1 -1
- metadata +3 -98
- data/test/_test_active.rb +0 -75
- data/test/_test_active_mimic.rb +0 -95
- data/test/_test_mimic_rails.rb +0 -123
- data/test/activerecord/result_test.rb +0 -31
- data/test/activesupport6/abstract_unit.rb +0 -44
- data/test/activesupport6/decoding_test.rb +0 -133
- data/test/activesupport6/encoding_test.rb +0 -542
- data/test/activesupport6/encoding_test_cases.rb +0 -98
- data/test/activesupport6/test_common.rb +0 -17
- data/test/activesupport6/test_helper.rb +0 -163
- data/test/activesupport6/time_zone_test_helpers.rb +0 -39
- data/test/activesupport7/abstract_unit.rb +0 -52
- data/test/activesupport7/decoding_test.rb +0 -125
- data/test/activesupport7/encoding_test.rb +0 -536
- data/test/activesupport7/encoding_test_cases.rb +0 -104
- data/test/activesupport7/time_zone_test_helpers.rb +0 -47
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -26
- data/test/helper.rb +0 -39
- data/test/isolated/shared.rb +0 -309
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/json_gem/json_addition_test.rb +0 -216
- data/test/json_gem/json_common_interface_test.rb +0 -155
- data/test/json_gem/json_encoding_test.rb +0 -107
- data/test/json_gem/json_ext_parser_test.rb +0 -21
- data/test/json_gem/json_fixtures_test.rb +0 -36
- data/test/json_gem/json_generator_test.rb +0 -413
- data/test/json_gem/json_generic_object_test.rb +0 -90
- data/test/json_gem/json_parser_test.rb +0 -477
- data/test/json_gem/json_string_matching_test.rb +0 -42
- data/test/json_gem/test_helper.rb +0 -30
- data/test/mem.rb +0 -34
- data/test/perf.rb +0 -102
- data/test/perf_compat.rb +0 -128
- data/test/perf_dump.rb +0 -50
- data/test/perf_fast.rb +0 -162
- data/test/perf_file.rb +0 -62
- data/test/perf_object.rb +0 -134
- data/test/perf_once.rb +0 -59
- data/test/perf_parser.rb +0 -183
- data/test/perf_saj.rb +0 -101
- data/test/perf_scp.rb +0 -140
- data/test/perf_simple.rb +0 -289
- data/test/perf_strict.rb +0 -137
- data/test/perf_wab.rb +0 -129
- data/test/prec.rb +0 -23
- data/test/sample/change.rb +0 -13
- data/test/sample/dir.rb +0 -18
- data/test/sample/doc.rb +0 -35
- data/test/sample/file.rb +0 -47
- data/test/sample/group.rb +0 -15
- data/test/sample/hasprops.rb +0 -15
- data/test/sample/layer.rb +0 -11
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -9
- data/test/sample/shape.rb +0 -34
- data/test/sample/text.rb +0 -19
- data/test/sample.rb +0 -54
- data/test/sample_json.rb +0 -37
- data/test/test_compat.rb +0 -567
- data/test/test_custom.rb +0 -555
- data/test/test_debian.rb +0 -50
- data/test/test_fast.rb +0 -526
- data/test/test_file.rb +0 -250
- data/test/test_gc.rb +0 -60
- data/test/test_generate.rb +0 -21
- data/test/test_hash.rb +0 -39
- data/test/test_integer_range.rb +0 -72
- data/test/test_null.rb +0 -376
- data/test/test_object.rb +0 -1030
- data/test/test_parser.rb +0 -11
- data/test/test_parser_debug.rb +0 -27
- data/test/test_parser_saj.rb +0 -337
- data/test/test_parser_usual.rb +0 -255
- data/test/test_rails.rb +0 -35
- data/test/test_saj.rb +0 -188
- data/test/test_scp.rb +0 -431
- data/test/test_strict.rb +0 -441
- data/test/test_various.rb +0 -801
- data/test/test_wab.rb +0 -311
- data/test/test_writer.rb +0 -396
- data/test/tests.rb +0 -33
- data/test/tests_mimic.rb +0 -23
- data/test/tests_mimic_addition.rb +0 -16
@@ -1,216 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
#frozen_string_literal: false
|
5
|
-
|
6
|
-
require 'json_gem/test_helper'
|
7
|
-
require 'date'
|
8
|
-
|
9
|
-
if REAL_JSON_GEM
|
10
|
-
require 'json/add/core'
|
11
|
-
require 'json/add/complex'
|
12
|
-
require 'json/add/rational'
|
13
|
-
require 'json/add/bigdecimal'
|
14
|
-
require 'json/add/ostruct'
|
15
|
-
else
|
16
|
-
#Oj.add_to_json()
|
17
|
-
Oj.add_to_json(Array, BigDecimal, Complex, Date, DateTime, Exception, Hash, Integer, OpenStruct, Range, Rational, Regexp, Struct, Time)
|
18
|
-
end
|
19
|
-
|
20
|
-
class JSONAdditionTest < Test::Unit::TestCase
|
21
|
-
include Test::Unit::TestCaseOmissionSupport
|
22
|
-
include Test::Unit::TestCasePendingSupport
|
23
|
-
|
24
|
-
class A
|
25
|
-
def self.json_creatable?
|
26
|
-
true
|
27
|
-
end
|
28
|
-
|
29
|
-
def initialize(a)
|
30
|
-
@a = a
|
31
|
-
end
|
32
|
-
|
33
|
-
attr_reader :a
|
34
|
-
|
35
|
-
def ==(other)
|
36
|
-
a == other.a
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.json_create(object)
|
40
|
-
new(*object['args'])
|
41
|
-
end
|
42
|
-
|
43
|
-
def to_json(*args)
|
44
|
-
{
|
45
|
-
'json_class' => self.class.name,
|
46
|
-
'args' => [ @a ],
|
47
|
-
}.to_json(*args)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class A2 < A
|
52
|
-
def to_json(*args)
|
53
|
-
{
|
54
|
-
'json_class' => self.class.name,
|
55
|
-
'args' => [ @a ],
|
56
|
-
}.to_json(*args)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class B
|
61
|
-
def self.json_creatable?
|
62
|
-
false
|
63
|
-
end
|
64
|
-
|
65
|
-
def to_json(*args)
|
66
|
-
{
|
67
|
-
'json_class' => self.class.name,
|
68
|
-
}.to_json(*args)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class C
|
73
|
-
def self.json_creatable?
|
74
|
-
false
|
75
|
-
end
|
76
|
-
|
77
|
-
def to_json(*args)
|
78
|
-
{
|
79
|
-
'json_class' => 'JSONAdditionTest::Nix',
|
80
|
-
}.to_json(*args)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_extended_json
|
85
|
-
a = A.new(666)
|
86
|
-
assert A.json_creatable?
|
87
|
-
json = JSON.generate(a)
|
88
|
-
a_again = JSON.parse(json, :create_additions => true)
|
89
|
-
assert_kind_of a.class, a_again
|
90
|
-
assert_equal a, a_again
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_extended_json_default
|
94
|
-
a = A.new(666)
|
95
|
-
assert A.json_creatable?
|
96
|
-
json = JSON.generate(a)
|
97
|
-
a_hash = JSON.parse(json)
|
98
|
-
assert_kind_of Hash, a_hash
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_extended_json_disabled
|
102
|
-
a = A.new(666)
|
103
|
-
assert A.json_creatable?
|
104
|
-
json = JSON.generate(a)
|
105
|
-
a_again = JSON.parse(json, :create_additions => true)
|
106
|
-
assert_kind_of a.class, a_again
|
107
|
-
assert_equal a, a_again
|
108
|
-
a_hash = JSON.parse(json, :create_additions => false)
|
109
|
-
assert_kind_of Hash, a_hash
|
110
|
-
assert_equal(
|
111
|
-
{"args"=>[666], "json_class"=>"JSONAdditionTest::A"}.sort_by { |k,| k },
|
112
|
-
a_hash.sort_by { |k,| k }
|
113
|
-
)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_extended_json_fail1
|
117
|
-
b = B.new
|
118
|
-
assert !B.json_creatable?
|
119
|
-
json = JSON.generate(b)
|
120
|
-
assert_equal({ "json_class"=>"JSONAdditionTest::B" }, JSON.parse(json))
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_extended_json_fail2
|
124
|
-
c = C.new
|
125
|
-
assert !C.json_creatable?
|
126
|
-
json = JSON.generate(c)
|
127
|
-
assert_raise(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) }
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_raw_strings
|
131
|
-
raw = ''
|
132
|
-
raw.respond_to?(:encode!) and raw.encode!(Encoding::ASCII_8BIT)
|
133
|
-
raw_array = []
|
134
|
-
for i in 0..255
|
135
|
-
raw << i
|
136
|
-
raw_array << i
|
137
|
-
end
|
138
|
-
json = raw.to_json_raw
|
139
|
-
json_raw_object = raw.to_json_raw_object
|
140
|
-
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
141
|
-
assert_equal hash, json_raw_object
|
142
|
-
assert_match(/\A\{.*\}\z/, json)
|
143
|
-
assert_match(/"json_class":"String"/, json)
|
144
|
-
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)
|
145
|
-
|
146
|
-
raw_again = JSON.parse(json, :create_additions => true)
|
147
|
-
assert_equal raw, raw_again
|
148
|
-
end
|
149
|
-
|
150
|
-
MyJsonStruct = Struct.new 'MyJsonStruct', :foo, :bar
|
151
|
-
|
152
|
-
def test_core
|
153
|
-
t = Time.now
|
154
|
-
assert_equal t, JSON(JSON(t), :create_additions => true)
|
155
|
-
|
156
|
-
d = Date.today
|
157
|
-
assert_equal d, JSON(JSON(d), :create_additions => true)
|
158
|
-
|
159
|
-
d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161)
|
160
|
-
assert_equal d, JSON(JSON(d), :create_additions => true)
|
161
|
-
|
162
|
-
assert_equal 1..10, JSON(JSON(1..10), :create_additions => true)
|
163
|
-
assert_equal 1...10, JSON(JSON(1...10), :create_additions => true)
|
164
|
-
assert_equal "a".."c", JSON(JSON("a".."c"), :create_additions => true)
|
165
|
-
assert_equal "a"..."c", JSON(JSON("a"..."c"), :create_additions => true)
|
166
|
-
|
167
|
-
s = MyJsonStruct.new 4711, 'foot'
|
168
|
-
assert_equal s, JSON(JSON(s), :create_additions => true)
|
169
|
-
|
170
|
-
struct = Struct.new :foo, :bar
|
171
|
-
s = struct.new 4711, 'foot'
|
172
|
-
assert_raise(JSON::JSONError) { JSON(s) }
|
173
|
-
|
174
|
-
begin
|
175
|
-
raise TypeError, "test me"
|
176
|
-
rescue TypeError => e
|
177
|
-
e_json = JSON.generate e
|
178
|
-
e_again = JSON e_json, :create_additions => true
|
179
|
-
assert_kind_of TypeError, e_again
|
180
|
-
assert_equal e.message, e_again.message
|
181
|
-
assert_equal e.backtrace, e_again.backtrace
|
182
|
-
end
|
183
|
-
|
184
|
-
assert_equal(/foo/, JSON(JSON(/foo/), :create_additions => true))
|
185
|
-
assert_equal(/foo/i, JSON(JSON(/foo/i), :create_additions => true))
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_utc_datetime
|
189
|
-
now = Time.now
|
190
|
-
d = DateTime.parse(now.to_s, :create_additions => true) # usual case
|
191
|
-
assert_equal d, JSON.parse(d.to_json, :create_additions => true)
|
192
|
-
d = DateTime.parse(now.utc.to_s) # of = 0
|
193
|
-
assert_equal d, JSON.parse(d.to_json, :create_additions => true)
|
194
|
-
d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(1, 24))
|
195
|
-
assert_equal d, JSON.parse(d.to_json, :create_additions => true)
|
196
|
-
d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(12, 24))
|
197
|
-
assert_equal d, JSON.parse(d.to_json, :create_additions => true)
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_rational_complex
|
201
|
-
assert_equal Rational(2, 9), JSON.parse(JSON(Rational(2, 9)), :create_additions => true)
|
202
|
-
assert_equal Complex(2, 9), JSON.parse(JSON(Complex(2, 9)), :create_additions => true)
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_bigdecimal
|
206
|
-
assert_equal BigDecimal('3.141', 23), JSON(JSON(BigDecimal('3.141', 23)), :create_additions => true)
|
207
|
-
assert_equal BigDecimal('3.141', 666), JSON(JSON(BigDecimal('3.141', 666)), :create_additions => true)
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_ostruct
|
211
|
-
o = OpenStruct.new
|
212
|
-
# XXX this won't work; o.foo = { :bar => true }
|
213
|
-
o.foo = { 'bar' => true }
|
214
|
-
assert_equal o, JSON.parse(JSON(o), :create_additions => true)
|
215
|
-
end
|
216
|
-
end
|
@@ -1,155 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
#frozen_string_literal: false
|
5
|
-
|
6
|
-
require 'json_gem/test_helper'
|
7
|
-
|
8
|
-
require 'stringio'
|
9
|
-
require 'tempfile'
|
10
|
-
|
11
|
-
class JSONCommonInterfaceTest < Test::Unit::TestCase
|
12
|
-
include Test::Unit::TestCaseOmissionSupport
|
13
|
-
include Test::Unit::TestCasePendingSupport
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@hash = {
|
17
|
-
'a' => 2,
|
18
|
-
#'b' => 5.23683071,
|
19
|
-
'c' => 'c',
|
20
|
-
'd' => [ 1, "b", 3.14 ],
|
21
|
-
'e' => { 'foo' => 'bar' },
|
22
|
-
'g' => "\"\0\037",
|
23
|
-
'h' => 1000.0,
|
24
|
-
'i' => 0.001
|
25
|
-
}
|
26
|
-
# Tired of chasing floating point rounding and precision. Oj now uses the
|
27
|
-
# Ruby float parser in compat mode yet on i386 machines there are issues
|
28
|
-
# with this test when the float is included.
|
29
|
-
#@json = '{"a":2,"b":5.23683071,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
|
30
|
-
#'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
|
31
|
-
@json = '{"a":2,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
|
32
|
-
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_index
|
36
|
-
assert_equal @json, JSON[@hash]
|
37
|
-
assert_equal @hash, JSON[@json]
|
38
|
-
end
|
39
|
-
|
40
|
-
##############################################################################
|
41
|
-
# The next tests are omitted as implementing them and using them is a
|
42
|
-
# performance hit. Use of the JSON.parse() and similar provide the same
|
43
|
-
# functionality and perform better.
|
44
|
-
|
45
|
-
def test_parser
|
46
|
-
assert_match(/::Parser\z/, JSON.parser.name)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_generator
|
50
|
-
assert_match(/::Generator\z/, JSON.generator.name)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_state
|
54
|
-
assert_match(/::Generator::State\z/, JSON.state.name)
|
55
|
-
end
|
56
|
-
|
57
|
-
# This doesn't have anything to do with JSON parsing or generation. It seems
|
58
|
-
# to be more of an internal tool that is exposed to users.
|
59
|
-
def test_deep_const_get
|
60
|
-
omit("mimic_JSON") unless REAL_JSON_GEM
|
61
|
-
assert_raise(ArgumentError) { JSON.deep_const_get('Nix::Da') }
|
62
|
-
assert_equal File::SEPARATOR, JSON.deep_const_get('File::SEPARATOR')
|
63
|
-
end
|
64
|
-
##############################################################################
|
65
|
-
|
66
|
-
def test_create_id
|
67
|
-
assert_equal 'json_class', JSON.create_id
|
68
|
-
JSON.create_id = 'foo_bar'
|
69
|
-
assert_equal 'foo_bar', JSON.create_id
|
70
|
-
ensure
|
71
|
-
JSON.create_id = 'json_class'
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_parse
|
75
|
-
assert_equal [ 1, 2, 3, ], JSON.parse('[ 1, 2, 3 ]')
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_parse_bang
|
79
|
-
# Modified this test to compare strings since NaN comparison fails if NaN
|
80
|
-
# was defined in different places even if it represents the same value.
|
81
|
-
assert_equal [ 1, NaN, 3, ].to_s, JSON.parse!('[ 1, NaN, 3 ]').to_s
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_generate
|
85
|
-
assert_equal '[1,2,3]', JSON.generate([ 1, 2, 3 ])
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_fast_generate
|
89
|
-
assert_equal '[1,2,3]', JSON.generate([ 1, 2, 3 ])
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_pretty_generate
|
93
|
-
assert_equal "[\n 1,\n 2,\n 3\n]", JSON.pretty_generate([ 1, 2, 3 ])
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_load
|
97
|
-
assert_equal @hash, JSON.load(@json)
|
98
|
-
tempfile = Tempfile.open('@json')
|
99
|
-
tempfile.write @json
|
100
|
-
tempfile.rewind
|
101
|
-
assert_equal @hash, JSON.load(tempfile)
|
102
|
-
stringio = StringIO.new(@json)
|
103
|
-
stringio.rewind
|
104
|
-
assert_equal @hash, JSON.load(stringio)
|
105
|
-
assert_equal nil, JSON.load(nil)
|
106
|
-
assert_equal nil, JSON.load('')
|
107
|
-
ensure
|
108
|
-
tempfile.close!
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_load_with_options
|
112
|
-
json = '{ "foo": NaN }'
|
113
|
-
assert JSON.load(json, nil, :allow_nan => true)['foo'].nan?
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_load_null
|
117
|
-
assert_equal nil, JSON.load(nil, nil, :allow_blank => true)
|
118
|
-
assert_raise(TypeError) { JSON.load(nil, nil, :allow_blank => false) }
|
119
|
-
assert_raise(JSON::ParserError) { JSON.load('', nil, :allow_blank => false) }
|
120
|
-
# The next tests are added by Oj to catch additional cases.
|
121
|
-
assert_equal nil, JSON.load('', nil, :allow_blank => true)
|
122
|
-
assert_raise(JSON::ParserError) { JSON.load('', nil, :allow_blank => false) }
|
123
|
-
assert_raise(JSON::ParserError) { JSON.load(' ', nil, :allow_blank => true) }
|
124
|
-
assert_raise(JSON::ParserError) { JSON.load(' ', nil, :allow_blank => false) }
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_dump
|
128
|
-
too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
129
|
-
assert_equal too_deep, JSON.dump(eval(too_deep))
|
130
|
-
assert_kind_of String, Marshal.dump(eval(too_deep))
|
131
|
-
if RUBY_ENGINE != 'truffleruby'
|
132
|
-
assert_raise(ArgumentError) { JSON.dump(eval(too_deep), 100) }
|
133
|
-
assert_raise(ArgumentError) { Marshal.dump(eval(too_deep), 100) }
|
134
|
-
end
|
135
|
-
assert_equal too_deep, JSON.dump(eval(too_deep), 101)
|
136
|
-
assert_kind_of String, Marshal.dump(eval(too_deep), 101)
|
137
|
-
output = StringIO.new
|
138
|
-
JSON.dump(eval(too_deep), output)
|
139
|
-
assert_equal too_deep, output.string
|
140
|
-
output = StringIO.new
|
141
|
-
JSON.dump(eval(too_deep), output, 101)
|
142
|
-
assert_equal too_deep, output.string
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_dump_should_modify_defaults
|
146
|
-
max_nesting = JSON.dump_default_options[:max_nesting]
|
147
|
-
JSON.dump([], StringIO.new, 10)
|
148
|
-
assert_equal max_nesting, JSON.dump_default_options[:max_nesting]
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_JSON
|
152
|
-
assert_equal @json, JSON(@hash)
|
153
|
-
assert_equal @hash, JSON(@json)
|
154
|
-
end
|
155
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
#frozen_string_literal: false
|
5
|
-
|
6
|
-
require 'json_gem/test_helper'
|
7
|
-
|
8
|
-
class JSONEncodingTest < Test::Unit::TestCase
|
9
|
-
include Test::Unit::TestCaseOmissionSupport
|
10
|
-
include Test::Unit::TestCasePendingSupport
|
11
|
-
|
12
|
-
def setup
|
13
|
-
@utf_8 = '"© ≠ €!"'
|
14
|
-
@ascii_8bit = @utf_8.dup.force_encoding('ascii-8bit')
|
15
|
-
@parsed = "© ≠ €!"
|
16
|
-
@generated = '"\u00a9 \u2260 \u20ac!"'
|
17
|
-
if String.method_defined?(:encode)
|
18
|
-
@utf_16_data = @parsed.encode('utf-16be', 'utf-8')
|
19
|
-
@utf_16be = @utf_8.encode('utf-16be', 'utf-8')
|
20
|
-
@utf_16le = @utf_8.encode('utf-16le', 'utf-8')
|
21
|
-
@utf_32be = @utf_8.encode('utf-32be', 'utf-8')
|
22
|
-
@utf_32le = @utf_8.encode('utf-32le', 'utf-8')
|
23
|
-
else
|
24
|
-
require 'iconv'
|
25
|
-
@utf_16_data, = Iconv.iconv('utf-16be', 'utf-8', @parsed)
|
26
|
-
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
|
27
|
-
@utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
|
28
|
-
@utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
|
29
|
-
@utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_parse
|
34
|
-
assert_equal @parsed, JSON.parse(@ascii_8bit)
|
35
|
-
assert_equal @parsed, JSON.parse(@utf_8)
|
36
|
-
assert_equal @parsed, JSON.parse(@utf_16be)
|
37
|
-
assert_equal @parsed, JSON.parse(@utf_16le)
|
38
|
-
assert_equal @parsed, JSON.parse(@utf_32be)
|
39
|
-
assert_equal @parsed, JSON.parse(@utf_32le)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_generate
|
43
|
-
assert_equal @generated, JSON.generate(@parsed, :ascii_only => true)
|
44
|
-
assert_equal @generated, JSON.generate(@utf_16_data, :ascii_only => true)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_unicode
|
48
|
-
assert_equal '""', ''.to_json
|
49
|
-
assert_equal '"\\b"', "\b".to_json
|
50
|
-
assert_equal '"\u0001"', 0x1.chr.to_json
|
51
|
-
assert_equal '"\u001f"', 0x1f.chr.to_json
|
52
|
-
assert_equal '" "', ' '.to_json
|
53
|
-
assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
|
54
|
-
utf8 = [ "© ≠ €! \01" ]
|
55
|
-
json = '["© ≠ €! \u0001"]'
|
56
|
-
assert_equal json, utf8.to_json(:ascii_only => false)
|
57
|
-
assert_equal utf8, JSON.parse(json)
|
58
|
-
json = '["\u00a9 \u2260 \u20ac! \u0001"]'
|
59
|
-
assert_equal json, utf8.to_json(:ascii_only => true)
|
60
|
-
assert_equal utf8, JSON.parse(json)
|
61
|
-
utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
|
62
|
-
json = "[\"\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212\"]"
|
63
|
-
assert_equal utf8, JSON.parse(json)
|
64
|
-
assert_equal json, utf8.to_json(:ascii_only => false)
|
65
|
-
utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
|
66
|
-
assert_equal utf8, JSON.parse(json)
|
67
|
-
json = "[\"\\u3042\\u3044\\u3046\\u3048\\u304a\"]"
|
68
|
-
assert_equal json, utf8.to_json(:ascii_only => true)
|
69
|
-
assert_equal utf8, JSON.parse(json)
|
70
|
-
utf8 = ['საქართველო']
|
71
|
-
json = '["საქართველო"]'
|
72
|
-
assert_equal json, utf8.to_json(:ascii_only => false)
|
73
|
-
json = "[\"\\u10e1\\u10d0\\u10e5\\u10d0\\u10e0\\u10d7\\u10d5\\u10d4\\u10da\\u10dd\"]"
|
74
|
-
assert_equal json, utf8.to_json(:ascii_only => true)
|
75
|
-
assert_equal utf8, JSON.parse(json)
|
76
|
-
assert_equal '["Ã"]', JSON.generate(["Ã"], :ascii_only => false)
|
77
|
-
assert_equal '["\\u00c3"]', JSON.generate(["Ã"], :ascii_only => true)
|
78
|
-
assert_equal ["€"], JSON.parse('["\u20ac"]')
|
79
|
-
utf8 = ["\xf0\xa0\x80\x81"]
|
80
|
-
json = "[\"\xf0\xa0\x80\x81\"]"
|
81
|
-
assert_equal json, JSON.generate(utf8, :ascii_only => false)
|
82
|
-
assert_equal utf8, JSON.parse(json)
|
83
|
-
json = '["\ud840\udc01"]'
|
84
|
-
assert_equal json, JSON.generate(utf8, :ascii_only => true)
|
85
|
-
assert_equal utf8, JSON.parse(json)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_chars
|
89
|
-
(0..0x7f).each do |i|
|
90
|
-
json = '["\u%04x"]' % i
|
91
|
-
i = i.chr
|
92
|
-
assert_equal i, JSON.parse(json).first[0]
|
93
|
-
if i == ?\b
|
94
|
-
generated = JSON.generate(["" << i])
|
95
|
-
assert '["\b"]' == generated || '["\10"]' == generated
|
96
|
-
elsif [?\n, ?\r, ?\t, ?\f].include?(i)
|
97
|
-
assert_equal '[' << ('' << i).dump << ']', JSON.generate(["" << i])
|
98
|
-
elsif i.chr < 0x20.chr
|
99
|
-
assert_equal json, JSON.generate(["" << i])
|
100
|
-
end
|
101
|
-
end
|
102
|
-
assert_raise(JSON::GeneratorError) do
|
103
|
-
JSON.generate(["\x80"], :ascii_only => true)
|
104
|
-
end
|
105
|
-
assert_equal "\302\200", JSON.parse('["\u0080"]').first
|
106
|
-
end
|
107
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
#frozen_string_literal: false
|
5
|
-
|
6
|
-
require 'json_gem/test_helper'
|
7
|
-
|
8
|
-
class JSONExtParserTest < Test::Unit::TestCase
|
9
|
-
include Test::Unit::TestCaseOmissionSupport
|
10
|
-
|
11
|
-
if defined?(JSON::Ext::Parser)
|
12
|
-
def test_allocate
|
13
|
-
parser = JSON::Ext::Parser.new("{}")
|
14
|
-
assert_raise(TypeError, '[ruby-core:35079]') do
|
15
|
-
parser.__send__(:initialize, "{}")
|
16
|
-
end
|
17
|
-
parser = JSON::Ext::Parser.allocate
|
18
|
-
assert_raise(TypeError, '[ruby-core:35079]') { parser.source }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
#frozen_string_literal: false
|
5
|
-
|
6
|
-
require 'json_gem/test_helper'
|
7
|
-
|
8
|
-
class JSONFixturesTest < Test::Unit::TestCase
|
9
|
-
def setup
|
10
|
-
fixtures = File.join(File.dirname(__FILE__), 'fixtures/{fail,pass}.json')
|
11
|
-
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
|
12
|
-
@passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
13
|
-
@failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_passing
|
17
|
-
for name, source in @passed
|
18
|
-
begin
|
19
|
-
assert JSON.parse(source),
|
20
|
-
"Did not pass for fixture '#{name}': #{source.inspect}"
|
21
|
-
rescue => e
|
22
|
-
warn "\nCaught #{e.class}(#{e}) for fixture '#{name}': #{source.inspect}\n#{e.backtrace * "\n"}"
|
23
|
-
raise e
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_failing
|
29
|
-
for name, source in @failed
|
30
|
-
assert_raise(JSON::ParserError, JSON::NestingError,
|
31
|
-
"Did not fail for fixture '#{name}': #{source.inspect}") do
|
32
|
-
JSON.parse(source)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|