oj 3.13.23 → 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 (178) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +86 -0
  3. data/README.md +2 -2
  4. data/ext/oj/buf.h +7 -6
  5. data/ext/oj/cache.c +29 -26
  6. data/ext/oj/cache.h +3 -2
  7. data/ext/oj/cache8.c +10 -9
  8. data/ext/oj/circarray.c +7 -5
  9. data/ext/oj/circarray.h +2 -2
  10. data/ext/oj/code.c +5 -12
  11. data/ext/oj/code.h +2 -2
  12. data/ext/oj/compat.c +20 -60
  13. data/ext/oj/custom.c +26 -59
  14. data/ext/oj/debug.c +3 -9
  15. data/ext/oj/dump.c +103 -53
  16. data/ext/oj/dump.h +1 -4
  17. data/ext/oj/dump_compat.c +557 -592
  18. data/ext/oj/dump_leaf.c +3 -5
  19. data/ext/oj/dump_object.c +42 -48
  20. data/ext/oj/dump_strict.c +10 -22
  21. data/ext/oj/encoder.c +1 -1
  22. data/ext/oj/err.c +2 -13
  23. data/ext/oj/err.h +9 -12
  24. data/ext/oj/extconf.rb +16 -7
  25. data/ext/oj/fast.c +63 -98
  26. data/ext/oj/intern.c +62 -47
  27. data/ext/oj/intern.h +3 -7
  28. data/ext/oj/mem.c +318 -0
  29. data/ext/oj/mem.h +53 -0
  30. data/ext/oj/mimic_json.c +54 -38
  31. data/ext/oj/object.c +33 -43
  32. data/ext/oj/odd.c +8 -6
  33. data/ext/oj/odd.h +4 -4
  34. data/ext/oj/oj.c +245 -216
  35. data/ext/oj/oj.h +83 -81
  36. data/ext/oj/parse.c +109 -153
  37. data/ext/oj/parse.h +21 -24
  38. data/ext/oj/parser.c +80 -67
  39. data/ext/oj/parser.h +9 -8
  40. data/ext/oj/rails.c +71 -94
  41. data/ext/oj/reader.c +9 -14
  42. data/ext/oj/reader.h +4 -2
  43. data/ext/oj/resolve.c +3 -4
  44. data/ext/oj/rxclass.c +6 -5
  45. data/ext/oj/rxclass.h +1 -1
  46. data/ext/oj/saj.c +13 -15
  47. data/ext/oj/saj2.c +37 -49
  48. data/ext/oj/saj2.h +1 -1
  49. data/ext/oj/scp.c +6 -20
  50. data/ext/oj/sparse.c +22 -70
  51. data/ext/oj/stream_writer.c +46 -48
  52. data/ext/oj/strict.c +22 -56
  53. data/ext/oj/string_writer.c +64 -40
  54. data/ext/oj/trace.h +31 -4
  55. data/ext/oj/usual.c +125 -114
  56. data/ext/oj/usual.h +7 -6
  57. data/ext/oj/util.h +1 -1
  58. data/ext/oj/val_stack.c +13 -2
  59. data/ext/oj/val_stack.h +8 -7
  60. data/ext/oj/wab.c +25 -57
  61. data/lib/oj/active_support_helper.rb +1 -3
  62. data/lib/oj/bag.rb +7 -1
  63. data/lib/oj/easy_hash.rb +4 -5
  64. data/lib/oj/error.rb +0 -1
  65. data/lib/oj/json.rb +162 -150
  66. data/lib/oj/mimic.rb +7 -7
  67. data/lib/oj/schandler.rb +5 -4
  68. data/lib/oj/state.rb +8 -5
  69. data/lib/oj/version.rb +1 -2
  70. data/lib/oj.rb +2 -0
  71. data/pages/InstallOptions.md +20 -0
  72. data/pages/Options.md +4 -0
  73. metadata +46 -121
  74. data/test/_test_active.rb +0 -76
  75. data/test/_test_active_mimic.rb +0 -96
  76. data/test/_test_mimic_rails.rb +0 -126
  77. data/test/activerecord/result_test.rb +0 -32
  78. data/test/activesupport4/decoding_test.rb +0 -108
  79. data/test/activesupport4/encoding_test.rb +0 -531
  80. data/test/activesupport4/test_helper.rb +0 -41
  81. data/test/activesupport5/abstract_unit.rb +0 -45
  82. data/test/activesupport5/decoding_test.rb +0 -133
  83. data/test/activesupport5/encoding_test.rb +0 -500
  84. data/test/activesupport5/encoding_test_cases.rb +0 -98
  85. data/test/activesupport5/test_helper.rb +0 -72
  86. data/test/activesupport5/time_zone_test_helpers.rb +0 -39
  87. data/test/activesupport6/abstract_unit.rb +0 -44
  88. data/test/activesupport6/decoding_test.rb +0 -133
  89. data/test/activesupport6/encoding_test.rb +0 -507
  90. data/test/activesupport6/encoding_test_cases.rb +0 -98
  91. data/test/activesupport6/test_common.rb +0 -17
  92. data/test/activesupport6/test_helper.rb +0 -163
  93. data/test/activesupport6/time_zone_test_helpers.rb +0 -39
  94. data/test/activesupport7/abstract_unit.rb +0 -49
  95. data/test/activesupport7/decoding_test.rb +0 -125
  96. data/test/activesupport7/encoding_test.rb +0 -486
  97. data/test/activesupport7/encoding_test_cases.rb +0 -104
  98. data/test/activesupport7/time_zone_test_helpers.rb +0 -47
  99. data/test/bar.rb +0 -11
  100. data/test/baz.rb +0 -16
  101. data/test/bug.rb +0 -16
  102. data/test/files.rb +0 -29
  103. data/test/foo.rb +0 -77
  104. data/test/helper.rb +0 -42
  105. data/test/isolated/shared.rb +0 -308
  106. data/test/isolated/test_mimic_after.rb +0 -13
  107. data/test/isolated/test_mimic_alone.rb +0 -12
  108. data/test/isolated/test_mimic_as_json.rb +0 -45
  109. data/test/isolated/test_mimic_before.rb +0 -13
  110. data/test/isolated/test_mimic_define.rb +0 -28
  111. data/test/isolated/test_mimic_rails_after.rb +0 -22
  112. data/test/isolated/test_mimic_rails_before.rb +0 -21
  113. data/test/isolated/test_mimic_redefine.rb +0 -15
  114. data/test/json_gem/json_addition_test.rb +0 -216
  115. data/test/json_gem/json_common_interface_test.rb +0 -153
  116. data/test/json_gem/json_encoding_test.rb +0 -107
  117. data/test/json_gem/json_ext_parser_test.rb +0 -20
  118. data/test/json_gem/json_fixtures_test.rb +0 -35
  119. data/test/json_gem/json_generator_test.rb +0 -396
  120. data/test/json_gem/json_generic_object_test.rb +0 -90
  121. data/test/json_gem/json_parser_test.rb +0 -477
  122. data/test/json_gem/json_string_matching_test.rb +0 -42
  123. data/test/json_gem/test_helper.rb +0 -30
  124. data/test/mem.rb +0 -33
  125. data/test/perf.rb +0 -107
  126. data/test/perf_compat.rb +0 -130
  127. data/test/perf_dump.rb +0 -50
  128. data/test/perf_fast.rb +0 -164
  129. data/test/perf_file.rb +0 -64
  130. data/test/perf_object.rb +0 -138
  131. data/test/perf_once.rb +0 -58
  132. data/test/perf_parser.rb +0 -189
  133. data/test/perf_saj.rb +0 -109
  134. data/test/perf_scp.rb +0 -152
  135. data/test/perf_simple.rb +0 -287
  136. data/test/perf_strict.rb +0 -139
  137. data/test/perf_wab.rb +0 -131
  138. data/test/prec.rb +0 -23
  139. data/test/sample/change.rb +0 -14
  140. data/test/sample/dir.rb +0 -19
  141. data/test/sample/doc.rb +0 -36
  142. data/test/sample/file.rb +0 -48
  143. data/test/sample/group.rb +0 -16
  144. data/test/sample/hasprops.rb +0 -16
  145. data/test/sample/layer.rb +0 -12
  146. data/test/sample/line.rb +0 -20
  147. data/test/sample/oval.rb +0 -10
  148. data/test/sample/rect.rb +0 -10
  149. data/test/sample/shape.rb +0 -35
  150. data/test/sample/text.rb +0 -20
  151. data/test/sample.rb +0 -54
  152. data/test/sample_json.rb +0 -37
  153. data/test/test_compat.rb +0 -540
  154. data/test/test_custom.rb +0 -544
  155. data/test/test_debian.rb +0 -53
  156. data/test/test_fast.rb +0 -530
  157. data/test/test_file.rb +0 -255
  158. data/test/test_gc.rb +0 -60
  159. data/test/test_generate.rb +0 -21
  160. data/test/test_hash.rb +0 -39
  161. data/test/test_integer_range.rb +0 -72
  162. data/test/test_null.rb +0 -376
  163. data/test/test_object.rb +0 -1025
  164. data/test/test_parser.rb +0 -11
  165. data/test/test_parser_debug.rb +0 -27
  166. data/test/test_parser_saj.rb +0 -335
  167. data/test/test_parser_usual.rb +0 -217
  168. data/test/test_rails.rb +0 -35
  169. data/test/test_saj.rb +0 -186
  170. data/test/test_scp.rb +0 -431
  171. data/test/test_strict.rb +0 -435
  172. data/test/test_various.rb +0 -752
  173. data/test/test_wab.rb +0 -309
  174. data/test/test_writer.rb +0 -380
  175. data/test/tests.rb +0 -33
  176. data/test/tests_mimic.rb +0 -23
  177. data/test/tests_mimic_addition.rb +0 -16
  178. data/test/zoo.rb +0 -13
