oj 3.13.11 → 3.15.0
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 +74 -0
- data/README.md +4 -2
- data/ext/oj/buf.h +11 -6
- data/ext/oj/cache.c +25 -24
- 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 +17 -24
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +17 -44
- data/ext/oj/custom.c +70 -141
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +128 -118
- data/ext/oj/dump.h +12 -8
- data/ext/oj/dump_compat.c +564 -641
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +70 -199
- data/ext/oj/dump_strict.c +22 -46
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +14 -5
- data/ext/oj/fast.c +75 -103
- data/ext/oj/intern.c +52 -50
- data/ext/oj/intern.h +4 -8
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +75 -47
- data/ext/oj/object.c +49 -66
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +140 -99
- data/ext/oj/oj.h +80 -51
- data/ext/oj/parse.c +162 -184
- data/ext/oj/parse.h +7 -10
- data/ext/oj/parser.c +89 -34
- data/ext/oj/parser.h +18 -7
- data/ext/oj/rails.c +82 -146
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +11 -12
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +6 -5
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +20 -31
- data/ext/oj/saj2.c +329 -93
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +26 -70
- data/ext/oj/stream_writer.c +12 -22
- data/ext/oj/strict.c +20 -52
- data/ext/oj/string_writer.c +21 -21
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +105 -150
- data/ext/oj/usual.h +68 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +1 -1
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +21 -26
- data/ext/oj/wab.c +31 -68
- data/lib/oj/active_support_helper.rb +0 -1
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +0 -1
- data/lib/oj/json.rb +4 -2
- data/lib/oj/mimic.rb +4 -2
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/state.rb +9 -6
- 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/Options.md +10 -0
- 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/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +20 -34
- 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 +9 -71
- 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 +4 -4
- 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 +48 -36
- 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 +13 -12
- data/test/perf.rb +21 -26
- 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 +12 -11
- data/test/perf_parser.rb +42 -48
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +57 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +68 -70
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +3 -3
- 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 +76 -42
- data/test/test_custom.rb +72 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +86 -90
- 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 +4 -4
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +85 -96
- data/test/test_parser.rb +6 -22
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +115 -23
- data/test/test_parser_usual.rb +6 -6
- 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 +30 -32
- data/test/test_various.rb +147 -99
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -4
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +33 -144
- 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 -16
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/zoo.rb +0 -13
data/test/test_parser_saj.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
|
-
$json =
|
8
|
+
$json = %|{
|
9
9
|
"array": [
|
10
10
|
{
|
11
11
|
"num" : 3,
|
@@ -18,13 +18,15 @@ $json = %{{
|
|
18
18
|
}
|
19
19
|
],
|
20
20
|
"boolean" : true
|
21
|
-
}
|
21
|
+
}|
|
22
22
|
|
23
23
|
class AllSaj < Oj::Saj
|
24
24
|
attr_accessor :calls
|
25
25
|
|
26
|
-
def initialize
|
26
|
+
def initialize
|
27
27
|
@calls = []
|
28
|
+
|
29
|
+
super
|
28
30
|
end
|
29
31
|
|
30
32
|
def hash_start(key)
|
@@ -53,6 +55,35 @@ class AllSaj < Oj::Saj
|
|
53
55
|
|
54
56
|
end # AllSaj
|
55
57
|
|
58
|
+
class LocSaj
|
59
|
+
attr_accessor :calls
|
60
|
+
|
61
|
+
def initialize
|
62
|
+
@calls = []
|
63
|
+
end
|
64
|
+
|
65
|
+
def hash_start(key, line, column)
|
66
|
+
@calls << [:hash_start, key, line, column]
|
67
|
+
end
|
68
|
+
|
69
|
+
def hash_end(key, line, column)
|
70
|
+
@calls << [:hash_end, key, line, column]
|
71
|
+
end
|
72
|
+
|
73
|
+
def array_start(key, line, column)
|
74
|
+
@calls << [:array_start, key, line, column]
|
75
|
+
end
|
76
|
+
|
77
|
+
def array_end(key, line, column)
|
78
|
+
@calls << [:array_end, key, line, column]
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_value(value, key, line, column)
|
82
|
+
@calls << [:add_value, value, key, line, column]
|
83
|
+
end
|
84
|
+
|
85
|
+
end # LocSaj
|
86
|
+
|
56
87
|
class SajTest < Minitest::Test
|
57
88
|
|
58
89
|
def test_nil
|
@@ -97,7 +128,7 @@ class SajTest < Minitest::Test
|
|
97
128
|
p = Oj::Parser.new(:saj)
|
98
129
|
p.handler = handler
|
99
130
|
p.parse(json)
|
100
|
-
assert_equal([[:add_value,
|
131
|
+
assert_equal([[:add_value, 12_345, nil]], handler.calls)
|
101
132
|
end
|
102
133
|
|
103
134
|
def test_float
|
@@ -106,7 +137,7 @@ class SajTest < Minitest::Test
|
|
106
137
|
p = Oj::Parser.new(:saj)
|
107
138
|
p.handler = handler
|
108
139
|
p.parse(json)
|
109
|
-
assert_equal([[:add_value,
|
140
|
+
assert_equal([[:add_value, 12_345.6789, nil]], handler.calls)
|
110
141
|
end
|
111
142
|
|
112
143
|
def test_float_exp
|
@@ -117,7 +148,44 @@ class SajTest < Minitest::Test
|
|
117
148
|
p.parse(json)
|
118
149
|
assert_equal(1, handler.calls.size)
|
119
150
|
assert_equal(:add_value, handler.calls[0][0])
|
120
|
-
assert_equal((
|
151
|
+
assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_bignum
|
155
|
+
handler = AllSaj.new()
|
156
|
+
json = %{-11.899999999999999}
|
157
|
+
p = Oj::Parser.new(:saj)
|
158
|
+
p.handler = handler
|
159
|
+
p.parse(json)
|
160
|
+
assert_equal(1, handler.calls.size)
|
161
|
+
assert_equal(:add_value, handler.calls[0][0])
|
162
|
+
assert_equal(-118_999, (handler.calls[0][1] * 10_000).to_i)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_bignum_loc
|
166
|
+
handler = LocSaj.new()
|
167
|
+
json = <<~JSON
|
168
|
+
{
|
169
|
+
"width": 192.33800000000002,
|
170
|
+
"xaxis": {
|
171
|
+
"anchor": "y"
|
172
|
+
}
|
173
|
+
}
|
174
|
+
JSON
|
175
|
+
|
176
|
+
p = Oj::Parser.new(:saj)
|
177
|
+
p.handler = handler
|
178
|
+
p.parse(json)
|
179
|
+
assert_equal(6, handler.calls.size)
|
180
|
+
assert_equal(1_923_380, (handler.calls[1][1] * 10_000).to_i)
|
181
|
+
handler.calls[1][1] = 1_923_380
|
182
|
+
assert_equal([[:hash_start, nil, 1, 1],
|
183
|
+
[:add_value, 1_923_380, 'width', 2, 30],
|
184
|
+
[:hash_start, 'xaxis', 3, 12],
|
185
|
+
[:add_value, 'y', 'anchor', 4, 17],
|
186
|
+
[:hash_end, 'xaxis', 5, 3],
|
187
|
+
[:hash_end, nil, 6, 1]],
|
188
|
+
handler.calls)
|
121
189
|
end
|
122
190
|
|
123
191
|
def test_array_empty
|
@@ -194,13 +262,13 @@ class SajTest < Minitest::Test
|
|
194
262
|
p.handler = handler
|
195
263
|
p.parse(json)
|
196
264
|
assert_equal([
|
197
|
-
|
265
|
+
[:array_start, nil],
|
198
266
|
[:add_value, true, nil],
|
199
267
|
[:array_end, nil],
|
200
|
-
|
268
|
+
[:array_start, nil],
|
201
269
|
[:add_value, false, nil],
|
202
270
|
[:array_end, nil],
|
203
|
-
|
271
|
+
], handler.calls)
|
204
272
|
end
|
205
273
|
|
206
274
|
def test_io
|
@@ -210,11 +278,11 @@ class SajTest < Minitest::Test
|
|
210
278
|
p.handler = handler
|
211
279
|
p.load(StringIO.new(json))
|
212
280
|
assert_equal([
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
281
|
+
[:array_start, nil],
|
282
|
+
[:add_value, true, nil],
|
283
|
+
[:add_value, false, nil],
|
284
|
+
[:array_end, nil],
|
285
|
+
], handler.calls)
|
218
286
|
end
|
219
287
|
|
220
288
|
def test_file
|
@@ -223,11 +291,11 @@ class SajTest < Minitest::Test
|
|
223
291
|
p.handler = handler
|
224
292
|
p.file('saj_test.json')
|
225
293
|
assert_equal([
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
294
|
+
[:array_start, nil],
|
295
|
+
[:add_value, true, nil],
|
296
|
+
[:add_value, false, nil],
|
297
|
+
[:array_end, nil],
|
298
|
+
], handler.calls)
|
231
299
|
end
|
232
300
|
|
233
301
|
def test_default
|
@@ -236,10 +304,34 @@ class SajTest < Minitest::Test
|
|
236
304
|
Oj::Parser.saj.handler = handler
|
237
305
|
Oj::Parser.saj.parse(json)
|
238
306
|
assert_equal([
|
239
|
-
|
307
|
+
[:array_start, nil],
|
240
308
|
[:add_value, true, nil],
|
241
309
|
[:array_end, nil],
|
242
|
-
|
310
|
+
], handler.calls)
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_loc
|
314
|
+
handler = LocSaj.new()
|
315
|
+
Oj::Parser.saj.handler = handler
|
316
|
+
Oj::Parser.saj.parse($json)
|
317
|
+
assert_equal([[:hash_start, nil, 1, 1],
|
318
|
+
[:array_start, 'array', 2, 12],
|
319
|
+
[:hash_start, nil, 3, 5],
|
320
|
+
[:add_value, 3, 'num', 4, 18],
|
321
|
+
[:add_value, 'message', 'string', 5, 25],
|
322
|
+
[:hash_start, 'hash', 6, 17],
|
323
|
+
[:hash_start, 'h2', 7, 17],
|
324
|
+
[:array_start, 'a', 8, 17],
|
325
|
+
[:add_value, 1, nil, 8, 20],
|
326
|
+
[:add_value, 2, nil, 8, 23],
|
327
|
+
[:add_value, 3, nil, 8, 26],
|
328
|
+
[:array_end, 'a', 8, 27],
|
329
|
+
[:hash_end, 'h2', 9, 9],
|
330
|
+
[:hash_end, 'hash', 10, 7],
|
331
|
+
[:hash_end, nil, 11, 5],
|
332
|
+
[:array_end, 'array', 12, 3],
|
333
|
+
[:add_value, true, 'boolean', 13, 18],
|
334
|
+
[:hash_end, nil, 14, 1]], handler.calls)
|
243
335
|
end
|
244
336
|
|
245
337
|
end
|
data/test/test_parser_usual.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
|
|
@@ -40,10 +40,10 @@ class UsualTest < Minitest::Test
|
|
40
40
|
[
|
41
41
|
['[]', []],
|
42
42
|
['[false]', [false]],
|
43
|
-
['[true,false]', [true,false]],
|
43
|
+
['[true,false]', [true, false]],
|
44
44
|
['[[]]', [[]]],
|
45
|
-
['[true,[],false]', [true,[],false]],
|
46
|
-
['[true,[true],false]', [true,[true],false]],
|
45
|
+
['[true,[],false]', [true, [], false]],
|
46
|
+
['[true,[true],false]', [true, [true], false]],
|
47
47
|
].each { |x|
|
48
48
|
doc = p.parse(x[0])
|
49
49
|
assert_equal(x[1], doc)
|
@@ -67,7 +67,7 @@ class UsualTest < Minitest::Test
|
|
67
67
|
|
68
68
|
def test_symbol_keys
|
69
69
|
p = Oj::Parser.new(:usual)
|
70
|
-
|
70
|
+
refute(p.symbol_keys)
|
71
71
|
p.symbol_keys = true
|
72
72
|
doc = p.parse('{"a": true, "b": false}')
|
73
73
|
assert_equal({a: true, b: false}, doc)
|
data/test/test_rails.rb
CHANGED
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,8 +23,10 @@ $json = %{{
|
|
23
23
|
class AllSaj < Oj::Saj
|
24
24
|
attr_accessor :calls
|
25
25
|
|
26
|
-
def initialize
|
26
|
+
def initialize
|
27
27
|
@calls = []
|
28
|
+
|
29
|
+
super
|
28
30
|
end
|
29
31
|
|
30
32
|
def hash_start(key)
|
@@ -95,14 +97,14 @@ class SajTest < Minitest::Test
|
|
95
97
|
handler = AllSaj.new()
|
96
98
|
json = %{12345}
|
97
99
|
Oj.saj_parse(handler, json)
|
98
|
-
assert_equal([[:add_value,
|
100
|
+
assert_equal([[:add_value, 12_345, nil]], handler.calls)
|
99
101
|
end
|
100
102
|
|
101
103
|
def test_float
|
102
104
|
handler = AllSaj.new()
|
103
105
|
json = %{12345.6789}
|
104
106
|
Oj.saj_parse(handler, json)
|
105
|
-
assert_equal([[:add_value,
|
107
|
+
assert_equal([[:add_value, 12_345.6789, nil]], handler.calls)
|
106
108
|
end
|
107
109
|
|
108
110
|
def test_float_exp
|
@@ -111,7 +113,7 @@ class SajTest < Minitest::Test
|
|
111
113
|
Oj.saj_parse(handler, json)
|
112
114
|
assert_equal(1, handler.calls.size)
|
113
115
|
assert_equal(:add_value, handler.calls[0][0])
|
114
|
-
assert_equal((
|
116
|
+
assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
|
115
117
|
end
|
116
118
|
|
117
119
|
def test_array_empty
|
@@ -177,10 +179,10 @@ class SajTest < Minitest::Test
|
|
177
179
|
handler = AllSaj.new()
|
178
180
|
json = %{12345xyz}
|
179
181
|
Oj.saj_parse(handler, json)
|
180
|
-
assert_equal([:add_value,
|
182
|
+
assert_equal([:add_value, 12_345, nil], handler.calls.first)
|
181
183
|
type, message, line, column = handler.calls.last
|
182
184
|
assert_equal([:error, 1, 6], [type, line, column])
|
183
|
-
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)
|
184
186
|
end
|
185
187
|
|
186
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
|
|
@@ -47,15 +46,16 @@ class AllHandler < Oj::ScHandler
|
|
47
46
|
@calls << [:hash_key, key]
|
48
47
|
return 'too' if 'two' == key
|
49
48
|
return :symbol if 'symbol' == key
|
49
|
+
|
50
50
|
key
|
51
51
|
end
|
52
52
|
|
53
|
-
def array_start
|
53
|
+
def array_start
|
54
54
|
@calls << [:array_start]
|
55
55
|
[]
|
56
56
|
end
|
57
57
|
|
58
|
-
def array_end
|
58
|
+
def array_end
|
59
59
|
@calls << [:array_end]
|
60
60
|
end
|
61
61
|
|
@@ -63,11 +63,11 @@ class AllHandler < Oj::ScHandler
|
|
63
63
|
@calls << [:add_value, value]
|
64
64
|
end
|
65
65
|
|
66
|
-
def hash_set(
|
66
|
+
def hash_set(_h, key, value)
|
67
67
|
@calls << [:hash_set, key, value]
|
68
68
|
end
|
69
69
|
|
70
|
-
def array_append(
|
70
|
+
def array_append(_a, value)
|
71
71
|
@calls << [:array_append, value]
|
72
72
|
end
|
73
73
|
|
@@ -75,18 +75,19 @@ end # AllHandler
|
|
75
75
|
|
76
76
|
class Closer < AllHandler
|
77
77
|
attr_accessor :io
|
78
|
+
|
78
79
|
def initialize(io)
|
79
80
|
super()
|
80
81
|
@io = io
|
81
82
|
end
|
82
83
|
|
83
|
-
def hash_start
|
84
|
+
def hash_start
|
84
85
|
@calls << [:hash_start]
|
85
86
|
@io.close
|
86
87
|
{}
|
87
88
|
end
|
88
89
|
|
89
|
-
def hash_set(
|
90
|
+
def hash_set(_h, key, value)
|
90
91
|
@calls << [:hash_set, key, value]
|
91
92
|
@io.close
|
92
93
|
end
|
@@ -135,14 +136,14 @@ class ScpTest < Minitest::Test
|
|
135
136
|
handler = AllHandler.new()
|
136
137
|
json = %{12345}
|
137
138
|
Oj.sc_parse(handler, json)
|
138
|
-
assert_equal([[:add_value,
|
139
|
+
assert_equal([[:add_value, 12_345]], handler.calls)
|
139
140
|
end
|
140
141
|
|
141
142
|
def test_float
|
142
143
|
handler = AllHandler.new()
|
143
144
|
json = %{12345.6789}
|
144
145
|
Oj.sc_parse(handler, json)
|
145
|
-
assert_equal([[:add_value,
|
146
|
+
assert_equal([[:add_value, 12_345.6789]], handler.calls)
|
146
147
|
end
|
147
148
|
|
148
149
|
def test_float_exp
|
@@ -151,7 +152,7 @@ class ScpTest < Minitest::Test
|
|
151
152
|
Oj.sc_parse(handler, json)
|
152
153
|
assert_equal(1, handler.calls.size)
|
153
154
|
assert_equal(:add_value, handler.calls[0][0])
|
154
|
-
assert_equal((
|
155
|
+
assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
|
155
156
|
end
|
156
157
|
|
157
158
|
def test_array_empty
|
@@ -230,9 +231,9 @@ class ScpTest < Minitest::Test
|
|
230
231
|
[:array_start],
|
231
232
|
[:hash_start],
|
232
233
|
[:hash_key, 'num'],
|
233
|
-
[:hash_set,
|
234
|
+
[:hash_set, 'num', 3],
|
234
235
|
[:hash_key, 'string'],
|
235
|
-
[:hash_set,
|
236
|
+
[:hash_set, 'string', 'message'],
|
236
237
|
[:hash_key, 'hash'],
|
237
238
|
[:hash_start],
|
238
239
|
[:hash_key, 'h2'],
|
@@ -243,17 +244,17 @@ class ScpTest < Minitest::Test
|
|
243
244
|
[:array_append, 2],
|
244
245
|
[:array_append, 3],
|
245
246
|
[:array_end],
|
246
|
-
[:hash_set,
|
247
|
+
[:hash_set, 'a', []],
|
247
248
|
[:hash_end],
|
248
|
-
[:hash_set,
|
249
|
+
[:hash_set, 'h2', {}],
|
249
250
|
[:hash_end],
|
250
|
-
[:hash_set,
|
251
|
+
[:hash_set, 'hash', {}],
|
251
252
|
[:hash_end],
|
252
253
|
[:array_append, {}],
|
253
254
|
[:array_end],
|
254
|
-
[:hash_set,
|
255
|
+
[:hash_set, 'array', []],
|
255
256
|
[:hash_key, 'boolean'],
|
256
|
-
[:hash_set,
|
257
|
+
[:hash_set, 'boolean', true],
|
257
258
|
[:hash_end],
|
258
259
|
[:add_value, {}]], handler.calls)
|
259
260
|
end
|
@@ -320,8 +321,7 @@ class ScpTest < Minitest::Test
|
|
320
321
|
end
|
321
322
|
|
322
323
|
def test_pipe
|
323
|
-
|
324
|
-
return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
324
|
+
skip 'needs fork' unless Process.respond_to?(:fork)
|
325
325
|
|
326
326
|
handler = AllHandler.new()
|
327
327
|
json = %{{"one":true,"two":false}}
|
@@ -347,18 +347,15 @@ class ScpTest < Minitest::Test
|
|
347
347
|
end
|
348
348
|
|
349
349
|
def test_bad_bignum
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
Oj.sc_parse(handler, json)
|
355
|
-
end
|
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)
|
356
354
|
end
|
357
355
|
end
|
358
356
|
|
359
357
|
def test_pipe_close
|
360
|
-
|
361
|
-
return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
358
|
+
skip 'needs fork' unless Process.respond_to?(:fork)
|
362
359
|
|
363
360
|
json = %{{"one":true,"two":false}}
|
364
361
|
IO.pipe do |read_io, write_io|
|
@@ -372,7 +369,7 @@ class ScpTest < Minitest::Test
|
|
372
369
|
rescue Exception => e
|
373
370
|
err = e.class.to_s
|
374
371
|
end
|
375
|
-
assert_equal(
|
372
|
+
assert_equal('IOError', err)
|
376
373
|
assert_equal([[:hash_start],
|
377
374
|
[:hash_key, 'one'],
|
378
375
|
[:hash_set, 'one', true]], handler.calls)
|
@@ -381,8 +378,8 @@ class ScpTest < Minitest::Test
|
|
381
378
|
write_io.write json[0..11]
|
382
379
|
sleep(0.1)
|
383
380
|
begin
|
384
|
-
write_io.write json[12
|
385
|
-
rescue Exception
|
381
|
+
write_io.write json[12..]
|
382
|
+
rescue Exception
|
386
383
|
# ignore, should fail to write
|
387
384
|
end
|
388
385
|
write_io.close
|
@@ -399,15 +396,16 @@ class ScpTest < Minitest::Test
|
|
399
396
|
# Not able to open a socket to run the test. Might be Travis.
|
400
397
|
return
|
401
398
|
end
|
402
|
-
Thread.start(json) do |
|
399
|
+
Thread.start(json) do |_j|
|
403
400
|
c = server.accept()
|
404
401
|
c.puts json[0..11]
|
405
402
|
10.times {
|
406
403
|
break if c.closed?
|
404
|
+
|
407
405
|
sleep(0.1)
|
408
406
|
}
|
409
407
|
unless c.closed?
|
410
|
-
c.puts json[12
|
408
|
+
c.puts json[12..]
|
411
409
|
c.close
|
412
410
|
end
|
413
411
|
end
|
@@ -424,7 +422,7 @@ class ScpTest < Minitest::Test
|
|
424
422
|
rescue Exception => e
|
425
423
|
err = e.class.to_s
|
426
424
|
end
|
427
|
-
assert_equal(
|
425
|
+
assert_equal('IOError', err)
|
428
426
|
assert_equal([[:hash_start],
|
429
427
|
[:hash_key, 'one'],
|
430
428
|
[:hash_set, 'one', true]], handler.calls)
|