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
data/test/test_wab.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
5
- $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
4
+ $LOAD_PATH << __dir__
5
+ @oj_dir = File.dirname(File.expand_path(__dir__))
6
6
  %w(lib ext).each do |dir|
7
- $: << File.join($oj_dir, dir)
7
+ $LOAD_PATH << File.join(@oj_dir, dir)
8
8
  end
9
9
 
10
10
  require 'minitest'
@@ -19,20 +19,22 @@ require 'oj'
19
19
  module WAB
20
20
  class UUID
21
21
  attr_reader :id
22
+
22
23
  def initialize(id)
23
24
  @id = id.downcase
24
- raise Exception.new("Invalid UUID format.") if /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.match(@id).nil?
25
+ raise StandardError.new('Invalid UUID format.') if /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.match(@id).nil?
25
26
  end
27
+
26
28
  def to_s
27
29
  @id
28
30
  end
31
+
29
32
  def ==(other)
30
33
  other.is_a?(self.class) && @id == other.id
31
34
  end
32
35
  end # UUID
33
36
  end # WAB
34
37
 
35
-
36
38
  class WabJuice < Minitest::Test
37
39
 
38
40
  module TestModule
@@ -52,16 +54,16 @@ class WabJuice < Minitest::Test
52
54
 
53
55
  def test_fixnum
54
56
  dump_and_load(0, false)
55
- dump_and_load(12345, false)
56
- dump_and_load(-54321, false)
57
+ dump_and_load(12_345, false)
58
+ dump_and_load(-54_321, false)
57
59
  dump_and_load(1, false)
58
60
  end
59
61
 
60
62
  def test_float
61
63
  dump_and_load(0.0, false)
62
- dump_and_load(12345.6789, false)
64
+ dump_and_load(12_345.6789, false)
63
65
  dump_and_load(70.35, false)
64
- dump_and_load(-54321.012, false)
66
+ dump_and_load(-54_321.012, false)
65
67
  dump_and_load(1.7775, false)
66
68
  dump_and_load(2.5024, false)
67
69
  dump_and_load(2.48e16, false)
@@ -89,7 +91,7 @@ class WabJuice < Minitest::Test
89
91
  end
90
92
 
91
93
  def test_encode
92
- dump_and_load("ぴーたー", false)
94
+ dump_and_load('ぴーたー', false)
93
95
  end
94
96
 
95
97
  def test_array
@@ -101,25 +103,25 @@ class WabJuice < Minitest::Test
101
103
  end
102
104
 
103
105
  def test_array_deep
104
- dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
106
+ dump_and_load([1, [2, [3, [4, [5, [6, [7, [8, [9, [10, [11, [12, [13, [14, [15, [16, [17, [18, [19, [20]]]]]]]]]]]]]]]]]]]], false)
105
107
  end
106
108
 
107
109
  def test_deep_nest
108
110
  skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'
109
111
 
110
112
  begin
111
- n = 10000
112
- Oj.wab_load('[' * n + ']' * n)
113
+ n = 10_000
114
+ Oj.wab_load(('[' * n) + (']' * n))
113
115
  rescue Exception => e
114
- assert(false, e.message)
116
+ refute(e.message)
115
117
  end
116
118
  end
117
119
 
118
120
  # Hash
119
121
  def test_hash
120
122
  dump_and_load({}, false)
121
- dump_and_load({ true: true, false: false}, false)
122
- dump_and_load({ true: true, array: [], hash: { }}, false)
123
+ dump_and_load({ tru: true, fals: false}, false)
124
+ dump_and_load({ tru: true, array: [], hash: {}}, false)
123
125
  end
124
126
 
125
127
  def test_hash_non_sym_keys
@@ -128,25 +130,25 @@ class WabJuice < Minitest::Test
128
130
 
129
131
  def test_hash_deep
