oj 3.9.2 → 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
 
@@ -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
 
@@ -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
@@ -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
 
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.2
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-10-02 00:00:00.000000000 Z
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