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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/ext/oj/fast.c +3 -6
  4. data/ext/oj/mimic_json.c +3 -6
  5. data/ext/oj/oj.c +2 -4
  6. data/ext/oj/parse.c +15 -5
  7. data/ext/oj/parser.c +1 -1
  8. data/ext/oj/parser.h +2 -0
  9. data/ext/oj/rails.c +1 -2
  10. data/ext/oj/saj.c +3 -6
  11. data/ext/oj/scp.c +3 -6
  12. data/ext/oj/stream_writer.c +1 -7
  13. data/ext/oj/strict.c +2 -4
  14. data/ext/oj/string_writer.c +1 -3
  15. data/lib/oj/version.rb +1 -1
  16. metadata +3 -98
  17. data/test/_test_active.rb +0 -75
  18. data/test/_test_active_mimic.rb +0 -95
  19. data/test/_test_mimic_rails.rb +0 -123
  20. data/test/activerecord/result_test.rb +0 -31
  21. data/test/activesupport6/abstract_unit.rb +0 -44
  22. data/test/activesupport6/decoding_test.rb +0 -133
  23. data/test/activesupport6/encoding_test.rb +0 -542
  24. data/test/activesupport6/encoding_test_cases.rb +0 -98
  25. data/test/activesupport6/test_common.rb +0 -17
  26. data/test/activesupport6/test_helper.rb +0 -163
  27. data/test/activesupport6/time_zone_test_helpers.rb +0 -39
  28. data/test/activesupport7/abstract_unit.rb +0 -52
  29. data/test/activesupport7/decoding_test.rb +0 -125
  30. data/test/activesupport7/encoding_test.rb +0 -536
  31. data/test/activesupport7/encoding_test_cases.rb +0 -104
  32. data/test/activesupport7/time_zone_test_helpers.rb +0 -47
  33. data/test/files.rb +0 -29
  34. data/test/foo.rb +0 -26
  35. data/test/helper.rb +0 -39
  36. data/test/isolated/shared.rb +0 -309
  37. data/test/isolated/test_mimic_after.rb +0 -13
  38. data/test/isolated/test_mimic_alone.rb +0 -12
  39. data/test/isolated/test_mimic_as_json.rb +0 -45
  40. data/test/isolated/test_mimic_before.rb +0 -13
  41. data/test/isolated/test_mimic_define.rb +0 -28
  42. data/test/isolated/test_mimic_rails_after.rb +0 -22
  43. data/test/isolated/test_mimic_rails_before.rb +0 -21
  44. data/test/isolated/test_mimic_redefine.rb +0 -15
  45. data/test/json_gem/json_addition_test.rb +0 -216
  46. data/test/json_gem/json_common_interface_test.rb +0 -155
  47. data/test/json_gem/json_encoding_test.rb +0 -107
  48. data/test/json_gem/json_ext_parser_test.rb +0 -21
  49. data/test/json_gem/json_fixtures_test.rb +0 -36
  50. data/test/json_gem/json_generator_test.rb +0 -413
  51. data/test/json_gem/json_generic_object_test.rb +0 -90
  52. data/test/json_gem/json_parser_test.rb +0 -477
  53. data/test/json_gem/json_string_matching_test.rb +0 -42
  54. data/test/json_gem/test_helper.rb +0 -30
  55. data/test/mem.rb +0 -34
  56. data/test/perf.rb +0 -102
  57. data/test/perf_compat.rb +0 -128
  58. data/test/perf_dump.rb +0 -50
  59. data/test/perf_fast.rb +0 -162
  60. data/test/perf_file.rb +0 -62
  61. data/test/perf_object.rb +0 -134
  62. data/test/perf_once.rb +0 -59
  63. data/test/perf_parser.rb +0 -183
  64. data/test/perf_saj.rb +0 -101
  65. data/test/perf_scp.rb +0 -140
  66. data/test/perf_simple.rb +0 -289
  67. data/test/perf_strict.rb +0 -137
  68. data/test/perf_wab.rb +0 -129
  69. data/test/prec.rb +0 -23
  70. data/test/sample/change.rb +0 -13
  71. data/test/sample/dir.rb +0 -18
  72. data/test/sample/doc.rb +0 -35
  73. data/test/sample/file.rb +0 -47
  74. data/test/sample/group.rb +0 -15
  75. data/test/sample/hasprops.rb +0 -15
  76. data/test/sample/layer.rb +0 -11
  77. data/test/sample/line.rb +0 -20
  78. data/test/sample/oval.rb +0 -10
  79. data/test/sample/rect.rb +0 -9
  80. data/test/sample/shape.rb +0 -34
  81. data/test/sample/text.rb +0 -19
  82. data/test/sample.rb +0 -54
  83. data/test/sample_json.rb +0 -37
  84. data/test/test_compat.rb +0 -567
  85. data/test/test_custom.rb +0 -555
  86. data/test/test_debian.rb +0 -50
  87. data/test/test_fast.rb +0 -526
  88. data/test/test_file.rb +0 -250
  89. data/test/test_gc.rb +0 -60
  90. data/test/test_generate.rb +0 -21
  91. data/test/test_hash.rb +0 -39
  92. data/test/test_integer_range.rb +0 -72
  93. data/test/test_null.rb +0 -376
  94. data/test/test_object.rb +0 -1030
  95. data/test/test_parser.rb +0 -11
  96. data/test/test_parser_debug.rb +0 -27
  97. data/test/test_parser_saj.rb +0 -337
  98. data/test/test_parser_usual.rb +0 -255
  99. data/test/test_rails.rb +0 -35
  100. data/test/test_saj.rb +0 -188
  101. data/test/test_scp.rb +0 -431
  102. data/test/test_strict.rb +0 -441
  103. data/test/test_various.rb +0 -801
  104. data/test/test_wab.rb +0 -311
  105. data/test/test_writer.rb +0 -396
  106. data/test/tests.rb +0 -33
  107. data/test/tests_mimic.rb +0 -23
  108. data/test/tests_mimic_addition.rb +0 -16
