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
data/test/test_compat.rb
DELETED
@@ -1,567 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
$LOAD_PATH << __dir__
|
5
|
-
@oj_dir = File.dirname(File.expand_path(__dir__))
|
6
|
-
%w(lib ext).each do |dir|
|
7
|
-
$LOAD_PATH << File.join(@oj_dir, dir)
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'minitest'
|
11
|
-
require 'minitest/autorun'
|
12
|
-
require 'stringio'
|
13
|
-
require 'date'
|
14
|
-
require 'bigdecimal'
|
15
|
-
require 'oj'
|
16
|
-
|
17
|
-
class CompatJuice < Minitest::Test
|
18
|
-
|
19
|
-
class Jeez
|
20
|
-
attr_accessor :x, :y
|
21
|
-
|
22
|
-
def initialize(x, y)
|
23
|
-
@x = x
|
24
|
-
@y = y
|
25
|
-
end
|
26
|
-
|
27
|
-
def eql?(o)
|
28
|
-
self.class == o.class && @x == o.x && @y == o.y
|
29
|
-
end
|
30
|
-
alias == eql?
|
31
|
-
|
32
|
-
def to_json(*_a)
|
33
|
-
%|{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}|
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.json_create(h)
|
37
|
-
new(h['x'], h['y'])
|
38
|
-
end
|
39
|
-
end # Jeez
|
40
|
-
|
41
|
-
class Argy
|
42
|
-
|
43
|
-
def to_json(*a)
|
44
|
-
%|{"args":"#{a}"}|
|
45
|
-
end
|
46
|
-
end # Argy
|
47
|
-
|
48
|
-
class Stringy
|
49
|
-
|
50
|
-
def to_s
|
51
|
-
%|[1,2]|
|
52
|
-
end
|
53
|
-
end # Stringy
|
54
|
-
|
55
|
-
module One
|
56
|
-
module Two
|
57
|
-
module Three
|
58
|
-
class Deep
|
59
|
-
|
60
|
-
def eql?(o)
|
61
|
-
self.class == o.class
|
62
|
-
end
|
63
|
-
alias == eql?
|
64
|
-
|
65
|
-
def to_json(*_a)
|
66
|
-
%|{"json_class":"#{self.class.name}"}|
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.json_create(_h)
|
70
|
-
new()
|
71
|
-
end
|
72
|
-
end # Deep
|
73
|
-
end # Three
|
74
|
-
end # Two
|
75
|
-
end # One
|
76
|
-
|
77
|
-
def setup
|
78
|
-
@default_options = Oj.default_options
|
79
|
-
# in compat mode other options other than the JSON gem globals and options
|
80
|
-
# are not used.
|
81
|
-
Oj.default_options = { :mode => :compat }
|
82
|
-
end
|
83
|
-
|
84
|
-
def teardown
|
85
|
-
Oj.default_options = @default_options
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_nil
|
89
|
-
dump_and_load(nil, false)
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_true
|
93
|
-
dump_and_load(true, false)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_false
|
97
|
-
dump_and_load(false, false)
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_fixnum
|
101
|
-
dump_and_load(0, false)
|
102
|
-
dump_and_load(12_345, false)
|
103
|
-
dump_and_load(-54_321, false)
|
104
|
-
dump_and_load(1, false)
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_fixnum_array
|
108
|
-
data = (1..1000).to_a
|
109
|
-
json = Oj.dump(data, mode: :compat)
|
110
|
-
assert_equal("[#{data.join(',')}]", json)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_float
|
114
|
-
dump_and_load(0.0, false)
|
115
|
-
dump_and_load(0.56, false)
|
116
|
-
dump_and_load(3.0, false)
|
117
|
-
dump_and_load(12_345.6789, false)
|
118
|
-
dump_and_load(70.35, false)
|
119
|
-
dump_and_load(-54_321.012, false)
|
120
|
-
dump_and_load(1.7775, false)
|
121
|
-
dump_and_load(2.5024, false)
|
122
|
-
dump_and_load(2.48e16, false)
|
123
|
-
dump_and_load(2.48e100 * 1.0e10, false)
|
124
|
-
dump_and_load(-2.48e100 * 1.0e10, false)
|
125
|
-
dump_and_load(1_405_460_727.723866, false)
|
126
|
-
dump_and_load(0.5773, false)
|
127
|
-
dump_and_load(0.6768, false)
|
128
|
-
dump_and_load(0.685, false)
|
129
|
-
dump_and_load(0.7032, false)
|
130
|
-
dump_and_load(0.7051, false)
|
131
|
-
dump_and_load(0.8274, false)
|
132
|
-
dump_and_load(0.9149, false)
|
133
|
-
dump_and_load(64.4, false)
|
134
|
-
dump_and_load(71.6, false)
|
135
|
-
dump_and_load(73.4, false)
|
136
|
-
dump_and_load(80.6, false)
|
137
|
-
dump_and_load(-95.640172, false)
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_string
|
141
|
-
dump_and_load('', false)
|
142
|
-
dump_and_load('abc', false)
|
143
|
-
dump_and_load("abc\ndef", false)
|
144
|
-
dump_and_load("a\u0041", false)
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_encode
|
148
|
-
opts = Oj.default_options
|
149
|
-
Oj.default_options = { :ascii_only => true }
|
150
|
-
json = Oj.dump('ぴーたー')
|
151
|
-
assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
|
152
|
-
Oj.default_options = opts
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_unicode
|
156
|
-
# hits the 3 normal ranges and one extended surrogate pair
|
157
|
-
json = %{"\\u019f\\u05e9\\u3074\\ud834\\udd1e"}
|
158
|
-
obj = Oj.load(json)
|
159
|
-
json2 = Oj.dump(obj, :ascii_only => true)
|
160
|
-
assert_equal(json, json2)
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_array
|
164
|
-
dump_and_load([], false)
|
165
|
-
dump_and_load([true, false], false)
|
166
|
-
dump_and_load(['a', 1, nil], false)
|
167
|
-
dump_and_load([[nil]], false)
|
168
|
-
dump_and_load([[nil], 58], false)
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_array_deep
|
172
|
-
dump_and_load([1, [2, [3, [4, [5, [6, [7, [8, [9, [10, [11, [12, [13, [14, [15, [16, [17, [18, [19, [20]]]]]]]]]]]]]]]]]]]], false)
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_symbol
|
176
|
-
json = Oj.dump(:abc, :mode => :compat)
|
177
|
-
assert_equal('"abc"', json)
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_time_xml_schema
|
181
|
-
t = Time.xmlschema('2012-01-05T23:58:07.123456000+09:00')
|
182
|
-
# t = Time.local(2012, 1, 5, 23, 58, 7, 123456)
|
183
|
-
json = Oj.dump(t, :mode => :compat)
|
184
|
-
assert_equal(%{"2012-01-05 23:58:07 +0900"}, json)
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_class
|
188
|
-
json = Oj.dump(CompatJuice, :mode => :compat)
|
189
|
-
assert_equal(%{"CompatJuice"}, json)
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_module
|
193
|
-
json = Oj.dump(One::Two, :mode => :compat)
|
194
|
-
assert_equal(%{"CompatJuice::One::Two"}, json)
|
195
|
-
end
|
196
|
-
|
197
|
-
# Hash
|
198
|
-
def test_non_str_hash
|
199
|
-
json = Oj.dump({ 1 => true, 0 => false }, :mode => :compat)
|
200
|
-
h = Oj.load(json, :mode => :strict)
|
201
|
-
assert_equal({ '1' => true, '0' => false }, h)
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_hash
|
205
|
-
dump_and_load({}, false)
|
206
|
-
dump_and_load({ 'true' => true, 'false' => false}, false)
|
207
|
-
dump_and_load({ 'true' => true, 'array' => [], 'hash' => { }}, false)
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_hash_deep
|
211
|
-
dump_and_load({'1' => {
|
212
|
-
'2' => {
|
213
|
-
'3' => {
|
214
|
-
'4' => {
|
215
|
-
'5' => {
|
216
|
-
'6' => {
|
217
|
-
'7' => {
|
218
|
-
'8' => {
|
219
|
-
'9' => {
|
220
|
-
'10' => {
|
221
|
-
'11' => {
|
222
|
-
'12' => {
|
223
|
-
'13' => {
|
224
|
-
'14' => {
|
225
|
-
'15' => {
|
226
|
-
'16' => {
|
227
|
-
'17' => {
|
228
|
-
'18' => {
|
229
|
-
'19' => {
|
230
|
-
'20' => {}}}}}}}}}}}}}}}}}}}}}, false)
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_hash_escaped_key
|
234
|
-
json = %{{"a\nb":true,"c\td":false}}
|
235
|
-
obj = Oj.compat_load(json)
|
236
|
-
assert_equal({"a\nb" => true, "c\td" => false}, obj)
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_invalid_escapes_handled
|
240
|
-
json = '{"subtext":"\"404er\” \w \k \3 \a"}'
|
241
|
-
obj = Oj.compat_load(json)
|
242
|
-
assert_equal({'subtext' => '"404er” w k 3 a'}, obj)
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_hash_escaping
|
246
|
-
json = Oj.to_json({'<>' => '<>'}, mode: :compat)
|
247
|
-
assert_equal('{"<>":"<>"}', json)
|
248
|
-
end
|
249
|
-
|
250
|
-
def test_bignum_object
|
251
|
-
dump_and_load(7 ** 55, false)
|
252
|
-
end
|
253
|
-
|
254
|
-
def test_json_object
|
255
|
-
obj = Jeez.new(true, 58)
|
256
|
-
json = Oj.to_json(obj)
|
257
|
-
assert(%|{"json_class":"CompatJuice::Jeez","x":true,"y":58}| == json ||
|
258
|
-
%|{"json_class":"CompatJuice::Jeez","y":58,"x":true}| == json)
|
259
|
-
dump_to_json_and_load(obj, false)
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_json_object_create_id
|
263
|
-
Oj.default_options = { :create_id => 'kson_class', :create_additions => true}
|
264
|
-
expected = Jeez.new(true, 58)
|
265
|
-
json = %{{"kson_class":"CompatJuice::Jeez","x":true,"y":58}}
|
266
|
-
obj = Oj.load(json)
|
267
|
-
assert_equal(expected, obj)
|
268
|
-
Oj.default_options = { :create_id => 'json_class' }
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_bignum_compat
|
272
|
-
json = Oj.dump(7 ** 55, :mode => :compat)
|
273
|
-
b = Oj.load(json, :mode => :strict)
|
274
|
-
assert_equal(30_226_801_971_775_055_948_247_051_683_954_096_612_865_741_943, b)
|
275
|
-
end
|
276
|
-
|
277
|
-
# BigDecimal
|
278
|
-
def test_bigdecimal
|
279
|
-
# BigDecimals are dumped as strings and can not be restored to the
|
280
|
-
# original value without using an undocumented feature of the JSON gem.
|
281
|
-
json = Oj.dump(BigDecimal('3.14159265358979323846'))
|
282
|
-
# 2.4.0 changes the exponent to lowercase
|
283
|
-
assert_equal('"0.314159265358979323846e1"', json.downcase)
|
284
|
-
end
|
285
|
-
|
286
|
-
def test_decimal_class
|
287
|
-
big = BigDecimal('3.14159265358979323846')
|
288
|
-
# :decimal_class is the undocumented feature.
|
289
|
-
json = Oj.load('3.14159265358979323846', mode: :compat, decimal_class: BigDecimal)
|
290
|
-
assert_equal(big, json)
|
291
|
-
end
|
292
|
-
|
293
|
-
def test_infinity
|
294
|
-
assert_raises(Oj::ParseError) { Oj.load('Infinity', :mode => :strict) }
|
295
|
-
x = Oj.load('Infinity', :mode => :compat)
|
296
|
-
assert_equal('Infinity', x.to_s)
|
297
|
-
end
|
298
|
-
|
299
|
-
# Time
|
300
|
-
def test_time_from_time_object
|
301
|
-
t = Time.new(2015, 1, 5, 21, 37, 7.123456, -8 * 3600)
|
302
|
-
expect = '"' + t.to_s + '"'
|
303
|
-
json = Oj.dump(t)
|
304
|
-
assert_equal(expect, json)
|
305
|
-
end
|
306
|
-
|
307
|
-
def test_date_compat
|
308
|
-
orig = Date.new(2012, 6, 19)
|
309
|
-
json = Oj.dump(orig, :mode => :compat)
|
310
|
-
x = Oj.load(json, :mode => :compat)
|
311
|
-
# Some Rubies implement Date as data and some as a real Object. Either are
|
312
|
-
# okay for the test.
|
313
|
-
if x.is_a?(String)
|
314
|
-
assert_equal(orig.to_s, x)
|
315
|
-
else # better be a Hash
|
316
|
-
assert_equal({'year' => orig.year, 'month' => orig.month, 'day' => orig.day, 'start' => orig.start}, x)
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_datetime_compat
|
321
|
-
orig = DateTime.new(2012, 6, 19, 20, 19, 27)
|
322
|
-
json = Oj.dump(orig, :mode => :compat)
|
323
|
-
x = Oj.load(json, :mode => :compat)
|
324
|
-
# Some Rubies implement Date as data and some as a real Object. Either are
|
325
|
-
# okay for the test.
|
326
|
-
assert_equal(orig.to_s, x)
|
327
|
-
end
|
328
|
-
|
329
|
-
# Stream IO
|
330
|
-
def test_io_string
|
331
|
-
json = %{{
|
332
|
-
"x":true,
|
333
|
-
"y":58,
|
334
|
-
"z": [1,2,3]
|
335
|
-
}
|
336
|
-
}
|
337
|
-
input = StringIO.new(json)
|
338
|
-
obj = Oj.compat_load(input)
|
339
|
-
assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
|
340
|
-
end
|
341
|
-
|
342
|
-
def test_io_file
|
343
|
-
filename = File.join(__dir__, 'open_file_test.json')
|
344
|
-
File.write(filename, %{{
|
345
|
-
"x":true,
|
346
|
-
"y":58,
|
347
|
-
"z": [1,2,3]
|
348
|
-
}
|
349
|
-
})
|
350
|
-
f = File.new(filename)
|
351
|
-
obj = Oj.compat_load(f)
|
352
|
-
f.close()
|
353
|
-
assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
|
354
|
-
end
|
355
|
-
|
356
|
-
# symbol_keys option
|
357
|
-
def test_symbol_keys
|
358
|
-
json = %{{
|
359
|
-
"x":true,
|
360
|
-
"y":58,
|
361
|
-
"z": [1,2,3]
|
362
|
-
}
|
363
|
-
}
|
364
|
-
obj = Oj.compat_load(json, :symbol_keys => true)
|
365
|
-
assert_equal({ :x => true, :y => 58, :z => [1, 2, 3]}, obj)
|
366
|
-
end
|
367
|
-
|
368
|
-
# comments
|
369
|
-
def test_comment_slash
|
370
|
-
json = %{{
|
371
|
-
"x":true,//three
|
372
|
-
"y":58,
|
373
|
-
"z": [1,2,
|
374
|
-
3 // six
|
375
|
-
]}
|
376
|
-
}
|
377
|
-
obj = Oj.compat_load(json)
|
378
|
-
assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_comment_c
|
382
|
-
json = %{{
|
383
|
-
"x"/*one*/:/*two*/true,
|
384
|
-
"y":58,
|
385
|
-
"z": [1,2,3]}
|
386
|
-
}
|
387
|
-
obj = Oj.compat_load(json)
|
388
|
-
assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
|
389
|
-
end
|
390
|
-
|
391
|
-
def test_comment
|
392
|
-
json = %{{
|
393
|
-
"x"/*one*/:/*two*/true,//three
|
394
|
-
"y":58/*four*/,
|
395
|
-
"z": [1,2/*five*/,
|
396
|
-
3 // six
|
397
|
-
]
|
398
|
-
}
|
399
|
-
}
|
400
|
-
obj = Oj.compat_load(json)
|
401
|
-
assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
|
402
|
-
end
|
403
|
-
|
404
|
-
# If mimic_JSON has not been called then Oj.dump will call to_json on the
|
405
|
-
# top level object only.
|
406
|
-
def test_json_object_top
|
407
|
-
obj = Jeez.new(true, 58)
|
408
|
-
dump_to_json_and_load(obj, false)
|
409
|
-
end
|
410
|
-
|
411
|
-
# A child to_json should not be called.
|
412
|
-
def test_json_object_child
|
413
|
-
obj = { 'child' => Jeez.new(true, 58) }
|
414
|
-
assert_equal('{"child":{"json_class":"CompatJuice::Jeez","x":true,"y":58}}', Oj.dump(obj))
|
415
|
-
end
|
416
|
-
|
417
|
-
def test_json_module_object
|
418
|
-
obj = One::Two::Three::Deep.new()
|
419
|
-
dump_to_json_and_load(obj, false)
|
420
|
-
end
|
421
|
-
|
422
|
-
def test_json_object_dump_create_id
|
423
|
-
expected = Jeez.new(true, 58)
|
424
|
-
json = Oj.to_json(expected)
|
425
|
-
obj = Oj.compat_load(json, :create_additions => true)
|
426
|
-
assert_equal(expected, obj)
|
427
|
-
end
|
428
|
-
|
429
|
-
def test_json_object_bad
|
430
|
-
json = %{{"json_class":"CompatJuice::Junk","x":true}}
|
431
|
-
begin
|
432
|
-
Oj.compat_load(json, :create_additions => true)
|
433
|
-
rescue Exception => e
|
434
|
-
assert_equal('ArgumentError', e.class().name)
|
435
|
-
return
|
436
|
-
end
|
437
|
-
assert(false, '*** expected an exception')
|
438
|
-
end
|
439
|
-
|
440
|
-
def test_json_object_create_cache
|
441
|
-
expected = Jeez.new(true, 58)
|
442
|
-
json = Oj.to_json(expected)
|
443
|
-
obj = Oj.compat_load(json, :class_cache => true, :create_additions => true)
|
444
|
-
assert_equal(expected, obj)
|
445
|
-
obj = Oj.compat_load(json, :class_cache => false, :create_additions => true)
|
446
|
-
assert_equal(expected, obj)
|
447
|
-
end
|
448
|
-
|
449
|
-
def test_json_object_create_id_other
|
450
|
-
expected = Jeez.new(true, 58)
|
451
|
-
json = Oj.to_json(expected)
|
452
|
-
json.gsub!('json_class', '_class_')
|
453
|
-
obj = Oj.compat_load(json, :create_id => '_class_', :create_additions => true)
|
454
|
-
assert_equal(expected, obj)
|
455
|
-
end
|
456
|
-
|
457
|
-
def test_json_object_create_deep
|
458
|
-
expected = One::Two::Three::Deep.new()
|
459
|
-
json = Oj.to_json(expected)
|
460
|
-
obj = Oj.compat_load(json, :create_additions => true)
|
461
|
-
assert_equal(expected, obj)
|
462
|
-
end
|
463
|
-
|
464
|
-
def test_range
|
465
|
-
json = Oj.dump(1..7)
|
466
|
-
assert_equal('"1..7"', json)
|
467
|
-
end
|
468
|
-
|
469
|
-
def test_arg_passing
|
470
|
-
json = Oj.to_json(Argy.new(), :max_nesting => 40)
|
471
|
-
assert_match(/.*max_nesting.*40.*/, json)
|
472
|
-
end
|
473
|
-
|
474
|
-
def test_max_nesting
|
475
|
-
assert_raises() { Oj.to_json([[[[[]]]]], :max_nesting => 3) }
|
476
|
-
assert_raises() { Oj.dump([[[[[]]]]], :max_nesting => 3, :mode=>:compat) }
|
477
|
-
|
478
|
-
assert_raises() { Oj.to_json([[]], :max_nesting => 1) }
|
479
|
-
assert_equal('[[]]', Oj.to_json([[]], :max_nesting => 2))
|
480
|
-
|
481
|
-
assert_raises() { Oj.dump([[]], :max_nesting => 1, :mode=>:compat) }
|
482
|
-
assert_equal('[[]]', Oj.dump([[]], :max_nesting => 2, :mode=>:compat))
|
483
|
-
|
484
|
-
assert_raises() { Oj.to_json([[3]], :max_nesting => 1) }
|
485
|
-
assert_equal('[[3]]', Oj.to_json([[3]], :max_nesting => 2))
|
486
|
-
|
487
|
-
assert_raises() { Oj.dump([[3]], :max_nesting => 1, :mode=>:compat) }
|
488
|
-
assert_equal('[[3]]', Oj.dump([[3]], :max_nesting => 2, :mode=>:compat))
|
489
|
-
|
490
|
-
end
|
491
|
-
|
492
|
-
def test_bad_unicode
|
493
|
-
assert_raises() { Oj.to_json("\xE4xy") }
|
494
|
-
end
|
495
|
-
|
496
|
-
def test_bad_unicode_e2
|
497
|
-
assert_raises() { Oj.to_json("L\xE2m ") }
|
498
|
-
end
|
499
|
-
|
500
|
-
def test_bad_unicode_start
|
501
|
-
assert_raises() { Oj.to_json("\x8abc") }
|
502
|
-
end
|
503
|
-
|
504
|
-
def test_parse_to_s
|
505
|
-
s = Stringy.new
|
506
|
-
assert_equal([1, 2], Oj.load(s, :mode => :compat))
|
507
|
-
end
|
508
|
-
|
509
|
-
def test_parse_large_string
|
510
|
-
error = assert_raises() { Oj.load(%|{"a":"aaaaaaaaaa\0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}|) }
|
511
|
-
assert_includes(error.message, 'NULL byte in string')
|
512
|
-
|
513
|
-
error = assert_raises() { Oj.load(%|{"a":"aaaaaaaaaaaaaaaaaaaa }|) }
|
514
|
-
assert_includes(error.message, 'quoted string not terminated')
|
515
|
-
|
516
|
-
json =<<~JSON
|
517
|
-
{
|
518
|
-
"a": "\\u3074\\u30fc\\u305f\\u30fc",
|
519
|
-
"b": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
520
|
-
}
|
521
|
-
JSON
|
522
|
-
assert_equal('ぴーたー', Oj.load(json)['a'])
|
523
|
-
end
|
524
|
-
|
525
|
-
def test_parse_large_escaped_string
|
526
|
-
invalid_json = %|{"a":"aaaa\\nbbbb\\rcccc\\tddd\\feee\\bf/\\\\\\u3074\\u30fc\\u305f\\u30fc }|
|
527
|
-
error = assert_raises() { Oj.load(invalid_json) }
|
528
|
-
assert_includes(error.message, 'quoted string not terminated')
|
529
|
-
|
530
|
-
json = '"aaaa\\nbbbb\\rcccc\\tddd\\feee\\bf/\\\\\\u3074\\u30fc\\u305f\\u30fc "'
|
531
|
-
assert_equal("aaaa\nbbbb\rcccc\tddd\feee\bf/\\ぴーたー ", Oj.load(json))
|
532
|
-
end
|
533
|
-
|
534
|
-
def test_invalid_to_s
|
535
|
-
obj = Object.new
|
536
|
-
def obj.to_s
|
537
|
-
nil
|
538
|
-
end
|
539
|
-
|
540
|
-
assert_raises(TypeError) { Oj.dump(obj, mode: :compat) }
|
541
|
-
end
|
542
|
-
|
543
|
-
def dump_and_load(obj, trace=false)
|
544
|
-
json = Oj.dump(obj)
|
545
|
-
puts json if trace
|
546
|
-
loaded = Oj.compat_load(json, :create_additions => true)
|
547
|
-
if obj.nil?
|
548
|
-
assert_nil(loaded)
|
549
|
-
else
|
550
|
-
assert_equal(obj, loaded)
|
551
|
-
end
|
552
|
-
loaded
|
553
|
-
end
|
554
|
-
|
555
|
-
def dump_to_json_and_load(obj, trace=false)
|
556
|
-
json = Oj.to_json(obj, :indent => ' ')
|
557
|
-
puts json if trace
|
558
|
-
loaded = Oj.compat_load(json, :create_additions => true)
|
559
|
-
if obj.nil?
|
560
|
-
assert_nil(loaded)
|
561
|
-
else
|
562
|
-
assert_equal(obj, loaded)
|
563
|
-
end
|
564
|
-
loaded
|
565
|
-
end
|
566
|
-
|
567
|
-
end
|