130
132
  dump_and_load({x1: {
131
- x2: {
132
- x3: {
133
- x4: {
134
- x5: {
135
- x6: {
136
- x7: {
137
- x8: {
138
- x9: {
139
- x10: {
140
- x11: {
141
- x12: {
142
- x13: {
143
- x14: {
144
- x15: {
145
- x16: {
146
- x17: {
147
- x18: {
148
- x19: {
149
- x20: {}}}}}}}}}}}}}}}}}}}}}, false)
133
+ x2: {
134
+ x3: {
135
+ x4: {
136
+ x5: {
137
+ x6: {
138
+ x7: {
139
+ x8: {
140
+ x9: {
141
+ x10: {
142
+ x11: {
143
+ x12: {
144
+ x13: {
145
+ x14: {
146
+ x15: {
147
+ x16: {
148
+ x17: {
149
+ x18: {
150
+ x19: {
151
+ x20: {}}}}}}}}}}}}}}}}}}}}}, false)
150
152
  end
151
153
 
152
154
  def test_non_str_hash
@@ -154,7 +156,7 @@ class WabJuice < Minitest::Test
154
156
  end
155
157
 
156
158
  def test_bignum_object
157
- dump_and_load(7 ** 55, false)
159
+ dump_and_load(7**55, false)
158
160
  end
159
161
 
160
162
  # BigDecimal
@@ -188,13 +190,13 @@ class WabJuice < Minitest::Test
188
190
  end
189
191
 
190
192
  def test_io_file
