oj 3.14.3 → 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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/ext/oj/custom.c +5 -15
  4. data/ext/oj/dump.c +27 -2
  5. data/ext/oj/mimic_json.c +21 -0
  6. data/ext/oj/object.c +7 -21
  7. data/ext/oj/oj.c +20 -0
  8. data/ext/oj/oj.h +3 -0
  9. data/ext/oj/strict.c +9 -27
  10. data/ext/oj/wab.c +9 -27
  11. data/lib/oj/version.rb +1 -1
  12. data/lib/oj.rb +3 -0
  13. data/pages/Options.md +4 -0
  14. data/test/_test_active.rb +8 -8
  15. data/test/_test_active_mimic.rb +7 -7
  16. data/test/_test_mimic_rails.rb +17 -19
  17. data/test/files.rb +14 -14
  18. data/test/foo.rb +5 -5
  19. data/test/helper.rb +4 -4
  20. data/test/mem.rb +8 -7
  21. data/test/perf.rb +21 -26
  22. data/test/perf_compat.rb +30 -32
  23. data/test/perf_dump.rb +25 -25
  24. data/test/perf_fast.rb +80 -82
  25. data/test/perf_file.rb +27 -29
  26. data/test/perf_object.rb +65 -68
  27. data/test/perf_once.rb +8 -7
  28. data/test/perf_parser.rb +40 -46
  29. data/test/perf_saj.rb +46 -53
  30. data/test/perf_scp.rb +57 -69
  31. data/test/perf_simple.rb +40 -38
  32. data/test/perf_strict.rb +68 -70
  33. data/test/perf_wab.rb +67 -69
  34. data/test/prec.rb +3 -3
  35. data/test/sample.rb +16 -15
  36. data/test/sample_json.rb +8 -7
  37. data/test/test_compat.rb +44 -46
  38. data/test/test_custom.rb +56 -42
  39. data/test/test_debian.rb +6 -9
  40. data/test/test_fast.rb +78 -72
  41. data/test/test_file.rb +16 -21
  42. data/test/test_gc.rb +5 -5
  43. data/test/test_generate.rb +5 -5
  44. data/test/test_hash.rb +4 -4
  45. data/test/test_integer_range.rb +9 -9
  46. data/test/test_null.rb +18 -20
  47. data/test/test_object.rb +76 -86
  48. data/test/test_parser.rb +4 -4
  49. data/test/test_parser_debug.rb +4 -4
  50. data/test/test_parser_saj.rb +31 -31
  51. data/test/test_parser_usual.rb +3 -3
  52. data/test/test_rails.rb +2 -2
  53. data/test/test_saj.rb +8 -8
  54. data/test/test_scp.rb +29 -29
  55. data/test/test_strict.rb +25 -31
  56. data/test/test_various.rb +121 -75
  57. data/test/test_wab.rb +43 -42
  58. data/test/test_writer.rb +46 -46
  59. data/test/tests.rb +7 -7
  60. data/test/tests_mimic.rb +6 -6
  61. data/test/tests_mimic_addition.rb +6 -6
  62. metadata +3 -6
  63. data/test/bar.rb +0 -11
  64. data/test/baz.rb +0 -16
  65. data/test/bug.rb +0 -16
  66. data/test/zoo.rb +0 -13
data/test/sample.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby -wW2
2
+ # frozen_string_literal: true
2
3
 
3
- if $0 == __FILE__
4
- $: << '.'
5
- $: << '..'
6
- $: << '../lib'
7
- $: << '../ext'
4
+ if $PROGRAM_NAME == __FILE__
5
+ $LOAD_PATH << '.'
6
+ $LOAD_PATH << '..'
7
+ $LOAD_PATH << '../lib'
8
+ $LOAD_PATH << '../ext'
8
9
  end
9
10
 
10
11
  require 'sample/doc'
@@ -12,7 +13,7 @@ require 'sample/doc'
12
13
  def sample_doc(size=3)
13
14
  colors = [ :black, :gray, :white, :red, :blue, :yellow, :green, :purple, :orange ]
