oj 3.13.23 → 3.16.9

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 (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -0
  3. data/README.md +2 -2
  4. data/ext/oj/buf.h +7 -6
  5. data/ext/oj/cache.c +29 -26
  6. data/ext/oj/cache.h +3 -2
  7. data/ext/oj/cache8.c +10 -9
  8. data/ext/oj/circarray.c +7 -5
  9. data/ext/oj/circarray.h +2 -2
  10. data/ext/oj/code.c +5 -12
  11. data/ext/oj/code.h +2 -2
  12. data/ext/oj/compat.c +20 -60
  13. data/ext/oj/custom.c +26 -59
  14. data/ext/oj/debug.c +3 -9
  15. data/ext/oj/dump.c +103 -53
  16. data/ext/oj/dump.h +1 -4
  17. data/ext/oj/dump_compat.c +557 -592
  18. data/ext/oj/dump_leaf.c +3 -5
  19. data/ext/oj/dump_object.c +42 -48
  20. data/ext/oj/dump_strict.c +10 -22
  21. data/ext/oj/encoder.c +1 -1
  22. data/ext/oj/err.c +2 -13
  23. data/ext/oj/err.h +9 -12
  24. data/ext/oj/extconf.rb +16 -7
  25. data/ext/oj/fast.c +60 -92
  26. data/ext/oj/intern.c +62 -47
  27. data/ext/oj/intern.h +3 -7
  28. data/ext/oj/mem.c +318 -0
  29. data/ext/oj/mem.h +53 -0
  30. data/ext/oj/mimic_json.c +51 -32
  31. data/ext/oj/object.c +33 -43
  32. data/ext/oj/odd.c +8 -6
  33. data/ext/oj/odd.h +4 -4
  34. data/ext/oj/oj.c +243 -212
  35. data/ext/oj/oj.h +83 -81
  36. data/ext/oj/parse.c +94 -148
  37. data/ext/oj/parse.h +21 -24
  38. data/ext/oj/parser.c +80 -67
  39. data/ext/oj/parser.h +7 -8
  40. data/ext/oj/rails.c +70 -92
  41. data/ext/oj/reader.c +9 -14
  42. data/ext/oj/reader.h +4 -2
  43. data/ext/oj/resolve.c +3 -4
  44. data/ext/oj/rxclass.c +6 -5
  45. data/ext/oj/rxclass.h +1 -1
  46. data/ext/oj/saj.c +10 -9
  47. data/ext/oj/saj2.c +37 -49
  48. data/ext/oj/saj2.h +1 -1
  49. data/ext/oj/scp.c +3 -14
  50. data/ext/oj/sparse.c +22 -70
  51. data/ext/oj/stream_writer.c +45 -41
  52. data/ext/oj/strict.c +20 -52
  53. data/ext/oj/string_writer.c +64 -38
  54. data/ext/oj/trace.h +31 -4
  55. data/ext/oj/usual.c +125 -114
  56. data/ext/oj/usual.h +7 -6
  57. data/ext/oj/util.h +1 -1
  58. data/ext/oj/val_stack.c +13 -2
  59. data/ext/oj/val_stack.h +8 -7
  60. data/ext/oj/wab.c +25 -57
  61. data/lib/oj/active_support_helper.rb +1 -3
  62. data/lib/oj/bag.rb +7 -1
  63. data/lib/oj/easy_hash.rb +4 -5
  64. data/lib/oj/error.rb +0 -1
  65. data/lib/oj/json.rb +162 -150
  66. data/lib/oj/mimic.rb +7 -7
  67. data/lib/oj/schandler.rb +5 -4
  68. data/lib/oj/state.rb +8 -5
  69. data/lib/oj/version.rb +1 -2
  70. data/lib/oj.rb +2 -0
  71. data/pages/InstallOptions.md +20 -0
  72. data/pages/Options.md +4 -0
  73. data/test/_test_active.rb +8 -9
  74. data/test/_test_active_mimic.rb +7 -8
  75. data/test/_test_mimic_rails.rb +17 -20
  76. data/test/activerecord/result_test.rb +5 -6
  77. data/test/activesupport6/encoding_test.rb +63 -28
  78. data/test/activesupport7/abstract_unit.rb +4 -1
  79. data/test/activesupport7/encoding_test.rb +72 -22
  80. data/test/files.rb +15 -15
  81. data/test/foo.rb +18 -69
  82. data/test/helper.rb +5 -8
  83. data/test/isolated/shared.rb +3 -2
  84. data/test/json_gem/json_addition_test.rb +2 -2
  85. data/test/json_gem/json_common_interface_test.rb +8 -6
  86. data/test/json_gem/json_encoding_test.rb +0 -0
  87. data/test/json_gem/json_ext_parser_test.rb +1 -0
  88. data/test/json_gem/json_fixtures_test.rb +3 -2
  89. data/test/json_gem/json_generator_test.rb +50 -33
  90. data/test/json_gem/json_generic_object_test.rb +11 -11
  91. data/test/json_gem/json_parser_test.rb +46 -46
  92. data/test/json_gem/json_string_matching_test.rb +9 -9
  93. data/test/mem.rb +13 -12
  94. data/test/perf.rb +21 -26
  95. data/test/perf_compat.rb +31 -33
  96. data/test/perf_dump.rb +28 -28
  97. data/test/perf_fast.rb +80 -82
  98. data/test/perf_file.rb +27 -29
  99. data/test/perf_object.rb +65 -69
  100. data/test/perf_once.rb +12 -11
  101. data/test/perf_parser.rb +42 -48
  102. data/test/perf_saj.rb +46 -54
  103. data/test/perf_scp.rb +57 -69
  104. data/test/perf_simple.rb +41 -39
  105. data/test/perf_strict.rb +68 -70
  106. data/test/perf_wab.rb +67 -69
  107. data/test/prec.rb +5 -5
  108. data/test/sample/change.rb +0 -1
  109. data/test/sample/dir.rb +0 -1
  110. data/test/sample/doc.rb +0 -1
  111. data/test/sample/file.rb +0 -1
  112. data/test/sample/group.rb +0 -1
  113. data/test/sample/hasprops.rb +0 -1
  114. data/test/sample/layer.rb +0 -1
  115. data/test/sample/rect.rb +0 -1
  116. data/test/sample/shape.rb +0 -1
  117. data/test/sample/text.rb +0 -1
  118. data/test/sample.rb +16 -16
  119. data/test/sample_json.rb +8 -8
  120. data/test/test_compat.rb +81 -54
  121. data/test/test_custom.rb +63 -52
  122. data/test/test_debian.rb +7 -10
  123. data/test/test_fast.rb +86 -90
  124. data/test/test_file.rb +24 -29
  125. data/test/test_gc.rb +5 -5
  126. data/test/test_generate.rb +5 -5
  127. data/test/test_hash.rb +4 -4
  128. data/test/test_integer_range.rb +9 -9
  129. data/test/test_null.rb +20 -20
  130. data/test/test_object.rb +92 -87
  131. data/test/test_parser.rb +4 -4
  132. data/test/test_parser_debug.rb +5 -5
  133. data/test/test_parser_saj.rb +27 -25
  134. data/test/test_parser_usual.rb +44 -6
  135. data/test/test_rails.rb +2 -2
  136. data/test/test_saj.rb +10 -8
  137. data/test/test_scp.rb +35 -35
  138. data/test/test_strict.rb +38 -32
  139. data/test/test_various.rb +146 -97
  140. data/test/test_wab.rb +46 -44
  141. data/test/test_writer.rb +63 -47
  142. data/test/tests.rb +7 -7
  143. data/test/tests_mimic.rb +6 -6
  144. data/test/tests_mimic_addition.rb +6 -6
  145. metadata +46 -26
  146. data/test/activesupport4/decoding_test.rb +0 -108
  147. data/test/activesupport4/encoding_test.rb +0 -531
  148. data/test/activesupport4/test_helper.rb +0 -41
  149. data/test/activesupport5/abstract_unit.rb +0 -45
  150. data/test/activesupport5/decoding_test.rb +0 -133
  151. data/test/activesupport5/encoding_test.rb +0 -500
  152. data/test/activesupport5/encoding_test_cases.rb +0 -98
  153. data/test/activesupport5/test_helper.rb +0 -72
  154. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
  155. data/test/bar.rb +0 -11
  156. data/test/baz.rb +0 -16
  157. data/test/bug.rb +0 -16
  158. data/test/zoo.rb +0 -13
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
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, 12345, nil]], handler.calls)
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, 12345.6789, nil]], handler.calls)
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,7 @@ 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((12345.6789e7 * 10000).to_i, (handler.calls[0][1] * 10000).to_i)
151
+ assert_equal((12_345.6789e7 * 10_000).to_i, (handler.calls[0][1] * 10_000).to_i)
150
152
  end
