oj 3.16.9 → 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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/ext/oj/fast.c +3 -6
  4. data/ext/oj/mimic_json.c +3 -6
  5. data/ext/oj/oj.c +2 -4
  6. data/ext/oj/parse.c +15 -5
  7. data/ext/oj/parser.c +1 -1
  8. data/ext/oj/parser.h +2 -0
  9. data/ext/oj/rails.c +1 -2
  10. data/ext/oj/saj.c +3 -6
  11. data/ext/oj/scp.c +3 -6
  12. data/ext/oj/stream_writer.c +1 -7
  13. data/ext/oj/strict.c +2 -4
  14. data/ext/oj/string_writer.c +1 -3
  15. data/lib/oj/version.rb +1 -1
  16. metadata +3 -98
  17. data/test/_test_active.rb +0 -75
  18. data/test/_test_active_mimic.rb +0 -95
  19. data/test/_test_mimic_rails.rb +0 -123
  20. data/test/activerecord/result_test.rb +0 -31
  21. data/test/activesupport6/abstract_unit.rb +0 -44
  22. data/test/activesupport6/decoding_test.rb +0 -133
  23. data/test/activesupport6/encoding_test.rb +0 -542
  24. data/test/activesupport6/encoding_test_cases.rb +0 -98
  25. data/test/activesupport6/test_common.rb +0 -17
  26. data/test/activesupport6/test_helper.rb +0 -163
  27. data/test/activesupport6/time_zone_test_helpers.rb +0 -39
  28. data/test/activesupport7/abstract_unit.rb +0 -52
  29. data/test/activesupport7/decoding_test.rb +0 -125
  30. data/test/activesupport7/encoding_test.rb +0 -536
  31. data/test/activesupport7/encoding_test_cases.rb +0 -104
  32. data/test/activesupport7/time_zone_test_helpers.rb +0 -47
  33. data/test/files.rb +0 -29
  34. data/test/foo.rb +0 -26
  35. data/test/helper.rb +0 -39
  36. data/test/isolated/shared.rb +0 -309
  37. data/test/isolated/test_mimic_after.rb +0 -13
  38. data/test/isolated/test_mimic_alone.rb +0 -12
  39. data/test/isolated/test_mimic_as_json.rb +0 -45
  40. data/test/isolated/test_mimic_before.rb +0 -13
  41. data/test/isolated/test_mimic_define.rb +0 -28
  42. data/test/isolated/test_mimic_rails_after.rb +0 -22
  43. data/test/isolated/test_mimic_rails_before.rb +0 -21
  44. data/test/isolated/test_mimic_redefine.rb +0 -15
  45. data/test/json_gem/json_addition_test.rb +0 -216
  46. data/test/json_gem/json_common_interface_test.rb +0 -155
  47. data/test/json_gem/json_encoding_test.rb +0 -107
  48. data/test/json_gem/json_ext_parser_test.rb +0 -21
  49. data/test/json_gem/json_fixtures_test.rb +0 -36
  50. data/test/json_gem/json_generator_test.rb +0 -413
  51. data/test/json_gem/json_generic_object_test.rb +0 -90
  52. data/test/json_gem/json_parser_test.rb +0 -477
  53. data/test/json_gem/json_string_matching_test.rb +0 -42
  54. data/test/json_gem/test_helper.rb +0 -30
  55. data/test/mem.rb +0 -34
  56. data/test/perf.rb +0 -102
  57. data/test/perf_compat.rb +0 -128
  58. data/test/perf_dump.rb +0 -50
  59. data/test/perf_fast.rb +0 -162
  60. data/test/perf_file.rb +0 -62
  61. data/test/perf_object.rb +0 -134
  62. data/test/perf_once.rb +0 -59
  63. data/test/perf_parser.rb +0 -183
  64. data/test/perf_saj.rb +0 -101
  65. data/test/perf_scp.rb +0 -140
  66. data/test/perf_simple.rb +0 -289
  67. data/test/perf_strict.rb +0 -137
  68. data/test/perf_wab.rb +0 -129
  69. data/test/prec.rb +0 -23
  70. data/test/sample/change.rb +0 -13
  71. data/test/sample/dir.rb +0 -18
  72. data/test/sample/doc.rb +0 -35
  73. data/test/sample/file.rb +0 -47
  74. data/test/sample/group.rb +0 -15
  75. data/test/sample/hasprops.rb +0 -15
  76. data/test/sample/layer.rb +0 -11
  77. data/test/sample/line.rb +0 -20
  78. data/test/sample/oval.rb +0 -10
  79. data/test/sample/rect.rb +0 -9
  80. data/test/sample/shape.rb +0 -34
  81. data/test/sample/text.rb +0 -19
  82. data/test/sample.rb +0 -54
  83. data/test/sample_json.rb +0 -37
  84. data/test/test_compat.rb +0 -567
  85. data/test/test_custom.rb +0 -555
  86. data/test/test_debian.rb +0 -50
  87. data/test/test_fast.rb +0 -526
  88. data/test/test_file.rb +0 -250
  89. data/test/test_gc.rb +0 -60
  90. data/test/test_generate.rb +0 -21
  91. data/test/test_hash.rb +0 -39
  92. data/test/test_integer_range.rb +0 -72
  93. data/test/test_null.rb +0 -376
  94. data/test/test_object.rb +0 -1030
  95. data/test/test_parser.rb +0 -11
  96. data/test/test_parser_debug.rb +0 -27
  97. data/test/test_parser_saj.rb +0 -337
  98. data/test/test_parser_usual.rb +0 -255
  99. data/test/test_rails.rb +0 -35
  100. data/test/test_saj.rb +0 -188
  101. data/test/test_scp.rb +0 -431
  102. data/test/test_strict.rb +0 -441
  103. data/test/test_various.rb +0 -801
  104. data/test/test_wab.rb +0 -311
  105. data/test/test_writer.rb +0 -396
  106. data/test/tests.rb +0 -33
  107. data/test/tests_mimic.rb +0 -23
  108. data/test/tests_mimic_addition.rb +0 -16