14
15
 
15
- d = ::Sample::Doc.new('Sample')
16
+ d = Sample::Doc.new('Sample')
16
17
 
17
18
  # add some history
18
19
  (0..size * 10).each do |i|
@@ -21,22 +22,22 @@ def sample_doc(size=3)
21
22
 
22
23
  # add some layers
23
24
  (1..size).each do |i|
24
- layer = ::Sample::Layer.new("Layer-#{i}")
25
+ layer = Sample::Layer.new("Layer-#{i}")
25
26
  (1..size).each do |j|
26
- g = ::Sample::Group.new
27
+ g = Sample::Group.new
27
28
  (1..size).each do |k|
28
- g2 = ::Sample::Group.new
29
- r = ::Sample::Rect.new((j * 40) + 10.0, i * 10.0,
30
- 10.123456 / k, 10.0 / k, colors[(i + j + k) % colors.size])
29
+ g2 = Sample::Group.new
30
+ r = Sample::Rect.new((j * 40) + 10.0, i * 10.0,
31
+ 10.123456 / k, 10.0 / k, colors[(i + j + k) % colors.size])
31
32
  r.add_prop(:part_of, layer.name)
32
33
  g2 << r
33
- g2 << ::Sample::Text.new("#{k} in #{j}", r.left, r.top, r.width, r.height)
34
+ g2 << Sample::Text.new("#{k} in #{j}", r.left, r.top, r.width, r.height)
34
35
  g << g2
35
36
  end
36
- g2 = ::Sample::Group.new
37
+ g2 = Sample::Group.new
37
38
  (1..size).each do |k|
38
- o = ::Sample::Oval.new((j * 40) + 12.0, (i * 10.0) + 2.0,
39
- 6.0 / k, 6.0 / k, colors[(i + j + k) % colors.size])
39
+ o = Sample::Oval.new((j * 40) + 12.0, (i * 10.0) + 2.0,
40
+ 6.0 / k, 6.0 / k, colors[(i + j + k) % colors.size])
40
41
  o.add_prop(:inside, true)
41
42
  g << o
42
43
  end
data/test/sample_json.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- if $0 == __FILE__
4
- $: << '.'
5
- $: << '..'
6
- $: << '../lib'
7
- $: << '../ext'
4
+ if $PROGRAM_NAME == __FILE__
5
+ $LOAD_PATH << '.'
6
+ $LOAD_PATH << '..'
7
+ $LOAD_PATH << '../lib'
8
+ $LOAD_PATH << '../ext'
8
9
  end
9
10
 
10
11
  require 'oj'
@@ -31,6 +32,6 @@ def sample_json(size=3)
31
32
  container
32
33
  end
33
34
 
34
- if $0 == __FILE__
35
- File.open('sample.json', "w") { |f| f.write(Oj.dump(sample_json(3), :indent => 2)) }
35
+ if $PROGRAM_NAME == __FILE__
36
+ File.write('sample.json', Oj.dump(sample_json(3), :indent => 2))
36
37
  end
data/test/test_compat.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'
@@ -29,18 +29,16 @@ class CompatJuice < Minitest::Test
29
29
  end
30
30
  alias == eql?
31
31
 
32
- def to_json(*a)
32
+ def to_json(*_a)
33
33
  %|{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}|
34
34
  end
35
35
 
36
36
  def self.json_create(h)
37
- self.new(h['x'], h['y'])
37
+ new(h['x'], h['y'])
38
38
  end
39
39
  end # Jeez
40
40
 
41
41
  class Argy
42
- def initialize()
43
- end
44
42
 
45
43
  def to_json(*a)
46
44
  %|{"args":"#{a}"}|
@@ -48,10 +46,8 @@ class CompatJuice < Minitest::Test
48
46
  end # Argy
49
47
 
50
48
  class Stringy
51
- def initialize()
52
- end
53
49
 
54
- def to_s()
50
+ def to_s
55
51
  %|[1,2]|
56
52
  end
57
53
  end # Stringy
