oj 2.0.14 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

@@ -29,7 +29,7 @@ def sample_doc(size=3)
29
29
  (1..size).each do |k|
30
30
  g2 = ::Sample::Group.new
31
31
  r = ::Sample::Rect.new(j * 40 + 10.0, i * 10.0,
32
- 10.123456 / k, 10.0 / k, colors[(i + j + k) % colors.size])
32
+ 10.123456 / k, 10.0 / k, colors[(i + j + k) % colors.size])
33
33
  r.add_prop(:part_of, layer.name)
34
34
  g2 << r
35
35
  g2 << ::Sample::Text.new("#{k} in #{j}", r.left, r.top, r.width, r.height)
@@ -38,7 +38,7 @@ def sample_doc(size=3)
38
38
  g2 = ::Sample::Group.new
39
39
  (1..size).each do |k|
40
40
  o = ::Sample::Oval.new(j * 40 + 12.0, i * 10.0 + 2.0,
41
- 6.0 / k, 6.0 / k, colors[(i + j + k) % colors.size])
41
+ 6.0 / k, 6.0 / k, colors[(i + j + k) % colors.size])
42
42
  o.add_prop(:inside, true)
43
43
  g << o
44
44
  end
@@ -0,0 +1,342 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
+ # required. That can be set in the RUBYOPT environment variable.
6
+ # export RUBYOPT=-w
7
+
8
+ $VERBOSE = true
9
+
10
+ $: << File.join(File.dirname(__FILE__), "../lib")
11
+ $: << File.join(File.dirname(__FILE__), "../ext")
12
+
13
+ require 'test/unit'
14
+ require 'stringio'
15
+ require 'date'
16
+ require 'bigdecimal'
17
+ require 'oj'
18
+
19
+ $ruby = RUBY_DESCRIPTION.split(' ')[0]
20
+ $ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
21
+
22
+ class Jeez
23
+ attr_accessor :x, :y
24
+
25
+ def initialize(x, y)
26
+ @x = x
27
+ @y = y
28
+ end
29
+
30
+ def eql?(o)
31
+ self.class == o.class && @x == o.x && @y == o.y
32
+ end
33
+ alias == eql?
34
+
35
+ def to_json(*a)
36
+ %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
37
+ end
38
+
39
+ def self.json_create(h)
40
+ self.new(h['x'], h['y'])
41
+ end
42
+ end # Jeez
43
+
44
+ module One
45
+ module Two
46
+ module Three
47
+ class Deep
48
+
49
+ def initialize()
50
+ end
51
+
52
+ def eql?(o)
53
+ self.class == o.class
54
+ end
55
+ alias == eql?
56
+
57
+ def to_hash()
58
+ {'json_class' => "#{self.class.name}"}
59
+ end
60
+
61
+ def to_json(*a)
62
+ %{{"json_class":"#{self.class.name}"}}
63
+ end
64
+
65
+ def self.json_create(h)
66
+ self.new()
67
+ end
68
+ end # Deep
69
+ end # Three
70
+ end # Two
71
+ end # One
72
+
73
+ def hash_eql(h1, h2)
74
+ return false if h1.size != h2.size
75
+ h1.keys.each do |k|
76
+ return false unless h1[k] == h2[k]
77
+ end
78
+ true
79
+ end
80
+
81
+ class CompatJuice < ::Test::Unit::TestCase
82
+
83
+ def test_nil
84
+ dump_and_load(nil, false)
85
+ end
86
+
87
+ def test_true
88
+ dump_and_load(true, false)
89
+ end
90
+
91
+ def test_false
92
+ dump_and_load(false, false)
93
+ end
94
+
95
+ def test_fixnum
96
+ dump_and_load(0, false)
97
+ dump_and_load(12345, false)
98
+ dump_and_load(-54321, false)
99
+ dump_and_load(1, false)
100
+ end
101
+
102
+ def test_float
103
+ dump_and_load(0.0, false)
104
+ dump_and_load(12345.6789, false)
105
+ dump_and_load(70.35, false)
106
+ dump_and_load(-54321.012, false)
107
+ dump_and_load(2.48e16, false)
108
+ dump_and_load(2.48e100 * 1.0e10, false)
109
+ dump_and_load(-2.48e100 * 1.0e10, false)
110
+ end
111
+
112
+ def test_string
113
+ dump_and_load('', false)
114
+ dump_and_load('abc', false)
115
+ dump_and_load("abc\ndef", false)
116
+ dump_and_load("a\u0041", false)
117
+ end
118
+
119
+ def test_encode
120
+ opts = Oj.default_options
121
+ Oj.default_options = { :ascii_only => false }
122
+ unless 'jruby' == $ruby
123
+ dump_and_load("ぴーたー", false)
124
+ end
125
+ Oj.default_options = { :ascii_only => true }
126
+ json = Oj.dump("ぴーたー")
127
+ assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
128
+ unless 'jruby' == $ruby
129
+ dump_and_load("ぴーたー", false)
130
+ end
131
+ Oj.default_options = opts
132
+ end
133
+
134
+ def test_unicode
135
+ # hits the 3 normal ranges and one extended surrogate pair
136
+ json = %{"\\u019f\\u05e9\\u3074\\ud834\\udd1e"}
137
+ obj = Oj.load(json)
138
+ json2 = Oj.dump(obj, :ascii_only => true)
139
+ assert_equal(json, json2)
140
+ end
141
+
142
+ def test_array
143
+ dump_and_load([], false)
144
+ dump_and_load([true, false], false)
145
+ dump_and_load(['a', 1, nil], false)
146
+ dump_and_load([[nil]], false)
147
+ dump_and_load([[nil], 58], false)
148
+ end
149
+
150
+ def test_array_deep
151
+ dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
152
+ end
153
+
154
+ # Hash
155
+ def test_hash
156
+ dump_and_load({}, false)
157
+ dump_and_load({ 'true' => true, 'false' => false}, false)
158
+ dump_and_load({ 'true' => true, 'array' => [], 'hash' => { }}, false)
159
+ end
160
+
161
+ def test_hash_deep
162
+ dump_and_load({'1' => {
163
+ '2' => {
164
+ '3' => {
165
+ '4' => {
166
+ '5' => {
167
+ '6' => {
168
+ '7' => {
169
+ '8' => {
170
+ '9' => {
171
+ '10' => {
172
+ '11' => {
173
+ '12' => {
174
+ '13' => {
175
+ '14' => {
176
+ '15' => {
177
+ '16' => {
178
+ '17' => {
179
+ '18' => {
180
+ '19' => {
181
+ '20' => {}}}}}}}}}}}}}}}}}}}}}, false)
182
+ end
183
+
184
+ def test_hash_escaped_key
185
+ json = %{{"a\nb":true,"c\td":false}}
186
+ obj = Oj.compat_load(json)
187
+ assert_equal({"a\nb" => true, "c\td" => false}, obj)
188
+ end
189
+
190
+ def test_bignum_object
191
+ dump_and_load(7 ** 55, false)
192
+ end
193
+
194
+ # BigDecimal
195
+ def test_bigdecimal_compat
196
+ dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
197
+ end
198
+
199
+ def test_bigdecimal_load
200
+ orig = BigDecimal.new('80.51')
201
+ json = Oj.dump(orig, :mode => :compat, :bigdecimal_as_decimal => true)
202
+ bg = Oj.load(json, :mode => :compat, :bigdecimal_load => true)
203
+ assert_equal(BigDecimal, bg.class)
204
+ assert_equal(orig, bg)
205
+ end
206
+
207
+ # Stream IO
208
+ def test_io_string
209
+ json = %{{
210
+ "x":true,
211
+ "y":58,
212
+ "z": [1,2,3]
213
+ }
214
+ }
215
+ input = StringIO.new(json)
216
+ obj = Oj.compat_load(input)
217
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
218
+ end
219
+
220
+ def test_io_file
221
+ filename = 'open_file_test.json'
222
+ File.open(filename, 'w') { |f| f.write(%{{
223
+ "x":true,
224
+ "y":58,
225
+ "z": [1,2,3]
226
+ }
227
+ }) }
228
+ f = File.new(filename)
229
+ obj = Oj.compat_load(f)
230
+ f.close()
231
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
232
+ end
233
+
234
+ # symbol_keys option
235
+ def test_symbol_keys
236
+ json = %{{
237
+ "x":true,
238
+ "y":58,
239
+ "z": [1,2,3]
240
+ }
241
+ }
242
+ obj = Oj.compat_load(json, :symbol_keys => true)
243
+ assert_equal({ :x => true, :y => 58, :z => [1, 2, 3]}, obj)
244
+ end
245
+
246
+ # comments
247
+ def test_comment_slash
248
+ json = %{{
249
+ "x":true,//three
250
+ "y":58,
251
+ "z": [1,2,
252
+ 3 // six
253
+ ]}
254
+ }
255
+ obj = Oj.compat_load(json)
256
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
257
+ end
258
+
259
+ def test_comment_c
260
+ json = %{{
261
+ "x"/*one*/:/*two*/true,
262
+ "y":58,
263
+ "z": [1,2,3]}
264
+ }
265
+ obj = Oj.compat_load(json)
266
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
267
+ end
268
+
269
+ def test_comment
270
+ json = %{{
271
+ "x"/*one*/:/*two*/true,//three
272
+ "y":58/*four*/,
273
+ "z": [1,2/*five*/,
274
+ 3 // six
275
+ ]
276
+ }
277
+ }
278
+ obj = Oj.compat_load(json)
279
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
280
+ end
281
+
282
+ def test_json_object_compat
283
+ obj = Jeez.new(true, 58)
284
+ dump_and_load(obj, false)
285
+ end
286
+
287
+ def test_json_module_object
288
+ obj = One::Two::Three::Deep.new()
289
+ dump_and_load(obj, false)
290
+ end
291
+
292
+ def test_json_object_create_id
293
+ expected = Jeez.new(true, 58)
294
+ json = Oj.dump(expected, :indent => 2, :mode => :compat)
295
+ obj = Oj.compat_load(json)
296
+ assert_equal(expected, obj)
297
+ end
298
+
299
+ def test_json_object_bad
300
+ json = %{{"json_class":"Junk","x":true}}
301
+ begin
302
+ Oj.compat_load(json)
303
+ rescue Exception => e
304
+ assert_equal("Oj::ParseError", e.class().name)
305
+ return
306
+ end
307
+ assert(false, "*** expected an exception")
308
+ end
309
+
310
+ def test_json_object_create_cache
311
+ expected = Jeez.new(true, 58)
312
+ json = Oj.dump(expected, :indent => 2, :mode => :compat)
313
+ obj = Oj.compat_load(json, :class_cache => true)
314
+ assert_equal(expected, obj)
315
+ obj = Oj.compat_load(json, :class_cache => false)
316
+ assert_equal(expected, obj)
317
+ end
318
+
319
+ def test_json_object_create_id_other
320
+ expected = Jeez.new(true, 58)
321
+ json = Oj.dump(expected, :indent => 2, :mode => :compat)
322
+ json.gsub!('json_class', '_class_')
323
+ obj = Oj.compat_load(json, :create_id => "_class_")
324
+ assert_equal(expected, obj)
325
+ end
326
+
327
+ def test_json_object_create_deep
328
+ expected = One::Two::Three::Deep.new()
329
+ json = Oj.dump(expected, :indent => 2, :mode => :compat)
330
+ obj = Oj.compat_load(json)
331
+ assert_equal(expected, obj)
332
+ end
333
+
334
+ def dump_and_load(obj, trace=false)
335
+ json = Oj.dump(obj, :indent => 2, :mode => :compat)
336
+ puts json if trace
337
+ loaded = Oj.compat_load(json);
338
+ assert_equal(obj, loaded)
339
+ loaded
340
+ end
341
+
342
+ end
@@ -0,0 +1,390 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
+ # required. That can be set in the RUBYOPT environment variable.
6
+ # export RUBYOPT=-w
7
+
8
+ $VERBOSE = true
9
+
10
+ $: << File.join(File.dirname(__FILE__), "../lib")
11
+ $: << File.join(File.dirname(__FILE__), "../ext")
12
+
13
+ require 'test/unit'
14
+ require 'stringio'
15
+ require 'date'
16
+ require 'bigdecimal'
17
+ require 'oj'
18
+
19
+ $ruby = RUBY_DESCRIPTION.split(' ')[0]
20
+ $ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
21
+
22
+ class Jeez
23
+ attr_accessor :x, :y
24
+
25
+ def initialize(x, y)
26
+ @x = x
27
+ @y = y
28
+ end
29
+
30
+ def eql?(o)
31
+ self.class == o.class && @x == o.x && @y == o.y
32
+ end
33
+ alias == eql?
34
+
35
+ def to_json(*a)
36
+ %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
37
+ end
38
+
39
+ def self.json_create(h)
40
+ self.new(h['x'], h['y'])
41
+ end
42
+ end # Jeez
43
+
44
+ module One
45
+ module Two
46
+ module Three
47
+ class Deep
48
+
49
+ def initialize()
50
+ end
51
+
52
+ def eql?(o)
53
+ self.class == o.class
54
+ end
55
+ alias == eql?
56
+
57
+ def to_hash()
58
+ {'json_class' => "#{self.class.name}"}
59
+ end
60
+
61
+ def to_json(*a)
62
+ %{{"json_class":"#{self.class.name}"}}
63
+ end
64
+
65
+ def self.json_create(h)
66
+ self.new()
67
+ end
68
+ end # Deep
69
+ end # Three
70
+ end # Two
71
+ end # One
72
+
73
+ class Stuck < Struct.new(:a, :b)
74
+ end
75
+
76
+ def hash_eql(h1, h2)
77
+ return false if h1.size != h2.size
78
+ h1.keys.each do |k|
79
+ return false unless h1[k] == h2[k]
80
+ end
81
+ true
82
+ end
83
+
84
+ class ObjectJuice < ::Test::Unit::TestCase
85
+
86
+ def test_nil
87
+ dump_and_load(nil, false)
88
+ end
89
+
90
+ def test_true
91
+ dump_and_load(true, false)
92
+ end
93
+
94
+ def test_false
95
+ dump_and_load(false, false)
96
+ end
97
+
98
+ def test_fixnum
99
+ dump_and_load(0, false)
100
+ dump_and_load(12345, false)
101
+ dump_and_load(-54321, false)
102
+ dump_and_load(1, false)
103
+ end
104
+
105
+ def test_float
106
+ dump_and_load(0.0, false)
107
+ dump_and_load(12345.6789, false)
108
+ dump_and_load(70.35, false)
109
+ dump_and_load(-54321.012, false)
110
+ dump_and_load(2.48e16, false)
111
+ dump_and_load(2.48e100 * 1.0e10, false)
112
+ dump_and_load(-2.48e100 * 1.0e10, false)
113
+ end
114
+
115
+ def test_string
116
+ dump_and_load('', false)
117
+ dump_and_load('abc', false)
118
+ dump_and_load("abc\ndef", false)
119
+ dump_and_load("a\u0041", false)
120
+ end
121
+
122
+ def test_symbol
123
+ dump_and_load(:abc, false)
124
+ dump_and_load(":abc", false)
125
+ end
126
+
127
+ def test_encode
128
+ opts = Oj.default_options
129
+ Oj.default_options = { :ascii_only => false }
130
+ unless 'jruby' == $ruby
131
+ dump_and_load("ぴーたー", false)
132
+ end
133
+ Oj.default_options = { :ascii_only => true }
134
+ json = Oj.dump("ぴーたー")
135
+ assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
136
+ unless 'jruby' == $ruby
137
+ dump_and_load("ぴーたー", false)
138
+ end
139
+ Oj.default_options = opts
140
+ end
141
+
142
+ def test_unicode
143
+ # hits the 3 normal ranges and one extended surrogate pair
144
+ json = %{"\\u019f\\u05e9\\u3074\\ud834\\udd1e"}
145
+ obj = Oj.load(json)
146
+ json2 = Oj.dump(obj, :ascii_only => true)
147
+ assert_equal(json, json2)
148
+ end
149
+
150
+ def test_array
151
+ dump_and_load([], false)
152
+ dump_and_load([true, false], false)
153
+ dump_and_load(['a', 1, nil], false)
154
+ dump_and_load([[nil]], false)
155
+ dump_and_load([[nil], 58], false)
156
+ end
157
+
158
+ def test_array_deep
159
+ dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
160
+ end
161
+
162
+ # Hash
163
+ def test_hash
164
+ dump_and_load({}, false)
165
+ dump_and_load({ 'true' => true, 'false' => false}, false)
166
+ dump_and_load({ 'true' => true, 'array' => [], 'hash' => { }}, false)
167
+ end
168
+
169
+ def test_hash_deep
170
+ dump_and_load({'1' => {
171
+ '2' => {
172
+ '3' => {
173
+ '4' => {
174
+ '5' => {
175
+ '6' => {
176
+ '7' => {
177
+ '8' => {
178
+ '9' => {
179
+ '10' => {
180
+ '11' => {
181
+ '12' => {
182
+ '13' => {
183
+ '14' => {
184
+ '15' => {
185
+ '16' => {
186
+ '17' => {
187
+ '18' => {
188
+ '19' => {
189
+ '20' => {}}}}}}}}}}}}}}}}}}}}}, false)
190
+ end
191
+
192
+ def test_hash_escaped_key
193
+ json = %{{"a\nb":true,"c\td":false}}
194
+ obj = Oj.object_load(json)
195
+ assert_equal({"a\nb" => true, "c\td" => false}, obj)
196
+ end
197
+
198
+ def test_bignum_object
199
+ dump_and_load(7 ** 55, false)
200
+ end
201
+
202
+ # BigDecimal
203
+ def test_bigdecimal_object
204
+ dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
205
+ end
206
+
207
+ def test_bigdecimal_load
208
+ orig = BigDecimal.new('80.51')
209
+ json = Oj.dump(orig, :mode => :object, :bigdecimal_as_decimal => true)
210
+ bg = Oj.load(json, :mode => :object, :bigdecimal_load => true)
211
+ assert_equal(BigDecimal, bg.class)
212
+ assert_equal(orig, bg)
213
+ end
214
+
215
+ # Stream IO
216
+ def test_io_string
217
+ json = %{{
218
+ "x":true,
219
+ "y":58,
220
+ "z": [1,2,3]
221
+ }
222
+ }
223
+ input = StringIO.new(json)
224
+ obj = Oj.object_load(input)
225
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
226
+ end
227
+
228
+ def test_io_file
229
+ filename = 'open_file_test.json'
230
+ File.open(filename, 'w') { |f| f.write(%{{
231
+ "x":true,
232
+ "y":58,
233
+ "z": [1,2,3]
234
+ }
235
+ }) }
236
+ f = File.new(filename)
237
+ obj = Oj.object_load(f)
238
+ f.close()
239
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
240
+ end
241
+
242
+ # symbol_keys option
243
+ def test_symbol_keys
244
+ json = %{{
245
+ "x":true,
246
+ "y":58,
247
+ "z": [1,2,3]
248
+ }
249
+ }
250
+ obj = Oj.object_load(json, :symbol_keys => true)
251
+ assert_equal({ :x => true, :y => 58, :z => [1, 2, 3]}, obj)
252
+ end
253
+
254
+ # comments
255
+ def test_comment_slash
256
+ json = %{{
257
+ "x":true,//three
258
+ "y":58,
259
+ "z": [1,2,
260
+ 3 // six
261
+ ]}
262
+ }
263
+ obj = Oj.object_load(json)
264
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
265
+ end
266
+
267
+ def test_comment_c
268
+ json = %{{
269
+ "x"/*one*/:/*two*/true,
270
+ "y":58,
271
+ "z": [1,2,3]}
272
+ }
273
+ obj = Oj.object_load(json)
274
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
275
+ end
276
+
277
+ def test_comment
278
+ json = %{{
279
+ "x"/*one*/:/*two*/true,//three
280
+ "y":58/*four*/,
281
+ "z": [1,2/*five*/,
282
+ 3 // six
283
+ ]
284
+ }
285
+ }
286
+ obj = Oj.object_load(json)
287
+ assert_equal({ 'x' => true, 'y' => 58, 'z' => [1, 2, 3]}, obj)
288
+ end
289
+
290
+ def test_json_module_object
291
+ obj = One::Two::Three::Deep.new()
292
+ dump_and_load(obj, false)
293
+ end
294
+
295
+ def test_time
296
+ t = Time.now()
297
+ dump_and_load(t, false)
298
+ end
299
+
300
+ def test_time_early
301
+ t = Time.xmlschema("1954-01-05T00:00:00.123456")
302
+ dump_and_load(t, false)
303
+ end
304
+
305
+ def test_json_object
306
+ obj = Jeez.new(true, 58)
307
+ dump_and_load(obj, false)
308
+ end
309
+
310
+ def test_json_object_create_deep
311
+ obj = One::Two::Three::Deep.new()
312
+ dump_and_load(obj, false)
313
+ end
314
+
315
+ def test_json_object_bad
316
+ json = %{{"^o":"Junk","x":true}}
317
+ begin
318
+ Oj.object_load(json)
319
+ rescue Exception => e
320
+ assert_equal("Oj::ParseError", e.class().name)
321
+ return
322
+ end
323
+ assert(false, "*** expected an exception")
324
+ end
325
+
326
+ def test_json_struct
327
+ unless 'jruby' == RUBY_DESCRIPTION.split(' ')[0]
328
+ obj = Stuck.new(false, 7)
329
+ dump_and_load(obj, false)
330
+ end
331
+ end
332
+
333
+ def test_json_non_str_hash
334
+ obj = { 59 => "young", false => true }
335
+ dump_and_load(obj, false)
336
+ end
337
+
338
+ def test_mixed_hash_object
339
+ json = Oj.dump({ 1 => true, 'nil' => nil, :sim => 4 })
340
+ h = Oj.object_load(json)
341
+ assert_equal({ 1 => true, 'nil' => nil, :sim => 4 }, h)
342
+ end
343
+
344
+ def test_circular_hash
345
+ h = { 'a' => 7 }
346
+ h['b'] = h
347
+ json = Oj.dump(h, :mode => :object, :indent => 2, :circular => true)
348
+ h2 = Oj.object_load(json, :circular => true)
349
+ assert_equal(h2['b'].__id__, h2.__id__)
350
+ end
351
+
352
+ def test_circular_array
353
+ a = [7]
354
+ a << a
355
+ json = Oj.dump(a, :mode => :object, :indent => 2, :circular => true)
356
+ a2 = Oj.object_load(json, :circular => true)
357
+ assert_equal(a2[1].__id__, a2.__id__)
358
+ end
359
+
360
+ def test_circular_object
361
+ obj = Jeez.new(nil, 58)
362
+ obj.x = obj
363
+ json = Oj.dump(obj, :mode => :object, :indent => 2, :circular => true)
364
+ obj2 = Oj.object_load(json, :circular => true)
365
+ assert_equal(obj2.x.__id__, obj2.__id__)
366
+ end
367
+
368
+ def test_circular
369
+ h = { 'a' => 7 }
370
+ obj = Jeez.new(h, 58)
371
+ obj.x['b'] = obj
372
+ json = Oj.dump(obj, :mode => :object, :indent => 2, :circular => true)
373
+ Oj.object_load(json, :circular => true)
374
+ assert_equal(obj.x.__id__, h.__id__)
375
+ assert_equal(h['b'].__id__, obj.__id__)
376
+ end
377
+
378
+ def test_odd_date
379
+ dump_and_load(Date.new(2012, 6, 19), false)
380
+ end
381
+
382
+ def dump_and_load(obj, trace=false)
383
+ json = Oj.dump(obj, :indent => 2, :mode => :object)
384
+ puts json if trace
385
+ loaded = Oj.object_load(json);
386
+ assert_equal(obj, loaded)
387
+ loaded
388
+ end
389
+
390
+ end