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_strict.rb DELETED
@@ -1,441 +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 StrictJuice < Minitest::Test
18
-
19
- module TestModule
20
- end
21
-
22
- class Jeez
23
- attr_accessor :x, :y
24
-
25
- def initialize(x, y)
26
- @x = x
27
- @y = y
28
- end
29
- end
30
-
31
- def setup
32
- @default_options = Oj.default_options
33
- # in strict mode other options other than the number formats are not used.
34
- Oj.default_options = { :mode => :strict }
35
- end
36
-
37
- def teardown
38
- Oj.default_options = @default_options
39
- end
40
-
41
- def test_nil
42
- dump_and_load(nil, false)
43
- end
44
-
45
- def test_true
46
- dump_and_load(true, false)
47
- end
48
-
49
- def test_false
50
- dump_and_load(false, false)
51
- end
52
-
53
- def test_fixnum
54
- dump_and_load(0, false)
55
- dump_and_load(12_345, false)
56
- dump_and_load(-54_321, false)
57
- dump_and_load(1, false)
58
- end
59
-
60
- def test_float
61
- dump_and_load(0.0, false)
62
- dump_and_load(12_345.6789, false)
63
- dump_and_load(70.35, false)
64
- dump_and_load(-54_321.012, false)
65
- dump_and_load(1.7775, false)
66
- dump_and_load(2.5024, false)
67
- dump_and_load(2.48e16, false)
68
- dump_and_load(2.48e100 * 1.0e10, false)
69
- dump_and_load(-2.48e100 * 1.0e10, false)
70
- end
71
-
72
- def test_invalid_float
73
- begin
74
- Oj.load("64ecb72d29191067f91ff95b")
75
- rescue Oj::ParseError => e
76
- assert(e.message == "Invalid float")
77
- return
78
- end
79
- assert(false, "*** expected an exception")
80
- end
81
-
82
- def test_nan_dump
83
- assert_equal('null', Oj.dump(0/0.0, :nan => :null))
84
- assert_equal('3.3e14159265358979323846', Oj.dump(0/0.0, :nan => :huge))
85
- begin
86
- Oj.dump(0/0.0, :nan => :word)
87
- rescue Exception
88
- assert(true)
89
- return
90
- end
91
- assert(false, '*** expected an exception')
92
- end
93
-
94
- def test_infinity_dump
95
- assert_equal('null', Oj.dump(1/0.0, :nan => :null))
96
- assert_equal('3.0e14159265358979323846', Oj.dump(1/0.0, :nan => :huge))
97
- begin
98
- Oj.dump(1/0.0, :nan => :word)
99
- rescue Exception
100
- assert(true)
101
- return
102
- end
103
- assert(false, '*** expected an exception')
104
- end
105
-
106
- def test_neg_infinity_dump
107
- assert_equal('null', Oj.dump(-1/0.0, :nan => :null))
108
- assert_equal('-3.0e14159265358979323846', Oj.dump(-1/0.0, :nan => :huge))
109
- begin
110
- Oj.dump(-1/0.0, :nan => :word)
111
- rescue Exception
112
- assert(true)
113
- return
114
- end
115
- assert(false, '*** expected an exception')
116
- end
117
-
118
- def test_string
119
- dump_and_load('', false)
120
- dump_and_load('abc', false)
121
- dump_and_load("abc\ndef", false)
122
- dump_and_load("a\u0041", false)
123
- end
124
-
125
- def test_encode
126
- opts = Oj.default_options
127
- Oj.default_options = { :ascii_only => false }
128
- dump_and_load('ぴーたー', false)
129
- Oj.default_options = { :ascii_only => true }
130
- json = Oj.dump('ぴーたー')
131
- assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
132
- dump_and_load('ぴーたー', false)
133
- Oj.default_options = opts
134
- end
135
-
136
- def test_unicode
137
- # hits the 3 normal ranges and one extended surrogate pair
138
- json = %{"\\u019f\\u05e9\\u3074\\ud834\\udd1e"}
139
- obj = Oj.load(json)
140
- json2 = Oj.dump(obj, :ascii_only => true)
141
- assert_equal(json, json2)
142
- end
143
-
144
- def test_unicode_long
145
- # tests buffer overflow
146
- json = %{"\\u019f\\u05e9\\u3074\\ud834\\udd1e #{'x' * 2000}"}
147
- obj = Oj.load(json)
148
- json2 = Oj.dump(obj, :ascii_only => true)
149
- assert_equal(json, json2)
150
- end
151
-
152
- def test_array
153
- dump_and_load([], false)
154
- dump_and_load([true, false], false)
155
- dump_and_load(['a', 1, nil], false)
156
- dump_and_load([[nil]], false)
157
- dump_and_load([[nil], 58], false)
158
- end
159
-
160
- def test_array_deep
161
- dump_and_load([1, [2, [3, [4, [5, [6, [7, [8, [9, [10, [11, [12, [13, [14, [15, [16, [17, [18, [19, [20]]]]]]]]]]]]]]]]]]]], false)
162
- end
163
-
164
- def test_deep_nest
165
- skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'
166
-
167
- begin
168
- n = 10_000
169
- Oj.strict_load(('[' * n) + (']' * n))
170
- rescue Exception => e
171
- refute(e.message)
172
- end
173
- end
174
-
175
- # Hash
176
- def test_hash
177
- dump_and_load({}, false)
178
- dump_and_load({ 'true' => true, 'false' => false}, false)
179
- dump_and_load({ 'true' => true, 'array' => [], 'hash' => { }}, false)
180
- end
181
-
182
- def test_hash_deep
183
- dump_and_load({'1' => {
184
- '2' => {
185
- '3' => {
186
- '4' => {
187
- '5' => {
188
- '6' => {
189
- '7' => {
190
- '8' => {
191
- '9' => {
192
- '10' => {
193
- '11' => {
194
- '12' => {
195
- '13' => {
196
- '14' => {
197
- '15' => {
198
- '16' => {
199
- '17' => {
200
- '18' => {
201
- '19' => {
202
- '20' => {}}}}}}}}}}}}}}}}}}}}}, false)
203
- end
204
-
205
- def test_hash_escaped_key
206
- json = %{{"a\nb":true,"c\td":false}}
207
- obj = Oj.strict_load(json)
208
- assert_equal({"a\nb" => true, "c\td" => false}, obj)
209
- end
210
-
211
- def test_non_str_hash
212
- begin
213
- Oj.dump({ 1 => true, 0 => false })
214
- rescue Exception
215
- assert(true)
216
- return
217
- end
218
- assert(false, '*** expected an exception')
219
- end
220
-
221
- def test_bignum_object
222
- dump_and_load(7 ** 55, false)
223
- end
224
-
225
- # BigDecimal
226
- def test_bigdecimal_strict
227
- Oj.default_options = { :bigdecimal_load => true}
228
- dump_and_load(BigDecimal('3.14159265358979323846'), false)
229
- end
230
-
231
- def test_bigdecimal_load
232
- orig = BigDecimal('80.51')
233
- json = Oj.dump(orig, :mode => :strict, :bigdecimal_as_decimal => true)
234
- bg = Oj.load(json, :mode => :strict, :bigdecimal_load => true)
235
- assert_equal(BigDecimal, bg.class)
236
- assert_equal(orig, bg)
237
- end
238
-
239
- def test_json_object
240
- obj = Jeez.new(true, 58)
241
- begin
242
- Oj.dump(obj)
243
- rescue Exception
244
- assert(true)
245
- return
246
- end
247
- assert(false, '*** expected an exception')
248
- end
249
-
250
- def test_range
251
- begin
252
- Oj.dump(1..7)
253
- rescue Exception
254
- assert(true)
255
- return
256
- end
257
- assert(false, '*** expected an exception')
258
- end
259
-
260
- # Stream IO
261
- def test_io_string
262
- json = %{{
263
- "x":true,
264
- "y":58,
265
- "z": [1,2,3]
266
- }
267
- }
268
- input = StringIO.new(json)
269
- obj = Oj.strict_load(input)
270
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
271
- end
272
-
273
- def test_io_file
274
- filename = File.join(__dir__, 'open_file_test.json')
275
- File.write(filename, %{{
276
- "x":true,
277
- "y":58,
278
- "z": [1,2,3]
279
- }
280
- })
281
- f = File.new(filename)
282
- obj = Oj.strict_load(f)
283
- f.close()
284
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
285
- end
286
-
287
- def test_symbol
288
- json = Oj.dump(:abc)
289
- assert_equal('"abc"', json)
290
- end
291
-
292
- def test_time
293
- t = Time.local(2012, 1, 5, 23, 58, 7)
294
- begin
295
- Oj.dump(t)
296
- rescue Exception
297
- assert(true)
298
- return
299
- end
300
- assert(false, '*** expected an exception')
301
- end
302
-
303
- def test_class
304
- begin
305
- Oj.dump(StrictJuice)
306
- rescue Exception
307
- assert(true)
308
- return
309
- end
310
- assert(false, '*** expected an exception')
311
- end
312
-
313
- def test_module
314
- begin
315
- Oj.dump(TestModule)
316
- rescue Exception
317
- assert(true)
318
- return
319
- end
320
- assert(false, '*** expected an exception')
321
- end
322
-
323
- # symbol_keys option
324
- def test_symbol_keys
325
- json = %{{
326
- "x":true,
327
- "y":58,
328
- "z": [1,2,3]
329
- }
330
- }
331
- obj = Oj.strict_load(json, :symbol_keys => true)
332
- assert_equal({ :x => true, :y => 58, :z => [1, 2, 3]}, obj)
333
- end
334
-
335
- def test_symbol_keys_safe
336
- json = %{{
337
- "x":true,
338
- "y":58,
339
- "z": [1,2,3]
340
- }
341
- }
342
- obj = Oj.safe_load(json)
343
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
344
- end
345
-
346
- # comments
347
- def test_comment_slash
348
- json = %{{
349
- "x":true,//three
350
- "y":58,
351
- "z": [1,2,
352
- 3 // six
353
- ]}
354
- }
355
- obj = Oj.strict_load(json)
356
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
357
- end
358
-
359
- def test_comment_c
360
- json = %{{
361
- "x"/*one*/:/*two*/true,
362
- "y":58,
363
- "z": [1,2,3]}
364
- }
365
- obj = Oj.strict_load(json)
366
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
367
- end
368
-
369
- def test_comment
370
- json = %{{
371
- "x"/*one*/:/*two*/true,//three
372
- "y":58/*four*/,
373
- "z": [1,2/*five*/,
374
- 3 // six
375
- ]
376
- }
377
- }
378
- obj = Oj.strict_load(json)
379
- assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
380
- end
381
-
382
- def test_double
383
- json = %{{ "x": 1}{ "y": 2}}
384
- results = []
385
- Oj.load(json, :mode => :strict) { |x| results << x }
386
-
387
- assert_equal([{ 'x' => 1 }, { 'y' => 2 }], results)
388
- end
389
-
390
- def test_invalid_decimal_dot_start
391
- assert_raises(Oj::ParseError) {
392
- Oj.load('.123', mode: :strict)
393
- }
394
- assert_raises(Oj::ParseError) {
395
- Oj.load('-.123', mode: :strict)
396
- }
397
- end
398
-
399
- def test_invalid_decimal_dot_end
400
- json = '123.'
401
- assert_raises(Oj::ParseError) {
402
- Oj.load(json, mode: :strict)
403
- }
404
- end
405
-
406
- def test_invalid_decimal_plus
407
- json = '+12'
408
- assert_raises(Oj::ParseError) {
409
- Oj.load(json, mode: :strict)
410
- }
411
- end
412
-
413
- def test_circular_hash
414
- h = { 'a' => 7 }
415
- h['b'] = h
416
- json = Oj.dump(h, :indent => 2, :circular => true)
417
- assert_equal(%|{
418
- "a":7,
419
- "b":null
420
- }
421
- |, json)
422
- end
423
-
424
- def test_omit_nil
425
- json = Oj.dump({'x' => {'a' => 1, 'b' => nil }, 'y' => nil}, :omit_nil => true)
426
- assert_equal(%|{"x":{"a":1}}|, json)
427
- end
428
-
429
- def dump_and_load(obj, trace=false)
430
- json = Oj.dump(obj, :indent => 2)
431
- puts json if trace
432
- loaded = Oj.strict_load(json)
433
- if obj.nil?
434
- assert_nil(loaded)
435
- else
436
- assert_equal(obj, loaded)
437
- end
438
- loaded
439
- end
440
-
441
- end