oj 2.18.3 → 3.13.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1324 -0
- data/README.md +51 -204
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +49 -72
- data/ext/oj/cache.c +326 -0
- data/ext/oj/cache.h +21 -0
- data/ext/oj/cache8.c +61 -64
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +37 -68
- data/ext/oj/circarray.h +16 -42
- data/ext/oj/code.c +221 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +231 -107
- data/ext/oj/custom.c +1125 -0
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +935 -2513
- data/ext/oj/dump.h +108 -0
- data/ext/oj/dump_compat.c +936 -0
- data/ext/oj/dump_leaf.c +164 -0
- data/ext/oj/dump_object.c +761 -0
- data/ext/oj/dump_strict.c +410 -0
- data/ext/oj/encode.h +7 -42
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +40 -54
- data/ext/oj/err.h +52 -46
- data/ext/oj/extconf.rb +21 -30
- data/ext/oj/fast.c +1097 -1080
- data/ext/oj/intern.c +301 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +893 -0
- data/ext/oj/object.c +549 -620
- data/ext/oj/odd.c +155 -167
- data/ext/oj/odd.h +37 -63
- data/ext/oj/oj.c +1661 -2063
- data/ext/oj/oj.h +341 -270
- data/ext/oj/parse.c +974 -737
- data/ext/oj/parse.h +105 -97
- data/ext/oj/parser.c +1526 -0
- data/ext/oj/parser.h +90 -0
- data/ext/oj/rails.c +1504 -0
- data/ext/oj/rails.h +18 -0
- data/ext/oj/reader.c +141 -163
- data/ext/oj/reader.h +75 -113
- data/ext/oj/resolve.c +45 -93
- data/ext/oj/resolve.h +7 -34
- data/ext/oj/rxclass.c +143 -0
- data/ext/oj/rxclass.h +26 -0
- data/ext/oj/saj.c +447 -511
- data/ext/oj/saj2.c +348 -0
- data/ext/oj/scp.c +91 -138
- data/ext/oj/sparse.c +793 -644
- data/ext/oj/stream_writer.c +331 -0
- data/ext/oj/strict.c +145 -109
- data/ext/oj/string_writer.c +493 -0
- data/ext/oj/trace.c +72 -0
- data/ext/oj/trace.h +28 -0
- data/ext/oj/usual.c +1254 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +62 -70
- data/ext/oj/val_stack.h +95 -129
- data/ext/oj/validate.c +51 -0
- data/ext/oj/wab.c +622 -0
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +17 -8
- data/lib/oj/error.rb +10 -11
- data/lib/oj/json.rb +176 -0
- data/lib/oj/mimic.rb +158 -19
- data/lib/oj/state.rb +132 -0
- data/lib/oj/version.rb +2 -2
- data/lib/oj.rb +1 -31
- data/pages/Advanced.md +22 -0
- data/pages/Compatibility.md +25 -0
- data/pages/Custom.md +23 -0
- data/pages/Encoding.md +65 -0
- data/pages/JsonGem.md +94 -0
- data/pages/Modes.md +161 -0
- data/pages/Options.md +327 -0
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +167 -0
- data/pages/Security.md +20 -0
- data/pages/WAB.md +13 -0
- data/test/activerecord/result_test.rb +32 -0
- data/test/activesupport4/decoding_test.rb +108 -0
- data/test/activesupport4/encoding_test.rb +531 -0
- data/test/activesupport4/test_helper.rb +41 -0
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +133 -0
- data/test/activesupport5/encoding_test.rb +500 -0
- data/test/activesupport5/encoding_test_cases.rb +98 -0
- data/test/activesupport5/test_helper.rb +72 -0
- data/test/activesupport5/time_zone_test_helpers.rb +39 -0
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/activesupport7/abstract_unit.rb +49 -0
- data/test/activesupport7/decoding_test.rb +125 -0
- data/test/activesupport7/encoding_test.rb +486 -0
- data/test/activesupport7/encoding_test_cases.rb +104 -0
- data/test/activesupport7/time_zone_test_helpers.rb +47 -0
- data/test/bar.rb +9 -0
- data/test/baz.rb +16 -0
- data/test/bug.rb +11 -46
- data/test/foo.rb +69 -16
- data/test/helper.rb +10 -1
- data/test/isolated/shared.rb +12 -8
- data/test/isolated/test_mimic_rails_after.rb +3 -3
- data/test/isolated/test_mimic_rails_before.rb +3 -3
- data/test/json_gem/json_addition_test.rb +216 -0
- data/test/json_gem/json_common_interface_test.rb +153 -0
- data/test/json_gem/json_encoding_test.rb +107 -0
- data/test/json_gem/json_ext_parser_test.rb +20 -0
- data/test/json_gem/json_fixtures_test.rb +35 -0
- data/test/json_gem/json_generator_test.rb +397 -0
- data/test/json_gem/json_generic_object_test.rb +90 -0
- data/test/json_gem/json_parser_test.rb +470 -0
- data/test/json_gem/json_string_matching_test.rb +42 -0
- data/test/json_gem/test_helper.rb +26 -0
- data/test/mem.rb +33 -0
- data/test/perf.rb +1 -1
- data/test/perf_compat.rb +30 -28
- data/test/perf_dump.rb +50 -0
- data/test/perf_object.rb +1 -1
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +189 -0
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +30 -19
- data/test/perf_wab.rb +131 -0
- data/test/prec.rb +23 -0
- data/test/sample.rb +0 -1
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +219 -102
- data/test/test_custom.rb +533 -0
- data/test/test_fast.rb +107 -35
- data/test/test_file.rb +19 -25
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +72 -0
- data/test/test_null.rb +376 -0
- data/test/test_object.rb +357 -70
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +245 -0
- data/test/test_parser_usual.rb +217 -0
- data/test/test_rails.rb +35 -0
- data/test/test_saj.rb +1 -1
- data/test/test_scp.rb +39 -2
- data/test/test_strict.rb +186 -7
- data/test/test_various.rb +160 -774
- data/test/test_wab.rb +307 -0
- data/test/test_writer.rb +90 -2
- data/test/tests.rb +24 -0
- data/test/tests_mimic.rb +14 -0
- data/test/tests_mimic_addition.rb +7 -0
- data/test/zoo.rb +13 -0
- metadata +194 -56
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
- data/test/activesupport_datetime_test.rb +0 -23
- data/test/bug2.rb +0 -10
- data/test/bug3.rb +0 -46
- data/test/bug_fast.rb +0 -32
- data/test/bug_load.rb +0 -24
- data/test/crash.rb +0 -111
- data/test/curl/curl_oj.rb +0 -46
- data/test/curl/get_oj.rb +0 -24
- data/test/curl/just_curl.rb +0 -31
- data/test/curl/just_oj.rb +0 -51
- data/test/example.rb +0 -11
- data/test/io.rb +0 -48
- data/test/isolated/test_mimic_rails_datetime.rb +0 -27
- data/test/mod.rb +0 -16
- data/test/rails.rb +0 -50
- data/test/russian.rb +0 -18
- data/test/struct.rb +0 -29
- data/test/test_serializer.rb +0 -59
- data/test/write_timebars.rb +0 -31
data/test/test_fast.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# coding: utf-8
|
3
|
+
# frozen_string_literal: true
|
3
4
|
|
4
5
|
$: << File.dirname(__FILE__)
|
5
6
|
|
6
7
|
require 'helper'
|
7
8
|
|
8
|
-
$json1 = %|{
|
9
|
-
"array": [
|
10
|
-
{
|
11
|
-
"num" : 3,
|
12
|
-
"string": "message",
|
13
|
-
"hash" : {
|
14
|
-
"h2" : {
|
15
|
-
"a" : [ 1, 2, 3 ]
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
19
|
-
],
|
20
|
-
"boolean" : true
|
21
|
-
}|
|
22
|
-
|
23
9
|
class DocTest < Minitest::Test
|
24
10
|
def setup
|
25
11
|
@default_options = Oj.default_options
|
12
|
+
@json1 = %|{
|
13
|
+
"array": [
|
14
|
+
{
|
15
|
+
"num" : 3,
|
16
|
+
"string": "message",
|
17
|
+
"hash" : {
|
18
|
+
"h2" : {
|
19
|
+
"a" : [ 1, 2, 3 ]
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
],
|
24
|
+
"boolean" : true
|
25
|
+
}|
|
26
26
|
end
|
27
27
|
|
28
28
|
def teardown
|
@@ -33,7 +33,18 @@ class DocTest < Minitest::Test
|
|
33
33
|
json = %{null}
|
34
34
|
Oj::Doc.open(json) do |doc|
|
35
35
|
assert_equal(NilClass, doc.type)
|
36
|
-
|
36
|
+
assert_nil(doc.fetch())
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_leaf_of_existing_path
|
41
|
+
json = %{{"foo": 1, "fizz": true}}
|
42
|
+
Oj::Doc.open(json) do |doc|
|
43
|
+
%w(/foo/bar /fizz/bar).each do |path|
|
44
|
+
assert_nil(doc.fetch(path))
|
45
|
+
assert_equal(:default, doc.fetch(path, :default))
|
46
|
+
refute(doc.exists?(path))
|
47
|
+
end
|
37
48
|
end
|
38
49
|
end
|
39
50
|
|
@@ -80,7 +91,11 @@ class DocTest < Minitest::Test
|
|
80
91
|
def test_fixnum
|
81
92
|
json = %{12345}
|
82
93
|
Oj::Doc.open(json) do |doc|
|
83
|
-
|
94
|
+
if '2.4.0' <= RUBY_VERSION
|
95
|
+
assert_equal(Integer, doc.type)
|
96
|
+
else
|
97
|
+
assert_equal(Fixnum, doc.type)
|
98
|
+
end
|
84
99
|
assert_equal(12345, doc.fetch())
|
85
100
|
end
|
86
101
|
end
|
@@ -156,7 +171,7 @@ class DocTest < Minitest::Test
|
|
156
171
|
end
|
157
172
|
|
158
173
|
def test_move
|
159
|
-
Oj::Doc.open(
|
174
|
+
Oj::Doc.open(@json1) do |doc|
|
160
175
|
[ '/',
|
161
176
|
'/array',
|
162
177
|
'/boolean',
|
@@ -189,7 +204,7 @@ class DocTest < Minitest::Test
|
|
189
204
|
end
|
190
205
|
|
191
206
|
def test_move_relative
|
192
|
-
Oj::Doc.open(
|
207
|
+
Oj::Doc.open(@json1) do |doc|
|
193
208
|
[['/', 'array', '/array'],
|
194
209
|
['/array', '1/num', '/array/1/num'],
|
195
210
|
['/array/1/hash', 'h2/a', '/array/1/hash/h2/a'],
|
@@ -205,14 +220,19 @@ class DocTest < Minitest::Test
|
|
205
220
|
end
|
206
221
|
|
207
222
|
def test_type
|
208
|
-
|
223
|
+
if '2.4.0' <= RUBY_VERSION
|
224
|
+
num_class = Integer
|
225
|
+
else
|
226
|
+
num_class = Fixnum
|
227
|
+
end
|
228
|
+
Oj::Doc.open(@json1) do |doc|
|
209
229
|
[['/', Hash],
|
210
230
|
['/array', Array],
|
211
231
|
['/array/1', Hash],
|
212
|
-
['/array/1/num',
|
232
|
+
['/array/1/num', num_class],
|
213
233
|
['/array/1/string', String],
|
214
234
|
['/array/1/hash/h2/a', Array],
|
215
|
-
['/array/1/hash/../num',
|
235
|
+
['/array/1/hash/../num', num_class],
|
216
236
|
['/array/1/hash/../..', Array],
|
217
237
|
].each do |path,type|
|
218
238
|
assert_equal(type, doc.type(path))
|
@@ -221,7 +241,7 @@ class DocTest < Minitest::Test
|
|
221
241
|
end
|
222
242
|
|
223
243
|
def test_local_key
|
224
|
-
Oj::Doc.open(
|
244
|
+
Oj::Doc.open(@json1) do |doc|
|
225
245
|
[['/', nil],
|
226
246
|
['/array', 'array'],
|
227
247
|
['/array/1', 1],
|
@@ -233,13 +253,17 @@ class DocTest < Minitest::Test
|
|
233
253
|
['/array/1/hash/../..', 'array'],
|
234
254
|
].each do |path,key|
|
235
255
|
doc.move(path)
|
236
|
-
|
256
|
+
if key.nil?
|
257
|
+
assert_nil(doc.local_key())
|
258
|
+
else
|
259
|
+
assert_equal(key, doc.local_key())
|
260
|
+
end
|
237
261
|
end
|
238
262
|
end
|
239
263
|
end
|
240
264
|
|
241
265
|
def test_fetch_move
|
242
|
-
Oj::Doc.open(
|
266
|
+
Oj::Doc.open(@json1) do |doc|
|
243
267
|
[['/array/1/num', 3],
|
244
268
|
['/array/1/string', 'message'],
|
245
269
|
['/array/1/hash/h2/a', [1, 2, 3]],
|
@@ -257,7 +281,7 @@ class DocTest < Minitest::Test
|
|
257
281
|
end
|
258
282
|
|
259
283
|
def test_fetch_path
|
260
|
-
Oj::Doc.open(
|
284
|
+
Oj::Doc.open(@json1) do |doc|
|
261
285
|
[['/array/1/num', 3],
|
262
286
|
['/array/1/string', 'message'],
|
263
287
|
['/array/1/hash/h2/a', [1, 2, 3]],
|
@@ -267,14 +291,30 @@ class DocTest < Minitest::Test
|
|
267
291
|
['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
|
268
292
|
['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
|
269
293
|
['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
|
294
|
+
['/nothing', nil],
|
295
|
+
['/array/10', nil],
|
270
296
|
].each do |path,val|
|
271
|
-
|
297
|
+
if val.nil?
|
298
|
+
assert_nil(doc.fetch(path))
|
299
|
+
else
|
300
|
+
assert_equal(val, doc.fetch(path))
|
301
|
+
end
|
272
302
|
end
|
273
303
|
end
|
304
|
+
# verify empty hash and arrays return nil when a member is requested
|
305
|
+
Oj::Doc.open('{}') do |doc|
|
306
|
+
assert_nil(doc.fetch('/x'))
|
307
|
+
assert_nil(doc.fetch('/0'))
|
308
|
+
end
|
309
|
+
Oj::Doc.open('[]') do |doc|
|
310
|
+
assert_nil(doc.fetch('/x'))
|
311
|
+
assert_nil(doc.fetch('/0'))
|
312
|
+
end
|
313
|
+
|
274
314
|
end
|
275
315
|
|
276
316
|
def test_move_fetch_path
|
277
|
-
Oj::Doc.open(
|
317
|
+
Oj::Doc.open(@json1) do |doc|
|
278
318
|
[['/array/1', 'num', 3],
|
279
319
|
['/array/1', 'string', 'message'],
|
280
320
|
['/array/1/hash', 'h2/a', [1, 2, 3]],
|
@@ -285,8 +325,22 @@ class DocTest < Minitest::Test
|
|
285
325
|
end
|
286
326
|
end
|
287
327
|
|
328
|
+
def test_exists
|
329
|
+
Oj::Doc.open(@json1) do |doc|
|
330
|
+
[['/array/1', true],
|
331
|
+
['/array/1', true],
|
332
|
+
['/array/1/hash', true],
|
333
|
+
['/array/1/dash', false],
|
334
|
+
['/array/3', false],
|
335
|
+
['/nothing', false],
|
336
|
+
].each do |path,val|
|
337
|
+
assert_equal(val, doc.exists?(path), "failed for #{path.inspect}")
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
288
342
|
def test_home
|
289
|
-
Oj::Doc.open(
|
343
|
+
Oj::Doc.open(@json1) do |doc|
|
290
344
|
doc.move('/array/1/num')
|
291
345
|
doc.home()
|
292
346
|
assert_equal('/', doc.where?)
|
@@ -294,7 +348,7 @@ class DocTest < Minitest::Test
|
|
294
348
|
end
|
295
349
|
|
296
350
|
def test_each_value_root
|
297
|
-
Oj::Doc.open(
|
351
|
+
Oj::Doc.open(@json1) do |doc|
|
298
352
|
values = []
|
299
353
|
doc.each_value() { |v| values << v.to_s }
|
300
354
|
assert_equal(['1', '2', '3', '3', 'message', 'true'], values.sort)
|
@@ -302,7 +356,7 @@ class DocTest < Minitest::Test
|
|
302
356
|
end
|
303
357
|
|
304
358
|
def test_each_value_move
|
305
|
-
Oj::Doc.open(
|
359
|
+
Oj::Doc.open(@json1) do |doc|
|
306
360
|
doc.move('/array/1/hash')
|
307
361
|
values = []
|
308
362
|
doc.each_value() { |v| values << v.to_s }
|
@@ -311,7 +365,7 @@ class DocTest < Minitest::Test
|
|
311
365
|
end
|
312
366
|
|
313
367
|
def test_each_value_path
|
314
|
-
Oj::Doc.open(
|
368
|
+
Oj::Doc.open(@json1) do |doc|
|
315
369
|
values = []
|
316
370
|
doc.each_value('/array/1/hash') { |v| values << v.to_s }
|
317
371
|
assert_equal(['1', '2', '3'], values.sort)
|
@@ -319,7 +373,7 @@ class DocTest < Minitest::Test
|
|
319
373
|
end
|
320
374
|
|
321
375
|
def test_each_child_move
|
322
|
-
Oj::Doc.open(
|
376
|
+
Oj::Doc.open(@json1) do |doc|
|
323
377
|
locations = []
|
324
378
|
doc.move('/array/1/hash/h2/a')
|
325
379
|
doc.each_child() { |d| locations << d.where? }
|
@@ -332,7 +386,7 @@ class DocTest < Minitest::Test
|
|
332
386
|
end
|
333
387
|
|
334
388
|
def test_each_child_path
|
335
|
-
Oj::Doc.open(
|
389
|
+
Oj::Doc.open(@json1) do |doc|
|
336
390
|
locations = []
|
337
391
|
doc.each_child('/array/1/hash/h2/a') { |d| locations << d.where? }
|
338
392
|
assert_equal(['/array/1/hash/h2/a/1', '/array/1/hash/h2/a/2', '/array/1/hash/h2/a/3'], locations)
|
@@ -342,6 +396,19 @@ class DocTest < Minitest::Test
|
|
342
396
|
end
|
343
397
|
end
|
344
398
|
|
399
|
+
def test_nested_each_child
|
400
|
+
h = {}
|
401
|
+
Oj::Doc.open('{"a":1,"c":[2],"d":3}') do |doc|
|
402
|
+
doc.each_child('/') do |child|
|
403
|
+
h[child.path] = child.fetch
|
404
|
+
child.each_child do |grandchild|
|
405
|
+
h[grandchild.path] = grandchild.fetch
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
assert_equal({"/a"=>1, "/c"=>[2], "/c/1"=>2, "/d"=>3}, h)
|
410
|
+
end
|
411
|
+
|
345
412
|
def test_size
|
346
413
|
Oj::Doc.open('[1,2,3]') do |doc|
|
347
414
|
assert_equal(4, doc.size)
|
@@ -438,6 +505,11 @@ class DocTest < Minitest::Test
|
|
438
505
|
assert_equal({'/a/x' => 2, '/b/y' => 4}, results)
|
439
506
|
end
|
440
507
|
|
508
|
+
def test_doc_empty
|
509
|
+
result = Oj::Doc.open("") { |doc| doc.each_child {} }
|
510
|
+
assert_nil(result)
|
511
|
+
end
|
512
|
+
|
441
513
|
def test_comment
|
442
514
|
json = %{{
|
443
515
|
"x"/*one*/:/*two*/true,//three
|
data/test/test_file.rb
CHANGED
@@ -130,6 +130,8 @@ class FileJuice < Minitest::Test
|
|
130
130
|
dump_and_load(t, false)
|
131
131
|
end
|
132
132
|
def test_time_object_early
|
133
|
+
# Windows does not support dates before 1970.
|
134
|
+
return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
133
135
|
t = Time.xmlschema("1954-01-05T00:00:00.123456")
|
134
136
|
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
|
135
137
|
dump_and_load(t, false)
|
@@ -145,7 +147,7 @@ class FileJuice < Minitest::Test
|
|
145
147
|
|
146
148
|
# Object with to_json()
|
147
149
|
def test_json_object_compat
|
148
|
-
Oj.default_options = { :mode => :compat, :use_to_json => true }
|
150
|
+
Oj.default_options = { :mode => :compat, :use_to_json => true, :create_additions => true }
|
149
151
|
obj = Jeez.new(true, 58)
|
150
152
|
json = Oj.dump(obj, :indent => 2)
|
151
153
|
assert(%{{"json_class":"FileJuice::Jeez","x":true,"y":58}
|
@@ -156,30 +158,20 @@ class FileJuice < Minitest::Test
|
|
156
158
|
Oj.default_options = { :mode => :compat, :use_to_json => false }
|
157
159
|
end
|
158
160
|
|
159
|
-
def test_as_json_object_compat_hash
|
160
|
-
Oj.default_options = { :mode => :compat, :use_as_json => true }
|
161
|
-
obj = Orange.new(true, 58)
|
162
|
-
json = Oj.dump(obj, :indent => 2)
|
163
|
-
assert(!json.nil?)
|
164
|
-
dump_and_load(obj, false)
|
165
|
-
end
|
166
|
-
|
167
161
|
# Range
|
168
162
|
def test_range_object
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
|
178
|
-
end
|
179
|
-
dump_and_load(1..7, false)
|
180
|
-
dump_and_load(1..1, false)
|
181
|
-
dump_and_load(1...7, false)
|
163
|
+
Oj.default_options = { :mode => :object }
|
164
|
+
json = Oj.dump(1..7, :mode => :object, :indent => 0)
|
165
|
+
if 'rubinius' == $ruby
|
166
|
+
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
167
|
+
elsif 'jruby' == $ruby
|
168
|
+
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
169
|
+
else
|
170
|
+
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
|
182
171
|
end
|
172
|
+
dump_and_load(1..7, false)
|
173
|
+
dump_and_load(1..1, false)
|
174
|
+
dump_and_load(1...7, false)
|
183
175
|
end
|
184
176
|
|
185
177
|
# BigNum
|
@@ -192,20 +184,20 @@ class FileJuice < Minitest::Test
|
|
192
184
|
def test_bigdecimal_strict
|
193
185
|
mode = Oj.default_options[:mode]
|
194
186
|
Oj.default_options = {:mode => :strict}
|
195
|
-
dump_and_load(BigDecimal
|
187
|
+
dump_and_load(BigDecimal('3.14159265358979323846'), false)
|
196
188
|
Oj.default_options = {:mode => mode}
|
197
189
|
end
|
198
190
|
|
199
191
|
def test_bigdecimal_null
|
200
192
|
mode = Oj.default_options[:mode]
|
201
193
|
Oj.default_options = {:mode => :null}
|
202
|
-
dump_and_load(BigDecimal
|
194
|
+
dump_and_load(BigDecimal('3.14159265358979323846'), false)
|
203
195
|
Oj.default_options = {:mode => mode}
|
204
196
|
end
|
205
197
|
|
206
198
|
def test_bigdecimal_object
|
207
199
|
Oj.default_options = {:mode => :object}
|
208
|
-
dump_and_load(BigDecimal
|
200
|
+
dump_and_load(BigDecimal('3.14159265358979323846'), false)
|
209
201
|
end
|
210
202
|
|
211
203
|
# Date
|
@@ -236,6 +228,8 @@ class FileJuice < Minitest::Test
|
|
236
228
|
end
|
237
229
|
assert_equal(obj.utc?, loaded.utc?)
|
238
230
|
assert_equal(obj.utc_offset, loaded.utc_offset)
|
231
|
+
elsif obj.nil?
|
232
|
+
assert_nil(loaded)
|
239
233
|
else
|
240
234
|
assert_equal(obj, loaded)
|
241
235
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
%w(lib ext).each do |dir|
|
7
|
+
$: << File.join($oj_dir, dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'minitest'
|
11
|
+
require 'minitest/autorun'
|
12
|
+
require 'oj'
|
13
|
+
|
14
|
+
class Generator < Minitest::Test
|
15
|
+
|
16
|
+
def test_before
|
17
|
+
json = Oj.generate({})
|
18
|
+
assert_equal("{}", json)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/test_hash.rb
CHANGED
@@ -5,7 +5,7 @@ $: << File.dirname(__FILE__)
|
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
8
|
-
class
|
8
|
+
class HashTest < Minitest::Test
|
9
9
|
|
10
10
|
module TestModule
|
11
11
|
end
|
@@ -25,5 +25,15 @@ class Hashi < Minitest::Test
|
|
25
25
|
assert_equal(3, obj[:abc])
|
26
26
|
assert_equal(3, obj.abc())
|
27
27
|
end
|
28
|
+
|
29
|
+
def test_marshal
|
30
|
+
h = Oj::EasyHash.new()
|
31
|
+
h['abc'] = 3
|
32
|
+
out = Marshal.dump(h)
|
33
|
+
|
34
|
+
obj = Marshal.load(out)
|
35
|
+
assert_equal(Oj::EasyHash, obj.class)
|
36
|
+
assert_equal(3, obj[:abc])
|
37
|
+
end
|
28
38
|
|
29
39
|
end # HashTest
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
6
|
+
%w(lib ext).each do |dir|
|
7
|
+
$: << File.join($oj_dir, dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'minitest'
|
11
|
+
require 'minitest/autorun'
|
12
|
+
require 'oj'
|
13
|
+
|
14
|
+
class IntegerRangeTest < Minitest::Test
|
15
|
+
def setup
|
16
|
+
@default_options = Oj.default_options
|
17
|
+
# in null mode other options other than the number formats are not used.
|
18
|
+
Oj.default_options = { :mode => :null, bigdecimal_as_decimal: true }
|
19
|
+
end
|
20
|
+
|
21
|
+
def teardown
|
22
|
+
Oj.default_options = @default_options
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_range
|
26
|
+
test = {s: 0, s2: -1, s3: 1, u: -2, u2: 2, u3: 9007199254740993}
|
27
|
+
exp = '{"s":0,"s2":-1,"s3":1,"u":"-2","u2":"2","u3":"9007199254740993"}'
|
28
|
+
assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_bignum
|
32
|
+
test = {u: -10000000000000000000, u2: 10000000000000000000}
|
33
|
+
exp = '{"u":"-10000000000000000000","u2":"10000000000000000000"}'
|
34
|
+
assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_valid_modes
|
38
|
+
test = {safe: 0, unsafe: 9007199254740993}
|
39
|
+
exp = '{"safe":0,"unsafe":"9007199254740993"}'
|
40
|
+
|
41
|
+
[:strict, :null, :compat, :rails, :custom].each do |mode|
|
42
|
+
assert_equal(exp, Oj.dump(test, mode: mode, integer_range: (-1..1)), "Invalid mode #{mode}")
|
43
|
+
end
|
44
|
+
|
45
|
+
exp = '{":safe":0,":unsafe":"9007199254740993"}'
|
46
|
+
[:object].each do |mode|
|
47
|
+
assert_equal(exp, Oj.dump(test, mode: mode, integer_range: (-1..1)), "Invalid mode #{mode}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_modes_without_opt
|
52
|
+
test = {safe:0, unsafe: 10000000000000000000}
|
53
|
+
exp = '{"safe":0,"unsafe":10000000000000000000}'
|
54
|
+
|
55
|
+
[:strict, :null, :compat, :rails, :custom].each do |mode|
|
56
|
+
assert_equal(exp, Oj.dump(test, mode: mode), "Invalid mode #{mode}")
|
57
|
+
end
|
58
|
+
|
59
|
+
exp = '{":safe":0,":unsafe":10000000000000000000}'
|
60
|
+
[:object].each do |mode|
|
61
|
+
assert_equal(exp, Oj.dump(test, mode: mode), "Invalid mode #{mode}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_accept_nil_and_false
|
66
|
+
test = {safe:0, unsafe: 10000000000000000000}
|
67
|
+
exp = '{"safe":0,"unsafe":10000000000000000000}'
|
68
|
+
|
69
|
+
assert_equal(exp, Oj.dump(test, integer_range: nil))
|
70
|
+
assert_equal(exp, Oj.dump(test, integer_range: false))
|
71
|
+
end
|
72
|
+
end
|