@@ -61,20 +57,17 @@ class CompatJuice < Minitest::Test
61
57
  module Three
62
58
  class Deep
63
59
 
64
- def initialize()
65
- end
66
-
67
60
  def eql?(o)
68
61
  self.class == o.class
69
62
  end
70
63
  alias == eql?
71
64
 
72
- def to_json(*a)
65
+ def to_json(*_a)
73
66
  %|{"json_class":"#{self.class.name}"}|
74
67
  end
75
68
 
76
- def self.json_create(h)
77
- self.new()
69
+ def self.json_create(_h)
70
+ new()
78
71
  end
79
72
  end # Deep
80
73
  end # Three
@@ -106,24 +99,30 @@ class CompatJuice < Minitest::Test
106
99
 
107
100
  def test_fixnum
108
101
  dump_and_load(0, false)
109
- dump_and_load(12345, false)
110
- dump_and_load(-54321, false)
102
+ dump_and_load(12_345, false)
103
+ dump_and_load(-54_321, false)
111
104
  dump_and_load(1, false)
112
105
  end
113
106
 
107
+ def test_fixnum_array
108
+ data = (1..1000).to_a
109
+ json = Oj.dump(data, mode: :compat)
110
+ assert_equal("[#{data.join(',')}]", json)
111
+ end
112
+
114
113
  def test_float
115
114
  dump_and_load(0.0, false)
116
115
  dump_and_load(0.56, false)
117
116
  dump_and_load(3.0, false)
118
- dump_and_load(12345.6789, false)
117
+ dump_and_load(12_345.6789, false)
119
118
  dump_and_load(70.35, false)
120
- dump_and_load(-54321.012, false)
119
+ dump_and_load(-54_321.012, false)
121
120
  dump_and_load(1.7775, false)
122
121
  dump_and_load(2.5024, false)
123
122
  dump_and_load(2.48e16, false)
124
123
  dump_and_load(2.48e100 * 1.0e10, false)
125
124
  dump_and_load(-2.48e100 * 1.0e10, false)
126
- dump_and_load(1405460727.723866, false)
125
+ dump_and_load(1_405_460_727.723866, false)
127
126
  dump_and_load(0.5773, false)
128
127
  dump_and_load(0.6768, false)
129
128
  dump_and_load(0.685, false)
@@ -148,7 +147,7 @@ class CompatJuice < Minitest::Test
148
147
  def test_encode
149
148
  opts = Oj.default_options
150
149
  Oj.default_options = { :ascii_only => true }
151
- json = Oj.dump("ぴーたー")
150
+ json = Oj.dump('ぴーたー')
152
151
  assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
153
152
  Oj.default_options = opts
154
153
  end
@@ -179,8 +178,8 @@ class CompatJuice < Minitest::Test
179
178
  end
180
179
 
181
180
  def test_time_xml_schema
182
- t = Time.xmlschema("2012-01-05T23:58:07.123456000+09:00")
183
- #t = Time.local(2012, 1, 5, 23, 58, 7, 123456)
181
+ t = Time.xmlschema('2012-01-05T23:58:07.123456000+09:00')
182
+ # t = Time.local(2012, 1, 5, 23, 58, 7, 123456)
184
183
  json = Oj.dump(t, :mode => :compat)
185
184
  assert_equal(%{"2012-01-05 23:58:07 +0900"}, json)
186
185
  end
@@ -199,8 +198,9 @@ class CompatJuice < Minitest::Test
199
198
  def test_non_str_hash
200
199
  json = Oj.dump({ 1 => true, 0 => false }, :mode => :compat)
201
200
  h = Oj.load(json, :mode => :strict)
202
- assert_equal({ "1" => true, "0" => false }, h)
201
+ assert_equal({ '1' => true, '0' => false }, h)
203
202
  end
203
+
204
204
  def test_hash
205
205
  dump_and_load({}, false)
206
206
  dump_and_load({ 'true' => true, 'false' => false}, false)
@@ -239,12 +239,12 @@ class CompatJuice < Minitest::Test
239
239
  def test_invalid_escapes_handled
