oj 3.9.2 → 3.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/oj/custom.c +2 -0
- data/ext/oj/dump.c +9 -12
- data/ext/oj/dump_compat.c +6 -9
- data/ext/oj/dump_object.c +14 -9
- data/ext/oj/mimic_json.c +4 -2
- data/ext/oj/oj.c +44 -27
- data/ext/oj/oj.h +4 -2
- data/ext/oj/parse.c +12 -3
- data/ext/oj/parse.h +1 -0
- data/ext/oj/rails.c +7 -2
- data/ext/oj/sparse.c +1 -1
- data/lib/oj/version.rb +1 -1
- data/pages/Rails.md +21 -21
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +68 -60
- data/test/activesupport5/encoding_test.rb +111 -96
- data/test/activesupport5/encoding_test_cases.rb +33 -25
- data/test/activesupport5/test_helper.rb +43 -21
- data/test/activesupport5/time_zone_test_helpers.rb +18 -3
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/bar.rb +8 -11
- data/test/baz.rb +16 -0
- data/test/foo.rb +154 -8
- data/test/test_compat.rb +0 -7
- data/test/test_custom.rb +6 -2
- data/test/test_integer_range.rb +1 -2
- data/test/test_object.rb +4 -3
- data/test/test_strict.rb +24 -1
- data/test/test_various.rb +41 -62
- metadata +20 -2
data/test/test_compat.rb
CHANGED
@@ -147,16 +147,9 @@ class CompatJuice < Minitest::Test
|
|
147
147
|
|
148
148
|
def test_encode
|
149
149
|
opts = Oj.default_options
|
150
|
-
Oj.default_options = { :ascii_only => false }
|
151
|
-
unless 'jruby' == $ruby
|
152
|
-
dump_and_load("ぴーたー", false)
|
153
|
-
end
|
154
150
|
Oj.default_options = { :ascii_only => true }
|
155
151
|
json = Oj.dump("ぴーたー")
|
156
152
|
assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
|
157
|
-
unless 'jruby' == $ruby
|
158
|
-
dump_and_load("ぴーたー", false)
|
159
|
-
end
|
160
153
|
Oj.default_options = opts
|
161
154
|
end
|
162
155
|
|
data/test/test_custom.rb
CHANGED
@@ -20,11 +20,12 @@ class CustomJuice < Minitest::Test
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class Jeez
|
23
|
-
attr_accessor :x, :y
|
23
|
+
attr_accessor :x, :y, :_z
|
24
24
|
|
25
25
|
def initialize(x, y)
|
26
26
|
@x = x
|
27
27
|
@y = y
|
28
|
+
@_z = x.to_s
|
28
29
|
end
|
29
30
|
def ==(o)
|
30
31
|
self.class == o.class && @x == o.x && @y = o.y
|
@@ -247,7 +248,10 @@ class CustomJuice < Minitest::Test
|
|
247
248
|
|
248
249
|
def test_object
|
249
250
|
obj = Jeez.new(true, 58)
|
250
|
-
Oj.dump(obj, :
|
251
|
+
json = Oj.dump(obj, create_id: "^o", use_to_json: false, use_as_json: false, use_to_hash: false)
|
252
|
+
assert_equal(%|{"x":true,"y":58,"_z":"true"}|, json)
|
253
|
+
json = Oj.dump(obj, create_id: "^o", use_to_json: false, use_as_json: false, use_to_hash: false, ignore_under: true)
|
254
|
+
assert_equal(%|{"x":true,"y":58}|, json)
|
251
255
|
dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
|
252
256
|
end
|
253
257
|
|
data/test/test_integer_range.rb
CHANGED
@@ -15,7 +15,7 @@ class IntegerRangeTest < Minitest::Test
|
|
15
15
|
def setup
|
16
16
|
@default_options = Oj.default_options
|
17
17
|
# in null mode other options other than the number formats are not used.
|
18
|
-
Oj.default_options = { :mode => :null }
|
18
|
+
Oj.default_options = { :mode => :null, bigdecimal_as_decimal: true }
|
19
19
|
end
|
20
20
|
|
21
21
|
def teardown
|
@@ -70,4 +70,3 @@ class IntegerRangeTest < Minitest::Test
|
|
70
70
|
assert_equal(exp, Oj.dump(test, integer_range: false))
|
71
71
|
end
|
72
72
|
end
|
73
|
-
|
data/test/test_object.rb
CHANGED
@@ -7,11 +7,12 @@ require 'helper'
|
|
7
7
|
|
8
8
|
class ObjectJuice < Minitest::Test
|
9
9
|
class Jeez
|
10
|
-
attr_accessor :x, :y
|
10
|
+
attr_accessor :x, :y, :_z
|
11
11
|
|
12
12
|
def initialize(x, y)
|
13
13
|
@x = x
|
14
14
|
@y = y
|
15
|
+
@_z = x.to_s
|
15
16
|
end
|
16
17
|
|
17
18
|
def eql?(o)
|
@@ -687,7 +688,7 @@ class ObjectJuice < Minitest::Test
|
|
687
688
|
|
688
689
|
def test_json_object_object
|
689
690
|
obj = Jeez.new(true, 58)
|
690
|
-
json = Oj.dump(obj, :
|
691
|
+
json = Oj.dump(obj, mode: :object, indent: 2, ignore_under: true)
|
691
692
|
assert(%{{
|
692
693
|
"^o":"ObjectJuice::Jeez",
|
693
694
|
"x":true,
|
@@ -799,7 +800,7 @@ class ObjectJuice < Minitest::Test
|
|
799
800
|
@xyz = 123
|
800
801
|
end
|
801
802
|
end
|
802
|
-
|
803
|
+
|
803
804
|
def test_exception_subclass
|
804
805
|
err = nil
|
805
806
|
begin
|
data/test/test_strict.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding:
|
2
|
+
# encoding: utf-8
|
3
3
|
|
4
4
|
$: << File.dirname(__FILE__)
|
5
5
|
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
@@ -379,6 +379,29 @@ class StrictJuice < Minitest::Test
|
|
379
379
|
assert_equal([{ 'x' => 1 }, { 'y' => 2 }], results)
|
380
380
|
end
|
381
381
|
|
382
|
+
def test_invalid_decimal_dot_start
|
383
|
+
assert_raises(Oj::ParseError) {
|
384
|
+
Oj.load('.123', mode: :strict)
|
385
|
+
}
|
386
|
+
assert_raises(Oj::ParseError) {
|
387
|
+
Oj.load('-.123', mode: :strict)
|
388
|
+
}
|
389
|
+
end
|
390
|
+
|
391
|
+
def test_invalid_decimal_dot_end
|
392
|
+
json = '123.'
|
393
|
+
assert_raises(Oj::ParseError) {
|
394
|
+
Oj.load(json, mode: :strict)
|
395
|
+
}
|
396
|
+
end
|
397
|
+
|
398
|
+
def test_invalid_decimal_plus
|
399
|
+
json = '+12'
|
400
|
+
assert_raises(Oj::ParseError) {
|
401
|
+
Oj.load(json, mode: :strict)
|
402
|
+
}
|
403
|
+
end
|
404
|
+
|
382
405
|
def test_circular_hash
|
383
406
|
h = { 'a' => 7 }
|
384
407
|
h['b'] = h
|
data/test/test_various.rb
CHANGED
@@ -96,70 +96,46 @@ class Juice < Minitest::Test
|
|
96
96
|
Oj.default_options = @default_options
|
97
97
|
end
|
98
98
|
|
99
|
-
=begin
|
100
|
-
# Depending on the order the values may have changed. The set_options sets
|
101
|
-
# should cover the function itself.
|
102
|
-
def test_get_options
|
103
|
-
opts = Oj.default_options()
|
104
|
-
assert_equal({ :indent=>0,
|
105
|
-
:second_precision=>9,
|
106
|
-
:circular=>false,
|
107
|
-
:class_cache=>true,
|
108
|
-
:auto_define=>false,
|
109
|
-
:symbol_keys=>false,
|
110
|
-
:bigdecimal_as_decimal=>true,
|
111
|
-
:use_to_json=>true,
|
112
|
-
:nilnil=>false,
|
113
|
-
:allow_gc=>true,
|
114
|
-
:quirks_mode=>true,
|
115
|
-
:allow_invalid_unicode=>false,
|
116
|
-
:float_precision=>15,
|
117
|
-
:mode=>:object,
|
118
|
-
:escape_mode=>:json,
|
119
|
-
:time_format=>:unix_zone,
|
120
|
-
:bigdecimal_load=>:auto,
|
121
|
-
:create_id=>'json_class'}, opts)
|
122
|
-
end
|
123
|
-
=end
|
124
99
|
def test_set_options
|
125
100
|
orig = Oj.default_options()
|
126
101
|
alt ={
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
135
|
-
:
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
142
|
-
:
|
143
|
-
:
|
144
|
-
:
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
154
|
-
:
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
160
|
-
:
|
161
|
-
:
|
162
|
-
:
|
102
|
+
indent: " - ",
|
103
|
+
second_precision: 5,
|
104
|
+
circular: true,
|
105
|
+
class_cache: false,
|
106
|
+
auto_define: true,
|
107
|
+
symbol_keys: true,
|
108
|
+
bigdecimal_as_decimal: false,
|
109
|
+
use_to_json: false,
|
110
|
+
use_to_hash: false,
|
111
|
+
use_as_json: false,
|
112
|
+
use_raw_json: false,
|
113
|
+
nilnil: true,
|
114
|
+
empty_string: true,
|
115
|
+
allow_gc: false,
|
116
|
+
quirks_mode: false,
|
117
|
+
allow_invalid_unicode: true,
|
118
|
+
float_precision: 13,
|
119
|
+
mode: :strict,
|
120
|
+
escape_mode: :ascii,
|
121
|
+
time_format: :unix_zone,
|
122
|
+
bigdecimal_load: :float,
|
123
|
+
create_id: 'classy',
|
124
|
+
create_additions: true,
|
125
|
+
space: 'z',
|
126
|
+
array_nl: 'a',
|
127
|
+
object_nl: 'o',
|
128
|
+
space_before: 'b',
|
129
|
+
nan: :huge,
|
130
|
+
hash_class: Hash,
|
131
|
+
omit_nil: false,
|
132
|
+
allow_nan: true,
|
133
|
+
integer_range: nil,
|
134
|
+
array_class: Array,
|
135
|
+
ignore: nil,
|
136
|
+
ignore_under: true,
|
137
|
+
trace: true,
|
138
|
+
safe: true,
|
163
139
|
}
|
164
140
|
Oj.default_options = alt
|
165
141
|
#keys = alt.keys
|
@@ -425,8 +401,11 @@ class Juice < Minitest::Test
|
|
425
401
|
def test_time_years
|
426
402
|
(-2020..2020).each { |year|
|
427
403
|
s = "%04d-03-01T15:14:13Z" % [year]
|
428
|
-
json = Oj.dump(Time.parse(s), mode: :custom, time_format: :xmlschema)
|
404
|
+
json = Oj.dump(Time.parse(s), mode: :custom, time_format: :xmlschema, second_precision: -1)
|
429
405
|
assert_equal(s, json[1..-2])
|
406
|
+
|
407
|
+
json = Oj.dump(Time.parse(s), mode: :custom, time_format: :xmlschema, second_precision: 3)
|
408
|
+
assert_equal(s[0..-2] + '.000Z', json[1..-2])
|
430
409
|
}
|
431
410
|
end
|
432
411
|
|
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.
|
4
|
+
version: 3.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -172,12 +172,21 @@ files:
|
|
172
172
|
- test/activesupport4/decoding_test.rb
|
173
173
|
- test/activesupport4/encoding_test.rb
|
174
174
|
- test/activesupport4/test_helper.rb
|
175
|
+
- test/activesupport5/abstract_unit.rb
|
175
176
|
- test/activesupport5/decoding_test.rb
|
176
177
|
- test/activesupport5/encoding_test.rb
|
177
178
|
- test/activesupport5/encoding_test_cases.rb
|
178
179
|
- test/activesupport5/test_helper.rb
|
179
180
|
- test/activesupport5/time_zone_test_helpers.rb
|
181
|
+
- test/activesupport6/abstract_unit.rb
|
182
|
+
- test/activesupport6/decoding_test.rb
|
183
|
+
- test/activesupport6/encoding_test.rb
|
184
|
+
- test/activesupport6/encoding_test_cases.rb
|
185
|
+
- test/activesupport6/test_common.rb
|
186
|
+
- test/activesupport6/test_helper.rb
|
187
|
+
- test/activesupport6/time_zone_test_helpers.rb
|
180
188
|
- test/bar.rb
|
189
|
+
- test/baz.rb
|
181
190
|
- test/files.rb
|
182
191
|
- test/foo.rb
|
183
192
|
- test/helper.rb
|
@@ -313,6 +322,7 @@ test_files:
|
|
313
322
|
- test/sample_json.rb
|
314
323
|
- test/activesupport5/encoding_test_cases.rb
|
315
324
|
- test/activesupport5/encoding_test.rb
|
325
|
+
- test/activesupport5/abstract_unit.rb
|
316
326
|
- test/activesupport5/time_zone_test_helpers.rb
|
317
327
|
- test/activesupport5/test_helper.rb
|
318
328
|
- test/activesupport5/decoding_test.rb
|
@@ -341,6 +351,7 @@ test_files:
|
|
341
351
|
- test/zoo.rb
|
342
352
|
- test/activerecord/result_test.rb
|
343
353
|
- test/_test_active_mimic.rb
|
354
|
+
- test/baz.rb
|
344
355
|
- test/tests_mimic_addition.rb
|
345
356
|
- test/test_writer.rb
|
346
357
|
- test/perf.rb
|
@@ -357,3 +368,10 @@ test_files:
|
|
357
368
|
- test/test_gc.rb
|
358
369
|
- test/files.rb
|
359
370
|
- test/test_various.rb
|
371
|
+
- test/activesupport6/encoding_test_cases.rb
|
372
|
+
- test/activesupport6/encoding_test.rb
|
373
|
+
- test/activesupport6/abstract_unit.rb
|
374
|
+
- test/activesupport6/time_zone_test_helpers.rb
|
375
|
+
- test/activesupport6/test_helper.rb
|
376
|
+
- test/activesupport6/test_common.rb
|
377
|
+
- test/activesupport6/decoding_test.rb
|