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_saj.rb DELETED
@@ -1,188 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
-
6
- require 'helper'
7
-
8
- $json = %{{
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
- class AllSaj < Oj::Saj
24
- attr_accessor :calls
25
-
26
- def initialize
27
- @calls = []
28
-
29
- super
30
- end
31
-
32
- def hash_start(key)
33
- @calls << [:hash_start, key]
34
- end
35
-
36
- def hash_end(key)
37
- @calls << [:hash_end, key]
38
- end
39
-
40
- def array_start(key)
41
- @calls << [:array_start, key]
42
- end
43
-
44
- def array_end(key)
45
- @calls << [:array_end, key]
46
- end
47
-
48
- def add_value(value, key)
49
- @calls << [:add_value, value, key]
50
- end
51
-
52
- def error(message, line, column)
53
- @calls << [:error, message, line, column]
54
- end
55
-
56
- end # AllSaj
57
-
58
- class SajTest < Minitest::Test
59
-
60
- def setup
61
- @default_options = Oj.default_options
62
- end
63
-
64
- def teardown
65
- Oj.default_options = @default_options
66
- end
67
-
68
- def test_nil
69
- handler = AllSaj.new()
70
- json = %{null}
71
- Oj.saj_parse(handler, json)
72
- assert_equal([[:add_value, nil, nil]], handler.calls)
73
- end
74
-
75
- def test_true
76
- handler = AllSaj.new()
77
- json = %{true}
78
- Oj.saj_parse(handler, json)
79
- assert_equal([[:add_value, true, nil]], handler.calls)
80
- end
81
-
82
- def test_false
83
- handler = AllSaj.new()
84
- json = %{false}
85
- Oj.saj_parse(handler, json)
86
- assert_equal([[:add_value, false, nil]], handler.calls)
87
- end
88
-
89
- def test_string
90
- handler = AllSaj.new()
91
- json = %{"a string"}
92
- Oj.saj_parse(handler, json)
93
- assert_equal([[:add_value, 'a string', nil]], handler.calls)
94
- end
95
-
96
- def test_fixnum
97
- handler = AllSaj.new()
98
- json = %{12345}
99
- Oj.saj_parse(handler, json)
100
- assert_equal([[:add_value, 12_345, nil]], handler.calls)
101
- end
102
-
103
- def test_float
104
- handler = AllSaj.new()
105
- json = %{12345.6789}
106
- Oj.saj_parse(handler, json)
107
- assert_equal([[:add_value, 12_345.6789, nil]], handler.calls)
108
- end
109
-
110
- def test_float_exp
111
- handler = AllSaj.new()
112
- json = %{12345.6789e7}
113
- Oj.saj_parse(handler, json)
114
- assert_equal(1, handler.calls.size)
115
- assert_equal(:add_value, handler.calls[0][0])
116
- assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
117
- end
118
-
119
- def test_array_empty
120
- handler = AllSaj.new()
121
- json = %{[]}
122
- Oj.saj_parse(handler, json)
123
- assert_equal([[:array_start, nil],
124
- [:array_end, nil]], handler.calls)
125
- end
126
-
127
- def test_array
128
- handler = AllSaj.new()
129
- json = %{[true,false]}
130
- Oj.saj_parse(handler, json)
131
- assert_equal([[:array_start, nil],
132
- [:add_value, true, nil],
133
- [:add_value, false, nil],
134
- [:array_end, nil]], handler.calls)
135
- end
136
-
137
- def test_hash_empty
138
- handler = AllSaj.new()
139
- json = %{{}}
140
- Oj.saj_parse(handler, json)
141
- assert_equal([[:hash_start, nil],
142
- [:hash_end, nil]], handler.calls)
143
- end
144
-
145
- def test_hash
146
- handler = AllSaj.new()
147
- json = %{{"one":true,"two":false}}
148
- Oj.saj_parse(handler, json)
149
- assert_equal([[:hash_start, nil],
150
- [:add_value, true, 'one'],
151
- [:add_value, false, 'two'],
152
- [:hash_end, nil]], handler.calls)
153
- end
154
-
155
- def test_full
156
- handler = AllSaj.new()
157
- Oj.saj_parse(handler, $json)
158
- assert_equal([[:hash_start, nil],
159
- [:array_start, 'array'],
160
- [:hash_start, nil],
161
- [:add_value, 3, 'num'],
162
- [:add_value, 'message', 'string'],
163
- [:hash_start, 'hash'],
164
- [:hash_start, 'h2'],
165
- [:array_start, 'a'],
166
- [:add_value, 1, nil],
167
- [:add_value, 2, nil],
168
- [:add_value, 3, nil],
169
- [:array_end, 'a'],
170
- [:hash_end, 'h2'],
171
- [:hash_end, 'hash'],
172
- [:hash_end, nil],
173
- [:array_end, 'array'],
174
- [:add_value, true, 'boolean'],
175
- [:hash_end, nil]], handler.calls)
176
- end
177
-
178
- def test_fixnum_bad
179
- handler = AllSaj.new()
180
- json = %{12345xyz}
181
- Oj.saj_parse(handler, json)
182
- assert_equal([:add_value, 12_345, nil], handler.calls.first)
183
- type, message, line, column = handler.calls.last
184
- assert_equal([:error, 1, 6], [type, line, column])
185
- assert_match(%r{invalid format, extra characters at line 1, column 6 \[(?:[A-Za-z]:/)?(?:[a-z.]+/)*saj\.c:\d+\]}, message)
186
- end
187
-
188
- end
data/test/test_scp.rb DELETED
@@ -1,431 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
-
6
- require 'helper'
7
- require 'socket'
8
- require 'stringio'
9
-
10
- $json = %{{
11
- "array": [
12
- {
13
- "num" : 3,
14
- "string": "message",
15
- "hash" : {
16
- "h2" : {
17
- "a" : [ 1, 2, 3 ]
18
- }
19
- }
20
- }
21
- ],
22
- "boolean" : true
23
- }}
24
-
25
- class NoHandler < Oj::ScHandler
26
- end
27
-
28
- class AllHandler < Oj::ScHandler
29
- attr_accessor :calls
30
-
31
- def initialize
32
- super
33
- @calls = []
34
- end
35
-
36
- def hash_start
37
- @calls << [:hash_start]
38
- {}
39
- end
40
-
41
- def hash_end
42
- @calls << [:hash_end]
43
- end
44
-
45
- def hash_key(key)
46
- @calls << [:hash_key, key]
47
- return 'too' if 'two' == key
48
- return :symbol if 'symbol' == key
49
-
50
- key
51
- end
52
-
53
- def array_start
54
- @calls << [:array_start]
55
- []
56
- end
57
-
58
- def array_end
59
- @calls << [:array_end]
60
- end
61
-
62
- def add_value(value)
63
- @calls << [:add_value, value]
64
- end
65
-
66
- def hash_set(_h, key, value)
67
- @calls << [:hash_set, key, value]
68
- end
69
-
70
- def array_append(_a, value)
71
- @calls << [:array_append, value]
72
- end
73
-
74
- end # AllHandler
75
-
76
- class Closer < AllHandler
77
- attr_accessor :io
78
-
79
- def initialize(io)
80
- super()
81
- @io = io
82
- end
83
-
84
- def hash_start
85
- @calls << [:hash_start]
86
- @io.close
87
- {}
88
- end
89
-
90
- def hash_set(_h, key, value)
91
- @calls << [:hash_set, key, value]
92
- @io.close
93
- end
94
-
95
- end # Closer
96
-
97
- class ScpTest < Minitest::Test
98
-
99
- def setup
100
- @default_options = Oj.default_options
101
- end
102
-
103
- def teardown
104
- Oj.default_options = @default_options
105
- end
106
-
107
- def test_nil
108
- handler = AllHandler.new()
109
- json = %{null}
110
- Oj.sc_parse(handler, json)
111
- assert_equal([[:add_value, nil]], handler.calls)
112
- end
113
-
114
- def test_true
115
- handler = AllHandler.new()
116
- json = %{true}
117
- Oj.sc_parse(handler, json)
118
- assert_equal([[:add_value, true]], handler.calls)
119
- end
120
-
121
- def test_false
122
- handler = AllHandler.new()
123
- json = %{false}
124
- Oj.sc_parse(handler, json)
125
- assert_equal([[:add_value, false]], handler.calls)
126
- end
127
-
128
- def test_string
129
- handler = AllHandler.new()
130
- json = %{"a string"}
131
- Oj.sc_parse(handler, json)
132
- assert_equal([[:add_value, 'a string']], handler.calls)
133
- end
134
-
135
- def test_fixnum
136
- handler = AllHandler.new()
137
- json = %{12345}
138
- Oj.sc_parse(handler, json)
139
- assert_equal([[:add_value, 12_345]], handler.calls)
140
- end
141
-
142
- def test_float
143
- handler = AllHandler.new()
144
- json = %{12345.6789}
145
- Oj.sc_parse(handler, json)
146
- assert_equal([[:add_value, 12_345.6789]], handler.calls)
147
- end
148
-
149
- def test_float_exp
150
- handler = AllHandler.new()
151
- json = %{12345.6789e7}
152
- Oj.sc_parse(handler, json)
153
- assert_equal(1, handler.calls.size)
154
- assert_equal(:add_value, handler.calls[0][0])
155
- assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
156
- end
157
-
158
- def test_array_empty
159
- handler = AllHandler.new()
160
- json = %{[]}
161
- Oj.sc_parse(handler, json)
162
- assert_equal([[:array_start],
163
- [:array_end],
164
- [:add_value, []]], handler.calls)
165
- end
166
-
167
- def test_array
168
- handler = AllHandler.new()
169
- json = %{[true,false]}
170
- Oj.sc_parse(handler, json)
171
- assert_equal([[:array_start],
172
- [:array_append, true],
173
- [:array_append, false],
174
- [:array_end],
175
- [:add_value, []]], handler.calls)
176
- end
177
-
178
- def test_hash_empty
179
- handler = AllHandler.new()
180
- json = %{{}}
181
- Oj.sc_parse(handler, json)
182
- assert_equal([[:hash_start],
183
- [:hash_end],
184
- [:add_value, {}]], handler.calls)
185
- end
186
-
187
- def test_hash
188
- handler = AllHandler.new()
189
- json = %{{"one":true,"two":false}}
190
- Oj.sc_parse(handler, json)
191
- assert_equal([[:hash_start],
192
- [:hash_key, 'one'],
193
- [:hash_set, 'one', true],
194
- [:hash_key, 'two'],
195
- [:hash_set, 'too', false],
196
- [:hash_end],
197
- [:add_value, {}]], handler.calls)
198
- end
199
-
200
- def test_hash_sym
201
- handler = AllHandler.new()
202
- json = %{{"one":true,"two":false}}
203
- Oj.sc_parse(handler, json, :symbol_keys => true)
204
- assert_equal([[:hash_start],
205
- [:hash_key, 'one'],
206
- [:hash_set, 'one', true],
207
- [:hash_key, 'two'],
208
- [:hash_set, 'too', false],
209
- [:hash_end],
210
- [:add_value, {}]], handler.calls)
211
- end
212
-
213
- def test_symbol_hash_key_without_symbol_keys
214
- handler = AllHandler.new()
215
- json = %{{"one":true,"symbol":false}}
216
- Oj.sc_parse(handler, json)
217
- assert_equal([[:hash_start],
218
- [:hash_key, 'one'],
219
- [:hash_set, 'one', true],
220
- [:hash_key, 'symbol'],
221
- [:hash_set, :symbol, false],
222
- [:hash_end],
223
- [:add_value, {}]], handler.calls)
224
- end
225
-
226
- def test_full
227
- handler = AllHandler.new()
228
- Oj.sc_parse(handler, $json)
229
- assert_equal([[:hash_start],
230
- [:hash_key, 'array'],
231
- [:array_start],
232
- [:hash_start],
233
- [:hash_key, 'num'],
234
- [:hash_set, 'num', 3],
235
- [:hash_key, 'string'],
236
- [:hash_set, 'string', 'message'],
237
- [:hash_key, 'hash'],
238
- [:hash_start],
239
- [:hash_key, 'h2'],
240
- [:hash_start],
241
- [:hash_key, 'a'],
242
- [:array_start],
243
- [:array_append, 1],
244
- [:array_append, 2],
245
- [:array_append, 3],
246
- [:array_end],
247
- [:hash_set, 'a', []],
248
- [:hash_end],
249
- [:hash_set, 'h2', {}],
250
- [:hash_end],
251
- [:hash_set, 'hash', {}],
252
- [:hash_end],
253
- [:array_append, {}],
254
- [:array_end],
255
- [:hash_set, 'array', []],
256
- [:hash_key, 'boolean'],
257
- [:hash_set, 'boolean', true],
258
- [:hash_end],
259
- [:add_value, {}]], handler.calls)
260
- end
261
-
262
- def test_double
263
- handler = AllHandler.new()
264
- json = %{{"one":true,"two":false}{"three":true,"four":false}}
265
- Oj.sc_parse(handler, json)
266
- assert_equal([[:hash_start],
267
- [:hash_key, 'one'],
268
- [:hash_set, 'one', true],
269
- [:hash_key, 'two'],
270
- [:hash_set, 'too', false],
271
- [:hash_end],
272
- [:add_value, {}],
273
- [:hash_start],
274
- [:hash_key, 'three'],
275
- [:hash_set, 'three', true],
276
- [:hash_key, 'four'],
277
- [:hash_set, 'four', false],
278
- [:hash_end],
279
- [:add_value, {}]], handler.calls)
280
- end
281
-
282
- def test_double_io
283
- handler = AllHandler.new()
284
- json = %{{"one":true,"two":false}{"three":true,"four":false}}
285
- Oj.sc_parse(handler, StringIO.new(json))
286
- assert_equal([[:hash_start],
287
- [:hash_key, 'one'],
288
- [:hash_set, 'one', true],
289
- [:hash_key, 'two'],
290
- [:hash_set, 'too', false],
291
- [:hash_end],
292
- [:add_value, {}],
293
- [:hash_start],
294
- [:hash_key, 'three'],
295
- [:hash_set, 'three', true],
296
- [:hash_key, 'four'],
297
- [:hash_set, 'four', false],
298
- [:hash_end],
299
- [:add_value, {}]], handler.calls)
300
- end
301
-
302
- def test_none
303
- handler = NoHandler.new()
304
- Oj.sc_parse(handler, $json)
305
- end
306
-
307
- def test_fixnum_bad
308
- handler = AllHandler.new()
309
- json = %{12345xyz}
310
- assert_raises Oj::ParseError do
311
- Oj.sc_parse(handler, json)
312
- end
313
- end
314
-
315
- def test_null_string
316
- handler = AllHandler.new()
317
- json = %{"\0"}
318
- assert_raises Oj::ParseError do
319
- Oj.sc_parse(handler, json)
320
- end
321
- end
322
-
323
- def test_pipe
324
- skip 'needs fork' unless Process.respond_to?(:fork)
325
-
326
- handler = AllHandler.new()
327
- json = %{{"one":true,"two":false}}
328
- IO.pipe do |read_io, write_io|
329
- if fork
330
- write_io.close
331
- Oj.sc_parse(handler, read_io)
332
- read_io.close
333
- assert_equal([[:hash_start],
334
- [:hash_key, 'one'],
335
- [:hash_set, 'one', true],
336
- [:hash_key, 'two'],
337
- [:hash_set, 'too', false],
338
- [:hash_end],
339
- [:add_value, {}]], handler.calls)
340
- else
341
- read_io.close
342
- write_io.write json
343
- write_io.close
344
- Process.exit(0)
345
- end
346
- end
347
- end
348
-
349
- def test_bad_bignum
350
- handler = AllHandler.new()
351
- json = %|{"big":-e123456789}|
352
- assert_raises Exception do # Can be either Oj::ParseError or ArgumentError depending on Ruby version
353
- Oj.sc_parse(handler, json)
354
- end
355
- end
356
-
357
- def test_pipe_close
358
- skip 'needs fork' unless Process.respond_to?(:fork)
359
-
360
- json = %{{"one":true,"two":false}}
361
- IO.pipe do |read_io, write_io|
362
- if fork
363
- write_io.close
364
- handler = Closer.new(read_io)
365
- err = nil
366
- begin
367
- Oj.sc_parse(handler, read_io)
368
- read_io.close
369
- rescue Exception => e
370
- err = e.class.to_s
371
- end
372
- assert_equal('IOError', err)
373
- assert_equal([[:hash_start],
374
- [:hash_key, 'one'],
375
- [:hash_set, 'one', true]], handler.calls)
376
- else
377
- read_io.close
378
- write_io.write json[0..11]
379
- sleep(0.1)
380
- begin
381
- write_io.write json[12..]
382
- rescue Exception
383
- # ignore, should fail to write
384
- end
385
- write_io.close
386
- Process.exit(0)
387
- end
388
- end
389
- end
390
-
391
- def test_socket_close
392
- json = %{{"one":true,"two":false}}
393
- begin
394
- server = TCPServer.new(8080)
395
- rescue
396
- # Not able to open a socket to run the test. Might be Travis.
397
- return
398
- end
399
- Thread.start(json) do |_j|
400
- c = server.accept()
401
- c.puts json[0..11]
402
- 10.times {
403
- break if c.closed?
404
-
405
- sleep(0.1)
406
- }
407
- unless c.closed?
408
- c.puts json[12..]
409
- c.close
410
- end
411
- end
412
- begin
413
- sock = TCPSocket.new('localhost', 8080)
414
- rescue
415
- # Not able to open a socket to run the test. Might be Travis.
416
- return
417
- end
418
- handler = Closer.new(sock)
419
- err = nil
420
- begin
421
- Oj.sc_parse(handler, sock)
422
- rescue Exception => e
423
- err = e.class.to_s
424
- end
425
- assert_equal('IOError', err)
426
- assert_equal([[:hash_start],
427
- [:hash_key, 'one'],
428
- [:hash_set, 'one', true]], handler.calls)
429
- end
430
-
431
- end