240
240
  json = '{"subtext":"\"404er\” \w \k \3 \a"}'
241
241
  obj = Oj.compat_load(json)
242
- assert_equal({"subtext" => "\"404er” w k 3 a"}, obj)
242
+ assert_equal({'subtext' => '"404er” w k 3 a'}, obj)
243
243
  end
244
244
 
245
245
  def test_hash_escaping
246
246
  json = Oj.to_json({'<>' => '<>'}, mode: :compat)
247
- assert_equal(json, '{"<>":"<>"}')
247
+ assert_equal('{"<>":"<>"}', json)
248
248
  end
249
249
 
250
250
  def test_bignum_object
@@ -271,7 +271,7 @@ class CompatJuice < Minitest::Test
271
271
  def test_bignum_compat
272
272
  json = Oj.dump(7 ** 55, :mode => :compat)
273
273
  b = Oj.load(json, :mode => :strict)
274
- assert_equal(30226801971775055948247051683954096612865741943, b)
274
+ assert_equal(30_226_801_971_775_055_948_247_051_683_954_096_612_865_741_943, b)
275
275
  end
276
276
 
277
277
  # BigDecimal
@@ -313,7 +313,7 @@ class CompatJuice < Minitest::Test
313
313
  if x.is_a?(String)
314
314
  assert_equal(orig.to_s, x)
315
315
  else # better be a Hash
316
- assert_equal({"year" => orig.year, "month" => orig.month, "day" => orig.day, "start" => orig.start}, x)
316
+ assert_equal({'year' => orig.year, 'month' => orig.month, 'day' => orig.day, 'start' => orig.start}, x)
317
317
  end
318
318
  end
319
319
 
@@ -340,15 +340,13 @@ class CompatJuice < Minitest::Test
340
340
  end
341
341
 
342
342
  def test_io_file
