oj 3.14.3 → 3.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/ext/oj/code.c +3 -10
  4. data/ext/oj/compat.c +5 -18
  5. data/ext/oj/custom.c +10 -28
  6. data/ext/oj/dump.c +40 -10
  7. data/ext/oj/dump.h +1 -4
  8. data/ext/oj/extconf.rb +4 -2
  9. data/ext/oj/fast.c +3 -6
  10. data/ext/oj/mimic_json.c +21 -1
  11. data/ext/oj/object.c +7 -21
  12. data/ext/oj/oj.c +24 -4
  13. data/ext/oj/oj.h +10 -6
  14. data/ext/oj/parse.c +3 -5
  15. data/ext/oj/parse.h +16 -14
  16. data/ext/oj/parser.h +2 -2
  17. data/ext/oj/reader.c +1 -3
  18. data/ext/oj/saj.c +1 -1
  19. data/ext/oj/strict.c +9 -27
  20. data/ext/oj/wab.c +9 -27
  21. data/lib/oj/active_support_helper.rb +2 -3
  22. data/lib/oj/json.rb +156 -149
  23. data/lib/oj/mimic.rb +3 -1
  24. data/lib/oj/version.rb +1 -1
  25. data/lib/oj.rb +3 -0
  26. data/pages/Options.md +4 -0
  27. data/test/_test_active.rb +8 -8
  28. data/test/_test_active_mimic.rb +7 -7
  29. data/test/_test_mimic_rails.rb +17 -19
  30. data/test/files.rb +14 -14
  31. data/test/foo.rb +15 -10
  32. data/test/helper.rb +4 -4
  33. data/test/mem.rb +8 -7
  34. data/test/perf.rb +21 -26
  35. data/test/perf_compat.rb +30 -32
  36. data/test/perf_dump.rb +27 -27
  37. data/test/perf_fast.rb +80 -82
  38. data/test/perf_file.rb +27 -29
  39. data/test/perf_object.rb +65 -68
  40. data/test/perf_once.rb +8 -7
  41. data/test/perf_parser.rb +40 -46
  42. data/test/perf_saj.rb +46 -53
  43. data/test/perf_scp.rb +57 -69
  44. data/test/perf_simple.rb +40 -38
  45. data/test/perf_strict.rb +68 -70
  46. data/test/perf_wab.rb +67 -69
  47. data/test/prec.rb +3 -3
  48. data/test/sample.rb +16 -15
  49. data/test/sample_json.rb +8 -7
  50. data/test/test_compat.rb +44 -46
  51. data/test/test_custom.rb +56 -42
  52. data/test/test_debian.rb +6 -9
  53. data/test/test_fast.rb +78 -72
  54. data/test/test_file.rb +16 -21
  55. data/test/test_gc.rb +5 -5
  56. data/test/test_generate.rb +5 -5
  57. data/test/test_hash.rb +4 -4
  58. data/test/test_integer_range.rb +9 -9
  59. data/test/test_null.rb +18 -20
  60. data/test/test_object.rb +76 -86
  61. data/test/test_parser.rb +4 -4
  62. data/test/test_parser_debug.rb +4 -4
  63. data/test/test_parser_saj.rb +31 -31
  64. data/test/test_parser_usual.rb +3 -3
  65. data/test/test_rails.rb +2 -2
  66. data/test/test_saj.rb +8 -8
  67. data/test/test_scp.rb +29 -29
  68. data/test/test_strict.rb +25 -31
  69. data/test/test_various.rb +121 -75
  70. data/test/test_wab.rb +43 -42
  71. data/test/test_writer.rb +46 -46
  72. data/test/tests.rb +7 -7
  73. data/test/tests_mimic.rb +6 -6
  74. data/test/tests_mimic_addition.rb +6 -6
  75. metadata +3 -6
  76. data/test/bar.rb +0 -11
  77. data/test/baz.rb +0 -16
  78. data/test/bug.rb +0 -16
  79. data/test/zoo.rb +0 -13
data/test/test_writer.rb CHANGED
@@ -1,7 +1,7 @@
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
7
 
@@ -55,13 +55,13 @@ class OjWriter < Minitest::Test
55
55
  def test_string_writer_nested_object