151
153
 
152
154
  def test_bignum
@@ -157,7 +159,7 @@ class SajTest < Minitest::Test
157
159
  p.parse(json)
158
160
  assert_equal(1, handler.calls.size)
159
161
  assert_equal(:add_value, handler.calls[0][0])
160
- assert_equal(-118999, (handler.calls[0][1] * 10000).to_i)
162
+ assert_equal(-118_999, (handler.calls[0][1] * 10_000).to_i)
161
163
  end
162
164
 
163
165
  def test_bignum_loc
@@ -175,10 +177,10 @@ class SajTest < Minitest::Test
175
177
  p.handler = handler
176
178
  p.parse(json)
177
179
  assert_equal(6, handler.calls.size)
178
- assert_equal(1_923_380, (handler.calls[1][1] * 10000).to_i)
180
+ assert_equal(1_923_380, (handler.calls[1][1] * 10_000).to_i)
179
181
  handler.calls[1][1] = 1_923_380
180
182
  assert_equal([[:hash_start, nil, 1, 1],
181
- [:add_value, 1923380, 'width', 2, 30],
183
+ [:add_value, 1_923_380, 'width', 2, 30],
182
184
  [:hash_start, 'xaxis', 3, 12],
183
185
  [:add_value, 'y', 'anchor', 4, 17],
184
186
  [:hash_end, 'xaxis', 5, 3],
@@ -260,13 +262,13 @@ class SajTest < Minitest::Test
260
262
  p.handler = handler
261
263
  p.parse(json)
262
264
  assert_equal([
263
- [:array_start, nil],
265
+ [:array_start, nil],
264
266
  [:add_value, true, nil],
265
267
  [:array_end, nil],
266
- [:array_start, nil],
268
+ [:array_start, nil],
267
269
  [:add_value, false, nil],
268
270
  [:array_end, nil],
269
- ], handler.calls)
271
+ ], handler.calls)
270
272
  end