metadata CHANGED
@@ -1,35 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.23
4
+ version: 3.16.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-11-06 00:00:00.000000000 Z
10
+ date: 2025-02-25 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: rake-compiler
13
+ name: bigdecimal
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '0.9'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '2.0'
23
- type: :development
18
+ version: '3.0'
19
+ type: :runtime
24
20
  prerelease: false
25
21
  version_requirements: !ruby/object:Gem::Requirement
26
22
  requirements:
27
23
  - - ">="
28
24
  - !ruby/object:Gem::Version
29
- version: '0.9'
30
- - - "<"
25
+ version: '3.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: ostruct
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '2.0'
32
+ version: '0.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.2'
33
40
  - !ruby/object:Gem::Dependency
34
41
  name: minitest
35
42
  requirement: !ruby/object:Gem::Requirement
@@ -44,6 +51,26 @@ dependencies:
44
51
  - - "~>"
45
52
  - !ruby/object:Gem::Version
46
53
  version: '5'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake-compiler
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0.9'
61
+ - - "<"
62
+ - !ruby/object:Gem::Version
63
+ version: '2.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0.9'
71
+ - - "<"
72
+ - !ruby/object:Gem::Version
73
+ version: '2.0'
47
74
  - !ruby/object:Gem::Dependency
48
75
  name: test-unit