@@ -1,413 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- # frozen_string_literal: false
5
-
6
- require 'json_gem/test_helper'
7
-
8
- class JSONGeneratorTest < Test::Unit::TestCase
9
- include Test::Unit::TestCaseOmissionSupport
10
- include Test::Unit::TestCasePendingSupport
11
-
12
- def setup
13
- @hash = {
14
- 'a' => 2,
15
- 'b' => 3.141,
16
- 'c' => 'c',
17
- 'd' => [ 1, "b", 3.14 ],
18
- 'e' => { 'foo' => 'bar' },
19
- 'g' => "\"\0\037",
20
- 'h' => 1000.0,
21
- 'i' => 0.001
22
- }
23
- @json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
24
- '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
25
- @json3 = <<~'EOT'.chomp
26
- {
27
- "a": 2,
28
- "b": 3.141,
29
- "c": "c",
30
- "d": [
31
- 1,
32
- "b",
33
- 3.14
34
- ],
35
- "e": {
36
- "foo": "bar"
37
- },
38
- "g": "\"\u0000\u001f",
39
- "h": 1000.0,
40
- "i": 0.001
41
- }
42
- EOT
43
- end
44
-
45
- def test_generate
46
- json = JSON.generate(@hash)
47
- assert_equal(JSON.parse(@json2), JSON.parse(json))
48
- json = JSON[@hash]
49
- assert_equal(JSON.parse(@json2), JSON.parse(json))
50
- parsed_json = JSON.parse(json)
51
- assert_equal(@hash, parsed_json)
52
- json = JSON.generate({1=>2})
53
- assert_equal('{"1":2}', json)
54
- parsed_json = JSON.parse(json)
55
- assert_equal({"1"=>2}, parsed_json)
56
- assert_equal '666', JSON.generate(666)
57
- end
58
-
59
- def test_generate_pretty
60
- json = JSON.pretty_generate(@hash)
61
- # hashes aren't (insertion) ordered on every ruby implementation
62
- assert_equal(@json3, json)
63
- assert_equal(JSON.parse(@json3), JSON.parse(json))
64
- parsed_json = JSON.parse(json)
65
- assert_equal(@hash, parsed_json)
66
- json = JSON.pretty_generate({1=>2})
67
- assert_equal(<<~'EOT'.chomp, json)
68
- {
69
- "1": 2
70
- }
71
- EOT
72
- parsed_json = JSON.parse(json)
73
- assert_equal({"1"=>2}, parsed_json)
74
- assert_equal '666', JSON.pretty_generate(666)
75
- json_nil_opts = JSON.pretty_generate({1=>2}, nil)
76
- assert_equal json, json_nil_opts
77
- end
78
-
79
- def test_generate_custom
80
- state = JSON::State.new(:space_before => " ", :space => " ", :indent => "<i>", :object_nl => "\n", :array_nl => "<a_nl>")
81
- json = JSON.generate({1=>{2=>3, 4=>[5, 6]}}, state)
82
- assert_equal(<<~'EOT'.chomp, json)
83
- {
84
- <i>"1" : {
85
- <i><i>"2" : 3,
86
- <i><i>"4" : [<a_nl><i><i><i>5,<a_nl><i><i><i>6<a_nl><i><i>]
87
- <i>}
88
- }
89
- EOT
90
- end
91
-
92
- def test_fast_generate
93
- json = JSON.fast_generate(@hash)
94
- assert_equal(JSON.parse(@json2), JSON.parse(json))
95
- parsed_json = JSON.parse(json)
96
- assert_equal(@hash, parsed_json)
97
- json = JSON.fast_generate({1=>2})
98
- assert_equal('{"1":2}', json)
99
- parsed_json = JSON.parse(json)
100
- assert_equal({"1"=>2}, parsed_json)
101
- assert_equal '666', JSON.fast_generate(666)
102
- end
103
-
104
- def test_own_state
105
- state = JSON::State.new
106
- json = JSON.generate(@hash, state)
107
- assert_equal(JSON.parse(@json2), JSON.parse(json))
108
- parsed_json = JSON.parse(json)
109
- assert_equal(@hash, parsed_json)
110
- json = JSON.generate({1=>2}, state)
111
- assert_equal('{"1":2}', json)
112
- parsed_json = JSON.parse(json)
113
- assert_equal({"1"=>2}, parsed_json)
114
- assert_equal '666', JSON.generate(666, state)
115
- end
116
-
117
- # TBD Implement JSON.state to return state class.
118
- # set state attributes from defaults
119
- # implement methods
120
- # circular should use circular in defaults or maybe always set to true, allow changes with [:check_circular]=
121
- def test_states
122
- json = JSON.generate({1=>2}, nil)
123
- assert_equal('{"1":2}', json)
124
- s = JSON.state.new
125
- assert s.check_circular?
126
- assert s[:check_circular?]
127
- h = { 1=>2 }
128
- h[3] = h
129
- assert_raise(JSON::NestingError) { JSON.generate(h) }
130
- assert_raise(JSON::NestingError) { JSON.generate(h, s) }
131
- s = JSON.state.new
132
- a = [ 1, 2 ]
133
- a << a
134
- assert_raise(JSON::NestingError) { JSON.generate(a, s) }
135
- assert s.check_circular?
136
- assert s[:check_circular?]
137
- end
138
-
139
- def test_pretty_state
140
- state = JSON::PRETTY_STATE_PROTOTYPE.dup
141
- # In come cases in Ruby 3.0 an :escape_slash is included in the state. It
142
- # seems to occur on travis but not locally.
143
- actual = state.to_h
144
- actual.delete(:escape_slash)
145
- actual.delete(:strict)
146
- actual.delete(:script_safe)
147
- assert_equal({
148
- :allow_nan => false,
149
- :array_nl => "\n",
150
- :ascii_only => false,
151
- :buffer_initial_length => 1024,
152
- :depth => 0,
153
- :indent => " ",
154
- :max_nesting => 100,
155
- :object_nl => "\n",
156
- :space => " ",
157
- :space_before => "",
158
- }.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
159
- end
160
-
161
- def test_safe_state
162
- state = JSON::SAFE_STATE_PROTOTYPE.dup
163
- # In come cases in Ruby 3.0 an :escape_slash is included in the state. It
164
- # seems to occur on travis but not locally.
165
- actual = state.to_h
166
- actual.delete(:escape_slash)
167
- actual.delete(:strict)
168
- actual.delete(:script_safe)
169
- assert_equal({
170
- :allow_nan => false,
171
- :array_nl => "",
172
- :ascii_only => false,
173
- :buffer_initial_length => 1024,
174
- :depth => 0,
175
- :indent => "",
176
- :max_nesting => 100,
177
- :object_nl => "",
178
- :space => "",
179
- :space_before => "",
180
- }.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
181
- end
182
-
183
- def test_fast_state
184
- state = JSON::FAST_STATE_PROTOTYPE.dup
185
- # In come cases in Ruby 3.0 an :escape_slash is included in the state. It
186
- # seems to occur on travis but not locally.
187
- actual = state.to_h
188
- actual.delete(:escape_slash)
189
- actual.delete(:strict)
190
- actual.delete(:script_safe)
191
- assert_equal({
192
- :allow_nan => false,
193
- :array_nl => "",
194
- :ascii_only => false,
195
- :buffer_initial_length => 1024,
196
- :depth => 0,
197
- :indent => "",
198
- :max_nesting => 0,
199
- :object_nl => "",
200
- :space => "",
201
- :space_before => "",
202
- }.sort_by { |n,| n.to_s }, actual.sort_by { |n,| n.to_s })
203
- end
204
-
205
- def test_allow_nan
206
- assert_raise(JSON::GeneratorError) { JSON.generate([JSON::NaN]) }
207
- assert_equal '[NaN]', JSON.generate([JSON::NaN], :allow_nan => true)
208
- assert_raise(JSON::GeneratorError) { JSON.fast_generate([JSON::NaN]) }
209
- assert_raise(JSON::GeneratorError) { JSON.pretty_generate([JSON::NaN]) }
210
- assert_equal "[\n NaN\n]", JSON.pretty_generate([JSON::NaN], :allow_nan => true)
211
- assert_raise(JSON::GeneratorError) { JSON.generate([JSON::Infinity]) }
212
- assert_equal '[Infinity]', JSON.generate([JSON::Infinity], :allow_nan => true)
213
- assert_raise(JSON::GeneratorError) { JSON.fast_generate([JSON::Infinity]) }
214
- assert_raise(JSON::GeneratorError) { JSON.pretty_generate([JSON::Infinity]) }
215
- assert_equal "[\n Infinity\n]", JSON.pretty_generate([JSON::Infinity], :allow_nan => true)
216
- assert_raise(JSON::GeneratorError) { JSON.generate([JSON::MinusInfinity]) }
217
- assert_equal '[-Infinity]', JSON.generate([JSON::MinusInfinity], :allow_nan => true)
218
- assert_raise(JSON::GeneratorError) { JSON.fast_generate([JSON::MinusInfinity]) }
219
- assert_raise(JSON::GeneratorError) { JSON.pretty_generate([JSON::MinusInfinity]) }
220
- assert_equal "[\n -Infinity\n]", JSON.pretty_generate([JSON::MinusInfinity], :allow_nan => true)
221
- end
222
-
223
- def test_depth
224
- ary = []; ary << ary
225
- assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
226
- assert_raise(JSON::NestingError) { JSON.generate(ary) }
227
- assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
228
- assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
229
- assert_raise(JSON::NestingError) { JSON.pretty_generate(ary) }
230
- assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
231
- s = JSON.state.new
232
- assert_equal 0, s.depth
233
- assert_raise(JSON::NestingError) { ary.to_json(s) }
234
- assert_equal 100, s.depth
235
- end
236
-
237
- def test_buffer_initial_length
238
- s = JSON.state.new
239
- assert_equal 1024, s.buffer_initial_length
240
- s.buffer_initial_length = 0
241
- assert_equal 1024, s.buffer_initial_length
242
- s.buffer_initial_length = -1
243
- assert_equal 1024, s.buffer_initial_length
244
- s.buffer_initial_length = 128
245
- assert_equal 128, s.buffer_initial_length
246
- end
247
-
248
- def test_gc
249
- if respond_to?(:assert_in_out_err)
250
- assert_in_out_err(%w[-rjson --disable-gems], <<-EOS, [], [])
251
- bignum_too_long_to_embed_as_string = 1234567890123456789012345
252
- expect = bignum_too_long_to_embed_as_string.to_s
253
- GC.stress = true
254
-
255
- 10.times do |i|
256
- tmp = bignum_too_long_to_embed_as_string.to_json
257
- raise "'\#{expect}' is expected, but '\#{tmp}'" unless tmp == expect
258
- end
259
- EOS
260
- end
261
- end if GC.respond_to?(:stress=)
262
-
263
- def test_configure_using_configure_and_merge
264
- numbered_state = {
265
- :indent => "1",
266
- :space => '2',
267
- :space_before => '3',
268
- :object_nl => '4',
269
- :array_nl => '5'
270
- }
271
- state1 = JSON.state.new
272
- state1.merge(numbered_state)
273
- assert_equal '1', state1.indent
274
- assert_equal '2', state1.space
275
- assert_equal '3', state1.space_before
276
- assert_equal '4', state1.object_nl
277
- assert_equal '5', state1.array_nl
278
- state2 = JSON.state.new
279
- state2.configure(numbered_state)
280
- assert_equal '1', state2.indent
281
- assert_equal '2', state2.space
282
- assert_equal '3', state2.space_before
283
- assert_equal '4', state2.object_nl
284
- assert_equal '5', state2.array_nl
285
- end
286
-
287
- def test_configure_hash_conversion
288
- state = JSON.state.new
289
- state.configure(:indent => '1')
290
- assert_equal '1', state.indent
291
- state = JSON.state.new
292
- foo = 'foo'
293
- assert_raise(TypeError) do
294
- state.configure(foo)
295
- end
296
- def foo.to_h
297
- { :indent => '2' }
298
- end
299
- state.configure(foo)
300
- assert_equal '2', state.indent
301
- end
302
-
303
- if defined?(JSON::Ext::Generator) && Process.respond_to?(:fork)
304
- # forking to avoid modifying core class of a parent process and
305
- # introducing race conditions of tests are run in parallel
306
- def test_broken_bignum # [ruby-core:38867]
307
- pid = fork do
308
- x = 1 << 64
309
- x.class.class_eval do
310
- def to_s
311
- end
312
- end
313
- begin
314
- j = JSON::Ext::Generator::State.new.generate(x)
315
- exit 1
316
- rescue TypeError
317
- exit 0
318
- end
319
- end
320
- _, status = Process.waitpid2(pid)
321
- assert status.success?
322
- end
323
- end
324
-
325
- def test_hash_likeness_set_symbol
326
- state = JSON.state.new
327
- assert_equal nil, state[:foo]
328
- assert_equal nil.class, state[:foo].class
329
- assert_equal nil, state['foo']
330
- state[:foo] = :bar
331
- assert_equal :bar, state[:foo]
332
- assert_equal :bar, state['foo']
333
- state_hash = state.to_hash
334
- assert_kind_of Hash, state_hash
335
- assert_equal :bar, state_hash[:foo]
336
- end
337
-
338
- def test_hash_likeness_set_string
339
- state = JSON.state.new
340
- assert_equal nil, state[:foo]
341
- assert_equal nil, state['foo']
342
- state['foo'] = :bar
343
- assert_equal :bar, state[:foo]
344
- assert_equal :bar, state['foo']
345
- state_hash = state.to_hash
346
- assert_kind_of Hash, state_hash
347
- assert_equal :bar, state_hash[:foo]
348
- end
349
-
350
- def test_json_generate
351
- assert_raise JSON::GeneratorError do
352
- assert_equal true, JSON.generate(["\xea"])
353
- end
354
- end
355
-
356
- def test_nesting
357
- too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
358
- too_deep_ary = eval too_deep
359
- assert_raise(JSON::NestingError) { JSON.generate too_deep_ary }
360
- assert_raise(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 100 }
361
- ok = JSON.generate too_deep_ary, :max_nesting => 102
362
- assert_equal too_deep, ok
363
- ok = JSON.generate too_deep_ary, :max_nesting => nil
364
- assert_equal too_deep, ok
365
- ok = JSON.generate too_deep_ary, :max_nesting => false
366
- assert_equal too_deep, ok
367
- ok = JSON.generate too_deep_ary, :max_nesting => 0
368
- assert_equal too_deep, ok
369
- end
370
-
371
- def test_backslash
372
- data = [ '\\.(?i:gif|jpe?g|png)$' ]
373
- json = '["\\\\.(?i:gif|jpe?g|png)$"]'
374
- assert_equal json, JSON.generate(data)
375
- #
376
- data = [ '\\"' ]
377
- json = '["\\\\\""]'
378
- assert_equal json, JSON.generate(data)
379
- #
380
- data = [ '/' ]
381
- json = '["/"]'
382
- assert_equal json, JSON.generate(data)
383
- #
384
- data = ['"']
385
- json = '["\""]'
386
- assert_equal json, JSON.generate(data)
387
- #
388
- data = ["'"]
389
- json = '["\\\'"]'
390
- assert_equal '["\'"]', JSON.generate(data)
391
- end
392
-
393
- def test_string_subclass
394
- s = Class.new(String) do
395
- def to_s; self; end
396
- undef to_json
397
- end
398
- assert_nothing_raised(SystemStackError) do
399
- assert_equal '["foo"]', JSON.generate([s.new('foo')])
400
- end
401
- end
402
-
403
- def test_invalid_to_json
404
- omit if REAL_JSON_GEM
405
-
406
- data = Object.new
407
- def data.to_json(*)
408
- nil
409
- end
410
-
411
- assert_raises(TypeError) { JSON.generate(data) }
412
- end
413
- end
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- #frozen_string_literal: false
5
-
6
- require 'json_gem/test_helper'
7
-
8
- class JSONGenericObjectTest < Test::Unit::TestCase
9
- include Test::Unit::TestCaseOmissionSupport
10
-
11
- def setup
12
- @go = JSON::GenericObject[ :a => 1, :b => 2 ]
13
- end
14
-
15
- def test_attributes
16
- assert_equal 1, @go.a
17
- assert_equal 1, @go[:a]
18
- assert_equal 2, @go.b
19
- assert_equal 2, @go[:b]
20
- assert_nil @go.c
21
- assert_nil @go[:c]
22
- end
23
-
24
- def test_generate_json
25
- switch_json_creatable do
26
- assert_equal @go, JSON(JSON(@go), :create_additions => true)
27
- end
28
- end
29
-
30
- def test_parse_json
31
- x = JSON(
32
- '{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }',
33
- :create_additions => true
34
- )
35
- assert_kind_of Hash,
36
- JSON(
37
- '{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }',
38
- :create_additions => true
39
- )
40
- switch_json_creatable do
41
- assert_equal @go, l =
42
- JSON(
43
- '{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }',
44
- :create_additions => true
45
- )
46
- assert_equal 1, l.a
47
- assert_equal @go,
48
- l = JSON('{ "a": 1, "b": 2 }', :object_class => JSON::GenericObject)
49
- assert_equal 1, l.a
50
- assert_equal JSON::GenericObject[:a => JSON::GenericObject[:b => 2]],
51
- l = JSON('{ "a": { "b": 2 } }', :object_class => JSON::GenericObject)
52
- assert_equal 2, l.a.b
53
- end
54
- end
55
-
56
- def test_from_hash
57
- result = JSON::GenericObject.from_hash(
58
- :foo => { :bar => { :baz => true }, :quux => [ { :foobar => true } ] })
59
- assert_kind_of JSON::GenericObject, result.foo
60
- assert_kind_of JSON::GenericObject, result.foo.bar
61
- assert_equal true, result.foo.bar.baz
62
- assert_kind_of JSON::GenericObject, result.foo.quux.first
63
- assert_equal true, result.foo.quux.first.foobar
64
- assert_equal true, JSON::GenericObject.from_hash(true)
65
- end
66
-
67
- def test_json_generic_object_load
68
- empty = JSON::GenericObject.load(nil)
69
- assert_kind_of JSON::GenericObject, empty
70
- simple_json = '{"json_class":"JSON::GenericObject","hello":"world"}'
71
- simple = JSON::GenericObject.load(simple_json)
72
- assert_kind_of JSON::GenericObject, simple
73
- assert_equal "world", simple.hello
74
- converting = JSON::GenericObject.load('{ "hello": "world" }')
75
- assert_kind_of JSON::GenericObject, converting
76
- assert_equal "world", converting.hello
77
-
78
- json = JSON::GenericObject.dump(JSON::GenericObject[:hello => 'world'])
79
- assert_equal JSON(json), JSON('{"json_class":"JSON::GenericObject","hello":"world"}')
80
- end
81
-
82
- private
83
-
84
- def switch_json_creatable
85
- JSON::GenericObject.json_creatable = true
86
- yield
87
- ensure
88
- JSON::GenericObject.json_creatable = false
89
- end
90
- end