271
273
 
272
274
  def test_io
@@ -276,11 +278,11 @@ class SajTest < Minitest::Test
276
278
  p.handler = handler
277
279
  p.load(StringIO.new(json))
278
280
  assert_equal([
279
- [:array_start, nil],
280
- [:add_value, true, nil],
281
- [:add_value, false, nil],
282
- [:array_end, nil],
283
- ], handler.calls)
281
+ [:array_start, nil],
282
+ [:add_value, true, nil],
283
+ [:add_value, false, nil],
284
+ [:array_end, nil],
285
+ ], handler.calls)
284
286
  end
285
287
 
286
288
  def test_file
@@ -289,11 +291,11 @@ class SajTest < Minitest::Test
289
291
  p.handler = handler
290
292
  p.file('saj_test.json')
291
293
  assert_equal([
292
- [:array_start, nil],
293
- [:add_value, true, nil],
294
- [:add_value, false, nil],
295
- [:array_end, nil],
296
- ], handler.calls)
294
+ [:array_start, nil],
295
+ [:add_value, true, nil],
296
+ [:add_value, false, nil],
297
+ [:array_end, nil],
298
+ ], handler.calls)
297
299
  end
298
300
 
299
301
  def test_default
@@ -302,10 +304,10 @@ class SajTest < Minitest::Test
302
304
  Oj::Parser.saj.handler = handler
303
305
  Oj::Parser.saj.parse(json)
304
306
  assert_equal([
305
- [:array_start, nil],
307
+ [:array_start, nil],
306
308
  [:add_value, true, nil],
307
309
  [:array_end, nil],
308
- ], handler.calls)
310
+ ], handler.calls)
309
311
  end
310
312
 
311
313
  def test_loc
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
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
- assert_equal(false, p.symbol_keys)
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)
@@ -114,6 +114,30 @@ class UsualTest < Minitest::Test
114
114
  assert_equal(Float, doc.class)
115
115
  end
116
116
 
117
+ def test_multi_parse
118
+ p = Oj::Parser.new(:usual)
119
+ out = []
120
+ p.parse('{"a":1}{"b":{"x":2}} {"c":3}') { |j| out.push(j) }
121
+ assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
122
+ end
123
+
124
+ def test_multi_load
125
+ p = Oj::Parser.new(:usual)
126
+ out = []
127
+ r, w = IO.pipe
128
+ thread = Thread.new do
129
+ ['{"a":1}', '{"b":{"x"', ':2}}{"c":', '3}'].each { |seg|
130
+ w.write(seg)
131
+ sleep(0.1)
132
+ }
133
+ w.close
134
+ end
135
+ p.load(r) { |j| out.push(j) }
136
+ r.close
137
+ thread.join
138
+ assert_equal([{'a'=>1}, {'b'=>{'x'=>2}},{'c'=>3}], out)
139
+ end
140
+
117
141
  def test_omit_null
118
142
  p = Oj::Parser.new(:usual)
119
143
  p.omit_null = true
@@ -147,6 +171,16 @@ class UsualTest < Minitest::Test
147
171
  assert_equal(MyHash, doc.class)