49
76
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +99,7 @@ extra_rdoc_files:
72
99
  - pages/Compatibility.md
73
100
  - pages/Custom.md
74
101
  - pages/Encoding.md
102
+ - pages/InstallOptions.md
75
103
  - pages/JsonGem.md
76
104
  - pages/Modes.md
77
105
  - pages/Options.md
@@ -110,6 +138,8 @@ files:
110
138
  - ext/oj/fast.c
111
139
  - ext/oj/intern.c
112
140
  - ext/oj/intern.h
141
+ - ext/oj/mem.c
142
+ - ext/oj/mem.h
113
143
  - ext/oj/mimic_json.c
114
144
  - ext/oj/object.c
115
145
  - ext/oj/odd.c
@@ -161,6 +191,7 @@ files:
161
191
  - pages/Compatibility.md
162
192
  - pages/Custom.md
163
193
  - pages/Encoding.md
194
+ - pages/InstallOptions.md
164
195
  - pages/JsonGem.md
165
196
  - pages/Modes.md
166
197
  - pages/Options.md
@@ -168,111 +199,6 @@ files:
168
199
  - pages/Rails.md
169
200
  - pages/Security.md
170
201
  - pages/WAB.md
171
- - test/_test_active.rb
172
- - test/_test_active_mimic.rb
173
- - test/_test_mimic_rails.rb
174
- - test/activerecord/result_test.rb
175
- - test/activesupport4/decoding_test.rb
176
- - test/activesupport4/encoding_test.rb
177
- - test/activesupport4/test_helper.rb
178
- - test/activesupport5/abstract_unit.rb
179
- - test/activesupport5/decoding_test.rb
180
- - test/activesupport5/encoding_test.rb
181
- - test/activesupport5/encoding_test_cases.rb
182
- - test/activesupport5/test_helper.rb
183
- - test/activesupport5/time_zone_test_helpers.rb
184
- - test/activesupport6/abstract_unit.rb
185
- - test/activesupport6/decoding_test.rb
186
- - test/activesupport6/encoding_test.rb
187
- - test/activesupport6/encoding_test_cases.rb
188
- - test/activesupport6/test_common.rb
189
- - test/activesupport6/test_helper.rb
190
- - test/activesupport6/time_zone_test_helpers.rb
191
- - test/activesupport7/abstract_unit.rb
192
- - test/activesupport7/decoding_test.rb
193
- - test/activesupport7/encoding_test.rb
194
- - test/activesupport7/encoding_test_cases.rb
195
- - test/activesupport7/time_zone_test_helpers.rb
196
- - test/bar.rb
197
- - test/baz.rb
198
- - test/bug.rb
199
- - test/files.rb
200
- - test/foo.rb
201
- - test/helper.rb
202
- - test/isolated/shared.rb
203
- - test/isolated/test_mimic_after.rb
204
- - test/isolated/test_mimic_alone.rb
205
- - test/isolated/test_mimic_as_json.rb
206
- - test/isolated/test_mimic_before.rb
207
- - test/isolated/test_mimic_define.rb
208
- - test/isolated/test_mimic_rails_after.rb
209
- - test/isolated/test_mimic_rails_before.rb
210
- - test/isolated/test_mimic_redefine.rb
211
- - test/json_gem/json_addition_test.rb
212
- - test/json_gem/json_common_interface_test.rb
213
- - test/json_gem/json_encoding_test.rb
214
- - test/json_gem/json_ext_parser_test.rb
215
- - test/json_gem/json_fixtures_test.rb
216
- - test/json_gem/json_generator_test.rb
217
- - test/json_gem/json_generic_object_test.rb
218
- - test/json_gem/json_parser_test.rb
219
- - test/json_gem/json_string_matching_test.rb
220
- - test/json_gem/test_helper.rb
221
- - test/mem.rb
222
- - test/perf.rb
223
- - test/perf_compat.rb
224
- - test/perf_dump.rb
225
- - test/perf_fast.rb
226
- - test/perf_file.rb
227
- - test/perf_object.rb
228
- - test/perf_once.rb
229
- - test/perf_parser.rb
230
- - test/perf_saj.rb
231
- - test/perf_scp.rb
232
- - test/perf_simple.rb
233
- - test/perf_strict.rb
234
- - test/perf_wab.rb
235
- - test/prec.rb
236
- - test/sample.rb
237
- - test/sample/change.rb
238
- - test/sample/dir.rb
239
- - test/sample/doc.rb
240
- - test/sample/file.rb
241
- - test/sample/group.rb
242
- - test/sample/hasprops.rb
243
- - test/sample/layer.rb
244
- - test/sample/line.rb
245
- - test/sample/oval.rb
246
- - test/sample/rect.rb
247
- - test/sample/shape.rb
248
- - test/sample/text.rb
249
- - test/sample_json.rb
250
- - test/test_compat.rb
251
- - test/test_custom.rb
252
- - test/test_debian.rb
253
- - test/test_fast.rb
254
- - test/test_file.rb
255
- - test/test_gc.rb
256
- - test/test_generate.rb
257
- - test/test_hash.rb
258
- - test/test_integer_range.rb
259
- - test/test_null.rb
260
- - test/test_object.rb
261
- - test/test_parser.rb
262
- - test/test_parser_debug.rb
263
- - test/test_parser_saj.rb
264
- - test/test_parser_usual.rb
265
- - test/test_rails.rb
266
- - test/test_saj.rb
267
- - test/test_scp.rb
268
- - test/test_strict.rb
269
- - test/test_various.rb
270
- - test/test_wab.rb
271
- - test/test_writer.rb
272
- - test/tests.rb
273
- - test/tests_mimic.rb
274
- - test/tests_mimic_addition.rb
275
- - test/zoo.rb
276
202
  homepage: http://www.ohler.com/oj