data/test/test_fast.rb DELETED
@@ -1,526 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
-
6
- require 'helper'
7
-
8
- class DocTest < Minitest::Test
9
- def setup
10
- @default_options = Oj.default_options
11
- @json1 = %|{
12
- "array": [
13
- {
14
- "num" : 3,
15
- "string": "message",
16
- "hash" : {
17
- "h2" : {
18
- "a" : [ 1, 2, 3 ]
19
- }
20
- }
21
- }
22
- ],
23
- "boolean" : true
24
- }|
25
- end
26
-
27
- def teardown
28
- Oj.default_options = @default_options
29
- end
30
-
31
- def test_nil
32
- json = %{null}
33
- Oj::Doc.open(json) do |doc|
34
- assert_equal(NilClass, doc.type)
35
- assert_nil(doc.fetch())
36
- end
37
- end
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
-
50
- def test_true
51
- json = %{true}
52
- Oj::Doc.open(json) do |doc|
53
- assert_equal(TrueClass, doc.type)
54
- assert(doc.fetch())
55
- end
56
- end
57
-
58
- def test_false
59
- json = %{false}
60
- Oj::Doc.open(json) do |doc|
61
- assert_equal(FalseClass, doc.type)
62
- refute(doc.fetch())
63
- end
64
- end
65
-
66
- def test_string
67
- json = %{"a string"}
68
- Oj::Doc.open(json) do |doc|
69
- assert_equal(String, doc.type)
70
- assert_equal('a string', doc.fetch())
71
- end
72
- end
73
-
74
- def test_encoding
75
- json = %{"ぴーたー"}
76
- Oj::Doc.open(json) do |doc|
77
- assert_equal(String, doc.type)
78
- assert_equal('ぴーたー', doc.fetch())
79
- end
80
- end
81
-
82
- def test_encoding_escaped
83
- json = %{"\\u3074\\u30fc\\u305f\\u30fc"}
84
- Oj::Doc.open(json) do |doc|
85
- assert_equal(String, doc.type)
86
- assert_equal('ぴーたー', doc.fetch())
87
- end
88
- end
89
-
90
- def test_fixnum
91
- json = %{12345}
92
- Oj::Doc.open(json) do |doc|
93
- assert_equal(Integer, doc.type)
94
- assert_equal(12_345, doc.fetch())
95
- end
96
- end
97
-
98
- def test_float
99
- json = %{12345.6789}
100
- Oj::Doc.open(json) do |doc|
101
- assert_equal(Float, doc.type)
102
- assert_in_delta(12_345.6789, doc.fetch())
103
- end
104
- end
105
-
106
- def test_float_exp
107
- json = %{12345.6789e7}
108
- Oj::Doc.open(json) do |doc|
109
- assert_equal(Float, doc.type)
110
- # assert_equal(12345.6789e7, doc.fetch())
111
- assert_equal(12_345.6789e7.to_i, doc.fetch().to_i)
112
- end
113
- end
114
-
115
- def test_array_empty
116
- json = %{[]}
117
- Oj::Doc.open(json) do |doc|
118
- assert_equal(Array, doc.type)
119
- assert_empty(doc.fetch())
120
- end
121
- end
122
-
123
- def test_array
124
- json = %{[true,false]}
125
- Oj::Doc.open(json) do |doc|
126
- assert_equal(Array, doc.type)
127
- assert_equal([true, false], doc.fetch())
128
- end
129
- end
130
-
131
- def test_hash_empty
132
- json = %{{}}
133
- Oj::Doc.open(json) do |doc|
134
- assert_equal(Hash, doc.type)
135
- assert_empty(doc.fetch())
136
- end
137
- end
138
-
139
- def test_hash
140
- json = %{{"one":true,"two":false}}
141
- Oj::Doc.open(json) do |doc|
142
- assert_equal(Hash, doc.type)
143
- assert_equal({'one' => true, 'two' => false}, doc.fetch())
144
- end
145
- end
146
-
147
- # move() and where?()
148
- def test_move_hash
149
- json = %{{"one":{"two":false}}}
150
- Oj::Doc.open(json) do |doc|
151
- doc.move('/one')
152
- assert_equal('/one', doc.where?)
153
- doc.move('/one/two')
154
- assert_equal('/one/two', doc.where?)
155
- end
156
- end
157
-
158
- def test_move_array
159
- json = %{[1,[2,true]]}
160
- Oj::Doc.open(json) do |doc|
161
- doc.move('/1')
162
- assert_equal('/1', doc.where?)
163
- doc.move('/2/1')
164
- assert_equal('/2/1', doc.where?)
165
- end
166
- end
167
-
168
- def test_move
169
- Oj::Doc.open(@json1) do |doc|
170
- [
171
- '/',
172
- '/array',
173
- '/boolean',
174
- '/array/1/hash/h2/a/3',
175
- ].each do |p|
176
- doc.move(p)
177
- assert_equal(p, doc.where?)
178
- end
179
- begin
180
- doc.move('/array/x')
181
- rescue Exception
182
- assert_equal('/', doc.where?)
183
- assert(true)
184
- end
185
- end
186
- end
187
-
188
- def test_move_slash
189
- Oj::Doc.open(%|{"top":{"a/b":3}}|) do |doc|
190
- doc.move('top/a\/b')
191
- assert_equal('/top/a\/b', doc.where?)
192
- end
193
- end
194
-
195
- def test_fetch_slash
196
- Oj::Doc.open(%|{"a/b":3}|) do |doc|
197
- x = doc.fetch('a\/b')
198
- assert_equal(3, x)
199
- end
200
- end
201
-
202
- def test_move_relative
203
- Oj::Doc.open(@json1) do |doc|
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|
212
- doc.move(start)
213
- doc.move(path)
214
- assert_equal(where, doc.where?)
215
- end
216
- end
217
- end
218
-
219
- def test_type
220
- Oj::Doc.open(@json1) do |doc|
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|
231
- assert_equal(type, doc.type(path))
232
- end
233
- end
234
- end
235
-
236
- def test_local_key
237
- Oj::Doc.open(@json1) do |doc|
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|
249
- doc.move(path)
250
- if key.nil?
251
- assert_nil(doc.local_key())
252
- else
253
- assert_equal(key, doc.local_key())
254
- end
255
- end
256
- end
257
- end
258
-
259
- def test_fetch_move
260
- Oj::Doc.open(@json1) do |doc|
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|
272
- doc.move(path)
273
- assert_equal(val, doc.fetch())
274
- end
275
- end
276
- end
277
-
278
- def test_fetch_path
279
- Oj::Doc.open(@json1) do |doc|
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
298
- end
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
309
- end
310
-
311
- def test_move_fetch_path
312
- Oj::Doc.open(@json1) do |doc|
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|
318
- doc.move(path)
319
- assert_equal(val, doc.fetch(fetch_path))
320
- end
321
- end
322
- end
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
-
339
- def test_home
340
- Oj::Doc.open(@json1) do |doc|
341
- doc.move('/array/1/num')
342
- doc.home()
343
- assert_equal('/', doc.where?)
344
- end
345
- end
346
-
347
- def test_each_value_root
348
- Oj::Doc.open(@json1) do |doc|
349
- values = []
350
- doc.each_value() { |v| values << v.to_s }
351
- assert_equal(['1', '2', '3', '3', 'message', 'true'], values.sort)
352
- end
353
- end
354
-
355
- def test_each_value_move
356
- Oj::Doc.open(@json1) do |doc|
357
- doc.move('/array/1/hash')
358
- values = []
359
- doc.each_value() { |v| values << v.to_s }
360
- assert_equal(['1', '2', '3'], values.sort)
361
- end
362
- end
363
-
364
- def test_each_value_path
365
- Oj::Doc.open(@json1) do |doc|
366
- values = []
367
- doc.each_value('/array/1/hash') { |v| values << v.to_s }
368
- assert_equal(['1', '2', '3'], values.sort)
369
- end
370
- end
371
-
372
- def test_each_child_move
373
- Oj::Doc.open(@json1) do |doc|
374
- locations = []
375
- doc.move('/array/1/hash/h2/a')
376
- doc.each_child() { |d| locations << d.where? }
377
- assert_equal(['/array/1/hash/h2/a/1', '/array/1/hash/h2/a/2', '/array/1/hash/h2/a/3'], locations)
378
- locations = []
379
- doc.move('/array/1')
380
- doc.each_child() { |d| locations << d.where? }
381
- assert_equal(['/array/1/num', '/array/1/string', '/array/1/hash'], locations)
382
- end
383
- end
384
-
385
- def test_each_child_path
386
- Oj::Doc.open(@json1) do |doc|
387
- locations = []
388
- doc.each_child('/array/1/hash/h2/a') { |d| locations << d.where? }
389
- assert_equal(['/array/1/hash/h2/a/1', '/array/1/hash/h2/a/2', '/array/1/hash/h2/a/3'], locations)
390
- locations = []
391
- doc.each_child('/array/1') { |d| locations << d.where? }
392
- assert_equal(['/array/1/num', '/array/1/string', '/array/1/hash'], locations)
393
- end
394
- end
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
-
409
- def test_size
410
- Oj::Doc.open('[1,2,3]') do |doc|
411
- assert_equal(4, doc.size)
412
- end
413
- Oj::Doc.open('{"a":[1,2,3]}') do |doc|
414
- assert_equal(5, doc.size)
415
- end
416
- end
417
-
418
- def test_open_file
419
- filename = File.join(__dir__, 'open_file_test.json')
420
- File.write(filename, '{"a":[1,2,3]}')
421
- Oj::Doc.open_file(filename) do |doc|
422
- assert_equal(5, doc.size)
423
- end
424
- end
425
-
426
- def test_open_close
427
- json = %{{"a":[1,2,3]}}
428
- doc = Oj::Doc.open(json)
429
- assert_equal(Oj::Doc, doc.class)
430
- assert_equal(5, doc.size)
431
- assert_equal('/', doc.where?)
432
- doc.move('a/1')
433
- doc.home()
434
- assert_equal(2, doc.fetch('/a/2'))
435
- assert_equal(2, doc.fetch('a/2'))
436
- doc.close()
437
- begin
438
- doc.home()
439
- rescue Exception
440
- assert(true)
441
- end
442
- end
443
-
444
- def test_file_open_close
445
- filename = File.join(__dir__, 'open_file_test.json')
446
- File.write(filename, '{"a":[1,2,3]}')
447
- doc = Oj::Doc.open_file(filename)
448
- assert_equal(Oj::Doc, doc.class)
449
- assert_equal(5, doc.size)
450
- assert_equal('/', doc.where?)
451
- doc.move('a/1')
452
- doc.home()
453
- assert_equal(2, doc.fetch('/a/2'))
454
- assert_equal(2, doc.fetch('a/2'))
455
- doc.close()
456
- begin
457
- doc.home()
458
- rescue Exception
459
- assert(true)
460
- end
461
- end
462
-
463
- def test_open_no_close
464
- json = %{{"a":[1,2,3]}}
465
- doc = Oj::Doc.open(json)
466
- assert_equal(Oj::Doc, doc.class)
467
- assert_equal(5, doc.size)
468
- assert_equal('/', doc.where?)
469
- doc.move('a/1')
470
- doc.home()
471
- assert_equal(2, doc.fetch('/a/2'))
472
- assert_equal(2, doc.fetch('a/2'))
473
- GC.start
474
- # a print statement confirms close is called
475
- end
476
-
477
- def test_dump
478
- Oj::Doc.open('[1,[2,3]]') do |doc|
479
- assert_equal('[1,[2,3]]', doc.dump())
480
- end
481
- Oj::Doc.open('[1,[2,3]]') do |doc|
482
- assert_equal('[2,3]', doc.dump('/2'))
483
- end
484
- end
485
-
486
- def test_each_leaf
487
- results = Oj::Doc.open('[1,[2,3]]') do |doc|
488
- h = {}
489
- doc.each_leaf() { |d| h[d.where?] = d.fetch() }
490
- h
491
- end
492
- assert_equal({'/1' => 1, '/2/1' => 2, '/2/2' => 3}, results)
493
- end
494
-
495
- def test_each_leaf_hash
496
- results = Oj::Doc.open('{"a":{"x":2},"b":{"y":4}}') do |doc|
497
- h = {}
498
- doc.each_leaf() { |d| h[d.where?] = d.fetch() }
499
- h
500
- end
501
- assert_equal({'/a/x' => 2, '/b/y' => 4}, results)
502
- end
503
-
504
- def test_doc_empty
505
- result = Oj::Doc.open('') { |doc| doc.each_child {} }
506
- assert_nil(result)
507
- end
508
-
509
- def test_comment
510
- json = %{{
511
- "x"/*one*/:/*two*/true,//three
512
- "y":58/*four*/,
513
- "z": [1,2/*five*/,
514
- 3 // six
515
- ]
516
- }
517
- }
518
- results = Oj::Doc.open(json) do |doc|
519
- h = {}
520
- doc.each_leaf() { |d| h[d.where?] = d.fetch() }
521
- h
522
- end
523
- assert_equal({'/x' => true, '/y' => 58, '/z/1' => 1, '/z/2' => 2, '/z/3' => 3}, results)
524
- end
525
-
526
- end # DocTest