oj 3.14.3 → 3.15.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/ext/oj/code.c +3 -10
- data/ext/oj/compat.c +5 -18
- data/ext/oj/custom.c +10 -28
- data/ext/oj/dump.c +40 -10
- data/ext/oj/dump.h +1 -4
- data/ext/oj/extconf.rb +4 -2
- data/ext/oj/fast.c +3 -6
- data/ext/oj/mimic_json.c +21 -1
- data/ext/oj/object.c +7 -21
- data/ext/oj/oj.c +24 -4
- data/ext/oj/oj.h +10 -6
- data/ext/oj/parse.c +3 -5
- data/ext/oj/parse.h +16 -14
- data/ext/oj/parser.h +2 -2
- data/ext/oj/reader.c +1 -3
- data/ext/oj/saj.c +1 -1
- data/ext/oj/strict.c +9 -27
- data/ext/oj/wab.c +9 -27
- data/lib/oj/active_support_helper.rb +2 -3
- data/lib/oj/json.rb +156 -149
- data/lib/oj/mimic.rb +3 -1
- data/lib/oj/version.rb +1 -1
- data/lib/oj.rb +3 -0
- data/pages/Options.md +4 -0
- data/test/_test_active.rb +8 -8
- data/test/_test_active_mimic.rb +7 -7
- data/test/_test_mimic_rails.rb +17 -19
- data/test/files.rb +14 -14
- data/test/foo.rb +15 -10
- data/test/helper.rb +4 -4
- data/test/mem.rb +8 -7
- data/test/perf.rb +21 -26
- data/test/perf_compat.rb +30 -32
- data/test/perf_dump.rb +27 -27
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -68
- data/test/perf_once.rb +8 -7
- data/test/perf_parser.rb +40 -46
- data/test/perf_saj.rb +46 -53
- data/test/perf_scp.rb +57 -69
- data/test/perf_simple.rb +40 -38
- data/test/perf_strict.rb +68 -70
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +3 -3
- data/test/sample.rb +16 -15
- data/test/sample_json.rb +8 -7
- data/test/test_compat.rb +44 -46
- data/test/test_custom.rb +56 -42
- data/test/test_debian.rb +6 -9
- data/test/test_fast.rb +78 -72
- data/test/test_file.rb +16 -21
- data/test/test_gc.rb +5 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +4 -4
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +18 -20
- data/test/test_object.rb +76 -86
- data/test/test_parser.rb +4 -4
- data/test/test_parser_debug.rb +4 -4
- data/test/test_parser_saj.rb +31 -31
- data/test/test_parser_usual.rb +3 -3
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +8 -8
- data/test/test_scp.rb +29 -29
- data/test/test_strict.rb +25 -31
- data/test/test_various.rb +121 -75
- data/test/test_wab.rb +43 -42
- data/test/test_writer.rb +46 -46
- data/test/tests.rb +7 -7
- data/test/tests_mimic.rb +6 -6
- data/test/tests_mimic_addition.rb +6 -6
- metadata +3 -6
- data/test/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/zoo.rb +0 -13
data/test/test_saj.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
|
|
@@ -23,7 +23,7 @@ $json = %{{
|
|
23
23
|
class AllSaj < Oj::Saj
|
24
24
|
attr_accessor :calls
|
25
25
|
|
26
|
-
def initialize
|
26
|
+
def initialize
|
27
27
|
@calls = []
|
28
28
|
|
29
29
|
super
|
@@ -97,14 +97,14 @@ class SajTest < Minitest::Test
|
|
97
97
|
handler = AllSaj.new()
|
98
98
|
json = %{12345}
|
99
99
|
Oj.saj_parse(handler, json)
|
100
|
-
assert_equal([[:add_value,
|
100
|
+
assert_equal([[:add_value, 12_345, nil]], handler.calls)
|
101
101
|
end
|
102
102
|
|
103
103
|
def test_float
|
104
104
|
handler = AllSaj.new()
|
105
105
|
json = %{12345.6789}
|
106
106
|
Oj.saj_parse(handler, json)
|
107
|
-
assert_equal([[:add_value,
|
107
|
+
assert_equal([[:add_value, 12_345.6789, nil]], handler.calls)
|
108
108
|
end
|
109
109
|
|
110
110
|
def test_float_exp
|
@@ -113,7 +113,7 @@ class SajTest < Minitest::Test
|
|
113
113
|
Oj.saj_parse(handler, json)
|
114
114
|
assert_equal(1, handler.calls.size)
|
115
115
|
assert_equal(:add_value, handler.calls[0][0])
|
116
|
-
assert_equal((
|
116
|
+
assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
|
117
117
|
end
|
118
118
|
|
119
119
|
def test_array_empty
|
@@ -179,10 +179,10 @@ class SajTest < Minitest::Test
|
|
179
179
|
handler = AllSaj.new()
|
180
180
|
json = %{12345xyz}
|
181
181
|
Oj.saj_parse(handler, json)
|
182
|
-
assert_equal([:add_value,
|
182
|
+
assert_equal([:add_value, 12_345, nil], handler.calls.first)
|
183
183
|
type, message, line, column = handler.calls.last
|
184
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]
|
185
|
+
assert_match(%r{invalid format, extra characters at line 1, column 6 \[(?:[A-Za-z]:/)?(?:[a-z.]+/)*saj\.c:\d+\]}, message)
|
186
186
|
end
|
187
187
|
|
188
188
|
end
|
data/test/test_scp.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
|
require 'socket'
|
@@ -23,23 +23,22 @@ $json = %{{
|
|
23
23
|
}}
|
24
24
|
|
25
25
|
class NoHandler < Oj::ScHandler
|
26
|
-
def initialize()
|
27
|
-
end
|
28
26
|
end
|
29
27
|
|
30
28
|
class AllHandler < Oj::ScHandler
|
31
29
|
attr_accessor :calls
|
32
30
|
|
33
|
-
def initialize
|
31
|
+
def initialize
|
32
|
+
super
|
34
33
|
@calls = []
|
35
34
|
end
|
36
35
|
|
37
|
-
def hash_start
|
36
|
+
def hash_start
|
38
37
|
@calls << [:hash_start]
|
39
38
|
{}
|
40
39
|
end
|
41
40
|
|
42
|
-
def hash_end
|
41
|
+
def hash_end
|
43
42
|
@calls << [:hash_end]
|
44
43
|
end
|
45
44
|
|
@@ -51,12 +50,12 @@ class AllHandler < Oj::ScHandler
|
|
51
50
|
key
|
52
51
|
end
|
53
52
|
|
54
|
-
def array_start
|
53
|
+
def array_start
|
55
54
|
@calls << [:array_start]
|
56
55
|
[]
|
57
56
|
end
|
58
57
|
|
59
|
-
def array_end
|
58
|
+
def array_end
|
60
59
|
@calls << [:array_end]
|
61
60
|
end
|
62
61
|
|
@@ -64,11 +63,11 @@ class AllHandler < Oj::ScHandler
|
|
64
63
|
@calls << [:add_value, value]
|
65
64
|
end
|
66
65
|
|
67
|
-
def hash_set(
|
66
|
+
def hash_set(_h, key, value)
|
68
67
|
@calls << [:hash_set, key, value]
|
69
68
|
end
|
70
69
|
|
71
|
-
def array_append(
|
70
|
+
def array_append(_a, value)
|
72
71
|
@calls << [:array_append, value]
|
73
72
|
end
|
74
73
|
|
@@ -76,18 +75,19 @@ end # AllHandler
|
|
76
75
|
|
77
76
|
class Closer < AllHandler
|
78
77
|
attr_accessor :io
|
78
|
+
|
79
79
|
def initialize(io)
|
80
80
|
super()
|
81
81
|
@io = io
|
82
82
|
end
|
83
83
|
|
84
|
-
def hash_start
|
84
|
+
def hash_start
|
85
85
|
@calls << [:hash_start]
|
86
86
|
@io.close
|
87
87
|
{}
|
88
88
|
end
|
89
89
|
|
90
|
-
def hash_set(
|
90
|
+
def hash_set(_h, key, value)
|
91
91
|
@calls << [:hash_set, key, value]
|
92
92
|
@io.close
|
93
93
|
end
|
@@ -136,14 +136,14 @@ class ScpTest < Minitest::Test
|
|
136
136
|
handler = AllHandler.new()
|
137
137
|
json = %{12345}
|
138
138
|
Oj.sc_parse(handler, json)
|
139
|
-
assert_equal([[:add_value,
|
139
|
+
assert_equal([[:add_value, 12_345]], handler.calls)
|
140
140
|
end
|
141
141
|
|
142
142
|
def test_float
|
143
143
|
handler = AllHandler.new()
|
144
144
|
json = %{12345.6789}
|
145
145
|
Oj.sc_parse(handler, json)
|
146
|
-
assert_equal([[:add_value,
|
146
|
+
assert_equal([[:add_value, 12_345.6789]], handler.calls)
|
147
147
|
end
|
148
148
|
|
149
149
|
def test_float_exp
|
@@ -152,7 +152,7 @@ class ScpTest < Minitest::Test
|
|
152
152
|
Oj.sc_parse(handler, json)
|
153
153
|
assert_equal(1, handler.calls.size)
|
154
154
|
assert_equal(:add_value, handler.calls[0][0])
|
155
|
-
assert_equal((
|
155
|
+
assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
|
156
156
|
end
|
157
157
|
|
158
158
|
def test_array_empty
|
@@ -231,9 +231,9 @@ class ScpTest < Minitest::Test
|
|
231
231
|
[:array_start],
|
232
232
|
[:hash_start],
|
233
233
|
[:hash_key, 'num'],
|
234
|
-
[:hash_set,
|
234
|
+
[:hash_set, 'num', 3],
|
235
235
|
[:hash_key, 'string'],
|
236
|
-
[:hash_set,
|
236
|
+
[:hash_set, 'string', 'message'],
|
237
237
|
[:hash_key, 'hash'],
|
238
238
|
[:hash_start],
|
239
239
|
[:hash_key, 'h2'],
|
@@ -244,17 +244,17 @@ class ScpTest < Minitest::Test
|
|
244
244
|
[:array_append, 2],
|
245
245
|
[:array_append, 3],
|
246
246
|
[:array_end],
|
247
|
-
[:hash_set,
|
247
|
+
[:hash_set, 'a', []],
|
248
248
|
[:hash_end],
|
249
|
-
[:hash_set,
|
249
|
+
[:hash_set, 'h2', {}],
|
250
250
|
[:hash_end],
|
251
|
-
[:hash_set,
|
251
|
+
[:hash_set, 'hash', {}],
|
252
252
|
[:hash_end],
|
253
253
|
[:array_append, {}],
|
254
254
|
[:array_end],
|
255
|
-
[:hash_set,
|
255
|
+
[:hash_set, 'array', []],
|
256
256
|
[:hash_key, 'boolean'],
|
257
|
-
[:hash_set,
|
257
|
+
[:hash_set, 'boolean', true],
|
258
258
|
[:hash_end],
|
259
259
|
[:add_value, {}]], handler.calls)
|
260
260
|
end
|
@@ -369,7 +369,7 @@ class ScpTest < Minitest::Test
|
|
369
369
|
rescue Exception => e
|
370
370
|
err = e.class.to_s
|
371
371
|
end
|
372
|
-
assert_equal(
|
372
|
+
assert_equal('IOError', err)
|
373
373
|
assert_equal([[:hash_start],
|
374
374
|
[:hash_key, 'one'],
|
375
375
|
[:hash_set, 'one', true]], handler.calls)
|
@@ -378,8 +378,8 @@ class ScpTest < Minitest::Test
|
|
378
378
|
write_io.write json[0..11]
|
379
379
|
sleep(0.1)
|
380
380
|
begin
|
381
|
-
write_io.write json[12
|
382
|
-
rescue Exception
|
381
|
+
write_io.write json[12..]
|
382
|
+
rescue Exception
|
383
383
|
# ignore, should fail to write
|
384
384
|
end
|
385
385
|
write_io.close
|
@@ -396,7 +396,7 @@ class ScpTest < Minitest::Test
|
|
396
396
|
# Not able to open a socket to run the test. Might be Travis.
|
397
397
|
return
|
398
398
|
end
|
399
|
-
Thread.start(json) do |
|
399
|
+
Thread.start(json) do |_j|
|
400
400
|
c = server.accept()
|
401
401
|
c.puts json[0..11]
|
402
402
|
10.times {
|
@@ -405,7 +405,7 @@ class ScpTest < Minitest::Test
|
|
405
405
|
sleep(0.1)
|
406
406
|
}
|
407
407
|
unless c.closed?
|
408
|
-
c.puts json[12
|
408
|
+
c.puts json[12..]
|
409
409
|
c.close
|
410
410
|
end
|
411
411
|
end
|
@@ -422,7 +422,7 @@ class ScpTest < Minitest::Test
|
|
422
422
|
rescue Exception => e
|
423
423
|
err = e.class.to_s
|
424
424
|
end
|
425
|
-
assert_equal(
|
425
|
+
assert_equal('IOError', err)
|
426
426
|
assert_equal([[:hash_start],
|
427
427
|
[:hash_key, 'one'],
|
428
428
|
[:hash_set, 'one', true]], handler.calls)
|
data/test/test_strict.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'
|
@@ -52,16 +52,16 @@ class StrictJuice < Minitest::Test
|
|
52
52
|
|
53
53
|
def test_fixnum
|
54
54
|
dump_and_load(0, false)
|
55
|
-
dump_and_load(
|
56
|
-
dump_and_load(-
|
55
|
+
dump_and_load(12_345, false)
|
56
|
+
dump_and_load(-54_321, false)
|
57
57
|
dump_and_load(1, false)
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_float
|
61
61
|
dump_and_load(0.0, false)
|
62
|
-
dump_and_load(
|
62
|
+
dump_and_load(12_345.6789, false)
|
63
63
|
dump_and_load(70.35, false)
|
64
|
-
dump_and_load(-
|
64
|
+
dump_and_load(-54_321.012, false)
|
65
65
|
dump_and_load(1.7775, false)
|
66
66
|
dump_and_load(2.5024, false)
|
67
67
|
dump_and_load(2.48e16, false)
|
@@ -78,7 +78,7 @@ class StrictJuice < Minitest::Test
|
|
78
78
|
assert(true)
|
79
79
|
return
|
80
80
|
end
|
81
|
-
assert(false,
|
81
|
+
assert(false, '*** expected an exception')
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_infinity_dump
|
@@ -90,7 +90,7 @@ class StrictJuice < Minitest::Test
|
|
90
90
|
assert(true)
|
91
91
|
return
|
92
92
|
end
|
93
|
-
assert(false,
|
93
|
+
assert(false, '*** expected an exception')
|
94
94
|
end
|
95
95
|
|
96
96
|
def test_neg_infinity_dump
|
@@ -102,7 +102,7 @@ class StrictJuice < Minitest::Test
|
|
102
102
|
assert(true)
|
103
103
|
return
|
104
104
|
end
|
105
|
-
assert(false,
|
105
|
+
assert(false, '*** expected an exception')
|
106
106
|
end
|
107
107
|
|
108
108
|
def test_string
|
@@ -115,15 +115,11 @@ class StrictJuice < Minitest::Test
|
|
115
115
|
def test_encode
|
116
116
|
opts = Oj.default_options
|
117
117
|
Oj.default_options = { :ascii_only => false }
|
118
|
-
|
119
|
-
dump_and_load("ぴーたー", false)
|
120
|
-
end
|
118
|
+
dump_and_load('ぴーたー', false)
|
121
119
|
Oj.default_options = { :ascii_only => true }
|
122
|
-
json = Oj.dump(
|
120
|
+
json = Oj.dump('ぴーたー')
|
123
121
|
assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
|
124
|
-
|
125
|
-
dump_and_load("ぴーたー", false)
|
126
|
-
end
|
122
|
+
dump_and_load('ぴーたー', false)
|
127
123
|
Oj.default_options = opts
|
128
124
|
end
|
129
125
|
|
@@ -159,10 +155,10 @@ class StrictJuice < Minitest::Test
|
|
159
155
|
skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'
|
160
156
|
|
161
157
|
begin
|
162
|
-
n =
|
158
|
+
n = 10_000
|
163
159
|
Oj.strict_load(('[' * n) + (']' * n))
|
164
160
|
rescue Exception => e
|
165
|
-
|
161
|
+
refute(e.message)
|
166
162
|
end
|
167
163
|
end
|
168
164
|
|
@@ -209,7 +205,7 @@ class StrictJuice < Minitest::Test
|
|
209
205
|
assert(true)
|
210
206
|
return
|
211
207
|
end
|
212
|
-
assert(false,
|
208
|
+
assert(false, '*** expected an exception')
|
213
209
|
end
|
214
210
|
|
215
211
|
def test_bignum_object
|
@@ -238,7 +234,7 @@ class StrictJuice < Minitest::Test
|
|
238
234
|
assert(true)
|
239
235
|
return
|
240
236
|
end
|
241
|
-
assert(false,
|
237
|
+
assert(false, '*** expected an exception')
|
242
238
|
end
|
243
239
|
|
244
240
|
def test_range
|
@@ -248,7 +244,7 @@ class StrictJuice < Minitest::Test
|
|
248
244
|
assert(true)
|
249
245
|
return
|
250
246
|
end
|
251
|
-
assert(false,
|
247
|
+
assert(false, '*** expected an exception')
|
252
248
|
end
|
253
249
|
|
254
250
|
# Stream IO
|
@@ -265,15 +261,13 @@ class StrictJuice < Minitest::Test
|
|
265
261
|
end
|
266
262
|
|
267
263
|
def test_io_file
|
268
|
-
filename = File.join(
|
269
|
-
File.
|
270
|
-
f.write(%{{
|
264
|
+
filename = File.join(__dir__, 'open_file_test.json')
|
265
|
+
File.write(filename, %{{
|
271
266
|
"x":true,
|
272
267
|
"y":58,
|
273
268
|
"z": [1,2,3]
|
274
269
|
}
|
275
270
|
})
|
276
|
-
}
|
277
271
|
f = File.new(filename)
|
278
272
|
obj = Oj.strict_load(f)
|
279
273
|
f.close()
|
@@ -293,7 +287,7 @@ class StrictJuice < Minitest::Test
|
|
293
287
|
assert(true)
|
294
288
|
return
|
295
289
|
end
|
296
|
-
assert(false,
|
290
|
+
assert(false, '*** expected an exception')
|
297
291
|
end
|
298
292
|
|
299
293
|
def test_class
|
@@ -303,7 +297,7 @@ class StrictJuice < Minitest::Test
|
|
303
297
|
assert(true)
|
304
298
|
return
|
305
299
|
end
|
306
|
-
assert(false,
|
300
|
+
assert(false, '*** expected an exception')
|
307
301
|
end
|
308
302
|
|
309
303
|
def test_module
|
@@ -313,7 +307,7 @@ class StrictJuice < Minitest::Test
|
|
313
307
|
assert(true)
|
314
308
|
return
|
315
309
|
end
|
316
|
-
assert(false,
|
310
|
+
assert(false, '*** expected an exception')
|
317
311
|
end
|
318
312
|
|
319
313
|
# symbol_keys option
|
@@ -425,7 +419,7 @@ class StrictJuice < Minitest::Test
|
|
425
419
|
def dump_and_load(obj, trace=false)
|
426
420
|
json = Oj.dump(obj, :indent => 2)
|
427
421
|
puts json if trace
|
428
|
-
loaded = Oj.strict_load(json)
|
422
|
+
loaded = Oj.strict_load(json)
|
429
423
|
if obj.nil?
|
430
424
|
assert_nil(loaded)
|
431
425
|
else
|