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/test_fast.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # coding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
- $: << File.dirname(__FILE__)
4
+ $LOAD_PATH << __dir__
6
5
 
7
6
  require 'helper'
8
7
 
@@ -52,7 +51,7 @@ class DocTest < Minitest::Test
52
51
  json = %{true}
53
52
  Oj::Doc.open(json) do |doc|
54
53
  assert_equal(TrueClass, doc.type)
55
- assert_equal(true, doc.fetch())
54
+ assert(doc.fetch())
56
55
  end
57
56
  end
58
57
 
@@ -60,7 +59,7 @@ class DocTest < Minitest::Test
60
59
  json = %{false}
61
60
  Oj::Doc.open(json) do |doc|
62
61
  assert_equal(FalseClass, doc.type)
63
- assert_equal(false, doc.fetch())
62
+ refute(doc.fetch())
64
63
  end
65
64
  end
66
65
 
@@ -76,7 +75,7 @@ class DocTest < Minitest::Test
76
75
  json = %{"ぴーたー"}
77
76
  Oj::Doc.open(json) do |doc|
78
77
  assert_equal(String, doc.type)
79
- assert_equal("ぴーたー", doc.fetch())
78
+ assert_equal('ぴーたー', doc.fetch())
80
79
  end
81
80
  end
82
81
 
@@ -84,7 +83,7 @@ class DocTest < Minitest::Test
84
83
  json = %{"\\u3074\\u30fc\\u305f\\u30fc"}
85
84
  Oj::Doc.open(json) do |doc|
86
85
  assert_equal(String, doc.type)
87
- assert_equal("ぴーたー", doc.fetch())
86
+ assert_equal('ぴーたー', doc.fetch())
88
87
  end
89
88
  end
90
89
 
@@ -92,7 +91,7 @@ class DocTest < Minitest::Test
92
91
  json = %{12345}
93
92
  Oj::Doc.open(json) do |doc|
94
93
  assert_equal(Integer, doc.type)
95
- assert_equal(12345, doc.fetch())
94
+ assert_equal(12_345, doc.fetch())
96
95
  end
97
96
  end
98
97
 
@@ -100,7 +99,7 @@ class DocTest < Minitest::Test
100
99
  json = %{12345.6789}
101
100
  Oj::Doc.open(json) do |doc|
102
101
  assert_equal(Float, doc.type)
103
- assert_equal(12345.6789, doc.fetch())
102
+ assert_in_delta(12_345.6789, doc.fetch())
104
103
  end
105
104
  end
106
105
 
@@ -108,8 +107,8 @@ class DocTest < Minitest::Test
108
107
  json = %{12345.6789e7}
109
108
  Oj::Doc.open(json) do |doc|
110
109
  assert_equal(Float, doc.type)
111
- #assert_equal(12345.6789e7, doc.fetch())
112
- assert_equal(12345.6789e7.to_i, doc.fetch().to_i)
110
+ # assert_equal(12345.6789e7, doc.fetch())
111
+ assert_equal(12_345.6789e7.to_i, doc.fetch().to_i)
113
112
  end
114
113
  end
115
114
 
@@ -117,7 +116,7 @@ class DocTest < Minitest::Test
117
116
  json = %{[]}
118
117
  Oj::Doc.open(json) do |doc|
119
118
  assert_equal(Array, doc.type)
120
- assert_equal([], doc.fetch())
119
+ assert_empty(doc.fetch())
121
120
  end
122
121
  end
123
122
 
@@ -133,7 +132,7 @@ class DocTest < Minitest::Test
133
132
  json = %{{}}
134
133
  Oj::Doc.open(json) do |doc|
135
134
  assert_equal(Hash, doc.type)
136
- assert_equal({}, doc.fetch())
135
+ assert_empty(doc.fetch())
137
136
  end
138
137
  end
139
138
 
@@ -168,7 +167,8 @@ class DocTest < Minitest::Test
168
167
 
169
168
  def test_move
170
169
  Oj::Doc.open(@json1) do |doc|