56
56
  w = Oj::StringWriter.new(:indent => 0)
57
57
  w.push_object()
58
- w.push_object("a1")
58
+ w.push_object('a1')
59
59
  w.pop()
60
- w.push_object("a2")
61
- w.push_object("b")
60
+ w.push_object('a2')
61
+ w.push_object('b')
62
62
  w.pop()
63
63
  w.pop()
64
- w.push_object("a3")
64
+ w.push_object('a3')
65
65
  w.pop()
66
66
  w.pop()
67
67
  assert_equal(%|{"a1":{},"a2":{"b":{}},"a3":{}}\n|, w.to_s)
@@ -94,7 +94,7 @@ class OjWriter < Minitest::Test
94
94
  w.push_value(7.3)
95
95
  w.push_value(true)
96
96
  w.push_value(nil)
97
- w.push_value("a string")
97
+ w.push_value('a string')
98
98
  w.push_value({'a' => 65})
99
99
  w.push_value([1, 2])
100
100
  w.pop()
@@ -118,10 +118,10 @@ class OjWriter < Minitest::Test
118
118
  def test_string_writer_block
119
119
  w = Oj::StringWriter.new(:indent => 0)
120
120
  w.push_object() {
121
- w.push_object("a1") {
121
+ w.push_object('a1') {
122
122
  w.push_value(7, 'a7')
123
123
  }
124
- w.push_array("a2") {
124
+ w.push_array('a2') {
125
125
  w.push_value('x')
126
126
  w.push_value(3)
127
127
  }
@@ -152,7 +152,7 @@ class OjWriter < Minitest::Test
152
152
  assert(true)
153
153
  return
154
154
  end
155
- assert(false, "*** expected an exception")
155
+ assert(false, '*** expected an exception')
156
156
  end
157
157
 
158
158
  def test_string_writer_array_key
@@ -166,7 +166,7 @@ class OjWriter < Minitest::Test
166
166
  assert(true)
167
167
  return
168
168
  end
169
- assert(false, "*** expected an exception")
169
+ assert(false, '*** expected an exception')
170
170
  end
171
171
 
172
172
  def test_string_writer_pop_with_key
@@ -177,7 +177,7 @@ class OjWriter < Minitest::Test
177
177
  assert(true)
178
178
  return
179
179
  end
180
- assert(false, "*** expected an exception")
180
+ assert(false, '*** expected an exception')
181
181
  end
182
182
 
183
183
  def test_string_writer_obj_no_key
@@ -189,7 +189,7 @@ class OjWriter < Minitest::Test
189
189
  assert(true)
190
190
  return
191
191
  end
192
- assert(false, "*** expected an exception")
192
+ assert(false, '*** expected an exception')
193
193
  end
194
194
 
195
195
  def test_string_writer_deep
@@ -208,9 +208,9 @@ class OjWriter < Minitest::Test
208
208
  def test_string_writer_pop_all
209
209
  w = Oj::StringWriter.new(:indent => 0)
210
210
  w.push_object()
211
- w.push_object("a1")
211
+ w.push_object('a1')
212
212
  w.pop()
213
- w.push_array("a2")
213
+ w.push_array('a2')
214
214
  w.push_value(3)
215
215
  w.push_array()
216
216
  w.pop_all()
@@ -228,23 +228,23 @@ class OjWriter < Minitest::Test
228
228
  # Stream Writer
229
229
 
230
230
  class SString < ::String
231
- alias :write :concat
231
+ alias write concat
232
232
  end
233
-
233
+
234
234
  def test_stream_writer_encoding
235
235
  output = SString.new.force_encoding(::Encoding::UTF_8)
236
236
  w = Oj::StreamWriter.new(output, :indent => 0)
237
237
  # Oddly enough, when pushing ASCII characters with UTF-8 encoding or even
238
238
  # ASCII-8BIT does not change the output encoding. Pushing any non-ASCII no
239
239
  # matter what the encoding changes the output encoding to ASCII-8BIT.
240
- x = "香港" # Hong Kong
240
+ x = '香港' # Hong Kong
241
241
  x = x.force_encoding('ASCII-8BIT')
242
242
  w.push_value(x)
243
243
  assert_equal(::Encoding::UTF_8, output.encoding)
244
244
  end
245
245
 
246
246
  def test_stream_writer_empty_array
247
- output = StringIO.open("", "w+")
247
+ output = StringIO.open('', 'w+')
248
248
  w = Oj::StreamWriter.new(output, :indent => 0)
249
249
  w.push_array()
250
250
  w.pop()
@@ -252,19 +252,19 @@ class OjWriter < Minitest::Test
252
252
  end
253
253
 
254
254
  def test_stream_writer_mixed_stringio
255
- output = StringIO.open("", "w+")
255
+ output = StringIO.open('', 'w+')
256
256
  w = Oj::StreamWriter.new(output, :indent => 0)
257
257
  w.push_object()
258
- w.push_object("a1")
258
+ w.push_object('a1')
259
259
  w.pop()
260
- w.push_object("a2")
261
- w.push_array("b")
260
+ w.push_object('a2')
261
+ w.push_array('b')
262
262
  w.push_value(7)
263
263
  w.push_value(true)
264
- w.push_value("string")
264
+ w.push_value('string')
265
265
  w.pop()
266
266
  w.pop()
267
- w.push_object("a3")
267
+ w.push_object('a3')
268
268
  w.pop()
269
269
  w.pop()
270
270
  result = output.string()
@@ -272,20 +272,20 @@ class OjWriter < Minitest::Test
272
272
  end
273
273
 
274
274
  def test_stream_writer_mixed_file
275
- filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
276
- File.open(filename, "w") do |f|
275
+ filename = File.join(__dir__, 'open_file_test.json')
276
+ File.open(filename, 'w') do |f|
277
277
  w = Oj::StreamWriter.new(f, :indent => 0)
278
278
  w.push_object()
279
- w.push_object("a1")
279
+ w.push_object('a1')
280
280
  w.pop()
281
- w.push_object("a2")
282
- w.push_array("b")
281
+ w.push_object('a2')
282
+ w.push_array('b')
283
283
  w.push_value(7)
284
284
  w.push_value(true)
285
- w.push_value("string")
285
+ w.push_value('string')
286
286
  w.pop()
287
287
  w.pop()
288
- w.push_object("a3")
288
+ w.push_object('a3')
289
289
  w.pop()
290
290
  w.pop()
291
291
  end
@@ -294,7 +294,7 @@ class OjWriter < Minitest::Test
294
294
  end
295
295
 
296
296
  def test_stream_writer_nested_key_object
297
- output = StringIO.open("", "w+")
297
+ output = StringIO.open('', 'w+')
298
298
  w = Oj::StreamWriter.new(output, :indent => 0)
299
299
  w.push_object()
300
300
  w.push_key('a1')
@@ -316,16 +316,16 @@ class OjWriter < Minitest::Test
316
316
 
317
317
  def push_stuff(w, pop_all=true)
318
318
  w.push_object()
319
- w.push_object("a1")
319
+ w.push_object('a1')
320
320
  w.pop()
321
- w.push_object("a2")
322
- w.push_array("b")
321
+ w.push_object('a2')
322
+ w.push_array('b')
323
323
  w.push_value(7)
324
324
  w.push_value(true)
325
- w.push_value("string")
325
+ w.push_value('string')
326
326
  w.pop()
327
327
  w.pop()
328
- w.push_object("a3")
328
+ w.push_object('a3')
329
329
  if pop_all
330
330
  w.pop_all()
331
331
  else
@@ -335,31 +335,31 @@ class OjWriter < Minitest::Test
335
335
  end
336
336
 
337
337
  def test_stream_writer_buf_small
338
- output = StringIO.open("", "w+")
338
+ output = StringIO.open('', 'w+')
339
339
  w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 20)
340
340
  push_stuff(w)
341
341
  assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
342
342
  end
343
343
 
344
344
  def test_stream_writer_buf_large
345
- output = StringIO.open("", "w+")
346
- w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 16000)
345
+ output = StringIO.open('', 'w+')
346
+ w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 16_000)
347
347
  push_stuff(w)
