oj 3.7.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +96 -0
  4. data/ext/oj/buf.h +103 -0
  5. data/ext/oj/cache8.c +107 -0
  6. data/ext/oj/cache8.h +48 -0
  7. data/ext/oj/circarray.c +68 -0
  8. data/ext/oj/circarray.h +23 -0
  9. data/ext/oj/code.c +235 -0
  10. data/ext/oj/code.h +42 -0
  11. data/ext/oj/compat.c +299 -0
  12. data/ext/oj/custom.c +1188 -0
  13. data/ext/oj/dump.c +1232 -0
  14. data/ext/oj/dump.h +94 -0
  15. data/ext/oj/dump_compat.c +973 -0
  16. data/ext/oj/dump_leaf.c +252 -0
  17. data/ext/oj/dump_object.c +837 -0
  18. data/ext/oj/dump_strict.c +433 -0
  19. data/ext/oj/encode.h +45 -0
  20. data/ext/oj/err.c +57 -0
  21. data/ext/oj/err.h +70 -0
  22. data/ext/oj/extconf.rb +47 -0
  23. data/ext/oj/fast.c +1771 -0
  24. data/ext/oj/hash.c +163 -0
  25. data/ext/oj/hash.h +46 -0
  26. data/ext/oj/hash_test.c +512 -0
  27. data/ext/oj/mimic_json.c +873 -0
  28. data/ext/oj/object.c +771 -0
  29. data/ext/oj/odd.c +231 -0
  30. data/ext/oj/odd.h +44 -0
  31. data/ext/oj/oj.c +1694 -0
  32. data/ext/oj/oj.h +381 -0
  33. data/ext/oj/parse.c +1085 -0
  34. data/ext/oj/parse.h +111 -0
  35. data/ext/oj/rails.c +1485 -0
  36. data/ext/oj/rails.h +21 -0
  37. data/ext/oj/reader.c +231 -0
  38. data/ext/oj/reader.h +151 -0
  39. data/ext/oj/resolve.c +102 -0
  40. data/ext/oj/resolve.h +14 -0
  41. data/ext/oj/rxclass.c +147 -0
  42. data/ext/oj/rxclass.h +27 -0
  43. data/ext/oj/saj.c +714 -0
  44. data/ext/oj/scp.c +224 -0
  45. data/ext/oj/sparse.c +910 -0
  46. data/ext/oj/stream_writer.c +363 -0
  47. data/ext/oj/strict.c +212 -0
  48. data/ext/oj/string_writer.c +512 -0
  49. data/ext/oj/trace.c +79 -0
  50. data/ext/oj/trace.h +28 -0
  51. data/ext/oj/util.c +136 -0
  52. data/ext/oj/util.h +19 -0
  53. data/ext/oj/val_stack.c +118 -0
  54. data/ext/oj/val_stack.h +185 -0
  55. data/ext/oj/wab.c +631 -0
  56. data/lib/oj.rb +21 -0
  57. data/lib/oj/active_support_helper.rb +41 -0
  58. data/lib/oj/bag.rb +88 -0
  59. data/lib/oj/easy_hash.rb +52 -0
  60. data/lib/oj/error.rb +22 -0
  61. data/lib/oj/json.rb +176 -0
  62. data/lib/oj/mimic.rb +267 -0
  63. data/lib/oj/saj.rb +66 -0
  64. data/lib/oj/schandler.rb +142 -0
  65. data/lib/oj/state.rb +131 -0
  66. data/lib/oj/version.rb +5 -0
  67. data/pages/Advanced.md +22 -0
  68. data/pages/Compatibility.md +25 -0
  69. data/pages/Custom.md +23 -0
  70. data/pages/Encoding.md +65 -0
  71. data/pages/JsonGem.md +79 -0
  72. data/pages/Modes.md +154 -0
  73. data/pages/Options.md +266 -0
  74. data/pages/Rails.md +116 -0
  75. data/pages/Security.md +20 -0
  76. data/pages/WAB.md +13 -0
  77. data/test/_test_active.rb +76 -0
  78. data/test/_test_active_mimic.rb +96 -0
  79. data/test/_test_mimic_rails.rb +126 -0
  80. data/test/activerecord/result_test.rb +27 -0
  81. data/test/activesupport4/decoding_test.rb +108 -0
  82. data/test/activesupport4/encoding_test.rb +531 -0
  83. data/test/activesupport4/test_helper.rb +41 -0
  84. data/test/activesupport5/decoding_test.rb +125 -0
  85. data/test/activesupport5/encoding_test.rb +485 -0
  86. data/test/activesupport5/encoding_test_cases.rb +90 -0
  87. data/test/activesupport5/test_helper.rb +50 -0
  88. data/test/activesupport5/time_zone_test_helpers.rb +24 -0
  89. data/test/big.rb +15 -0
  90. data/test/files.rb +29 -0
  91. data/test/foo.rb +33 -0
  92. data/test/helper.rb +26 -0
  93. data/test/isolated/shared.rb +308 -0
  94. data/test/isolated/test_mimic_after.rb +13 -0
  95. data/test/isolated/test_mimic_alone.rb +12 -0
  96. data/test/isolated/test_mimic_as_json.rb +45 -0
  97. data/test/isolated/test_mimic_before.rb +13 -0
  98. data/test/isolated/test_mimic_define.rb +28 -0
  99. data/test/isolated/test_mimic_rails_after.rb +22 -0
  100. data/test/isolated/test_mimic_rails_before.rb +21 -0
  101. data/test/isolated/test_mimic_redefine.rb +15 -0
  102. data/test/json_gem/json_addition_test.rb +216 -0
  103. data/test/json_gem/json_common_interface_test.rb +148 -0
  104. data/test/json_gem/json_encoding_test.rb +107 -0
  105. data/test/json_gem/json_ext_parser_test.rb +20 -0
  106. data/test/json_gem/json_fixtures_test.rb +35 -0
  107. data/test/json_gem/json_generator_test.rb +383 -0
  108. data/test/json_gem/json_generic_object_test.rb +90 -0
  109. data/test/json_gem/json_parser_test.rb +470 -0
  110. data/test/json_gem/json_string_matching_test.rb +42 -0
  111. data/test/json_gem/test_helper.rb +18 -0
  112. data/test/mem.rb +35 -0
  113. data/test/perf.rb +107 -0
  114. data/test/perf_compat.rb +130 -0
  115. data/test/perf_fast.rb +164 -0
  116. data/test/perf_file.rb +64 -0
  117. data/test/perf_object.rb +138 -0
  118. data/test/perf_saj.rb +109 -0
  119. data/test/perf_scp.rb +151 -0
  120. data/test/perf_simple.rb +287 -0
  121. data/test/perf_strict.rb +145 -0
  122. data/test/perf_wab.rb +131 -0
  123. data/test/sample.rb +54 -0
  124. data/test/sample/change.rb +14 -0
  125. data/test/sample/dir.rb +19 -0
  126. data/test/sample/doc.rb +36 -0
  127. data/test/sample/file.rb +48 -0
  128. data/test/sample/group.rb +16 -0
  129. data/test/sample/hasprops.rb +16 -0
  130. data/test/sample/layer.rb +12 -0
  131. data/test/sample/line.rb +20 -0
  132. data/test/sample/oval.rb +10 -0
  133. data/test/sample/rect.rb +10 -0
  134. data/test/sample/shape.rb +35 -0
  135. data/test/sample/text.rb +20 -0
  136. data/test/sample_json.rb +37 -0
  137. data/test/test_compat.rb +509 -0
  138. data/test/test_custom.rb +406 -0
  139. data/test/test_debian.rb +53 -0
  140. data/test/test_fast.rb +470 -0
  141. data/test/test_file.rb +239 -0
  142. data/test/test_gc.rb +49 -0
  143. data/test/test_hash.rb +29 -0
  144. data/test/test_integer_range.rb +73 -0
  145. data/test/test_null.rb +376 -0
  146. data/test/test_object.rb +1018 -0
  147. data/test/test_saj.rb +186 -0
  148. data/test/test_scp.rb +433 -0
  149. data/test/test_strict.rb +410 -0
  150. data/test/test_various.rb +739 -0
  151. data/test/test_wab.rb +307 -0
  152. data/test/test_writer.rb +380 -0
  153. data/test/tests.rb +24 -0
  154. data/test/tests_mimic.rb +14 -0
  155. data/test/tests_mimic_addition.rb +7 -0
  156. metadata +359 -0
