oj 3.9.1 → 3.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/oj/compat.c +5 -5
  4. data/ext/oj/custom.c +6 -2
  5. data/ext/oj/dump.c +10 -13
  6. data/ext/oj/dump_compat.c +8 -10
  7. data/ext/oj/dump_object.c +18 -11
  8. data/ext/oj/dump_strict.c +6 -5
  9. data/ext/oj/extconf.rb +5 -0
  10. data/ext/oj/mimic_json.c +15 -3
  11. data/ext/oj/object.c +2 -1
  12. data/ext/oj/oj.c +47 -28
  13. data/ext/oj/oj.h +4 -2
  14. data/ext/oj/parse.c +16 -3
  15. data/ext/oj/parse.h +1 -0
  16. data/ext/oj/rails.c +37 -4
  17. data/ext/oj/sparse.c +5 -0
  18. data/ext/oj/util.c +5 -5
  19. data/ext/oj/wab.c +9 -9
  20. data/lib/oj/version.rb +1 -1
  21. data/pages/Rails.md +60 -21
  22. data/test/activesupport5/abstract_unit.rb +45 -0
  23. data/test/activesupport5/decoding_test.rb +68 -60
  24. data/test/activesupport5/encoding_test.rb +111 -96
  25. data/test/activesupport5/encoding_test_cases.rb +33 -25
  26. data/test/activesupport5/test_helper.rb +43 -21
  27. data/test/activesupport5/time_zone_test_helpers.rb +18 -3
  28. data/test/activesupport6/abstract_unit.rb +44 -0
  29. data/test/activesupport6/decoding_test.rb +133 -0
  30. data/test/activesupport6/encoding_test.rb +507 -0
  31. data/test/activesupport6/encoding_test_cases.rb +98 -0
  32. data/test/activesupport6/test_common.rb +17 -0
  33. data/test/activesupport6/test_helper.rb +163 -0
  34. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  35. data/test/bar.rb +21 -11
  36. data/test/baz.rb +16 -0
  37. data/test/foo.rb +39 -8
  38. data/test/test_compat.rb +0 -7
  39. data/test/test_custom.rb +25 -6
  40. data/test/test_integer_range.rb +1 -2
  41. data/test/test_object.rb +12 -3
  42. data/test/test_rails.rb +26 -0
  43. data/test/test_strict.rb +24 -1
  44. data/test/test_various.rb +41 -62
  45. data/test/tests.rb +1 -0
  46. metadata +23 -3
@@ -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, :create_id => "^o", :use_to_json => false, :use_as_json => false, :use_to_hash => false)
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
 
@@ -466,10 +470,10 @@ class CustomJuice < Minitest::Test
466
470
 
467
471
  def test_time
468
472
  obj = Time.now()
469
- dump_and_load(obj, false, :time_format => :unix, :create_id => "^o", :create_additions => true)
470
- dump_and_load_inspect(obj, false, :time_format => :unix_zone, :create_id => "^o", :create_additions => true)
471
- dump_and_load_inspect(obj, false, :time_format => :xmlschema, :create_id => "^o", :create_additions => true)
472
- dump_and_load_inspect(obj, false, :time_format => :ruby, :create_id => "^o", :create_additions => true)
473
+ dump_load_dump(obj, false, :time_format => :unix, :create_id => "^o", :create_additions => true)
474
+ dump_load_dump(obj, false, :time_format => :unix_zone, :create_id => "^o", :create_additions => true)
475
+ dump_load_dump(obj, false, :time_format => :xmlschema, :create_id => "^o", :create_additions => true)
476
+ dump_load_dump(obj, false, :time_format => :ruby, :create_id => "^o", :create_additions => true)
473
477
  end
474
478
 
475
479
  def dump_and_load(obj, trace=false, options={})
@@ -500,4 +504,19 @@ class CustomJuice < Minitest::Test
500
504
  loaded
501
505
  end
502
506
 
507
+ def dump_load_dump(obj, trace=false, options={})
508
+ options = options.merge(:indent => 2, :mode => :custom)
509
+ json = Oj.dump(obj, options)
510
+ puts json if trace
511
+
512
+ loaded = Oj.load(json, options);
513
+ if obj.nil?
514
+ assert_nil(loaded)
515
+ else
516
+ json2 = Oj.dump(loaded, options)
517
+ assert_equal(json, json2)
518
+ end
519
+ loaded
520
+ end
521
+
503
522
  end
@@ -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
-
@@ -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, :mode => :object, :indent => 2)
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
@@ -868,6 +869,14 @@ class ObjectJuice < Minitest::Test
868
869
  assert_equal(a2[1].__id__, a2.__id__)
869
870
  end
870
871
 
872
+ def test_circular_array3
873
+ a = ['^r1']
874
+ json = Oj.dump(a, mode: :object, circular: true)
875
+ assert_equal(%{["^i1","\\u005er1"]}, json)
876
+ a2 = Oj.load(json, mode: :object, circular: true)
877
+ assert_equal(a, a2)
878
+ end
879
+
871
880
  def test_circular_hash2