348
348
  assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
349
349
  end
350
350
 
351
351
  def test_stream_writer_buf_flush
352
- output = StringIO.open("", "w+")
352
+ output = StringIO.open('', 'w+')
353
353
  w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 4096)
354
354
  push_stuff(w, false)
355
355
  # no flush so nothing should be in the output yet
356
- assert_equal("", output.string())
356
+ assert_equal('', output.string())
357
357
  w.flush()
358
358
  assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
359
359
  end
360
-
360
+
361
361
  def test_stream_writer_buf_flush_small
362
- output = StringIO.open("", "w+")
362
+ output = StringIO.open('', 'w+')
363
363
  w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 30)
364
364
  push_stuff(w, false)
365
365
  # flush should be called at 30 bytes but since the writes are chunky flush
@@ -370,7 +370,7 @@ class OjWriter < Minitest::Test
370
370
  end
371
371
 
372
372
  def test_stream_writer_push_null_value_with_key
373
- output = StringIO.open("", "w+")
373
+ output = StringIO.open('', 'w+')
374
374
  w = Oj::StreamWriter.new(output, :indent => 0)
375
375
  w.push_object()
376
376
  w.push_value(nil, 'nothing')
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.14.3
4
+ version: 3.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -188,9 +188,6 @@ files:
188
188
  - test/activesupport7/encoding_test.rb
