oj 3.16.7 → 3.16.10

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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/ext/oj/fast.c +3 -6
  4. data/ext/oj/mimic_json.c +3 -6
  5. data/ext/oj/oj.c +2 -4
  6. data/ext/oj/parse.c +31 -19
  7. data/ext/oj/parser.c +1 -1
  8. data/ext/oj/parser.h +2 -0
  9. data/ext/oj/rails.c +1 -2
  10. data/ext/oj/saj.c +3 -6
  11. data/ext/oj/scp.c +3 -6
  12. data/ext/oj/stream_writer.c +3 -13
  13. data/ext/oj/strict.c +2 -4
  14. data/ext/oj/string_writer.c +1 -3
  15. data/ext/oj/usual.c +2 -2
  16. data/lib/oj/version.rb +1 -1
  17. metadata +3 -98
  18. data/test/_test_active.rb +0 -75
  19. data/test/_test_active_mimic.rb +0 -95
  20. data/test/_test_mimic_rails.rb +0 -123
  21. data/test/activerecord/result_test.rb +0 -31
  22. data/test/activesupport6/abstract_unit.rb +0 -44
  23. data/test/activesupport6/decoding_test.rb +0 -133
  24. data/test/activesupport6/encoding_test.rb +0 -542
  25. data/test/activesupport6/encoding_test_cases.rb +0 -98
  26. data/test/activesupport6/test_common.rb +0 -17
  27. data/test/activesupport6/test_helper.rb +0 -163
  28. data/test/activesupport6/time_zone_test_helpers.rb +0 -39
  29. data/test/activesupport7/abstract_unit.rb +0 -52
  30. data/test/activesupport7/decoding_test.rb +0 -125
  31. data/test/activesupport7/encoding_test.rb +0 -536
  32. data/test/activesupport7/encoding_test_cases.rb +0 -104
  33. data/test/activesupport7/time_zone_test_helpers.rb +0 -47
  34. data/test/files.rb +0 -29
  35. data/test/foo.rb +0 -26
  36. data/test/helper.rb +0 -39
  37. data/test/isolated/shared.rb +0 -309
  38. data/test/isolated/test_mimic_after.rb +0 -13
  39. data/test/isolated/test_mimic_alone.rb +0 -12
  40. data/test/isolated/test_mimic_as_json.rb +0 -45
  41. data/test/isolated/test_mimic_before.rb +0 -13
  42. data/test/isolated/test_mimic_define.rb +0 -28
  43. data/test/isolated/test_mimic_rails_after.rb +0 -22
  44. data/test/isolated/test_mimic_rails_before.rb +0 -21
  45. data/test/isolated/test_mimic_redefine.rb +0 -15
  46. data/test/json_gem/json_addition_test.rb +0 -216
  47. data/test/json_gem/json_common_interface_test.rb +0 -155
  48. data/test/json_gem/json_encoding_test.rb +0 -107
  49. data/test/json_gem/json_ext_parser_test.rb +0 -21
  50. data/test/json_gem/json_fixtures_test.rb +0 -36
  51. data/test/json_gem/json_generator_test.rb +0 -413
  52. data/test/json_gem/json_generic_object_test.rb +0 -90
  53. data/test/json_gem/json_parser_test.rb +0 -477
  54. data/test/json_gem/json_string_matching_test.rb +0 -42
  55. data/test/json_gem/test_helper.rb +0 -30
  56. data/test/mem.rb +0 -34
  57. data/test/perf.rb +0 -102
  58. data/test/perf_compat.rb +0 -128
  59. data/test/perf_dump.rb +0 -50
  60. data/test/perf_fast.rb +0 -162
  61. data/test/perf_file.rb +0 -62
  62. data/test/perf_object.rb +0 -134
  63. data/test/perf_once.rb +0 -59
  64. data/test/perf_parser.rb +0 -183
  65. data/test/perf_saj.rb +0 -101
  66. data/test/perf_scp.rb +0 -140
  67. data/test/perf_simple.rb +0 -289
  68. data/test/perf_strict.rb +0 -137
  69. data/test/perf_wab.rb +0 -129
  70. data/test/prec.rb +0 -23
  71. data/test/sample/change.rb +0 -13
  72. data/test/sample/dir.rb +0 -18
  73. data/test/sample/doc.rb +0 -35
  74. data/test/sample/file.rb +0 -47
  75. data/test/sample/group.rb +0 -15
  76. data/test/sample/hasprops.rb +0 -15
  77. data/test/sample/layer.rb +0 -11
  78. data/test/sample/line.rb +0 -20
  79. data/test/sample/oval.rb +0 -10
  80. data/test/sample/rect.rb +0 -9
  81. data/test/sample/shape.rb +0 -34
  82. data/test/sample/text.rb +0 -19
  83. data/test/sample.rb +0 -54
  84. data/test/sample_json.rb +0 -37
  85. data/test/test_compat.rb +0 -567
  86. data/test/test_custom.rb +0 -555
  87. data/test/test_debian.rb +0 -50
  88. data/test/test_fast.rb +0 -526
  89. data/test/test_file.rb +0 -250
  90. data/test/test_gc.rb +0 -60
  91. data/test/test_generate.rb +0 -21
  92. data/test/test_hash.rb +0 -39
  93. data/test/test_integer_range.rb +0 -72
  94. data/test/test_null.rb +0 -376
  95. data/test/test_object.rb +0 -1030
  96. data/test/test_parser.rb +0 -11
  97. data/test/test_parser_debug.rb +0 -27
  98. data/test/test_parser_saj.rb +0 -337
  99. data/test/test_parser_usual.rb +0 -251
  100. data/test/test_rails.rb +0 -35
  101. data/test/test_saj.rb +0 -188
  102. data/test/test_scp.rb +0 -431
  103. data/test/test_strict.rb +0 -441
  104. data/test/test_various.rb +0 -801
  105. data/test/test_wab.rb +0 -311
  106. data/test/test_writer.rb +0 -380
  107. data/test/tests.rb +0 -33
  108. data/test/tests_mimic.rb +0 -23
  109. data/test/tests_mimic_addition.rb +0 -16