872
881
  h = { 'a' => 7 }
873
882
  h['b'] = h
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'helper'
7
+
8
+ class RailsJuice < Minitest::Test
9
+
10
+ def test_bigdecimal_dump
11
+ orig = Oj.default_options
12
+ Oj.default_options = { mode: :rails, bigdecimal_as_decimal: true }
13
+ bd = BigDecimal('123')
14
+ json = Oj.dump(bd)
15
+ Oj.default_options = orig
16
+
17
+ assert_equal('0.123e3', json.downcase)
18
+
19
+ json = Oj.dump(bd, mode: :rails, bigdecimal_as_decimal: false)
20
+ assert_equal('"0.123e3"', json.downcase)
21
+
22
+ json = Oj.dump(bd, mode: :rails, bigdecimal_as_decimal: true)
23
+ assert_equal('0.123e3', json.downcase)
24
+ end
25
+
26
+ end
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
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
@@ -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
- :indent=>" - ",
128
- :second_precision=>5,
129
- :circular=>true,
130
- :class_cache=>false,
131
- :auto_define=>true,
132
- :symbol_keys=>true,
133
- :bigdecimal_as_decimal=>false,
134
- :use_to_json=>false,
135
- :use_to_hash=>false,
136
- :use_as_json=>false,
137
- :use_raw_json=>false,
138
- :nilnil=>true,
139
- :empty_string=>true,
140
- :allow_gc=>false,
141
- :quirks_mode=>false,
142
- :allow_invalid_unicode=>true,
143
- :float_precision=>13,
144
- :mode=>:strict,
145
- :escape_mode=>:ascii,
146
- :time_format=>:unix_zone,
147
- :bigdecimal_load=>:float,
148
- :create_id=>'classy',
149
- :create_additions=>true,
150
- :space=>'z',
151
- :array_nl=>'a',
152
- :object_nl=>'o',
153
- :space_before=>'b',
154
- :nan=>:huge,
155
- :hash_class=>Hash,
156
- :omit_nil=>false,
157
- :allow_nan=>true,
158
- :integer_range=>nil,
159
- :array_class=>Array,
160
- :ignore=>nil,
161
- :trace=>true,
162
- :safe=>true,
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
 
@@ -19,6 +19,7 @@ require 'test_saj'
19
19
  require 'test_scp'
20
20
  require 'test_strict'
21
21
  require 'test_various'
22
+ require 'test_rails'
22
23
  require 'test_wab'
23
24
  require 'test_writer'
24
25
  require 'test_integer_range'
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.9.1
4
+ version: 3.10.3
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-08-31 00:00:00.000000000 Z
11
+ date: 2020-03-01 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
@@ -234,6 +243,7 @@ files:
234
243
  - test/test_integer_range.rb
235
244
  - test/test_null.rb
236
245
  - test/test_object.rb
246
+ - test/test_rails.rb
237
247
  - test/test_saj.rb
238
248
  - test/test_scp.rb
239
249
  - test/test_strict.rb
@@ -273,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
283
  - !ruby/object:Gem::Version
274
284
  version: '0'
275
285
  requirements: []
276
- rubygems_version: 3.0.3
286
+ rubygems_version: 3.1.2
277
287
  signing_key:
278
288
  specification_version: 4
279
289
  summary: A fast JSON parser and serializer.
@@ -313,6 +323,7 @@ test_files:
313
323
  - test/sample_json.rb
314
324
  - test/activesupport5/encoding_test_cases.rb
315
325
  - test/activesupport5/encoding_test.rb
326
+ - test/activesupport5/abstract_unit.rb
316
327
  - test/activesupport5/time_zone_test_helpers.rb
317
328
  - test/activesupport5/test_helper.rb
318
329
  - test/activesupport5/decoding_test.rb
@@ -341,8 +352,10 @@ test_files:
341
352
  - test/zoo.rb
342
353
  - test/activerecord/result_test.rb
343
354
  - test/_test_active_mimic.rb
355
+ - test/baz.rb
344
356
  - test/tests_mimic_addition.rb
345
357
  - test/test_writer.rb
358
+ - test/test_rails.rb
346
359
  - test/perf.rb
347
360
  - test/isolated/test_mimic_define.rb
348
361
  - test/isolated/test_mimic_after.rb
@@ -357,3 +370,10 @@ test_files:
357
370
  - test/test_gc.rb
358
371
  - test/files.rb
359
372
  - test/test_various.rb
373
+ - test/activesupport6/encoding_test_cases.rb
374
+ - test/activesupport6/encoding_test.rb
375
+ - test/activesupport6/abstract_unit.rb
376
+ - test/activesupport6/time_zone_test_helpers.rb
377
+ - test/activesupport6/test_helper.rb
378
+ - test/activesupport6/test_common.rb
379
+ - test/activesupport6/decoding_test.rb