oj 3.8.0 → 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/oj/custom.c +61 -36
  4. data/ext/oj/dump.c +9 -12
  5. data/ext/oj/dump_compat.c +6 -9
  6. data/ext/oj/dump_object.c +14 -9
  7. data/ext/oj/extconf.rb +1 -0
  8. data/ext/oj/mimic_json.c +4 -2
  9. data/ext/oj/object.c +8 -5
  10. data/ext/oj/oj.c +47 -30
  11. data/ext/oj/oj.h +6 -4
  12. data/ext/oj/parse.c +15 -2
  13. data/ext/oj/parse.h +1 -0
  14. data/ext/oj/rails.c +9 -2
  15. data/ext/oj/resolve.c +3 -3
  16. data/ext/oj/sparse.c +4 -0
  17. data/ext/oj/util.c +5 -5
  18. data/ext/oj/val_stack.c +9 -9
  19. data/ext/oj/val_stack.h +9 -9
  20. data/lib/oj/json.rb +1 -1
  21. data/lib/oj/version.rb +1 -1
  22. data/pages/Options.md +4 -0
  23. data/pages/Rails.md +21 -21
  24. data/test/activesupport5/abstract_unit.rb +45 -0
  25. data/test/activesupport5/decoding_test.rb +68 -60
  26. data/test/activesupport5/encoding_test.rb +111 -96
  27. data/test/activesupport5/encoding_test_cases.rb +33 -25
  28. data/test/activesupport5/test_helper.rb +43 -21
  29. data/test/activesupport5/time_zone_test_helpers.rb +18 -3
  30. data/test/activesupport6/abstract_unit.rb +44 -0
  31. data/test/activesupport6/decoding_test.rb +133 -0
  32. data/test/activesupport6/encoding_test.rb +507 -0
  33. data/test/activesupport6/encoding_test_cases.rb +98 -0
  34. data/test/activesupport6/test_common.rb +17 -0
  35. data/test/activesupport6/test_helper.rb +163 -0
  36. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  37. data/test/bar.rb +8 -11
  38. data/test/baz.rb +16 -0
  39. data/test/test_compat.rb +0 -7
  40. data/test/test_custom.rb +6 -2
  41. data/test/test_integer_range.rb +1 -2
  42. data/test/test_object.rb +4 -3
  43. data/test/test_strict.rb +24 -1
  44. data/test/test_various.rb +41 -62
  45. metadata +20 -2
@@ -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.8.0
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-07-17 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