@@ -0,0 +1,406 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
6
+ %w(lib ext).each do |dir|
7
+ $: << File.join($oj_dir, dir)
8
+ end
9
+
10
+ require 'minitest'
11
+ require 'minitest/autorun'
12
+ require 'stringio'
13
+ require 'date'
14
+ require 'bigdecimal'
15
+ require 'oj'
16
+
17
+ class CustomJuice < Minitest::Test
18
+
19
+ module TestModule
20
+ end
21
+
22
+ class Jeez
23
+ attr_accessor :x, :y
24
+
25
+ def initialize(x, y)
26
+ @x = x
27
+ @y = y
28
+ end
29
+ def ==(o)
30
+ self.class == o.class && @x == o.x && @y = o.y
31
+ end
32
+ def to_json(*args)
33
+ %|{"xx":#{@x},"yy":#{y}}|
34
+ end
35
+ def as_json(*args)
36
+ {'a' => @x, :b => @y }
37
+ end
38
+ def to_hash()
39
+ {'b' => @x, 'n' => @y }
40
+ end
41
+ end
42
+
43
+ def setup
44
+ @default_options = Oj.default_options
45
+ Oj.default_options = { :mode => :custom }
46
+ end
47
+
48
+ def teardown
49
+ Oj.default_options = @default_options
50
+ end
51
+
52
+ def test_nil
53
+ dump_and_load(nil, false)
54
+ end
55
+
56
+ def test_true
57
+ dump_and_load(true, false)
58
+ end
59
+
60
+ def test_false
61
+ dump_and_load(false, false)
62
+ end
63
+
64
+ def test_fixnum
65
+ dump_and_load(0, false)
66
+ dump_and_load(12345, false)
67
+ dump_and_load(-54321, false)
68
+ dump_and_load(1, false)
69
+ end
70
+
71
+ def test_float
72
+ dump_and_load(0.0, false)
73
+ dump_and_load(12345.6789, false)
74
+ dump_and_load(70.35, false)
75
+ dump_and_load(-54321.012, false)
76
+ dump_and_load(1.7775, false)
77
+ dump_and_load(2.5024, false)
78
+ dump_and_load(2.48e16, false)
79
+ dump_and_load(2.48e100 * 1.0e10, false)
80
+ dump_and_load(-2.48e100 * 1.0e10, false)
81
+ end
82
+
83
+ def test_nan_dump
84
+ assert_equal('null', Oj.dump(0/0.0, :nan => :null))
85
+ assert_equal('3.3e14159265358979323846', Oj.dump(0/0.0, :nan => :huge))
86
+ assert_equal('NaN', Oj.dump(0/0.0, :nan => :word))
87
+ begin
88
+ Oj.dump(0/0.0, :nan => :raise)
89
+ rescue Exception
90
+ assert(true)
91
+ return
92
+ end
93
+ assert(false, "*** expected an exception")
94
+ end
95
+
96
+ def test_infinity_dump
97
+ assert_equal('null', Oj.dump(1/0.0, :nan => :null))
98
+ assert_equal('3.0e14159265358979323846', Oj.dump(1/0.0, :nan => :huge))
99
+ assert_equal('Infinity', Oj.dump(1/0.0, :nan => :word))
100
+ begin
101
+ Oj.dump(1/0.0, :nan => :raise)
102
+ rescue Exception
103
+ assert(true)
104
+ return
105
+ end
106
+ assert(false, "*** expected an exception")
107
+ end
108
+
109
+ def test_neg_infinity_dump
110
+ assert_equal('null', Oj.dump(-1/0.0, :nan => :null))
111
+ assert_equal('-3.0e14159265358979323846', Oj.dump(-1/0.0, :nan => :huge))
112
+ assert_equal('-Infinity', Oj.dump(-1/0.0, :nan => :word))
113
+ begin
114
+ Oj.dump(-1/0.0, :nan => :raise)
115
+ rescue Exception
116
+ assert(true)
117
+ return
118
+ end
119
+ assert(false, "*** expected an exception")
120
+ end
121
+
122
+ def test_string
123
+ dump_and_load('', false)
124
+ dump_and_load('abc', false)
125
+ dump_and_load("abc\ndef", false)
126
+ dump_and_load("a\u0041", false)
127
+ end
128
+
129
+ def test_string_ascii
130
+ json = Oj.dump("ぴーたー", :escape_mode => :ascii)
131
+ assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
132
+ dump_and_load("ぴーたー", false, :escape_mode => :ascii)
133
+ end
134
+
135
+ def test_string_json
136
+ json = Oj.dump("ぴーたー", :escape_mode => :json)
137
+ assert_equal(%{"ぴーたー"}, json)
138
+ dump_and_load("ぴーたー", false, :escape_mode => :json)
139
+ end
140
+
141
+ def test_array
142
+ dump_and_load([], false)
143
+ dump_and_load([true, false], false)
144
+ dump_and_load(['a', 1, nil], false)
145
+ dump_and_load([[nil]], false)
146
+ dump_and_load([[nil], 58], false)
147
+ end
148
+
149
+ def test_array_deep
150
+ dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
151
+ end
152
+
153
+ def test_deep_nest
154
+ begin
155
+ n = 10000
156
+ Oj.strict_load('[' * n + ']' * n)
157
+ rescue Exception => e
158
+ assert(false, e.message)
159
+ end
160
+ end
161
+
162
+ def test_hash
163
+ dump_and_load({}, false)
164
+ dump_and_load({ 'true' => true, 'false' => false}, false)
165
+ dump_and_load({ 'true' => true, 'array' => [], 'hash' => { }}, false)
166
+ end
167
+
168
+ def test_hash_deep
169
+ dump_and_load({'1' => {
170
+ '2' => {
171
+ '3' => {
172
+ '4' => {
173
+ '5' => {
174
+ '6' => {
175
+ '7' => {
176
+ '8' => {
177
+ '9' => {
178
+ '10' => {
179
+ '11' => {
180
+ '12' => {
181
+ '13' => {
182
+ '14' => {
183
+ '15' => {
184
+ '16' => {
185
+ '17' => {
186
+ '18' => {
187
+ '19' => {
188
+ '20' => {}}}}}}}}}}}}}}}}}}}}}, false)
189
+ end
190
+
191
+ def test_hash_escaped_key
192
+ json = %{{"a\nb":true,"c\td":false}}
193
+ obj = Oj.load(json)
194
+ assert_equal({"a\nb" => true, "c\td" => false}, obj)
195
+ end
196
+
197
+ def test_hash_non_string_key
198
+ assert_equal(%|{"1":true}|, Oj.dump({ 1 => true }, :indent => 0))
199
+ end
200
+
201
+ def test_bignum_object
202
+ dump_and_load(7 ** 55, false)
203
+ end
204
+
205
+ def test_bigdecimal
206
+ assert_equal('0.314159265358979323846e1', Oj.dump(BigDecimal('3.14159265358979323846'), bigdecimal_as_decimal: true).downcase())
207
+ assert_equal('"0.314159265358979323846e1"', Oj.dump(BigDecimal('3.14159265358979323846'), bigdecimal_as_decimal: false).downcase())
208
+ dump_and_load(BigDecimal('3.14159265358979323846'), false, :bigdecimal_load => true)
209
+ end
210
+
211
+ def test_object
212
+ obj = Jeez.new(true, 58)
213
+ Oj.dump(obj, :create_id => "^o", :use_to_json => false, :use_as_json => false, :use_to_hash => false)
214
+ dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
215
+ end
216
+
217
+ def test_object_to_json
218
+ obj = Jeez.new(true, 58)
219
+ json = Oj.dump(obj, :use_to_json => true, :use_as_json => false, :use_to_hash => false)
220
+ assert_equal(%|{"xx":true,"yy":58}|, json)
221
+ end
222
+
223
+ def test_object_as_json
224
+ obj = Jeez.new(true, 58)
225
+ json = Oj.dump(obj, :use_to_json => false, :use_as_json => true, :use_to_hash => false)
226
+ assert_equal(%|{"a":true,"b":58}|, json)
227
+ end
228
+
229
+ def test_object_to_hash
230
+ obj = Jeez.new(true, 58)
231
+ json = Oj.dump(obj, :use_to_json => false, :use_as_json => false, :use_to_hash => true)
232
+ assert_equal(%|{"b":true,"n":58}|, json)
233
+ end
234
+
235
+ def test_symbol
236
+ json = Oj.dump(:abc)
237
+ assert_equal('"abc"', json)
238
+ end
239
+
240
+ def test_class
241
+ assert_equal(%|"CustomJuice"|, Oj.dump(CustomJuice))
242
+ end
243
+
244
+ def test_module
245
+ assert_equal(%|"CustomJuice::TestModule"|, Oj.dump(TestModule))
246
+ end
247
+
248
+ def test_symbol_keys
249
+ json = %|{
250
+ "x":true,
251
+ "y":58,
252
+ "z": [1,2,3]
253
+ }
254
+ |
255
+ obj = Oj.load(json, :symbol_keys => true)
256
+ assert_equal({ :x => true, :y => 58, :z => [1, 2, 3]}, obj)
257
+ end
258
+
259
+ def test_double
260
+ json = %{{ "x": 1}{ "y": 2}}
261
+ results = []
262
+ Oj.load(json, :mode => :strict) { |x| results << x }
263
+
264
+ assert_equal([{ 'x' => 1 }, { 'y' => 2 }], results)
265
+ end
266
+
267
+ def test_circular_hash
268
+ h = { 'a' => 7 }
269
+ h['b'] = h
270
+ json = Oj.dump(h, :indent => 2, :circular => true)
271
+ assert_equal(%|{
272
+ "a":7,
273
+ "b":null
274
+ }
275
+ |, json)
276
+ end
277
+
278
+ def test_omit_nil
279
+ json = Oj.dump({'x' => {'a' => 1, 'b' => nil }, 'y' => nil}, :omit_nil => true)
280
+ assert_equal(%|{"x":{"a":1}}|, json)
281
+ end
282
+
283
+ def test_complex
284
+ obj = Complex(2, 9)
285
+ dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
286
+ end
287
+
288
+ def test_rational
289
+ obj = Rational(2, 9)
290
+ dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
291
+ end
292
+
293
+ def test_range
294
+ obj = 3..8
295
+ dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
296
+ end
297
+
298
+ def test_date
299
+ obj = Date.new(2017, 1, 5)
300
+ dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
301
+ end
302
+
303
+ def test_date_unix
304
+ obj = Date.new(2017, 1, 5)
305
+ json = Oj.dump(obj, :indent => 2, time_format: :unix)
306
+ assert_equal('1483574400.000000000', json)
307
+ end
308
+
309
+ def test_date_unix_zone
310
+ obj = Date.new(2017, 1, 5)
311
+ json = Oj.dump(obj, :indent => 2, time_format: :unix_zone)
312
+ assert_equal('1483574400.000000000', json)
313
+ end
314
+
315
+ def test_date_ruby
316
+ obj = Date.new(2017, 1, 5)
317
+ json = Oj.dump(obj, :indent => 2, time_format: :ruby)
318
+ assert_equal('"2017-01-05"', json)
319
+ end
320
+
321
+ def test_date_xmlschema
322
+ obj = Date.new(2017, 1, 5)
323
+ json = Oj.dump(obj, :indent => 2, time_format: :xmlschema)
324
+ assert_equal('"2017-01-05"', json)
325
+ end
326
+
327
+ def test_datetime
328
+ obj = DateTime.new(2017, 1, 5, 10, 20, 30)
329
+ dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
330
+ end
331
+
332
+ def test_datetime_unix
333
+ obj = DateTime.new(2017, 1, 5, 10, 20, 30, '-0500')
334
+ json = Oj.dump(obj, :indent => 2, time_format: :unix)
335
+ assert_equal('1483629630.000000000', json)
336
+ end
337
+
338
+ def test_datetime_unix_zone
339
+ # older versions seems to have issues getting the utc offset.
340
+ if '2.4' <= RUBY_VERSION
341
+ obj = DateTime.new(2017, 1, 5, 10, 20, 30, '-0500')
342
+ json = Oj.dump(obj, :indent => 2, time_format: :unix_zone)
343
+ assert_equal('1483629630.000000000e-18000', json)
344
+ end
345
+ end
346
+
347
+ def test_datetime_ruby
348
+ obj = DateTime.new(2017, 1, 5, 10, 20, 30, '-0500')
349
+ json = Oj.dump(obj, :indent => 2, time_format: :ruby)
350
+ assert_equal('"2017-01-05T10:20:30-05:00"', json)
351
+ end
352
+
353
+ def test_datetime_xmlschema
354
+ obj = DateTime.new(2017, 1, 5, 10, 20, 30, '-0500')
355
+ json = Oj.dump(obj, :indent => 2, time_format: :xmlschema)
356
+ assert_equal('"2017-01-05T10:20:30-05:00"', json)
357
+ end
358
+
359
+ def test_regexp
360
+ # this notation must be used to get an == match later
361
+ obj = /(?ix-m:^yes$)/
362
+ dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
363
+ end
364
+
365
+ def test_openstruct
366
+ obj = OpenStruct.new(:a => 1, 'b' => 2)
367
+ dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
368
+ end
369
+
370
+ def test_time
371
+ obj = Time.now()
372
+ dump_and_load(obj, false, :time_format => :unix, :create_id => "^o", :create_additions => true)
373
+ dump_and_load_inspect(obj, false, :time_format => :unix_zone, :create_id => "^o", :create_additions => true)
374
+ dump_and_load_inspect(obj, false, :time_format => :xmlschema, :create_id => "^o", :create_additions => true)
375
+ dump_and_load_inspect(obj, false, :time_format => :ruby, :create_id => "^o", :create_additions => true)
376
+ end
377
+
378
+ def dump_and_load(obj, trace=false, options={})
379
+ options = options.merge(:indent => 2, :mode => :custom)
380
+ json = Oj.dump(obj, options)
381
+ puts json if trace
382
+
383
+ loaded = Oj.load(json, options);
384
+ if obj.nil?
385
+ assert_nil(loaded)
386
+ else
387
+ assert_equal(obj, loaded)
388
+ end
389
+ loaded
390
+ end
391
+
392
+ def dump_and_load_inspect(obj, trace=false, options={})
393
+ options = options.merge(:indent => 2, :mode => :custom)
394
+ json = Oj.dump(obj, options)
395
+ puts json if trace
396
+
397
+ loaded = Oj.load(json, options);
398
+ if obj.nil?
399
+ assert_nil(loaded)
400
+ else
401
+ assert_equal(obj.inspect, loaded.inspect)
402
+ end
403
+ loaded
404
+ end
405
+
406
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'helper'
4
+
5
+ class DebJuice < Minitest::Test
6
+ class Jam
7
+ attr_accessor :x, :y
8
+
9
+ def initialize(x, y)
10
+ @x = x
11
+ @y = y
12
+ end
13
+
14
+ def eql?(o)
15
+ self.class == o.class && @x == o.x && @y == o.y
16
+ end
17
+ alias == eql?
18
+
19
+ end# Jam
20
+
21
+ # contributed by sauliusg to fix as_json
22
+ class Orange < Jam
23
+ def initialize(x, y)
24
+ super
25
+ end
26
+
27
+ def as_json()
28
+ { :json_class => self.class,
29
+ :x => @x,
30
+ :y => @y }
31
+ end
32
+
33
+ def self.json_create(h)
34
+ self.new(h['x'], h['y'])
35
+ end
36
+ end
37
+
38
+ def test_as_json_object_compat_hash_cached
39
+ Oj.default_options = { :mode => :compat, :class_cache => true, :use_as_json => true }
40
+ obj = Orange.new(true, 58)
41
+ json = Oj.dump(obj, :indent => 2)
42
+ assert(!json.nil?)
43
+ dump_and_load(obj, true)
44
+ end
45
+
46
+ def dump_and_load(obj, trace=false)
47
+ json = Oj.dump(obj, :indent => 2)
48
+ loaded = Oj.load(json);
49
+ assert_equal(obj, loaded)
50
+ loaded
51
+ end
52
+
53
+ end