189
189
  - test/activesupport7/encoding_test_cases.rb
190
190
  - test/activesupport7/time_zone_test_helpers.rb
191
- - test/bar.rb
192
- - test/baz.rb
193
- - test/bug.rb
194
191
  - test/files.rb
195
192
  - test/foo.rb
196
193
  - test/helper.rb
@@ -267,7 +264,6 @@ files:
267
264
  - test/tests.rb
268
265
  - test/tests_mimic.rb
269
266
  - test/tests_mimic_addition.rb
270
- - test/zoo.rb
271
267
  homepage: http://www.ohler.com/oj
272
268
  licenses:
273
269
  - MIT
@@ -278,6 +274,7 @@ metadata:
278
274
  homepage_uri: http://www.ohler.com/oj/
279
275
  source_code_uri: https://github.com/ohler55/oj
280
276
  wiki_uri: https://github.com/ohler55/oj/wiki
277
+ rubygems_mfa_required: 'true'
281
278
  post_install_message:
282
279
  rdoc_options:
283
280
  - "--title"
data/test/bar.rb DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $: << '.'
4
- $: << File.join(File.dirname(__FILE__), "../lib")
5
- $: << File.join(File.dirname(__FILE__), "../ext")
6
-
7
- require 'oj'
8
-
9
- Oj.mimic_JSON
10
-
11
- "\xAE".to_json
data/test/baz.rb DELETED
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $: << File.dirname(__FILE__)
4
- $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
5
- %w(lib ext).each do |dir|
6
- $: << File.join($oj_dir, dir)
7
- end
8
-
9
- require 'oj'
10
- Oj.mimic_JSON()
11
-
12
- begin
13
- ::JSON.load('name=&email=&subject=&comment=&submit=Send+Message')
14
- rescue ::JSON::ParserError
15
- puts "*** Pass"
16
- end
data/test/bug.rb DELETED
@@ -1,16 +0,0 @@
1
- $: << '.'
2
- $: << File.join(File.dirname(__FILE__), "../lib")
3
- $: << File.join(File.dirname(__FILE__), "../ext")
4
-
5
-
6
- #require 'bundler/setup'
7
- require 'oj'
8
- require 'active_support'
9
- require 'active_support/time_with_zone'
10
- require 'tzinfo'
11
-
12
- puts ActiveSupport::TimeWithZone
13
-
14
- json = File.read('./bug.json')
15
-
16
- Oj.load(json)
data/test/zoo.rb DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #require 'json'
4
-
5
- $: << File.dirname(__FILE__)
6
- require 'helper'
7
- require 'oj'
8
-
9
- Oj.mimic_JSON
10
- puts "\u3074"
11
-
12
- puts JSON.dump(["\u3074"])
13
- puts JSON.generate(["\u3074"])