171
- [ '/',
170
+ [
171
+ '/',
172
172
  '/array',
173
173
  '/boolean',
174
174
  '/array/1/hash/h2/a/3',
@@ -201,12 +201,13 @@ class DocTest < Minitest::Test
201
201
 
202
202
  def test_move_relative
203
203
  Oj::Doc.open(@json1) do |doc|
204
- [['/', 'array', '/array'],
205
- ['/array', '1/num', '/array/1/num'],
206
- ['/array/1/hash', 'h2/a', '/array/1/hash/h2/a'],
207
- ['/array/1', 'hash/h2/a/2', '/array/1/hash/h2/a/2'],
208
- ['/array/1/hash', '../string', '/array/1/string'],
209
- ['/array/1/hash', '..', '/array/1'],
204
+ [
205
+ ['/', 'array', '/array'],
206
+ ['/array', '1/num', '/array/1/num'],
207
+ ['/array/1/hash', 'h2/a', '/array/1/hash/h2/a'],
208
+ ['/array/1', 'hash/h2/a/2', '/array/1/hash/h2/a/2'],
209
+ ['/array/1/hash', '../string', '/array/1/string'],
210
+ ['/array/1/hash', '..', '/array/1'],
210
211
  ].each do |start, path, where|
211
212
  doc.move(start)
212
213
  doc.move(path)
@@ -217,14 +218,15 @@ class DocTest < Minitest::Test
217
218
 
218
219
  def test_type
219
220
  Oj::Doc.open(@json1) do |doc|
220
- [['/', Hash],
221
- ['/array', Array],
222
- ['/array/1', Hash],
223
- ['/array/1/num', Integer],
224
- ['/array/1/string', String],
225
- ['/array/1/hash/h2/a', Array],
226
- ['/array/1/hash/../num', Integer],
227
- ['/array/1/hash/../..', Array],
221
+ [
222
+ ['/', Hash],
223
+ ['/array', Array],
224
+ ['/array/1', Hash],
225
+ ['/array/1/num', Integer],
226
+ ['/array/1/string', String],
227
+ ['/array/1/hash/h2/a', Array],
228
+ ['/array/1/hash/../num', Integer],
229
+ ['/array/1/hash/../..', Array],
228
230
  ].each do |path, type|
229
231
  assert_equal(type, doc.type(path))
230
232
  end
@@ -233,15 +235,16 @@ class DocTest < Minitest::Test
233
235
 
234
236
  def test_local_key
235
237
  Oj::Doc.open(@json1) do |doc|
236
- [['/', nil],
237
- ['/array', 'array'],
238
- ['/array/1', 1],
239
- ['/array/1/num', 'num'],
240
- ['/array/1/string', 'string'],
241
- ['/array/1/hash/h2/a', 'a'],
242
- ['/array/1/hash/../num', 'num'],
243
- ['/array/1/hash/..', 1],
244
- ['/array/1/hash/../..', 'array'],
238
+ [
239
+ ['/', nil],
240
+ ['/array', 'array'],
241
+ ['/array/1', 1],
242
+ ['/array/1/num', 'num'],
243
+ ['/array/1/string', 'string'],
244
+ ['/array/1/hash/h2/a', 'a'],
245
+ ['/array/1/hash/../num', 'num'],
246
+ ['/array/1/hash/..', 1],
247
+ ['/array/1/hash/../..', 'array'],
245
248
  ].each do |path, key|
246
249
  doc.move(path)
247
250
  if key.nil?
@@ -255,15 +258,16 @@ class DocTest < Minitest::Test
255
258
 
256
259
  def test_fetch_move
257
260
  Oj::Doc.open(@json1) do |doc|
258
- [['/array/1/num', 3],
259
- ['/array/1/string', 'message'],
260
- ['/array/1/hash/h2/a', [1, 2, 3]],
261
- ['/array/1/hash/../num', 3],
262
- ['/array/1/hash/..', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
263
- ['/array/1/hash/../..', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
264
- ['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
265
- ['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
266
- ['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
261
+ [
262
+ ['/array/1/num', 3],
263
+ ['/array/1/string', 'message'],
264
+ ['/array/1/hash/h2/a', [1, 2, 3]],
265
+ ['/array/1/hash/../num', 3],
266
+ ['/array/1/hash/..', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
267
+ ['/array/1/hash/../..', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
268
+ ['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
269
+ ['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
270
+ ['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
267
271
  ].each do |path, val|
268
272
  doc.move(path)
269
273
  assert_equal(val, doc.fetch())
@@ -273,17 +277,18 @@ class DocTest < Minitest::Test
273
277
 
274
278
  def test_fetch_path
275
279
  Oj::Doc.open(@json1) do |doc|
276
- [['/array/1/num', 3],
277
- ['/array/1/string', 'message'],
278
- ['/array/1/hash/h2/a', [1, 2, 3]],
279
- ['/array/1/hash/../num', 3],
280
- ['/array/1/hash/..', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
281
- ['/array/1/hash/../..', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
282
- ['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
283
- ['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
284
- ['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
285
- ['/nothing', nil],
286
- ['/array/10', nil],
280
+ [
281
+ ['/array/1/num', 3],
282
+ ['/array/1/string', 'message'],
283
+ ['/array/1/hash/h2/a', [1, 2, 3]],
284
+ ['/array/1/hash/../num', 3],
285
+ ['/array/1/hash/..', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
286
+ ['/array/1/hash/../..', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
287
+ ['/array/1', {'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}],
288
+ ['/array', [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}]],
289
+ ['/', {'array' => [{'num' => 3, 'string' => 'message', 'hash' => {'h2' => {'a' => [1, 2, 3]}}}], 'boolean' => true}],
290
+ ['/nothing', nil],
291
+ ['/array/10', nil],
287
292
  ].each do |path, val|
288
293
  if val.nil?
289
294
  assert_nil(doc.fetch(path))
@@ -305,9 +310,10 @@ class DocTest < Minitest::Test
305
310
 
306
311
  def test_move_fetch_path
307
312
  Oj::Doc.open(@json1) do |doc|
308
- [['/array/1', 'num', 3],
309
- ['/array/1', 'string', 'message'],
310
- ['/array/1/hash', 'h2/a', [1, 2, 3]],
313
+ [
314
+ ['/array/1', 'num', 3],
315
+ ['/array/1', 'string', 'message'],
316
+ ['/array/1/hash', 'h2/a', [1, 2, 3]],
311
317
  ].each do |path, fetch_path, val|
312
318
  doc.move(path)
313
319
  assert_equal(val, doc.fetch(fetch_path))
@@ -317,12 +323,13 @@ class DocTest < Minitest::Test
317
323
 
318
324
  def test_exists
319
325
  Oj::Doc.open(@json1) do |doc|
320
- [['/array/1', true],
321
- ['/array/1', true],
322
- ['/array/1/hash', true],
323
- ['/array/1/dash', false],
324
- ['/array/3', false],
325
- ['/nothing', false],
326
+ [
327
+ ['/array/1', true],
328
+ ['/array/1', true],
329
+ ['/array/1/hash', true],
330
+ ['/array/1/dash', false],
331
+ ['/array/3', false],
332
+ ['/nothing', false],
326
333
  ].each do |path, val|
327
334
  assert_equal(val, doc.exists?(path), "failed for #{path.inspect}")
328
335
  end
@@ -396,7 +403,7 @@ class DocTest < Minitest::Test
396
403
  end
397
404
  end
398
405
  end
399
- assert_equal({"/a"=>1, "/c"=>[2], "/c/1"=>2, "/d"=>3}, h)
406
+ assert_equal({'/a'=>1, '/c'=>[2], '/c/1'=>2, '/d'=>3}, h)
400
407
  end
401
408
 
402
409
  def test_size
@@ -409,8 +416,8 @@ class DocTest < Minitest::Test
409
416
  end
410
417
 
411
418
  def test_open_file
412
- filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
413
- File.open(filename, 'w') { |f| f.write('{"a":[1,2,3]}') }
419
+ filename = File.join(__dir__, 'open_file_test.json')
420
+ File.write(filename, '{"a":[1,2,3]}')
414
421
  Oj::Doc.open_file(filename) do |doc|
415
422
  assert_equal(5, doc.size)
416
423
  end
@@ -435,8 +442,8 @@ class DocTest < Minitest::Test
435
442
  end
436
443
 
437
444
  def test_file_open_close
438
- filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
439
- File.open(filename, 'w') { |f| f.write('{"a":[1,2,3]}') }
445
+ filename = File.join(__dir__, 'open_file_test.json')
446
+ File.write(filename, '{"a":[1,2,3]}')
440
447
  doc = Oj::Doc.open_file(filename)
441
448
  assert_equal(Oj::Doc, doc.class)
442
449
  assert_equal(5, doc.size)
@@ -463,7 +470,6 @@ class DocTest < Minitest::Test
463
470
  doc.home()
464
471
  assert_equal(2, doc.fetch('/a/2'))
465
472
  assert_equal(2, doc.fetch('a/2'))
466
- doc = nil
467
473
  GC.start
468
474
  # a print statement confirms close is called
469
475
  end
@@ -496,7 +502,7 @@ class DocTest < Minitest::Test
496
502
  end
497
503
 
498
504
  def test_doc_empty
499
- result = Oj::Doc.open("") { |doc| doc.each_child {} }
505
+ result = Oj::Doc.open('') { |doc| doc.each_child {} }
500
506
  assert_nil(result)
501
507
  end
502
508
 
data/test/test_file.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
 
@@ -22,32 +22,26 @@ class FileJuice < Minitest::Test
22
22
  end # Jam
23
23
 
24
24
  class Jeez < Jam
25
- def initialize(x, y)
26
- super
27
- end
28
25
 
29
26
  def to_json(*_args)
30
27
  %{{"json_class":"#{self.class}","x":#{@x},"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 # Jeez
37
34
 
38
35
  class Orange < Jam
39
- def initialize(x, y)
40
- super
41
- end
42
36
 
43
- def as_json()
37
+ def as_json
44
38
  { :json_class => self.class,
45
39
  :x => @x,
46
40
  :y => @y }
47
41
  end
48
42
 
49
43
  def self.json_create(h)
50
- self.new(h['x'], h['y'])
44
+ new(h['x'], h['y'])
51
45
  end
52
46
  end
53
47
 
@@ -73,8 +67,8 @@ class FileJuice < Minitest::Test
73
67
 
74
68
  def test_fixnum
75
69
  dump_and_load(0, false)
76
- dump_and_load(12345, false)
77
- dump_and_load(-54321, false)
70
+ dump_and_load(12_345, false)
71
+ dump_and_load(-54_321, false)
78
72
  dump_and_load(1, false)
79
73
  end
80
74
 
@@ -82,9 +76,9 @@ class FileJuice < Minitest::Test
82
76
  mode = Oj.default_options()[:mode]
83
77
  Oj.default_options = {:mode => :object}
84
78
  dump_and_load(0.0, false)
85
- dump_and_load(12345.6789, false)
79
+ dump_and_load(12_345.6789, false)
86
80
  dump_and_load(70.35, false)
87
- dump_and_load(-54321.012, false)
81
+ dump_and_load(-54_321.012, false)
88
82
  dump_and_load(1.7775, false)
89
83
  dump_and_load(2.5024, false)
90
84
  dump_and_load(2.48e16, false)
@@ -118,9 +112,9 @@ class FileJuice < Minitest::Test
118
112
  # Symbol
119
113
  def test_symbol_object
120
114
  Oj.default_options = { :mode => :object }
121
- #dump_and_load(''.to_sym, false)
115
+ # dump_and_load(''.to_sym, false)
122
116
  dump_and_load(:abc, false)
123
- dump_and_load(':xyz'.to_sym, false)
117
+ dump_and_load(:":xyz", false)
124
118
  end
125
119
 
126
120
  # Time
@@ -129,10 +123,11 @@ class FileJuice < Minitest::Test
129
123
  Oj.default_options = { :mode => :object, :time_format => :unix_zone }
130
124
  dump_and_load(t, false)
131
125
  end
126
+
132
127
  def test_time_object_early
133
128
  skip 'Windows does not support dates before 1970.' if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
134
129
 
135
- t = Time.xmlschema("1954-01-05T00:00:00.123456")
130
+ t = Time.xmlschema('1954-01-05T00:00:00.123456')
136
131
  Oj.default_options = { :mode => :object, :time_format => :unix_zone }
137
132
  dump_and_load(t, false)
138
133
  end
@@ -165,7 +160,7 @@ class FileJuice < Minitest::Test
165
160
  if $ruby == 'ruby'
166
161
  assert_equal(%{{"^u":["Range",1,7,false]}}, json)
167
162
  else
168
- assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
163
+ assert_equal(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}}, json)
169
164
  end
170
165
  dump_and_load(1..7, false)
171
166
  dump_and_load(1..1, false)
@@ -229,8 +224,8 @@ class FileJuice < Minitest::Test
229
224
  end
230
225
 
231
226
  def dump_and_load(obj, trace=false)
232
- filename = File.join(File.dirname(__FILE__), 'file_test.json')
233
- File.open(filename, "w") { |f|
227
+ filename = File.join(__dir__, 'file_test.json')
228
+ File.open(filename, 'w') { |f|
234
229
  Oj.to_stream(f, obj, :indent => 2)
235
230
  }
236
231
  puts "\n*** file: '#{File.read(filename)}'" if trace
data/test/test_gc.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
 
@@ -14,13 +14,13 @@ class GCTest < Minitest::Test
14
14
  @child = child
15
15
  end
16
16
 
17
- def to_hash()
18
- { 'json_class' => "#{self.class}", 'x' => x, 'child' => child }
17
+ def to_hash
18
+ { 'json_class' => self.class.to_s, 'x' => x, 'child' => child }
19
19
  end
20
20
 
21
21
  def self.json_create(h)
22
22
  GC.start
23
- self.new(h['x'], h['child'])
23
+ new(h['x'], h['child'])
24
24
  end
25
25
  end # Goo
26
26
 
@@ -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'
@@ -15,7 +15,7 @@ class Generator < Minitest::Test
15
15
 
16
16
  def test_before
17
17
  json = Oj.generate({})
18
- assert_equal("{}", json)
18
+ assert_equal('{}', json)
19
19
  end
20
20
 
21
21
  end
data/test/test_hash.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
 
@@ -19,7 +19,7 @@ class HashTest < Minitest::Test
19
19
 
20
20
  def test_load
21
21
  obj = Oj.load(%|{"abc":3}|, :mode => :compat, :hash_class => Oj::EasyHash)
22
-
22
+
23
23
  assert_equal(Oj::EasyHash, obj.class)
24
24
  assert_equal(3, obj['abc'])
25
25
  assert_equal(3, obj[:abc])
@@ -35,5 +35,5 @@ class HashTest < Minitest::Test
35
35
  assert_equal(Oj::EasyHash, obj.class)
36
36
  assert_equal(3, obj[:abc])
37
37
  end
38
-
38
+
39
39
  end # HashTest
@@ -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'
@@ -23,19 +23,19 @@ class IntegerRangeTest < Minitest::Test
23
23
  end
24
24
 
25
25
  def test_range
26
- test = {s: 0, s2: -1, s3: 1, u: -2, u2: 2, u3: 9007199254740993}
26
+ test = {s: 0, s2: -1, s3: 1, u: -2, u2: 2, u3: 9_007_199_254_740_993}
27
27
  exp = '{"s":0,"s2":-1,"s3":1,"u":"-2","u2":"2","u3":"9007199254740993"}'
28
28
  assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
29
29
  end
30
30
 
31
31
  def test_bignum
32
- test = {u: -10000000000000000000, u2: 10000000000000000000}
32
+ test = {u: -10_000_000_000_000_000_000, u2: 10_000_000_000_000_000_000}
33
33
  exp = '{"u":"-10000000000000000000","u2":"10000000000000000000"}'
34
34
  assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
35
35
  end
36
36
 
37
37
  def test_valid_modes
38
- test = {safe: 0, unsafe: 9007199254740993}
38
+ test = {safe: 0, unsafe: 9_007_199_254_740_993}
39
39
  exp = '{"safe":0,"unsafe":"9007199254740993"}'
40
40
 
41
41
  [:strict, :null, :compat, :rails, :custom].each do |mode|
@@ -49,7 +49,7 @@ class IntegerRangeTest < Minitest::Test
49
49
  end
50
50
 
51
51
  def test_modes_without_opt
52
- test = {safe: 0, unsafe: 10000000000000000000}
52
+ test = {safe: 0, unsafe: 10_000_000_000_000_000_000}
53
53
  exp = '{"safe":0,"unsafe":10000000000000000000}'
54
54
 
55
55
  [:strict, :null, :compat, :rails, :custom].each do |mode|
@@ -63,7 +63,7 @@ class IntegerRangeTest < Minitest::Test
63
63
  end
64
64
 
65
65
  def test_accept_nil_and_false
66
- test = {safe: 0, unsafe: 10000000000000000000}
66
+ test = {safe: 0, unsafe: 10_000_000_000_000_000_000}
67
67
  exp = '{"safe":0,"unsafe":10000000000000000000}'
68
68
 
69
69
  assert_equal(exp, Oj.dump(test, integer_range: nil))
data/test/test_null.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'
@@ -52,16 +52,16 @@ class NullJuice < Minitest::Test
52
52
 
53
53
  def test_fixnum
54
54
  dump_and_load(0, false)
55
- dump_and_load(12345, false)
56
- dump_and_load(-54321, false)
55
+ dump_and_load(12_345, false)
56
+ dump_and_load(-54_321, false)
57
57
  dump_and_load(1, false)
58
58
  end
59
59
 
60
60
  def test_float
61
61
  dump_and_load(0.0, false)
62
- dump_and_load(12345.6789, false)
62
+ dump_and_load(12_345.6789, false)
63
63
  dump_and_load(70.35, false)
64
- dump_and_load(-54321.012, false)
64
+ dump_and_load(-54_321.012, false)
65
65
  dump_and_load(1.7775, false)
66
66
  dump_and_load(2.5024, false)
67
67
  dump_and_load(2.48e16, false)
@@ -78,7 +78,7 @@ class NullJuice < Minitest::Test
78
78
  assert(true)
79
79
  return
80
80
  end
81
- assert(false, "*** expected an exception")
81
+ assert(false, '*** expected an exception')
82
82
  end
83
83
 
84
84
  def test_infinity_dump
@@ -90,7 +90,7 @@ class NullJuice < Minitest::Test
90
90
  assert(true)
91
91
  return
92
92
  end
93
- assert(false, "*** expected an exception")
93
+ assert(false, '*** expected an exception')
94
94
  end
95
95
 
96
96
  def test_neg_infinity_dump
@@ -102,7 +102,7 @@ class NullJuice < Minitest::Test
102
102
  assert(true)
103
103
  return
104
104
  end
105
- assert(false, "*** expected an exception")
105
+ assert(false, '*** expected an exception')
106
106
  end
107
107
 
108
108
  def test_string
@@ -116,13 +116,13 @@ class NullJuice < Minitest::Test
116
116
  opts = Oj.default_options
117
117
  Oj.default_options = { :ascii_only => false }
118
118
  unless 'jruby' == $ruby
119
- dump_and_load("ぴーたー", false)
119
+ dump_and_load('ぴーたー', false)
120
120
  end
121
121
  Oj.default_options = { :ascii_only => true }
122
- json = Oj.dump("ぴーたー")
122
+ json = Oj.dump('ぴーたー')
123
123
  assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
124
124
  unless 'jruby' == $ruby
125
- dump_and_load("ぴーたー", false)
125
+ dump_and_load('ぴーたー', false)
126
126
  end
127
127
  Oj.default_options = opts
128
128
  end
@@ -198,7 +198,7 @@ class NullJuice < Minitest::Test
198
198
  assert(true)
199
199
  return
200
200
  end
201
- assert(false, "*** expected an exception")
201
+ assert(false, '*** expected an exception')
202
202
  end
203
203
 
204
204
  def test_bignum_object
@@ -244,15 +244,13 @@ class NullJuice < Minitest::Test
244
244
  end
245
245
 
246
246
  def test_io_file
247
- filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
248
- File.open(filename, 'w') { |f|
249
- f.write(%{{
247
+ filename = File.join(__dir__, 'open_file_test.json')
248
+ File.write(filename, %{{
250
249
  "x":true,
251
250
  "y":58,
252
251
  "z": [1,2,3]
253
252
  }
254
253
  })
255
- }
256
254
  f = File.new(filename)
257
255
  obj = Oj.strict_load(f)
258
256
  f.close()
@@ -366,7 +364,7 @@ class NullJuice < Minitest::Test
366
364
  def dump_and_load(obj, trace=false)
367
365
  json = Oj.dump(obj, :indent => 2)
368
366
  puts json if trace
369
- loaded = Oj.strict_load(json);
367
+ loaded = Oj.strict_load(json)
370
368
  if obj.nil?
371
369
  assert_nil(loaded)
372
370
  else