191
- filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
192
- File.open(filename, 'w') { |f| f.write(%{{
193
+ filename = File.join(__dir__, 'open_file_test.json')
194
+ File.write(filename, %{{
193
195
  "x":true,
194
196
  "y":58,
195
197
  "z": [1,2,3]
196
198
  }
197
- }) }
199
+ })
198
200
  f = File.new(filename)
199
201
  obj = Oj.wab_load(f)
200
202
  f.close()
@@ -207,13 +209,13 @@ class WabJuice < Minitest::Test
207
209
  end
208
210
 
209
211
  def test_time
210
- t = Time.gm(2017, 1, 5, 23, 58, 7, 123456.789)
212
+ t = Time.gm(2017, 1, 5, 23, 58, 7, 123_456.789)
211
213
  json = Oj.dump(t, mode: :wab)
212
214
  assert_equal('"2017-01-05T23:58:07.123456789Z"', json)
213
215
  # must load and convert to json as the Time#== does not match identical
214
216
  # times due to the way it tracks fractional seconds.
215
- loaded = Oj.wab_load(json);
216
- assert_equal(json, Oj.dump(loaded, mode: :wab), "json mismatch after load")
217
+ loaded = Oj.wab_load(json)
218
+ assert_equal(json, Oj.dump(loaded, mode: :wab), 'json mismatch after load')
217
219
  end
218
220
 
219
221
  def test_uuid
@@ -297,7 +299,7 @@ class WabJuice < Minitest::Test
297
299
  def dump_and_load(obj, trace=false)
298
300
  json = Oj.dump(obj, mode: :wab, indent: 2)
299
301
  puts json if trace
300
- loaded = Oj.wab_load(json);
302
+ loaded = Oj.wab_load(json)
301
303
  if obj.nil?
302
304
  assert_nil(loaded)
303
305
  else
data/test/test_writer.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+ # frozen_string_literal: false
3
3
 
4
- $: << File.dirname(__FILE__)
4
+ $LOAD_PATH << __dir__
5
5
 
6
6
  require 'helper'
7
+ require 'open3'
7
8
 
8
9
  class OjWriter < Minitest::Test
9
10
 
@@ -55,13 +56,13 @@ class OjWriter < Minitest::Test
55
56
  def test_string_writer_nested_object
56
57
  w = Oj::StringWriter.new(:indent => 0)
57
58
  w.push_object()
58
- w.push_object("a1")
59
+ w.push_object('a1')
59
60
  w.pop()
60
- w.push_object("a2")
61
- w.push_object("b")
61
+ w.push_object('a2')
62
+ w.push_object('b')
62
63
  w.pop()
63
64
  w.pop()
64
- w.push_object("a3")
65
+ w.push_object('a3')
65
66
  w.pop()
66
67
  w.pop()
67
68
  assert_equal(%|{"a1":{},"a2":{"b":{}},"a3":{}}\n|, w.to_s)
@@ -94,9 +95,9 @@ class OjWriter < Minitest::Test
94
95
  w.push_value(7.3)
95
96
  w.push_value(true)
96
97
  w.push_value(nil)
97
- w.push_value("a string")
98
+ w.push_value('a string')
98
99
  w.push_value({'a' => 65})
99
- w.push_value([1,2])
100
+ w.push_value([1, 2])
100
101
  w.pop()
101
102
  assert_equal(%|[
102
103
  7,
@@ -118,10 +119,10 @@ class OjWriter < Minitest::Test
118
119
  def test_string_writer_block
119
120
  w = Oj::StringWriter.new(:indent => 0)
120
121
  w.push_object() {
121
- w.push_object("a1") {
122
+ w.push_object('a1') {
122
123
  w.push_value(7, 'a7')
123
124
  }
124
- w.push_array("a2") {
125
+ w.push_array('a2') {
125
126
  w.push_value('x')
126
127
  w.push_value(3)
127
128
  }
@@ -152,7 +153,7 @@ class OjWriter < Minitest::Test
152
153
  assert(true)
153
154
  return
154
155
  end
155
- assert(false, "*** expected an exception")
156
+ assert(false, '*** expected an exception')
156
157
  end
157
158
 
158
159
  def test_string_writer_array_key
@@ -166,7 +167,7 @@ class OjWriter < Minitest::Test
166
167
  assert(true)
167
168
  return
168
169
  end
169
- assert(false, "*** expected an exception")
170
+ assert(false, '*** expected an exception')
170
171
  end
171
172
 
172
173
  def test_string_writer_pop_with_key
@@ -177,7 +178,7 @@ class OjWriter < Minitest::Test
177
178
  assert(true)
178
179
  return
179
180
  end
180
- assert(false, "*** expected an exception")
181
+ assert(false, '*** expected an exception')
181
182
  end
182
183
 
183
184
  def test_string_writer_obj_no_key
@@ -189,7 +190,7 @@ class OjWriter < Minitest::Test
189
190
  assert(true)
190
191
  return
191
192
  end
192
- assert(false, "*** expected an exception")
193
+ assert(false, '*** expected an exception')
193
194
  end
194
195
 
195
196
  def test_string_writer_deep
@@ -208,9 +209,9 @@ class OjWriter < Minitest::Test
208
209
  def test_string_writer_pop_all
209
210
  w = Oj::StringWriter.new(:indent => 0)
210
211
  w.push_object()
211
- w.push_object("a1")
212
+ w.push_object('a1')
212
213
  w.pop()
213
- w.push_array("a2")
214
+ w.push_array('a2')
214
215
  w.push_value(3)
215
216
  w.push_array()
216
217
  w.pop_all()
@@ -228,23 +229,23 @@ class OjWriter < Minitest::Test
228
229
  # Stream Writer
229
230
 
230
231
  class SString < ::String
231
- alias :write :concat
232
+ alias write concat
232
233
  end
233
-
234
+
234
235
  def test_stream_writer_encoding
235
236
  output = SString.new.force_encoding(::Encoding::UTF_8)
236
237
  w = Oj::StreamWriter.new(output, :indent => 0)
237
238
  # Oddly enough, when pushing ASCII characters with UTF-8 encoding or even
238
239
  # ASCII-8BIT does not change the output encoding. Pushing any non-ASCII no
239
240
  # matter what the encoding changes the output encoding to ASCII-8BIT.
240
- x = "香港" # Hong Kong
241
+ x = '香港' # Hong Kong
241
242
  x = x.force_encoding('ASCII-8BIT')
242
243
  w.push_value(x)
243
244
  assert_equal(::Encoding::UTF_8, output.encoding)
244
245
  end
245
246
 
246
247
  def test_stream_writer_empty_array
247
- output = StringIO.open("", "w+")
248
+ output = StringIO.open('', 'w+')
248
249
  w = Oj::StreamWriter.new(output, :indent => 0)
249
250
  w.push_array()
250
251
  w.pop()
@@ -252,19 +253,19 @@ class OjWriter < Minitest::Test
252
253
  end
253
254
 
254
255
  def test_stream_writer_mixed_stringio
255
- output = StringIO.open("", "w+")
256
+ output = StringIO.open('', 'w+')
256
257
  w = Oj::StreamWriter.new(output, :indent => 0)
257
258
  w.push_object()
258
- w.push_object("a1")
259
+ w.push_object('a1')
259
260
  w.pop()
260
- w.push_object("a2")
261
- w.push_array("b")
261
+ w.push_object('a2')
262
+ w.push_array('b')
262
263
  w.push_value(7)
263
264
  w.push_value(true)
264
- w.push_value("string")
265
+ w.push_value('string')
265
266
  w.pop()
266
267
  w.pop()
267
- w.push_object("a3")
268
+ w.push_object('a3')
268
269
  w.pop()
269
270
  w.pop()
270
271
  result = output.string()
@@ -272,20 +273,20 @@ class OjWriter < Minitest::Test
272
273
  end
273
274
 
274
275
  def test_stream_writer_mixed_file
275
- filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
276
- File.open(filename, "w") do |f|
276
+ filename = File.join(__dir__, 'open_file_test.json')
277
+ File.open(filename, 'w') do |f|
277
278
  w = Oj::StreamWriter.new(f, :indent => 0)
278
279
  w.push_object()
279
- w.push_object("a1")
280
+ w.push_object('a1')
280
281
  w.pop()
281
- w.push_object("a2")
282
- w.push_array("b")
282
+ w.push_object('a2')
283
+ w.push_array('b')
283
284
  w.push_value(7)
284
285
  w.push_value(true)
285
- w.push_value("string")
286
+ w.push_value('string')
286
287
  w.pop()
287
288
  w.pop()
288
- w.push_object("a3")
289
+ w.push_object('a3')
289
290
  w.pop()
290
291
  w.pop()
291
292
  end
@@ -294,7 +295,7 @@ class OjWriter < Minitest::Test
294
295
  end
295
296
 
296
297
  def test_stream_writer_nested_key_object
297
- output = StringIO.open("", "w+")
298
+ output = StringIO.open('', 'w+')
298
299
  w = Oj::StreamWriter.new(output, :indent => 0)
299
300
  w.push_object()
300
301
  w.push_key('a1')
@@ -316,16 +317,16 @@ class OjWriter < Minitest::Test
316
317
 
317
318
  def push_stuff(w, pop_all=true)
318
319
  w.push_object()
319
- w.push_object("a1")
320
+ w.push_object('a1')
320
321
  w.pop()
321
- w.push_object("a2")
322
- w.push_array("b")
322
+ w.push_object('a2')
323
+ w.push_array('b')
323
324
  w.push_value(7)
324
325
  w.push_value(true)
325
- w.push_value("string")
326
+ w.push_value('string')
326
327
  w.pop()
327
328
  w.pop()
328
- w.push_object("a3")
329
+ w.push_object('a3')
329
330
  if pop_all
330
331
  w.pop_all()
331
332
  else
@@ -335,31 +336,31 @@ class OjWriter < Minitest::Test
335
336
  end
336
337
 
337
338
  def test_stream_writer_buf_small
338
- output = StringIO.open("", "w+")
339
+ output = StringIO.open('', 'w+')
339
340
  w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 20)
340
341
  push_stuff(w)
341
342
  assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
342
343
  end
343
344
 
344
345
  def test_stream_writer_buf_large
345
- output = StringIO.open("", "w+")
346
- w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 16000)
346
+ output = StringIO.open('', 'w+')
347
+ w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 16_000)
347
348
  push_stuff(w)
348
349
  assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
349
350
  end
350
351
 
351
352
  def test_stream_writer_buf_flush
352
- output = StringIO.open("", "w+")
353
+ output = StringIO.open('', 'w+')
353
354
  w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 4096)
354
355
  push_stuff(w, false)
355
356
  # no flush so nothing should be in the output yet
356
- assert_equal("", output.string())
357
+ assert_equal('', output.string())
357
358
  w.flush()
358
359
  assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
359
360
  end
360
-
361
+
361
362
  def test_stream_writer_buf_flush_small
362
- output = StringIO.open("", "w+")
363
+ output = StringIO.open('', 'w+')
363
364
  w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 30)
364
365
  push_stuff(w, false)
365
366
  # flush should be called at 30 bytes but since the writes are chunky flush
@@ -370,11 +371,26 @@ class OjWriter < Minitest::Test
370
371
  end
371
372
 
372
373
  def test_stream_writer_push_null_value_with_key
373
- output = StringIO.open("", "w+")
374
+ output = StringIO.open('', 'w+')
374
375
  w = Oj::StreamWriter.new(output, :indent => 0)
375
376
  w.push_object()
376
377
  w.push_value(nil, 'nothing')
377
378
  w.pop()
378
379
  assert_equal(%|{"nothing":null}\n|, output.string())
379
380
  end
381
+
382
+ def test_stream_writer_subprocess
383
+ skip if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
384
+
385
+ Open3.popen3("/bin/bash", "-c", "cat > /dev/null") do |stdin, _stdout, _stderr, _wait_thr|
386
+ w = Oj::StreamWriter.new(stdin, :indent => 0)
387
+ w.push_array()
388
+ chunk = "{\"foo\":\"#{"bar"*1000}\"}"
389
+ 1000.times do |_|
390
+ w.push_json(chunk)
391
+ end
392
+ w.pop()
393
+ stdin.close
394
+ end
395
+ end
380
396
  end # OjWriter
data/test/tests.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
5
- $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
4
+ $LOAD_PATH << __dir__
5
+ @oj_dir = File.dirname(File.expand_path(__dir__))
6
6
  %w(lib ext).each do |dir|
7
- $: << File.join($oj_dir, dir)
7
+ $LOAD_PATH << File.join(@oj_dir, dir)
8
8
  end
9
9
 
10
10
  require 'test_compat'
@@ -25,9 +25,9 @@ require 'test_integer_range'
25
25
 
26
26
  at_exit do
27
27
  require 'helper'
28
- if '3.1.0' <= RUBY_VERSION && !(RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/)
29
- #Oj::debug_odd("teardown before GC.verify_compaction_references")
28
+ if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
29
+ # Oj::debug_odd("teardown before GC.verify_compaction_references")
30
30
  verify_gc_compaction
31
- #Oj::debug_odd("teardown after GC.verify_compaction_references")
31
+ # Oj::debug_odd("teardown after GC.verify_compaction_references")
32
32
  end
33
33
  end
data/test/tests_mimic.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
5
- $: << File.join(File.dirname(__FILE__), 'json_gem')
4
+ $LOAD_PATH << __dir__
5
+ $LOAD_PATH << File.join(__dir__, 'json_gem')
6
6
 
7
7
  require 'json_common_interface_test'
8
8
  require 'json_encoding_test'
@@ -15,9 +15,9 @@ require 'json_string_matching_test'
15
15
 
16
16
  at_exit do
17
17
  require 'helper'
18
- if '3.1.0' <= RUBY_VERSION && !(RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/)
19
- #Oj::debug_odd("teardown before GC.verify_compaction_references")
18
+ if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
19
+ # Oj::debug_odd("teardown before GC.verify_compaction_references")
20
20
  verify_gc_compaction
21
- #Oj::debug_odd("teardown after GC.verify_compaction_references")
21
+ # Oj::debug_odd("teardown after GC.verify_compaction_references")
22
22
  end
23
23
  end
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << File.dirname(__FILE__)
5
- $: << File.join(File.dirname(__FILE__), 'json_gem')
4
+ $LOAD_PATH << __dir__
5
+ $LOAD_PATH << File.join(__dir__, 'json_gem')
6
6
 
7
7
  require 'json_addition_test'
8
8
 
9
9
  at_exit do
10
10
  require 'helper'
11
- if '3.1.0' <= RUBY_VERSION && !(RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/)
12
- #Oj::debug_odd("teardown before GC.verify_compaction_references")
11
+ if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
12
+ # Oj::debug_odd("teardown before GC.verify_compaction_references")
13
13
  verify_gc_compaction
14
- #Oj::debug_odd("teardown after GC.verify_compaction_references")
14
+ # Oj::debug_odd("teardown after GC.verify_compaction_references")
15
15
  end
16
16
  end