oj 3.13.17 → 3.16.3
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 +77 -0
- data/README.md +4 -2
- data/ext/oj/buf.h +7 -6
- data/ext/oj/cache.c +29 -26
- data/ext/oj/cache.h +3 -2
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +7 -5
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +5 -12
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +20 -60
- data/ext/oj/custom.c +44 -96
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +69 -39
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +557 -592
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +42 -48
- data/ext/oj/dump_strict.c +10 -22
- 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 +16 -6
- data/ext/oj/fast.c +76 -106
- data/ext/oj/intern.c +63 -51
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +43 -30
- data/ext/oj/object.c +61 -70
- data/ext/oj/odd.c +8 -6
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +243 -205
- data/ext/oj/oj.h +82 -78
- data/ext/oj/parse.c +123 -188
- data/ext/oj/parse.h +23 -24
- data/ext/oj/parser.c +103 -63
- data/ext/oj/parser.h +19 -9
- data/ext/oj/rails.c +68 -92
- data/ext/oj/reader.c +10 -15
- 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 +10 -9
- data/ext/oj/saj2.c +74 -92
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +22 -70
- data/ext/oj/stream_writer.c +43 -35
- data/ext/oj/strict.c +20 -52
- data/ext/oj/string_writer.c +60 -34
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +125 -150
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +14 -3
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/wab.c +25 -57
- data/lib/oj/active_support_helper.rb +1 -3
- 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 +162 -150
- data/lib/oj/mimic.rb +6 -2
- 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/files.rb +15 -15
- data/test/foo.rb +9 -72
- 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 +8 -6
- 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 +53 -37
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +47 -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 +28 -28
- 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 +5 -5
- 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 +80 -53
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +86 -90
- data/test/test_file.rb +28 -35
- 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 +94 -96
- data/test/test_parser.rb +6 -22
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +61 -22
- data/test/test_parser_usual.rb +16 -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 +40 -32
- data/test/test_various.rb +148 -100
- 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 +36 -27
- 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/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
- 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_parser_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)
|
@@ -56,7 +58,7 @@ end # AllSaj
|
|
56
58
|
class LocSaj
|
57
59
|
attr_accessor :calls
|
58
60
|
|
59
|
-
def initialize
|
61
|
+
def initialize
|
60
62
|
@calls = []
|
61
63
|
end
|
62
64
|
|
@@ -126,7 +128,7 @@ class SajTest < Minitest::Test
|
|
126
128
|
p = Oj::Parser.new(:saj)
|
127
129
|
p.handler = handler
|
128
130
|
p.parse(json)
|
129
|
-
assert_equal([[:add_value,
|
131
|
+
assert_equal([[:add_value, 12_345, nil]], handler.calls)
|
130
132
|
end
|
131
133
|
|
132
134
|
def test_float
|
@@ -135,7 +137,7 @@ class SajTest < Minitest::Test
|
|
135
137
|
p = Oj::Parser.new(:saj)
|
136
138
|
p.handler = handler
|
137
139
|
p.parse(json)
|
138
|
-
assert_equal([[:add_value,
|
140
|
+
assert_equal([[:add_value, 12_345.6789, nil]], handler.calls)
|
139
141
|
end
|
140
142
|
|
141
143
|
def test_float_exp
|
@@ -146,7 +148,44 @@ class SajTest < Minitest::Test
|
|
146
148
|
p.parse(json)
|
147
149
|
assert_equal(1, handler.calls.size)
|
148
150
|
assert_equal(:add_value, handler.calls[0][0])
|
149
|
-
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)
|
150
189
|
end
|
151
190
|
|
152
191
|
def test_array_empty
|
@@ -223,13 +262,13 @@ class SajTest < Minitest::Test
|
|
223
262
|
p.handler = handler
|
224
263
|
p.parse(json)
|
225
264
|
assert_equal([
|
226
|
-
|
265
|
+
[:array_start, nil],
|
227
266
|
[:add_value, true, nil],
|
228
267
|
[:array_end, nil],
|
229
|
-
|
268
|
+
[:array_start, nil],
|
230
269
|
[:add_value, false, nil],
|
231
270
|
[:array_end, nil],
|
232
|
-
|
271
|
+
], handler.calls)
|
233
272
|
end
|
234
273
|
|
235
274
|
def test_io
|
@@ -239,11 +278,11 @@ class SajTest < Minitest::Test
|
|
239
278
|
p.handler = handler
|
240
279
|
p.load(StringIO.new(json))
|
241
280
|
assert_equal([
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
281
|
+
[:array_start, nil],
|
282
|
+
[:add_value, true, nil],
|
283
|
+
[:add_value, false, nil],
|
284
|
+
[:array_end, nil],
|
285
|
+
], handler.calls)
|
247
286
|
end
|
248
287
|
|
249
288
|
def test_file
|
@@ -252,11 +291,11 @@ class SajTest < Minitest::Test
|
|
252
291
|
p.handler = handler
|
253
292
|
p.file('saj_test.json')
|
254
293
|
assert_equal([
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
294
|
+
[:array_start, nil],
|
295
|
+
[:add_value, true, nil],
|
296
|
+
[:add_value, false, nil],
|
297
|
+
[:array_end, nil],
|
298
|
+
], handler.calls)
|
260
299
|
end
|
261
300
|
|
262
301
|
def test_default
|
@@ -265,10 +304,10 @@ class SajTest < Minitest::Test
|
|
265
304
|
Oj::Parser.saj.handler = handler
|
266
305
|
Oj::Parser.saj.parse(json)
|
267
306
|
assert_equal([
|
268
|
-
|
307
|
+
[:array_start, nil],
|
269
308
|
[:add_value, true, nil],
|
270
309
|
[:array_end, nil],
|
271
|
-
|
310
|
+
], handler.calls)
|
272
311
|
end
|
273
312
|
|
274
313
|
def test_loc
|
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)
|
@@ -147,6 +147,16 @@ class UsualTest < Minitest::Test
|
|
147
147
|
assert_equal(MyHash, doc.class)
|
148
148
|
end
|
149
149
|
|
150
|
+
def test_empty
|
151
|
+
p = Oj::Parser.new(:usual)
|
152
|
+
p.raise_on_empty = false
|
153
|
+
doc = p.parse(' ')
|
154
|
+
assert_nil(doc)
|
155
|
+
|
156
|
+
p.raise_on_empty = true
|
157
|
+
assert_raises(Oj::ParseError) { p.parse(' ') }
|
158
|
+
end
|
159
|
+
|
150
160
|
class MyClass
|
151
161
|
attr_accessor :a
|
152
162
|
attr_accessor :b
|
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)
|