data/test/test_file.rb DELETED
@@ -1,250 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
-
6
- require 'helper'
7
-
8
- class FileJuice < Minitest::Test
9
- class Jam
10
- attr_accessor :x, :y
11
-
12
- def initialize(x, y)
13
- @x = x
14
- @y = y
15
- end
16
-
17
- def eql?(o)
18
- self.class == o.class && @x == o.x && @y == o.y
19
- end
20
- alias == eql?
21
-
22
- end # Jam
23
-
24
- class Jeez < Jam
25
-
26
- def to_json(*_args)
27
- %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
28
- end
29
-
30
- def self.json_create(h)
31
- new(h['x'], h['y'])
32
- end
33
- end # Jeez
34
-
35
- class Orange < Jam
36
-
37
- def as_json
38
- { :json_class => self.class,
39
- :x => @x,
40
- :y => @y }
41
- end
42
-
43
- def self.json_create(h)
44
- new(h['x'], h['y'])
45
- end
46
- end
47
-
48
- def setup
49
- @default_options = Oj.default_options
50
- end
51
-
52
- def teardown
53
- Oj.default_options = @default_options
54
- end
55
-
56
- def test_nil
57
- dump_and_load(nil, false)
58
- end
59
-
60
- def test_true
61
- dump_and_load(true, false)
62
- end
63
-
64
- def test_false
65
- dump_and_load(false, false)
66
- end
67
-
68
- def test_fixnum
69
- dump_and_load(0, false)
70
- dump_and_load(12_345, false)
71
- dump_and_load(-54_321, false)
72
- dump_and_load(1, false)
73
- end
74
-
75
- def test_float
76
- mode = Oj.default_options()[:mode]
77
- Oj.default_options = {:mode => :object}
78
- dump_and_load(0.0, false)
79
- dump_and_load(12_345.6789, false)
80
- dump_and_load(70.35, false)
81
- dump_and_load(-54_321.012, false)
82
- dump_and_load(1.7775, false)
83
- dump_and_load(2.5024, false)
84
- dump_and_load(2.48e16, false)
85
- dump_and_load(2.48e100 * 1.0e10, false)
86
- dump_and_load(-2.48e100 * 1.0e10, false)
87
- dump_and_load(1/0.0, false)
88
- Oj.default_options = {:mode => mode}
89
- end
90
-
91
- def test_string
92
- dump_and_load('', false)
93
- dump_and_load('abc', false)
94
- dump_and_load("abc\ndef", false)
95
- dump_and_load("a\u0041", false)
96
- assert_equal("a\u0000a", dump_and_load("a\u0000a", false))
97
- end
98
-
99
- def test_string_object
100
- dump_and_load('abc', false)
101
- dump_and_load(':abc', false)
102
- end
103
-
104
- def test_array
105
- dump_and_load([], false)
106
- dump_and_load([true, false], false)
107
- dump_and_load(['a', 1, nil], false)
108
- dump_and_load([[nil]], false)
109
- dump_and_load([[nil], 58], false)
110
- end
111
-
112
- # Symbol
113
- def test_symbol_object
114
- Oj.default_options = { :mode => :object }
115
- # dump_and_load(''.to_sym, false)
116
- dump_and_load(:abc, false)
117
- dump_and_load(:":xyz", false)
118
- end
119
-
120
- # Time
121
- def test_time_object
122
- t = Time.now()
123
- Oj.default_options = { :mode => :object, :time_format => :unix_zone }
124
- dump_and_load(t, false)
125
- end
126
-
127
- def test_time_object_early
128
- skip 'Windows does not support dates before 1970.' if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
129
-
130
- t = Time.xmlschema('1954-01-05T00:00:00.123456')
131
- Oj.default_options = { :mode => :object, :time_format => :unix_zone }
132
- dump_and_load(t, false)
133
- end
134
-
135
- # Hash
136
- def test_hash
137
- Oj.default_options = { :mode => :strict }
138
- dump_and_load({}, false)
139
- dump_and_load({ 'true' => true, 'false' => false}, false)
140
- dump_and_load({ 'true' => true, 'array' => [], 'hash' => { }}, false)
141
- end
142
-
143
- # Object with to_json()
144
- def test_json_object_compat
145
- Oj.default_options = { :mode => :compat, :use_to_json => true, :create_additions => true }
146
- obj = Jeez.new(true, 58)
147
- json = Oj.dump(obj, :indent => 2)
148
- assert(%{{"json_class":"FileJuice::Jeez","x":true,"y":58}
149
- } == json ||
150
- %{{"json_class":"FileJuice::Jeez","y":58,"x":true}
151
- } == json)
152
- dump_and_load(obj, false)
153
- Oj.default_options = { :mode => :compat, :use_to_json => false }
154
- end
155
-
156
- # Range
157
- def test_range_object
158
- Oj.default_options = { :mode => :object }
159
- json = Oj.dump(1..7, :mode => :object, :indent => 0)
160
- if $ruby == 'ruby'
161
- assert_equal(%{{"^u":["Range",1,7,false]}}, json)
162
- else
163
- assert_equal(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}}, json)
164
- end
165
- dump_and_load(1..7, false)
166
- dump_and_load(1..1, false)
167
- dump_and_load(1...7, false)
168
- end
169
-
170
- # BigNum
171
- def test_bignum_object
172
- Oj.default_options = { :mode => :compat }
173
- dump_and_load(7 ** 55, false)
174
- end
175
-
176
- # BigDecimal
177
- def test_bigdecimal_strict
178
- mode = Oj.default_options[:mode]
179
- Oj.default_options = {:mode => :strict}
180
- dump_and_load(BigDecimal('3.14159265358979323846'), false)
181
- Oj.default_options = {:mode => mode}
182
- end
183
-
184
- def test_bigdecimal_null
185
- mode = Oj.default_options[:mode]
186
- Oj.default_options = {:mode => :null}
187
- dump_and_load(BigDecimal('3.14159265358979323846'), false)
188
- Oj.default_options = {:mode => mode}
189
- end
190
-
191
- def test_bigdecimal_object
192
- Oj.default_options = {:mode => :object}
193
- dump_and_load(BigDecimal('3.14159265358979323846'), false)
194
- end
195
-
196
- # Date
197
- def test_date_object
198
- Oj.default_options = { :mode => :object }
199
- dump_and_load(Date.new(2012, 6, 19), false)
200
- end
201
-
202
- # DateTime
203
- def test_datetime_object
204
- Oj.default_options = { :mode => :object }
205
- dump_and_load(DateTime.new(2012, 6, 19), false)
206
- end
207
-
208
- def test_load_unicode_path
209
- json =<<~JSON
210
- {
211
- "x":true,
212
- "y":58,
213
- "z": [1,2,3]
214
- }
215
- JSON
216
-
217
- Tempfile.create('file_test_conceição1.json') do |f|
218
- f.write(json)
219
- f.close
220
-
221
- objects = Oj.load_file(f.path)
222
- assert_equal(Oj.load(json), objects)
223
- end
224
- end
225
-
226
- def dump_and_load(obj, trace=false)
227
- filename = File.join(__dir__, 'file_test.json')
228
- File.open(filename, 'w') { |f|
229
- Oj.to_stream(f, obj, :indent => 2)
230
- }
231
- puts "\n*** file: '#{File.read(filename)}'" if trace
232
- loaded = Oj.load_file(filename)
233
- if obj.is_a?(Time) && loaded.is_a?(Time)
234
- assert_equal(obj.tv_sec, loaded.tv_sec)
235
- if obj.respond_to?(:tv_nsec)
236
- assert_equal(obj.tv_nsec, loaded.tv_nsec)
237
- else
238
- assert_equal(obj.tv_usec, loaded.tv_usec)
239
- end
240
- assert_equal(obj.utc?, loaded.utc?)
241
- assert_equal(obj.utc_offset, loaded.utc_offset)
242
- elsif obj.nil?
243
- assert_nil(loaded)
244
- else
245
- assert_equal(obj, loaded)
246
- end
247
- loaded
248
- end
249
-
250
- end
data/test/test_gc.rb DELETED
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
-
6
- require 'helper'
7
-
8
- class GCTest < Minitest::Test
9
- class Goo
10
- attr_accessor :x, :child
11
-
12
- def initialize(x, child)
13
- @x = x
14
- @child = child
15
- end
16
-
17
- def to_hash
18
- { 'json_class' => self.class.to_s, 'x' => x, 'child' => child }
19
- end
20
-
21
- def self.json_create(h)
22
- GC.start
23
- new(h['x'], h['child'])
24
- end
25
- end # Goo
26
-
27
- def setup
28
- @default_options = Oj.default_options
29
- GC.stress = true
30
- end
31
-
32
- def teardown
33
- Oj.default_options = @default_options
34
- GC.stress = false
35
- end
36
-
37
- # if no crash then the GC marking is working
38
- def test_parse_compat_gc
39
- g = Goo.new(0, nil)
40
- 100.times { |i| g = Goo.new(i, g) }
41
- json = Oj.dump(g, :mode => :compat)
42
- Oj.compat_load(json)
43
- end
44
-
45
- def test_parse_object_gc
46
- g = Goo.new(0, nil)
47
- 100.times { |i| g = Goo.new(i, g) }
48
- json = Oj.dump(g, :mode => :object)
49
- Oj.object_load(json)
50
- end
51
-
52
- def test_parse_gc
53
- json = '{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}'
54
-
55
- 50.times do
56
- data = Oj.load(json)
57
- assert_equal(json, Oj.dump(data))
58
- end
59
- end
60
- end
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
- @oj_dir = File.dirname(File.expand_path(__dir__))
6
- %w(lib ext).each do |dir|
7
- $LOAD_PATH << File.join(@oj_dir, dir)
8
- end
9
-
10
- require 'minitest'
11
- require 'minitest/autorun'
12
- require 'oj'
13
-
14
- class Generator < Minitest::Test
15
-
16
- def test_before
17
- json = Oj.generate({})
18
- assert_equal('{}', json)
19
- end
20
-
21
- end
data/test/test_hash.rb DELETED
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
-
6
- require 'helper'
7
-
8
- class HashTest < Minitest::Test
9
-
10
- module TestModule
11
- end
12
-
13
- def test_dump
14
- h = Oj::EasyHash.new()
15
- h['abc'] = 3
16
- out = Oj.dump(h, :mode => :compat)
17
- assert_equal(%|{"abc":3}|, out)
18
- end
19
-
20
- def test_load
21
- obj = Oj.load(%|{"abc":3}|, :mode => :compat, :hash_class => Oj::EasyHash)
22
-
23
- assert_equal(Oj::EasyHash, obj.class)
24
- assert_equal(3, obj['abc'])
25
- assert_equal(3, obj[:abc])
26
- assert_equal(3, obj.abc())
27
- end
28
-
29
- def test_marshal
30
- h = Oj::EasyHash.new()
31
- h['abc'] = 3
32
- out = Marshal.dump(h)
33
-
34
- obj = Marshal.load(out)
35
- assert_equal(Oj::EasyHash, obj.class)
36
- assert_equal(3, obj[:abc])
37
- end
38
-
39
- end # HashTest
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- $LOAD_PATH << __dir__
5
- @oj_dir = File.dirname(File.expand_path(__dir__))
6
- %w(lib ext).each do |dir|
7
- $LOAD_PATH << File.join(@oj_dir, dir)
8
- end
9
-
10
- require 'minitest'
11
- require 'minitest/autorun'
12
- require 'oj'
13
-
14
- class IntegerRangeTest < Minitest::Test
15
- def setup
16
- @default_options = Oj.default_options
17
- # in null mode other options other than the number formats are not used.
18
- Oj.default_options = { :mode => :null, bigdecimal_as_decimal: true }
19
- end
20
-
21
- def teardown
22
- Oj.default_options = @default_options
23
- end
24
-
25
- def test_range
26
- test = {s: 0, s2: -1, s3: 1, u: -2, u2: 2, u3: 9_007_199_254_740_993}
27
- exp = '{"s":0,"s2":-1,"s3":1,"u":"-2","u2":"2","u3":"9007199254740993"}'
28
- assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
29
- end
30
-
31
- def test_bignum
32
- test = {u: -10_000_000_000_000_000_000, u2: 10_000_000_000_000_000_000}
33
- exp = '{"u":"-10000000000000000000","u2":"10000000000000000000"}'
34
- assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
35
- end
36
-
37
- def test_valid_modes
38
- test = {safe: 0, unsafe: 9_007_199_254_740_993}
39
- exp = '{"safe":0,"unsafe":"9007199254740993"}'
40
-
41
- [:strict, :null, :compat, :rails, :custom].each do |mode|
42
- assert_equal(exp, Oj.dump(test, mode: mode, integer_range: (-1..1)), "Invalid mode #{mode}")
43
- end
44
-
45
- exp = '{":safe":0,":unsafe":"9007199254740993"}'
46
- [:object].each do |mode|
47
- assert_equal(exp, Oj.dump(test, mode: mode, integer_range: (-1..1)), "Invalid mode #{mode}")
48
- end
49
- end
50
-
51
- def test_modes_without_opt
52
- test = {safe: 0, unsafe: 10_000_000_000_000_000_000}
53
- exp = '{"safe":0,"unsafe":10000000000000000000}'
54
-
55
- [:strict, :null, :compat, :rails, :custom].each do |mode|
56
- assert_equal(exp, Oj.dump(test, mode: mode), "Invalid mode #{mode}")
57
- end
58
-
59
- exp = '{":safe":0,":unsafe":10000000000000000000}'
60
- [:object].each do |mode|
61
- assert_equal(exp, Oj.dump(test, mode: mode), "Invalid mode #{mode}")
62
- end
63
- end
64
-
65
- def test_accept_nil_and_false
66
- test = {safe: 0, unsafe: 10_000_000_000_000_000_000}
67
- exp = '{"safe":0,"unsafe":10000000000000000000}'
68
-
69
- assert_equal(exp, Oj.dump(test, integer_range: nil))
70
- assert_equal(exp, Oj.dump(test, integer_range: false))
71
- end
72
- end