277
203
  licenses:
278
204
  - MIT
@@ -283,7 +209,7 @@ metadata:
283
209
  homepage_uri: http://www.ohler.com/oj/
284
210
  source_code_uri: https://github.com/ohler55/oj
285
211
  wiki_uri: https://github.com/ohler55/oj/wiki
286
- post_install_message:
212
+ rubygems_mfa_required: 'true'
287
213
  rdoc_options:
288
214
  - "--title"
289
215
  - Oj
@@ -295,15 +221,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
295
221
  requirements:
296
222
  - - ">="
297
223
  - !ruby/object:Gem::Version
298
- version: '2.4'
224
+ version: '2.7'
299
225
  required_rubygems_version: !ruby/object:Gem::Requirement
300
226
  requirements:
301
227
  - - ">="
302
228
  - !ruby/object:Gem::Version
303
229
  version: '0'
304
230
  requirements: []
305
- rubygems_version: 3.3.3
306
- signing_key:
231
+ rubygems_version: 3.6.2
307
232
  specification_version: 4
308
233
  summary: A fast JSON parser and serializer.
309
234
  test_files: []
data/test/_test_active.rb DELETED
@@ -1,76 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- $: << File.dirname(__FILE__)
5
- %w(lib ext test).each do |dir|
6
- $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
7
- end
8
-
9
- require 'minitest'
10
- require 'minitest/autorun'
11
-
12
- require 'sqlite3'
13
- require 'active_record'
14
- require 'oj'
15
-
16
- #Oj.mimic_JSON()
17
- Oj.default_options = {mode: :compat, indent: 2}
18
-
19
- #ActiveRecord::Base.logger = Logger.new(STDERR)
20
-
21
- ActiveRecord::Base.establish_connection(
22
- :adapter => "sqlite3",
23
- :database => ":memory:"
24
- )
25
-
26
- ActiveRecord::Schema.define do
27
- create_table :users do |table|
28
- table.column :first_name, :string
29
- table.column :last_name, :string
30
- table.column :email, :string
31
- end
32
- end
33
-
34
- class User < ActiveRecord::Base
35
- end
36
-
37
- class ActiveTest < Minitest::Test
38
-
39
- def test_active
40
- User.find_or_create_by(first_name: "John", last_name: "Smith", email: "john@example.com")
41
- User.find_or_create_by(first_name: "Joan", last_name: "Smith", email: "joan@example.com")
42
-
43
- # Single instance.
44
- assert_equal(%|{
45
- "id":1,
46
- "first_name":"John",
47
- "last_name":"Smith",
48
- "email":"john@example.com"
49
- }
50
- |, Oj.dump(User.first))
51
-
52
- # Array of instances.
53
- assert_equal(%|[
54
- {
55
- "id":1,
56
- "first_name":"John",
57
- "last_name":"Smith",
58
- "email":"john@example.com"
59
- },
60
- {
61
- "id":2,
62
- "first_name":"Joan",
63
- "last_name":"Smith",
64
- "email":"joan@example.com"
65
- }
66
- ]
67
- |, Oj.dump(User.all))
68
-
69
- # Single instance as json. (not Oj)
70
- assert_equal(%|{"id":1,"first_name":"John","last_name":"Smith","email":"john@example.com"}|, User.first.to_json)
71
-
72
- # Array of instances as json. (not Oj)
73
- assert_equal(%|[{"id":1,"first_name":"John","last_name":"Smith","email":"john@example.com"},{"id":2,"first_name":"Joan","last_name":"Smith","email":"joan@example.com"}]|, User.all.to_json)
74
-
75
- end
76
- end
@@ -1,96 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- $: << File.dirname(__FILE__)
5
- %w(lib ext test).each do |dir|
6
- $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
7
- end
8
-
9
- require 'minitest'
10
- require 'minitest/autorun'
11
-
12
- require 'sqlite3'
13
- require 'active_record'
14
- require 'oj'
15
-
16
- Oj.mimic_JSON()
17
- Oj.default_options = {mode: :compat, indent: 2}
18
-
19
- #ActiveRecord::Base.logger = Logger.new(STDERR)
20
-
21
- ActiveRecord::Base.establish_connection(
22
- :adapter => "sqlite3",
23
- :database => ":memory:"
24
- )
25
-
26
- ActiveRecord::Schema.define do
27
- create_table :users do |table|
28
- table.column :first_name, :string
29
- table.column :last_name, :string
30
- table.column :email, :string
31
- end
32
- end
33
-
34
- class User < ActiveRecord::Base
35
- end
36
-
37
- class ActiveTest < Minitest::Test
38
-
39
- def test_active
40
- User.find_or_create_by(first_name: "John", last_name: "Smith", email: "john@example.com")
41
- User.find_or_create_by(first_name: "Joan", last_name: "Smith", email: "joan@example.com")
42
-
43
- # Single instance.
44
- assert_equal(%|{
45
- "id":1,
46
- "first_name":"John",
47
- "last_name":"Smith",
48
- "email":"john@example.com"
49
- }
50
- |, Oj.dump(User.first))
51
-
52
- # Array of instances.
53
- assert_equal(%|[
54
- {
55
- "id":1,
56
- "first_name":"John",
57
- "last_name":"Smith",
58
- "email":"john@example.com"
59
- },
60
- {
61
- "id":2,
62
- "first_name":"Joan",
63
- "last_name":"Smith",
64
- "email":"joan@example.com"
65
- }
66
- ]
67
- |, Oj.dump(User.all))
68
-
69
- # Single instance as json. (not Oj)
70
- assert_equal(%|{
71
- "id":1,
72
- "first_name":"John",
73
- "last_name":"Smith",
74
- "email":"john@example.com"
75
- }
76
- |, User.first.to_json)
77
-
78
- # Array of instances as json. (not Oj)
79
- assert_equal(%|[
80
- {
81
- "id":1,
82
- "first_name":"John",
83
- "last_name":"Smith",
84
- "email":"john@example.com"
85
- },
86
- {
87
- "id":2,
88
- "first_name":"Joan",
89
- "last_name":"Smith",
90
- "email":"joan@example.com"
91
- }
92
- ]
93
- |, User.all.to_json)
94
-
95
- end
96
- end
@@ -1,126 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- $: << File.dirname(__FILE__)
5
-
6
- require 'helper'
7
- #Oj.mimic_JSON
8
- require 'rails/all'
9
-
10
- require 'active_model'
11
- require 'active_model_serializers'
12
- require 'active_support/json'
13
- require 'active_support/time'
14
- require 'active_support/all'
15
-
16
- require 'oj/active_support_helper'
17
-
18
- Oj.mimic_JSON
19
-
20
- class Category
21
- include ActiveModel::Model
22
- include ActiveModel::SerializerSupport
23
-
24
- attr_accessor :id, :name
25
-
26
- def initialize(id, name)
27
- @id = id
28
- @name = name
29
- end
30
- end
31
-
32
- class CategorySerializer < ActiveModel::Serializer
33
- attributes :id, :name
34
- end
35
-
36
- class MimicRails < Minitest::Test
37
-
38
- def test_mimic_exception
39
- begin
40
- ActiveSupport::JSON.decode("{")
41
- puts "Failed"
42
- rescue ActiveSupport::JSON.parse_error
43
- assert(true)
44
- rescue Exception
45
- assert(false, 'Expected a JSON::ParserError')
46
- end
47
- end
48
-
49
- def test_dump_string
50
- Oj.default_options= {:indent => 2}
51
- json = ActiveSupport::JSON.encode([1, true, nil])
52
- assert_equal(%{[
53
- 1,
54
- true,
55
- null
56
- ]
57
- }, json)
58
- end
59
-
60
- def test_dump_rational
61
- Oj.default_options= {:indent => 2}
62
- json = ActiveSupport::JSON.encode([1, true, Rational(1)])
63
- assert_equal(%{[
64
- 1,
65
- true,
66
- "1/1"
67
- ]
68
- }, json)
69
- end
70
-
71
- def test_dump_range
72
- Oj.default_options= {:indent => 2}
73
- json = ActiveSupport::JSON.encode([1, true, '01'..'12'])
74
- assert_equal(%{[
75
- 1,
76
- true,
77
- "01..12"
78
- ]
79
- }, json)
80
- end
81
-
82
- def test_dump_object
83
- Oj.default_options= {:indent => 2}
84
- category = Category.new(1, 'test')
85
- serializer = CategorySerializer.new(category)
86
-
87
- json = serializer.to_json()
88
- puts "*** serializer.to_json() #{serializer.to_json()}"
89
- json = serializer.as_json()
90
- puts "*** serializer.as_json() #{serializer.as_json()}"
91
- json = JSON.dump(serializer)
92
- puts "*** JSON.dump(serializer) #{JSON.dump(serializer)}"
93
-
94
- puts "*** category.to_json() #{category.to_json()}"
95
- puts "*** category.as_json() #{category.as_json()}"
96
- puts "*** JSON.dump(serializer) #{JSON.dump(category)}"
97
- puts "*** Oj.dump(serializer) #{Oj.dump(category)}"
98
-
99
- end
100
-
101
- def test_dump_object_array
102
- Oj.default_options= {:indent => 2}
103
- cat1 = Category.new(1, 'test')
104
- cat2 = Category.new(2, 'test')
105
- a = Array.wrap([cat1, cat2])
106
-
107
- #serializer = CategorySerializer.new(a)
108
-
109
- puts "*** a.to_json() #{a.to_json()}"
110
- puts "*** a.as_json() #{a.as_json()}"
111
- puts "*** JSON.dump(a) #{JSON.dump(a)}"
112
- puts "*** Oj.dump(a) #{Oj.dump(a)}"
113
- end
114
-
115
- def test_dump_time
116
- Oj.default_options= {:indent => 2}
117
- now = ActiveSupport::TimeZone['America/Chicago'].parse("2014-11-01 13:20:47")
118
- json = Oj.dump(now, mode: :object, time_format: :xmlschema)
119
- #puts "*** json: #{json}"
120
-
121
- oj_dump = Oj.load(json, mode: :object, time_format: :xmlschema)
122
- #puts "Now: #{now}\n Oj: #{oj_dump}"
123
- assert_equal("2014-11-01T13:20:47-05:00", oj_dump.xmlschema)
124
- end
125
-
126
- end # MimicRails
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $: << File.dirname(__FILE__)
4
- $: << File.dirname(File.dirname(__FILE__))
5
-
6
- require 'helper'
7
- require "rails/all"
8
-
9
- Oj::Rails.set_encoder()
10
- Oj::Rails.optimize()
11
-
12
- Oj.default_options = { mode: :rails }
13
-
14
- class ActiveRecordResultTest < Minitest::Test
15
- def test_hash_rows
16
-
17
- result = ActiveRecord::Result.new(["one", "two"],
18
- [
19
- ["row 1 col 1", "row 1 col 2"],
20
- ["row 2 col 1", "row 2 col 2"],
21
- ["row 3 col 1", "row 3 col 2"],
22
- ])
23
- #puts "*** result: #{Oj.dump(result, indent: 2)}"
24
- json_result = if ActiveRecord.version >= Gem::Version.new("6")
25
- result.to_a
26
- else
27
- result.to_hash
28
- end
29
-
30
- assert_equal Oj.dump(result, mode: :rails), Oj.dump(json_result)
31
- end
32
- end
@@ -1,108 +0,0 @@
1
- # encoding: utf-8
2
- require 'activesupport4/test_helper'
3
- require 'active_support/json'
4
- require 'active_support/time'
5
-
6
- class TestJSONDecoding < ActiveSupport::TestCase
7
- class Foo
8
- def self.json_create(object)
9
- "Foo"
10
- end
11
- end
12
-
13
- TESTS = {
14
- %q({"returnTo":{"\/categories":"\/"}}) => {"returnTo" => {"/categories" => "/"}},
15
- %q({"return\\"To\\":":{"\/categories":"\/"}}) => {"return\"To\":" => {"/categories" => "/"}},
16
- %q({"returnTo":{"\/categories":1}}) => {"returnTo" => {"/categories" => 1}},
17
- %({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]},
18
- %({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]},
19
- %({"a": "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"},
20
- %({"a": "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
21
- # multibyte
22
- %({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"},
23
- %({"a": "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)},
24
- %({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
25
- %(["2007-01-01 01:12:34 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34)],
26
- %(["2007-01-01 01:12:34 Z", "2007-01-01 01:12:35 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34), Time.utc(2007, 1, 1, 1, 12, 35)],
27
- # no time zone
28
- %({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
29
- # invalid date
30
- %({"a": "1089-10-40"}) => {'a' => "1089-10-40"},
31
- # xmlschema date notation
32
- %({"a": "2009-08-10T19:01:02Z"}) => {'a' => Time.utc(2009, 8, 10, 19, 1, 2)},
33
- %({"a": "2009-08-10T19:01:02+02:00"}) => {'a' => Time.utc(2009, 8, 10, 17, 1, 2)},
34
- %({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.utc(2009, 8, 11, 00, 1, 2)},
35
- # needs to be *exact*
36
- %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "},
37
- %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"},
38
- %([]) => [],
39
- %({}) => {},
40
- %({"a":1}) => {"a" => 1},
41
- %({"a": ""}) => {"a" => ""},
42
- %({"a":"\\""}) => {"a" => "\""},
43
- %({"a": null}) => {"a" => nil},
44
- %({"a": true}) => {"a" => true},
45
- %({"a": false}) => {"a" => false},
46
- %q({"bad":"\\\\","trailing":""}) => {"bad" => "\\", "trailing" => ""},
47
- %q({"a": "http:\/\/test.host\/posts\/1"}) => {"a" => "http://test.host/posts/1"},
48
- %q({"a": "\u003cunicode\u0020escape\u003e"}) => {"a" => "<unicode escape>"},
49
- %q({"a": "\\\\u0020skip double backslashes"}) => {"a" => "\\u0020skip double backslashes"},
50
- %q({"a": "\u003cbr /\u003e"}) => {'a' => "<br />"},
51
- %q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]},
52
- # test combination of dates and escaped or unicode encoded data in arrays
53
- %q([{"d":"1970-01-01", "s":"\u0020escape"},{"d":"1970-01-01", "s":"\u0020escape"}]) =>
54
- [{'d' => Date.new(1970, 1, 1), 's' => ' escape'},{'d' => Date.new(1970, 1, 1), 's' => ' escape'}],
55
- %q([{"d":"1970-01-01","s":"http:\/\/example.com"},{"d":"1970-01-01","s":"http:\/\/example.com"}]) =>
56
- [{'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'},
57
- {'d' => Date.new(1970, 1, 1), 's' => 'http://example.com'}],
58
- # tests escaping of "\n" char with Yaml backend
59
- %q({"a":"\n"}) => {"a"=>"\n"},
60
- %q({"a":"\u000a"}) => {"a"=>"\n"},
61
- %q({"a":"Line1\u000aLine2"}) => {"a"=>"Line1\nLine2"},
62
- # prevent json unmarshalling
63
- %q({"json_class":"TestJSONDecoding::Foo"}) => {"json_class"=>"TestJSONDecoding::Foo"},
64
- # json "fragments" - these are invalid JSON, but ActionPack relies on this
65
- %q("a string") => "a string",
66
- %q(1.1) => 1.1,
67
- %q(1) => 1,
68
- %q(-1) => -1,
69
- %q(true) => true,
70
- %q(false) => false,
71
- %q(null) => nil
72
- }
73
-
74
- TESTS.each_with_index do |(json, expected), index|
75
- test "json decodes #{index}" do
76
- prev = ActiveSupport.parse_json_times
77
- ActiveSupport.parse_json_times = true
78
- silence_warnings do
79
- if expected.nil?
80
- assert_nil ActiveSupport::JSON.decode(json), "JSON decoding failed for #{json}"
81
- else
82
- assert_equal expected, ActiveSupport::JSON.decode(json), "JSON decoding failed for #{json}"
83
- end
84
- end
85
- ActiveSupport.parse_json_times = prev
86
- end
87
- end
88
-
89
- test "json decodes time json with time parsing disabled" do
90
- prev = ActiveSupport.parse_json_times
91
- ActiveSupport.parse_json_times = false
92
- expected = {"a" => "2007-01-01 01:12:34 Z"}
93
- assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"}))
94
- ActiveSupport.parse_json_times = prev
95
- end
96
-
97
- def test_failed_json_decoding
98
- assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%(undefined)) }
99
- assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({a: 1})) }
100
- assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({: 1})) }
101
- assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%()) }
102
- end
103
-
104
- def test_cannot_pass_unsupported_options
105
- assert_raise(ArgumentError) { ActiveSupport::JSON.decode("", create_additions: true) }
106
- end
107
- end
108
-