148
172
  end
149
173
 
174
+ def test_empty
175
+ p = Oj::Parser.new(:usual)
176
+ p.raise_on_empty = false
177
+ doc = p.parse(' ')
178
+ assert_nil(doc)
179
+
180
+ p.raise_on_empty = true
181
+ assert_raises(Oj::ParseError) { p.parse(' ') }
182
+ end
183
+
150
184
  class MyClass
151
185
  attr_accessor :a
152
186
  attr_accessor :b
@@ -183,6 +217,10 @@ class UsualTest < Minitest::Test
183
217
 
184
218
  doc = p.parse('{"a":true,"^":"UsualTest::MyClass","b":false}')
185
219
  assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
220
+
221
+ p.create_id = 'class'
222
+ doc = p.parse('{"a":true,"class":"UsualTest::MyClass","b":false}')
223
+ assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
186
224
  end
187
225
 
188
226
  def test_missing_class
data/test/test_rails.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
4
+ $LOAD_PATH << __dir__
5
5
 
6
6
  require 'helper'
7
7
 
data/test/test_saj.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
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, 12345, nil]], handler.calls)
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, 12345.6789, nil]], handler.calls)
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((12345.6789e7 * 10000).to_i, (handler.calls[0][1] * 10000).to_i)
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, 12345, nil], handler.calls.first)
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]:\/)?(?:[a-z\.]+/)*saj\.c:\d+\]}, message)
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
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
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(h, key, value)
66
+ def hash_set(_h, key, value)
67
67
  @calls << [:hash_set, key, value]
68
68
  end
69
69
 
70
- def array_append(a, value)
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(h, key, value)
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, 12345]], handler.calls)
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, 12345.6789]], handler.calls)
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((12345.6789e7 * 10000).to_i, (handler.calls[0][1] * 10000).to_i)
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, "num", 3],
234
+ [:hash_set, 'num', 3],
234
235
  [:hash_key, 'string'],
235
- [:hash_set, "string", "message"],
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, "a", []],
247
+ [:hash_set, 'a', []],
247
248
  [:hash_end],
248
- [:hash_set, "h2", {}],
249
+ [:hash_set, 'h2', {}],
249
250
  [:hash_end],
250
- [:hash_set, "hash", {}],
251
+ [:hash_set, 'hash', {}],
251
252
  [:hash_end],
252
253
  [:array_append, {}],
253
254
  [:array_end],
254
- [:hash_set, "array", []],
255
+ [:hash_set, 'array', []],
255
256
  [:hash_key, 'boolean'],
256
- [:hash_set, "boolean", true],
257
+ [:hash_set, 'boolean', true],
257
258
  [:hash_end],
258
259
  [:add_value, {}]], handler.calls)
259
260
  end
@@ -346,12 +347,10 @@ class ScpTest < Minitest::Test
346
347
  end
347
348
 
348
349
  def test_bad_bignum
349
- if '2.4.0' < RUBY_VERSION
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
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)
355
354
  end
356
355
  end
357
356
 
@@ -370,7 +369,7 @@ class ScpTest < Minitest::Test
370
369
  rescue Exception => e
371
370
  err = e.class.to_s
372
371
  end
373
- assert_equal("IOError", err)
372
+ assert_equal('IOError', err)
374
373
  assert_equal([[:hash_start],
375
374
  [:hash_key, 'one'],
376
375
  [:hash_set, 'one', true]], handler.calls)
@@ -379,8 +378,8 @@ class ScpTest < Minitest::Test
379
378
  write_io.write json[0..11]
380
379
  sleep(0.1)
381
380
  begin
382
- write_io.write json[12..-1]
383
- rescue Exception => e
381
+ write_io.write json[12..]
382
+ rescue Exception
384
383
  # ignore, should fail to write
385
384
  end
386
385
  write_io.close
@@ -397,15 +396,16 @@ class ScpTest < Minitest::Test
397
396
  # Not able to open a socket to run the test. Might be Travis.
398
397
  return
399
398
  end
400
- Thread.start(json) do |j|
399
+ Thread.start(json) do |_j|
401
400
  c = server.accept()
402
401
  c.puts json[0..11]
403
402
  10.times {
404
403
  break if c.closed?
404
+
405
405
  sleep(0.1)
406
406
  }
407
407
  unless c.closed?
408
- c.puts json[12..-1]
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("IOError", err)
425
+ assert_equal('IOError', err)
426
426
  assert_equal([[:hash_start],
427
427
  [:hash_key, 'one'],
428
428
  [:hash_set, 'one', true]], handler.calls)