oj 3.11.5 → 3.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1421 -0
- data/README.md +19 -5
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +20 -6
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +8 -6
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +19 -33
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +27 -77
- data/ext/oj/custom.c +86 -179
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +256 -249
- data/ext/oj/dump.h +26 -12
- data/ext/oj/dump_compat.c +565 -642
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +65 -187
- data/ext/oj/dump_strict.c +27 -51
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +24 -8
- data/ext/oj/extconf.rb +21 -6
- data/ext/oj/fast.c +149 -149
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +121 -106
- data/ext/oj/object.c +85 -162
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +542 -411
- data/ext/oj/oj.h +99 -73
- data/ext/oj/parse.c +175 -187
- data/ext/oj/parse.h +26 -24
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +101 -0
- data/ext/oj/rails.c +112 -159
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +11 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +5 -24
- data/ext/oj/rxclass.c +7 -6
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +22 -33
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +5 -28
- data/ext/oj/sparse.c +28 -72
- data/ext/oj/stream_writer.c +50 -40
- data/ext/oj/strict.c +56 -61
- data/ext/oj/string_writer.c +72 -39
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +14 -3
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +63 -88
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +1 -2
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +9 -7
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +12 -8
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/Compatibility.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +8 -3
- data/pages/Options.md +43 -5
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +14 -2
- data/test/_test_active.rb +8 -9
- data/test/_test_active_mimic.rb +7 -8
- data/test/_test_mimic_rails.rb +17 -20
- data/test/activerecord/result_test.rb +5 -6
- data/test/activesupport6/encoding_test.rb +63 -28
- data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
- data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
- data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
- data/test/files.rb +15 -15
- data/test/foo.rb +16 -45
- data/test/helper.rb +11 -8
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +8 -6
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +56 -38
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +54 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +7 -3
- data/test/mem.rb +34 -0
- data/test/perf.rb +22 -27
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +50 -0
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -69
- data/test/perf_once.rb +59 -0
- data/test/perf_parser.rb +183 -0
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +58 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +74 -82
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +5 -5
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +16 -16
- data/test/sample_json.rb +8 -8
- data/test/test_compat.rb +95 -43
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +135 -79
- data/test/test_file.rb +41 -30
- data/test/test_gc.rb +16 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +5 -5
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +99 -96
- data/test/test_parser.rb +11 -0
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +337 -0
- data/test/test_parser_usual.rb +251 -0
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +37 -39
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +165 -84
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -5
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +74 -128
- data/ext/oj/hash.c +0 -131
- data/ext/oj/hash.h +0 -19
- data/ext/oj/hash_test.c +0 -491
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/bar.rb +0 -35
- data/test/baz.rb +0 -16
- data/test/zoo.rb +0 -13
data/test/test_fast.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
@@ -36,11 +36,22 @@ class DocTest < Minitest::Test
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def test_leaf_of_existing_path
|
40
|
+
json = %{{"foo": 1, "fizz": true}}
|
41
|
+
Oj::Doc.open(json) do |doc|
|
42
|
+
%w(/foo/bar /fizz/bar).each do |path|
|
43
|
+
assert_nil(doc.fetch(path))
|
44
|
+
assert_equal(:default, doc.fetch(path, :default))
|
45
|
+
refute(doc.exists?(path))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
39
50
|
def test_true
|
40
51
|
json = %{true}
|
41
52
|
Oj::Doc.open(json) do |doc|
|
42
53
|
assert_equal(TrueClass, doc.type)
|
43
|
-
|
54
|
+
assert(doc.fetch())
|
44
55
|
end
|
45
56
|
end
|
46
57
|
|
@@ -48,7 +59,7 @@ class DocTest < Minitest::Test
|
|
48
59
|
json = %{false}
|
49
60
|
Oj::Doc.open(json) do |doc|
|
50
61
|
assert_equal(FalseClass, doc.type)
|
51
|
-
|
62
|
+
refute(doc.fetch())
|
52
63
|
end
|
53
64
|
end
|
54
65
|
|
@@ -64,7 +75,7 @@ class DocTest < Minitest::Test
|
|
64
75
|
json = %{"ぴーたー"}
|
65
76
|
Oj::Doc.open(json) do |doc|
|
66
77
|
assert_equal(String, doc.type)
|
67
|
-
assert_equal(
|
78
|
+
assert_equal('ぴーたー', doc.fetch())
|
68
79
|
end
|
69
80
|
end
|
70
81
|
|
@@ -72,19 +83,15 @@ class DocTest < Minitest::Test
|
|
72
83
|
json = %{"\\u3074\\u30fc\\u305f\\u30fc"}
|
73
84
|
Oj::Doc.open(json) do |doc|
|
74
85
|
assert_equal(String, doc.type)
|
75
|
-
assert_equal(
|
86
|
+
assert_equal('ぴーたー', doc.fetch())
|
76
87
|
end
|
77
88
|
end
|
78
89
|
|
79
90
|
def test_fixnum
|
80
91
|
json = %{12345}
|
81
92
|
Oj::Doc.open(json) do |doc|
|
82
|
-
|
83
|
-
|
84
|
-
else
|
85
|
-
assert_equal(Fixnum, doc.type)
|
86
|
-
end
|
87
|
-
assert_equal(12345, doc.fetch())
|
93
|
+
assert_equal(Integer, doc.type)
|
94
|
+
assert_equal(12_345, doc.fetch())
|
88
95
|
end
|
89
96
|
end
|
90
97
|
|
@@ -92,7 +99,7 @@ class DocTest < Minitest::Test
|
|
92
99
|
json = %{12345.6789}
|
93
100
|
Oj::Doc.open(json) do |doc|
|
94
101
|
assert_equal(Float, doc.type)
|
95
|
-
|
102
|
+
assert_in_delta(12_345.6789, doc.fetch())
|
96
103
|
end
|
97
104
|
end
|
98
105
|
|
@@ -100,8 +107,8 @@ class DocTest < Minitest::Test
|
|
100
107
|
json = %{12345.6789e7}
|
101
108
|
Oj::Doc.open(json) do |doc|
|
102
109
|
assert_equal(Float, doc.type)
|
103
|
-
#assert_equal(12345.6789e7, doc.fetch())
|
104
|
-
assert_equal(
|
110
|
+
# assert_equal(12345.6789e7, doc.fetch())
|
111
|
+
assert_equal(12_345.6789e7.to_i, doc.fetch().to_i)
|
105
112
|
end
|
106
113
|
end
|
107
114
|
|
@@ -109,7 +116,7 @@ class DocTest < Minitest::Test
|
|
109
116
|
json = %{[]}
|
110
117
|
Oj::Doc.open(json) do |doc|
|
111
118
|
assert_equal(Array, doc.type)
|
112
|
-
|
119
|
+
assert_empty(doc.fetch())
|
113
120
|
end
|
114
121
|
end
|
115
122
|
|
@@ -125,7 +132,7 @@ class DocTest < Minitest::Test
|
|
125
132
|
json = %{{}}
|
126
133
|
Oj::Doc.open(json) do |doc|
|
127
134
|
assert_equal(Hash, doc.type)
|
128
|
-
|
135
|
+
assert_empty(doc.fetch())
|
129
136
|
end
|
130
137
|
end
|
131
138
|
|
@@ -160,7 +167,8 @@ class DocTest < Minitest::Test
|
|
160
167
|
|
161
168
|
def test_move
|
162
169
|
Oj::Doc.open(@json1) do |doc|
|
163
|
-
[
|
170
|
+
[
|
171
|
+
'/',
|
164
172
|
'/array',
|
165
173
|
'/boolean',
|
166
174
|
'/array/1/hash/h2/a/3',
|
@@ -193,13 +201,14 @@ class DocTest < Minitest::Test
|
|
193
201
|
|
194
202
|
def test_move_relative
|
195
203
|
Oj::Doc.open(@json1) do |doc|
|
196
|
-
[
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
204
|
+
[
|
205
|
+
['/', 'array', '/array'],
|
206
|
+
['/array', '1/num', '/array/1/num'],
|
207
|
+
['/array/1/hash', 'h2/a', '/array/1/hash/h2/a'],
|
208
|
+
['/array/1', 'hash/h2/a/2', '/array/1/hash/h2/a/2'],
|
209
|
+
['/array/1/hash', '../string', '/array/1/string'],
|
210
|
+
['/array/1/hash', '..', '/array/1'],
|
211
|
+
].each do |start, path, where|
|
203
212
|
doc.move(start)
|
204
213
|
doc.move(path)
|
205
214
|
assert_equal(where, doc.where?)
|
@@ -208,21 +217,17 @@ class DocTest < Minitest::Test
|
|
208
217
|
end
|
209
218
|
|
210
219
|
def test_type
|
211
|
-
if '2.4.0' <= RUBY_VERSION
|
212
|
-
num_class = Integer
|
213
|
-
else
|
214
|
-
num_class = Fixnum
|
215
|
-
end
|
216
220
|
Oj::Doc.open(@json1) do |doc|
|
217
|
-
[
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
221
|
+
[
|
222
|
+
['/', Hash],
|
223
|
+
['/array', Array],
|
224
|
+
['/array/1', Hash],
|
225
|
+
['/array/1/num', Integer],
|
226
|
+
['/array/1/string', String],
|
227
|
+
['/array/1/hash/h2/a', Array],
|
228
|
+
['/array/1/hash/../num', Integer],
|
229
|
+
['/array/1/hash/../..', Array],
|
230
|
+
].each do |path, type|
|
226
231
|
assert_equal(type, doc.type(path))
|
227
232
|
end
|
228
233
|
end
|
@@ -230,16 +235,17 @@ class DocTest < Minitest::Test
|
|
230
235
|
|
231
236
|
def test_local_key
|
232
237
|
Oj::Doc.open(@json1) do |doc|
|
233
|
-
[
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
238
|
+
[
|
239
|
+
['/', nil],
|
240
|
+
['/array', 'array'],
|
241
|
+
['/array/1', 1],
|
242
|
+
['/array/1/num', 'num'],
|
243
|
+
['/array/1/string', 'string'],
|
244
|
+
['/array/1/hash/h2/a', 'a'],
|
245
|
+
['/array/1/hash/../num', 'num'],
|
246
|
+
['/array/1/hash/..', 1],
|
247
|
+
['/array/1/hash/../..', 'array'],
|
248
|
+
].each do |path, key|
|
243
249
|
doc.move(path)
|
244
250
|
if key.nil?
|
245
251
|
assert_nil(doc.local_key())
|
@@ -252,16 +258,17 @@ class DocTest < Minitest::Test
|
|
252
258
|
|
253
259
|
def test_fetch_move
|
254
260
|
Oj::Doc.open(@json1) do |doc|
|
255
|
-
[
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
261
|
+
[
|
262
|
+
['/array/1/num', 3],
|
263
|
+
['/array/1/string', 'message'],
|
264
|
+
['/array/1/hash/h2/a', [1, 2, 3]],
|
265
|
+
['/array/1/hash/../num', 3],
|
266
|
+
['/array/1/hash/..', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
|
267
|
+
['/array/1/hash/../..', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
|
268
|
+
['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
|
269
|
+
['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
|
270
|
+
['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
|
271
|
+
].each do |path, val|
|
265
272
|
doc.move(path)
|
266
273
|
assert_equal(val, doc.fetch())
|
267
274
|
end
|
@@ -270,33 +277,65 @@ class DocTest < Minitest::Test
|
|
270
277
|
|
271
278
|
def test_fetch_path
|
272
279
|
Oj::Doc.open(@json1) do |doc|
|
273
|
-
[
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
280
|
+
[
|
281
|
+
['/array/1/num', 3],
|
282
|
+
['/array/1/string', 'message'],
|
283
|
+
['/array/1/hash/h2/a', [1, 2, 3]],
|
284
|
+
['/array/1/hash/../num', 3],
|
285
|
+
['/array/1/hash/..', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
|
286
|
+
['/array/1/hash/../..', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
|
287
|
+
['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
|
288
|
+
['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
|
289
|
+
['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
|
290
|
+
['/nothing', nil],
|
291
|
+
['/array/10', nil],
|
292
|
+
].each do |path, val|
|
293
|
+
if val.nil?
|
294
|
+
assert_nil(doc.fetch(path))
|
295
|
+
else
|
296
|
+
assert_equal(val, doc.fetch(path))
|
297
|
+
end
|
284
298
|
end
|
285
299
|
end
|
300
|
+
# verify empty hash and arrays return nil when a member is requested
|
301
|
+
Oj::Doc.open('{}') do |doc|
|
302
|
+
assert_nil(doc.fetch('/x'))
|
303
|
+
assert_nil(doc.fetch('/0'))
|
304
|
+
end
|
305
|
+
Oj::Doc.open('[]') do |doc|
|
306
|
+
assert_nil(doc.fetch('/x'))
|
307
|
+
assert_nil(doc.fetch('/0'))
|
308
|
+
end
|
286
309
|
end
|
287
310
|
|
288
311
|
def test_move_fetch_path
|
289
312
|
Oj::Doc.open(@json1) do |doc|
|
290
|
-
[
|
291
|
-
|
292
|
-
|
293
|
-
|
313
|
+
[
|
314
|
+
['/array/1', 'num', 3],
|
315
|
+
['/array/1', 'string', 'message'],
|
316
|
+
['/array/1/hash', 'h2/a', [1, 2, 3]],
|
317
|
+
].each do |path, fetch_path, val|
|
294
318
|
doc.move(path)
|
295
319
|
assert_equal(val, doc.fetch(fetch_path))
|
296
320
|
end
|
297
321
|
end
|
298
322
|
end
|
299
323
|
|
324
|
+
def test_exists
|
325
|
+
Oj::Doc.open(@json1) do |doc|
|
326
|
+
[
|
327
|
+
['/array/1', true],
|
328
|
+
['/array/1', true],
|
329
|
+
['/array/1/hash', true],
|
330
|
+
['/array/1/dash', false],
|
331
|
+
['/array/3', false],
|
332
|
+
['/nothing', false],
|
333
|
+
].each do |path, val|
|
334
|
+
assert_equal(val, doc.exists?(path), "failed for #{path.inspect}")
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
300
339
|
def test_home
|
301
340
|
Oj::Doc.open(@json1) do |doc|
|
302
341
|
doc.move('/array/1/num')
|
@@ -354,6 +393,19 @@ class DocTest < Minitest::Test
|
|
354
393
|
end
|
355
394
|
end
|
356
395
|
|
396
|
+
def test_nested_each_child
|
397
|
+
h = {}
|
398
|
+
Oj::Doc.open('{"a":1,"c":[2],"d":3}') do |doc|
|
399
|
+
doc.each_child('/') do |child|
|
400
|
+
h[child.path] = child.fetch
|
401
|
+
child.each_child do |grandchild|
|
402
|
+
h[grandchild.path] = grandchild.fetch
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
assert_equal({'/a'=>1, '/c'=>[2], '/c/1'=>2, '/d'=>3}, h)
|
407
|
+
end
|
408
|
+
|
357
409
|
def test_size
|
358
410
|
Oj::Doc.open('[1,2,3]') do |doc|
|
359
411
|
assert_equal(4, doc.size)
|
@@ -364,8 +416,8 @@ class DocTest < Minitest::Test
|
|
364
416
|
end
|
365
417
|
|
366
418
|
def test_open_file
|
367
|
-
filename = File.join(
|
368
|
-
File.
|
419
|
+
filename = File.join(__dir__, 'open_file_test.json')
|
420
|
+
File.write(filename, '{"a":[1,2,3]}')
|
369
421
|
Oj::Doc.open_file(filename) do |doc|
|
370
422
|
assert_equal(5, doc.size)
|
371
423
|
end
|
@@ -390,8 +442,8 @@ class DocTest < Minitest::Test
|
|
390
442
|
end
|
391
443
|
|
392
444
|
def test_file_open_close
|
393
|
-
filename = File.join(
|
394
|
-
File.
|
445
|
+
filename = File.join(__dir__, 'open_file_test.json')
|
446
|
+
File.write(filename, '{"a":[1,2,3]}')
|
395
447
|
doc = Oj::Doc.open_file(filename)
|
396
448
|
assert_equal(Oj::Doc, doc.class)
|
397
449
|
assert_equal(5, doc.size)
|
@@ -418,7 +470,6 @@ class DocTest < Minitest::Test
|
|
418
470
|
doc.home()
|
419
471
|
assert_equal(2, doc.fetch('/a/2'))
|
420
472
|
assert_equal(2, doc.fetch('a/2'))
|
421
|
-
doc = nil
|
422
473
|
GC.start
|
423
474
|
# a print statement confirms close is called
|
424
475
|
end
|
@@ -450,6 +501,11 @@ class DocTest < Minitest::Test
|
|
450
501
|
assert_equal({'/a/x' => 2, '/b/y' => 4}, results)
|
451
502
|
end
|
452
503
|
|
504
|
+
def test_doc_empty
|
505
|
+
result = Oj::Doc.open('') { |doc| doc.each_child {} }
|
506
|
+
assert_nil(result)
|
507
|
+
end
|
508
|
+
|
453
509
|
def test_comment
|
454
510
|
json = %{{
|
455
511
|
"x"/*one*/:/*two*/true,//three
|
data/test/test_file.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
@@ -19,35 +19,29 @@ class FileJuice < Minitest::Test
|
|
19
19
|
end
|
20
20
|
alias == eql?
|
21
21
|
|
22
|
-
end# Jam
|
22
|
+
end # Jam
|
23
23
|
|
24
24
|
class Jeez < Jam
|
25
|
-
def initialize(x, y)
|
26
|
-
super
|
27
|
-
end
|
28
25
|
|
29
|
-
def to_json()
|
26
|
+
def to_json(*_args)
|
30
27
|
%{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
|
31
28
|
end
|
32
29
|
|
33
30
|
def self.json_create(h)
|
34
|
-
|
31
|
+
new(h['x'], h['y'])
|
35
32
|
end
|
36
|
-
end# Jeez
|
33
|
+
end # Jeez
|
37
34
|
|
38
35
|
class Orange < Jam
|
39
|
-
def initialize(x, y)
|
40
|
-
super
|
41
|
-
end
|
42
36
|
|
43
|
-
def as_json
|
37
|
+
def as_json
|
44
38
|
{ :json_class => self.class,
|
45
39
|
:x => @x,
|
46
40
|
:y => @y }
|
47
41
|
end
|
48
42
|
|
49
43
|
def self.json_create(h)
|
50
|
-
|
44
|
+
new(h['x'], h['y'])
|
51
45
|
end
|
52
46
|
end
|
53
47
|
|
@@ -73,8 +67,8 @@ class FileJuice < Minitest::Test
|
|
73
67
|
|
74
68
|
def test_fixnum
|
75
69
|
dump_and_load(0, false)
|
76
|
-
dump_and_load(
|
77
|
-
dump_and_load(-
|
70
|
+
dump_and_load(12_345, false)
|
71
|
+
dump_and_load(-54_321, false)
|
78
72
|
dump_and_load(1, false)
|
79
73
|
end
|
80
74
|
|
@@ -82,9 +76,9 @@ class FileJuice < Minitest::Test
|
|
82
76
|
mode = Oj.default_options()[:mode]
|
83
77
|
Oj.default_options = {:mode => :object}
|
84
78
|
dump_and_load(0.0, false)
|
85
|
-
dump_and_load(
|
79
|
+
dump_and_load(12_345.6789, false)
|
86
80
|
dump_and_load(70.35, false)
|
87
|
-
dump_and_load(-
|
81
|
+
dump_and_load(-54_321.012, false)
|
88
82
|
dump_and_load(1.7775, false)
|
89
83
|
dump_and_load(2.5024, false)
|
90
84
|
dump_and_load(2.48e16, false)
|
@@ -118,9 +112,9 @@ class FileJuice < Minitest::Test
|
|
118
112
|
# Symbol
|
119
113
|
def test_symbol_object
|
120
114
|
Oj.default_options = { :mode => :object }
|
121
|
-
#dump_and_load(''.to_sym, false)
|
115
|
+
# dump_and_load(''.to_sym, false)
|
122
116
|
dump_and_load(:abc, false)
|
123
|
-
dump_and_load(
|
117
|
+
dump_and_load(:":xyz", false)
|
124
118
|
end
|
125
119
|
|
126
120
|
# Time
|
@@ -129,10 +123,11 @@ class FileJuice < Minitest::Test
|
|
129
123
|
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
|
130
124
|
dump_and_load(t, false)
|
131
125
|
end
|
126
|
+
|
132
127
|
def test_time_object_early
|
133
|
-
|
134
|
-
|
135
|
-
t = Time.xmlschema(
|
128
|
+
skip 'Windows does not support dates before 1970.' if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
129
|
+
|
130
|
+
t = Time.xmlschema('1954-01-05T00:00:00.123456')
|
136
131
|
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
|
137
132
|
dump_and_load(t, false)
|
138
133
|
end
|
@@ -162,12 +157,10 @@ class FileJuice < Minitest::Test
|
|
162
157
|
def test_range_object
|
163
158
|
Oj.default_options = { :mode => :object }
|
164
159
|
json = Oj.dump(1..7, :mode => :object, :indent => 0)
|
165
|
-
if
|
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
|
160
|
+
if $ruby == 'ruby'
|
170
161
|
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
|
162
|
+
else
|
163
|
+
assert_equal(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}}, json)
|
171
164
|
end
|
172
165
|
dump_and_load(1..7, false)
|
173
166
|
dump_and_load(1..1, false)
|
@@ -212,9 +205,27 @@ class FileJuice < Minitest::Test
|
|
212
205
|
dump_and_load(DateTime.new(2012, 6, 19), false)
|
213
206
|
end
|
214
207
|
|
208
|
+
def test_load_unicode_path
|
209
|
+
json =<<~JSON
|
210
|
+
{
|
211
|
+
"x":true,
|
212
|
+
"y":58,
|
213
|
+
"z": [1,2,3]
|
214
|
+
}
|
215
|
+
JSON
|
216
|
+
|
217
|
+
Tempfile.create('file_test_conceição1.json') do |f|
|
218
|
+
f.write(json)
|
219
|
+
f.close
|
220
|
+
|
221
|
+
objects = Oj.load_file(f.path)
|
222
|
+
assert_equal(Oj.load(json), objects)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
215
226
|
def dump_and_load(obj, trace=false)
|
216
|
-
filename = File.join(
|
217
|
-
File.open(filename,
|
227
|
+
filename = File.join(__dir__, 'file_test.json')
|
228
|
+
File.open(filename, 'w') { |f|
|
218
229
|
Oj.to_stream(f, obj, :indent => 2)
|
219
230
|
}
|
220
231
|
puts "\n*** file: '#{File.read(filename)}'" if trace
|
data/test/test_gc.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
@@ -14,22 +14,24 @@ class GCTest < Minitest::Test
|
|
14
14
|
@child = child
|
15
15
|
end
|
16
16
|
|
17
|
-
def to_hash
|
18
|
-
{ 'json_class' =>
|
17
|
+
def to_hash
|
18
|
+
{ 'json_class' => self.class.to_s, 'x' => x, 'child' => child }
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.json_create(h)
|
22
22
|
GC.start
|
23
|
-
|
23
|
+
new(h['x'], h['child'])
|
24
24
|
end
|
25
25
|
end # Goo
|
26
26
|
|
27
27
|
def setup
|
28
28
|
@default_options = Oj.default_options
|
29
|
+
GC.stress = true
|
29
30
|
end
|
30
31
|
|
31
32
|
def teardown
|
32
33
|
Oj.default_options = @default_options
|
34
|
+
GC.stress = false
|
33
35
|
end
|
34
36
|
|
35
37
|
# if no crash then the GC marking is working
|
@@ -46,4 +48,13 @@ class GCTest < Minitest::Test
|
|
46
48
|
json = Oj.dump(g, :mode => :object)
|
47
49
|
Oj.object_load(json)
|
48
50
|
end
|
51
|
+
|
52
|
+
def test_parse_gc
|
53
|
+
json = '{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}'
|
54
|
+
|
55
|
+
50.times do
|
56
|
+
data = Oj.load(json)
|
57
|
+
assert_equal(json, Oj.dump(data))
|
58
|
+
end
|
59
|
+
end
|
49
60
|
end
|
data/test/test_generate.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
|
+
@oj_dir = File.dirname(File.expand_path(__dir__))
|
6
6
|
%w(lib ext).each do |dir|
|
7
|
-
|
7
|
+
$LOAD_PATH << File.join(@oj_dir, dir)
|
8
8
|
end
|
9
9
|
|
10
10
|
require 'minitest'
|
@@ -15,7 +15,7 @@ class Generator < Minitest::Test
|
|
15
15
|
|
16
16
|
def test_before
|
17
17
|
json = Oj.generate({})
|
18
|
-
assert_equal(
|
18
|
+
assert_equal('{}', json)
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
data/test/test_hash.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
8
|
-
class
|
8
|
+
class HashTest < Minitest::Test
|
9
9
|
|
10
10
|
module TestModule
|
11
11
|
end
|
@@ -19,7 +19,7 @@ class Hashi < Minitest::Test
|
|
19
19
|
|
20
20
|
def test_load
|
21
21
|
obj = Oj.load(%|{"abc":3}|, :mode => :compat, :hash_class => Oj::EasyHash)
|
22
|
-
|
22
|
+
|
23
23
|
assert_equal(Oj::EasyHash, obj.class)
|
24
24
|
assert_equal(3, obj['abc'])
|
25
25
|
assert_equal(3, obj[:abc])
|
@@ -35,5 +35,5 @@ class Hashi < Minitest::Test
|
|
35
35
|
assert_equal(Oj::EasyHash, obj.class)
|
36
36
|
assert_equal(3, obj[:abc])
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
end # HashTest
|