343
- filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
344
- File.open(filename, 'w') { |f|
345
- f.write(%{{
343
+ filename = File.join(__dir__, 'open_file_test.json')
344
+ File.write(filename, %{{
346
345
  "x":true,
347
346
  "y":58,
348
347
  "z": [1,2,3]
349
348
  }
350
349
  })
351
- }
352
350
  f = File.new(filename)
353
351
  obj = Oj.compat_load(f)
354
352
  f.close()
@@ -412,7 +410,7 @@ class CompatJuice < Minitest::Test
412
410
 
413
411
  # A child to_json should not be called.
414
412
  def test_json_object_child
415
- obj = { "child" => Jeez.new(true, 58) }
413
+ obj = { 'child' => Jeez.new(true, 58) }
416
414
  assert_equal('{"child":{"json_class":"CompatJuice::Jeez","x":true,"y":58}}', Oj.dump(obj))
417
415
  end
418
416
 
@@ -433,10 +431,10 @@ class CompatJuice < Minitest::Test
433
431
  begin
434
432
  Oj.compat_load(json, :create_additions => true)
435
433
  rescue Exception => e
436
- assert_equal("ArgumentError", e.class().name)
434
+ assert_equal('ArgumentError', e.class().name)
437
435
  return
438
436
  end
439
- assert(false, "*** expected an exception")
437
+ assert(false, '*** expected an exception')
440
438
  end
441
439
 
442
440
  def test_json_object_create_cache
@@ -452,7 +450,7 @@ class CompatJuice < Minitest::Test
452
450
  expected = Jeez.new(true, 58)
453
451
  json = Oj.to_json(expected)
454
452
  json.gsub!('json_class', '_class_')
455
- obj = Oj.compat_load(json, :create_id => "_class_", :create_additions => true)
453
+ obj = Oj.compat_load(json, :create_id => '_class_', :create_additions => true)
456
454
  assert_equal(expected, obj)
457
455
  end
458
456
 
@@ -492,10 +490,10 @@ class CompatJuice < Minitest::Test
492
490
 
493
491
  def test_parse_large_string
494
492
  error = assert_raises() { Oj.load(%|{"a":"aaaaaaaaaa\0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}|) }
495
- assert(error.message.include?('NULL byte in string'))
493
+ assert_includes(error.message, 'NULL byte in string')
496
494
 
497
495
  error = assert_raises() { Oj.load(%|{"a":"aaaaaaaaaaaaaaaaaaaa }|) }
498
- assert(error.message.include?('quoted string not terminated'))
496
+ assert_includes(error.message, 'quoted string not terminated')
499
497
 
500
498
  json =<<~JSON
501
499
  {
@@ -503,15 +501,15 @@ class CompatJuice < Minitest::Test
503
501
  "b": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa"
504
502
  }
505
503
  JSON
506
- assert_equal("ぴーたー", Oj.load(json)['a'])
504
+ assert_equal('ぴーたー', Oj.load(json)['a'])
507
505
  end
508
506
 
509
507
  def test_parse_large_escaped_string
510
- invalid_json = %|{"a":\"aaaa\\nbbbb\\rcccc\\tddd\\feee\\bf\/\\\\\\u3074\\u30fc\\u305f\\u30fc }|
508
+ invalid_json = %|{"a":"aaaa\\nbbbb\\rcccc\\tddd\\feee\\bf/\\\\\\u3074\\u30fc\\u305f\\u30fc }|
511
509
  error = assert_raises() { Oj.load(invalid_json) }
512
- assert(error.message.include?('quoted string not terminated'))
510
+ assert_includes(error.message, 'quoted string not terminated')
513
511
 
514
- json = "\"aaaa\\nbbbb\\rcccc\\tddd\\feee\\bf\/\\\\\\u3074\\u30fc\\u305f\\u30fc \""
512
+ json = '"aaaa\\nbbbb\\rcccc\\tddd\\feee\\bf/\\\\\\u3074\\u30fc\\u305f\\u30fc "'
515
513
  assert_equal("aaaa\nbbbb\rcccc\tddd\feee\bf/\\ぴーたー ", Oj.load(json))
516
514
  end
517
515
 
@@ -527,7 +525,7 @@ class CompatJuice < Minitest::Test
527
525
  def dump_and_load(obj, trace=false)
528
526
  json = Oj.dump(obj)
529
527
  puts json if trace
530
- loaded = Oj.compat_load(json, :create_additions => true);
528
+ loaded = Oj.compat_load(json, :create_additions => true)
531
529
  if obj.nil?
532
530
  assert_nil(loaded)
533
531
  else
@@ -539,7 +537,7 @@ class CompatJuice < Minitest::Test
539
537
  def dump_to_json_and_load(obj, trace=false)
540
538
  json = Oj.to_json(obj, :indent => ' ')
541
539
  puts json if trace
542
- loaded = Oj.compat_load(json, :create_additions => true);
540
+ loaded = Oj.compat_load(json, :create_additions => true)
543
541
  if obj.nil?
544
542
  assert_nil(loaded)
545
543
  else
data/test/test_custom.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'
@@ -27,19 +27,24 @@ class CustomJuice < Minitest::Test
27
27
  @y = y
28
28
  @_z = x.to_s
29
29
  end
30
+
30
31
  def ==(o)
31
32
  self.class == o.class && @x == o.x && @y = o.y
32
33
  end
33
- def to_json(*args)
34
+
35
+ def to_json(*_args)
34
36
  %|{"xx":#{@x},"yy":#{y}}|
35
37
  end
36
- def raw_json(depth, indent)
38
+
39
+ def raw_json(_depth, _indent)
37
40
  %|{"xxx":#{@x},"yyy":#{y}}|
38
41
  end
39
- def as_json(*args)
42
+
43
+ def as_json(*_args)
40
44
  {'a' => @x, :b => @y }
41
45
  end
42
- def to_hash()
46
+
47
+ def to_hash
43
48
  {'b' => @x, 'n' => @y }
44
49
  end
45
50
  end
@@ -51,10 +56,12 @@ class CustomJuice < Minitest::Test
51
56
  @x = x
52
57
  @y = y
53
58
  end
59
+
54
60
  def ==(o)
55
61
  self.class == o.class && @x == o.x && @y = o.y
56
62
  end
57
- def as_json(*args)
63
+
64
+ def as_json(*_args)
58
65
  {'a' => @x, :b => @y }
59
66
  end
60
67
  end
@@ -66,10 +73,12 @@ class CustomJuice < Minitest::Test
66
73
  @x = x
67
74
  @y = y
68
75
  end
76
+
69
77
  def ==(o)
70
78
  self.class == o.class && @x == o.x && @y = o.y
71
79
  end
72
- def as_json(*args)
80
+
81
+ def as_json(*_args)
73
82
  a = @x
74
83
  a = a.as_json if a.respond_to?('as_json')
75
84
  b = @y
@@ -101,16 +110,16 @@ class CustomJuice < Minitest::Test
101
110
 
102
111
  def test_fixnum
103
112
  dump_and_load(0, false)
104
- dump_and_load(12345, false)
105
- dump_and_load(-54321, false)
113
+ dump_and_load(12_345, false)
114
+ dump_and_load(-54_321, false)
106
115
  dump_and_load(1, false)
107
116
  end
108
117
 
109
118
  def test_float
110
119
  dump_and_load(0.0, false)
111
- dump_and_load(12345.6789, false)
120
+ dump_and_load(12_345.6789, false)
112
121
  dump_and_load(70.35, false)
113
- dump_and_load(-54321.012, false)
122
+ dump_and_load(-54_321.012, false)
114
123
  dump_and_load(1.7775, false)
115
124
  dump_and_load(2.5024, false)
116
125
  dump_and_load(2.48e16, false)
@@ -119,12 +128,12 @@ class CustomJuice < Minitest::Test
119
128
  end
120
129
 
121
130
  def test_float_parse
122
- f = Oj.load("12.123456789012345678", mode: :custom, bigdecimal_load: :float);
131
+ f = Oj.load('12.123456789012345678', mode: :custom, bigdecimal_load: :float)
123
132
  assert_equal(Float, f.class)
124
133
  end
125
134
 
126
135
  def test_float_parse_fast
127
- f = Oj.load("12.123456789012345678", mode: :custom, bigdecimal_load: :fast);
136
+ f = Oj.load('12.123456789012345678', mode: :custom, bigdecimal_load: :fast)
128
137
  assert_equal(Float, f.class)
129
138
  assert(12.12345678901234 <= f && f < 12.12345678901236)
130
139
  end
@@ -139,7 +148,7 @@ class CustomJuice < Minitest::Test
139
148
  assert(true)
140
149
  return
141
150
  end
142
- assert(false, "*** expected an exception")
151
+ assert(false, '*** expected an exception')
143
152
  end
144
153
 
145
154
  def test_infinity_dump
@@ -152,7 +161,7 @@ class CustomJuice < Minitest::Test
152
161
  assert(true)
153
162
  return
154
163
  end
155
- assert(false, "*** expected an exception")
164
+ assert(false, '*** expected an exception')
156
165
  end
157
166
 
158
167
  def test_neg_infinity_dump
@@ -165,7 +174,7 @@ class CustomJuice < Minitest::Test
165
174
  assert(true)
166
175
  return
167
176
  end
168
- assert(false, "*** expected an exception")
177
+ assert(false, '*** expected an exception')
169
178
  end
170
179
 
171
180
  def test_string
@@ -176,15 +185,15 @@ class CustomJuice < Minitest::Test
176
185
  end
177
186
 
178
187
  def test_string_ascii
179
- json = Oj.dump("ぴーたー", :escape_mode => :ascii)
188
+ json = Oj.dump('ぴーたー', :escape_mode => :ascii)
180
189
  assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
181
- dump_and_load("ぴーたー", false, :escape_mode => :ascii)
190
+ dump_and_load('ぴーたー', false, :escape_mode => :ascii)
182
191
  end
183
192
 
184
193
  def test_string_json
185
- json = Oj.dump("ぴーたー", :escape_mode => :json)
194
+ json = Oj.dump('ぴーたー', :escape_mode => :json)
186
195
  assert_equal(%{"ぴーたー"}, json)
187
- dump_and_load("ぴーたー", false, :escape_mode => :json)
196
+ dump_and_load('ぴーたー', false, :escape_mode => :json)
188
197
  end
189
198
 
190
199
  def test_array
@@ -203,10 +212,10 @@ class CustomJuice < Minitest::Test
203
212
  skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'
204
213
 
205
214
  begin
206
- n = 10000
215
+ n = 10_000
207
216
  Oj.strict_load(('[' * n) + (']' * n))
208
217
  rescue Exception => e
209
- assert(false, e.message)
218
+ refute(e.message)
210
219
  end
211
220
  end
212
221
 
@@ -261,11 +270,11 @@ class CustomJuice < Minitest::Test
261
270
 
262
271
  def test_object
263
272
  obj = Jeez.new(true, 58)
264
- json = Oj.dump(obj, create_id: "^o", use_to_json: false, use_as_json: false, use_to_hash: false)
273
+ json = Oj.dump(obj, create_id: '^o', use_to_json: false, use_as_json: false, use_to_hash: false)
265
274
  assert_equal(%|{"x":true,"y":58,"_z":"true"}|, json)
266
- json = Oj.dump(obj, create_id: "^o", use_to_json: false, use_as_json: false, use_to_hash: false, ignore_under: true)
275
+ json = Oj.dump(obj, create_id: '^o', use_to_json: false, use_as_json: false, use_to_hash: false, ignore_under: true)
267
276
  assert_equal(%|{"x":true,"y":58}|, json)
268
- dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
277
+ dump_and_load(obj, false, :create_id => '^o', :create_additions => true)
269
278
  end
270
279
 
271
280
  def test_object_to_json
@@ -393,24 +402,29 @@ class CustomJuice < Minitest::Test
393
402
  assert_equal(%|{"x":{"a":1}}|, json)
394
403
  end
395
404
 
405
+ def test_omit_null_byte
406
+ json = Oj.dump({ "fo\x00o" => "b\x00ar" }, :omit_null_byte => true)
407
+ assert_equal(%|{"foo":"bar"}|, json)
408
+ end
409
+
396
410
  def test_complex
397
411
  obj = Complex(2, 9)
398
- dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
412
+ dump_and_load(obj, false, :create_id => '^o', :create_additions => true)
399
413
  end
400
414
 
401
415
  def test_rational
402
416
  obj = Rational(2, 9)
403
- dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
417
+ dump_and_load(obj, false, :create_id => '^o', :create_additions => true)
404
418
  end
405
419
 
406
420
  def test_range
407
421
  obj = 3..8
408
- dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
422
+ dump_and_load(obj, false, :create_id => '^o', :create_additions => true)
409
423
  end
410
424
 
411
425
  def test_date
412
426
  obj = Date.new(2017, 1, 5)
413
- dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
427
+ dump_and_load(obj, false, :create_id => '^o', :create_additions => true)
414
428
  end
415
429
 
416
430
  def test_date_unix
@@ -439,7 +453,7 @@ class CustomJuice < Minitest::Test
439
453
 
440
454
  def test_datetime
441
455
  obj = DateTime.new(2017, 1, 5, 10, 20, 30)
442
- dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
456
+ dump_and_load(obj, false, :create_id => '^o', :create_additions => true)
443
457
  end
444
458
 
445
459
  def test_datetime_unix
@@ -469,12 +483,12 @@ class CustomJuice < Minitest::Test
469
483
  def test_regexp
470
484
  # this notation must be used to get an == match later
471
485
  obj = /(?ix-m:^yes$)/
472
- dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
486
+ dump_and_load(obj, false, :create_id => '^o', :create_additions => true)
473
487
  end
474
488
 
475
489
  def test_openstruct
476
490
  obj = OpenStruct.new(:a => 1, 'b' => 2)
477
- dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
491
+ dump_and_load(obj, false, :create_id => '^o', :create_additions => true)
478
492
  end
479
493
 
480
494
  def test_time
@@ -484,14 +498,14 @@ class CustomJuice < Minitest::Test
484
498
  # These two forms should be able to recreate the time precisely,
485
499
  # so we check they can load a dumped version and recreate the
486
500
  # original object correctly.
487
- dump_and_load(obj, false, :time_format => :unix, :create_id => "^o", :create_additions => true)
488
- dump_and_load(obj, false, :time_format => :unix_zone, :create_id => "^o", :create_additions => true)
501
+ dump_and_load(obj, false, :time_format => :unix, :create_id => '^o', :create_additions => true)
502
+ dump_and_load(obj, false, :time_format => :unix_zone, :create_id => '^o', :create_additions => true)
489
503
  # These two forms will lose precision while dumping as they don't
490
504
  # preserve full precision. We check that a dumped version is equal
491
505
  # to that version loaded and dumped a second time, but don't check
492
506
  # that the loaded Ruby objects is still the same as the original.
493
- dump_load_dump(obj, false, :time_format => :xmlschema, :create_id => "^o", :create_additions => true)
494
- dump_load_dump(obj, false, :time_format => :ruby, :create_id => "^o", :create_additions => true)
507
+ dump_load_dump(obj, false, :time_format => :xmlschema, :create_id => '^o', :create_additions => true)
508
+ dump_load_dump(obj, false, :time_format => :ruby, :create_id => '^o', :create_additions => true)
495
509
  end
496
510
 
497
511
  def dump_and_load(obj, trace=false, options={})
@@ -499,7 +513,7 @@ class CustomJuice < Minitest::Test
499
513
  json = Oj.dump(obj, options)
500
514
  puts json if trace
501
515
 
502
- loaded = Oj.load(json, options);
516
+ loaded = Oj.load(json, options)
503
517
  if obj.nil?
504
518
  assert_nil(loaded)
505
519
  else
@@ -513,7 +527,7 @@ class CustomJuice < Minitest::Test
513
527
  json = Oj.dump(obj, options)
514
528
  puts json if trace
515
529
 
516
- loaded = Oj.load(json, options);
530
+ loaded = Oj.load(json, options)
517
531
  if obj.nil?
518
532
  assert_nil(loaded)
519
533
  else
@@ -527,7 +541,7 @@ class CustomJuice < Minitest::Test
527
541
  json = Oj.dump(obj, options)
528
542
  puts json if trace
529
543
 
530
- loaded = Oj.load(json, options);
544
+ loaded = Oj.load(json, options)
531
545
  if obj.nil?
532
546
  assert_nil(loaded)
533
547
  else
data/test/test_debian.rb CHANGED
@@ -1,4 +1,4 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'helper'
4
4
 
@@ -20,18 +20,15 @@ class DebJuice < Minitest::Test
20
20
 
21
21
  # contributed by sauliusg to fix as_json
22
22
  class Orange < Jam
23
- def initialize(x, y)
24
- super
25
- end
26
23
 
27
- def as_json()
24
+ def as_json
28
25
  { :json_class => self.class,
29
26
  :x => @x,
30
27
  :y => @y }
31
28
  end
32
29
 
33
30
  def self.json_create(h)
34
- self.new(h['x'], h['y'])
31
+ new(h['x'], h['y'])
35
32
  end
36
33
  end
37
34
 
@@ -39,13 +36,13 @@ class DebJuice < Minitest::Test
39
36
  Oj.default_options = { :mode => :compat, :class_cache => true, :use_as_json => true }
40
37
  obj = Orange.new(true, 58)
41
38
  json = Oj.dump(obj, :indent => 2)
42
- assert(!json.nil?)
39
+ refute_nil(json)
43
40
  dump_and_load(obj, true)
44
41
  end
45
42
 
46
- def dump_and_load(obj, trace=false)
43
+ def dump_and_load(obj, _trace=false)
47
44
  json = Oj.dump(obj, :indent => 2)
48
- loaded = Oj.load(json);
45
+ loaded = Oj.load(json)
49
46
  assert_equal(obj, loaded)
50
47
  loaded
51
48
  end