scout 5.7.3.pre.2 → 5.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/CHANGELOG.markdown +4 -0
  2. data/lib/scout/version.rb +1 -1
  3. data/vendor/json_pure/.gitignore +12 -0
  4. data/vendor/json_pure/.travis.yml +20 -0
  5. data/vendor/json_pure/CHANGES +282 -0
  6. data/vendor/json_pure/COPYING +58 -0
  7. data/vendor/json_pure/COPYING-json-jruby +57 -0
  8. data/vendor/json_pure/GPL +340 -0
  9. data/vendor/json_pure/Gemfile +11 -0
  10. data/vendor/json_pure/README-json-jruby.markdown +33 -0
  11. data/vendor/json_pure/README.rdoc +358 -0
  12. data/vendor/json_pure/Rakefile +412 -0
  13. data/vendor/json_pure/TODO +1 -0
  14. data/vendor/json_pure/VERSION +1 -0
  15. data/vendor/json_pure/data/example.json +1 -0
  16. data/vendor/json_pure/data/index.html +38 -0
  17. data/vendor/json_pure/data/prototype.js +4184 -0
  18. data/vendor/json_pure/diagrams/.keep +0 -0
  19. data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +181 -0
  20. data/vendor/json_pure/ext/json/ext/generator/depend +1 -0
  21. data/vendor/json_pure/ext/json/ext/generator/extconf.rb +14 -0
  22. data/vendor/json_pure/ext/json/ext/generator/generator.c +1435 -0
  23. data/vendor/json_pure/ext/json/ext/generator/generator.h +148 -0
  24. data/vendor/json_pure/ext/json/ext/parser/depend +1 -0
  25. data/vendor/json_pure/ext/json/ext/parser/extconf.rb +13 -0
  26. data/vendor/json_pure/ext/json/ext/parser/parser.c +2204 -0
  27. data/vendor/json_pure/ext/json/ext/parser/parser.h +77 -0
  28. data/vendor/json_pure/ext/json/ext/parser/parser.rl +927 -0
  29. data/vendor/json_pure/install.rb +23 -0
  30. data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +167 -0
  31. data/vendor/json_pure/java/src/json/ext/Generator.java +444 -0
  32. data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +232 -0
  33. data/vendor/json_pure/java/src/json/ext/GeneratorService.java +43 -0
  34. data/vendor/json_pure/java/src/json/ext/GeneratorState.java +543 -0
  35. data/vendor/json_pure/java/src/json/ext/OptionsReader.java +114 -0
  36. data/vendor/json_pure/java/src/json/ext/Parser.java +2644 -0
  37. data/vendor/json_pure/java/src/json/ext/Parser.rl +968 -0
  38. data/vendor/json_pure/java/src/json/ext/ParserService.java +35 -0
  39. data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +121 -0
  40. data/vendor/json_pure/java/src/json/ext/StringDecoder.java +167 -0
  41. data/vendor/json_pure/java/src/json/ext/StringEncoder.java +106 -0
  42. data/vendor/json_pure/java/src/json/ext/Utils.java +89 -0
  43. data/vendor/json_pure/json-java.gemspec +23 -0
  44. data/vendor/json_pure/json.gemspec +37 -0
  45. data/vendor/json_pure/json_pure.gemspec +39 -0
  46. data/vendor/json_pure/lib/json.rb +62 -0
  47. data/vendor/json_pure/lib/json/add/bigdecimal.rb +28 -0
  48. data/vendor/json_pure/lib/json/add/complex.rb +22 -0
  49. data/vendor/json_pure/lib/json/add/core.rb +11 -0
  50. data/vendor/json_pure/lib/json/add/date.rb +34 -0
  51. data/vendor/json_pure/lib/json/add/date_time.rb +50 -0
  52. data/vendor/json_pure/lib/json/add/exception.rb +31 -0
  53. data/vendor/json_pure/lib/json/add/ostruct.rb +31 -0
  54. data/vendor/json_pure/lib/json/add/range.rb +29 -0
  55. data/vendor/json_pure/lib/json/add/rational.rb +22 -0
  56. data/vendor/json_pure/lib/json/add/regexp.rb +30 -0
  57. data/vendor/json_pure/lib/json/add/struct.rb +30 -0
  58. data/vendor/json_pure/lib/json/add/symbol.rb +25 -0
  59. data/vendor/json_pure/lib/json/add/time.rb +38 -0
  60. data/vendor/json_pure/lib/json/common.rb +487 -0
  61. data/vendor/json_pure/lib/json/ext.rb +21 -0
  62. data/vendor/json_pure/lib/json/ext/.keep +0 -0
  63. data/vendor/json_pure/lib/json/generic_object.rb +70 -0
  64. data/vendor/json_pure/lib/json/pure.rb +21 -0
  65. data/vendor/json_pure/lib/json/pure/generator.rb +522 -0
  66. data/vendor/json_pure/lib/json/pure/parser.rb +359 -0
  67. data/vendor/json_pure/lib/json/version.rb +8 -0
  68. data/vendor/json_pure/tests/fixtures/fail1.json +1 -0
  69. data/vendor/json_pure/tests/fixtures/fail10.json +1 -0
  70. data/vendor/json_pure/tests/fixtures/fail11.json +1 -0
  71. data/vendor/json_pure/tests/fixtures/fail12.json +1 -0
  72. data/vendor/json_pure/tests/fixtures/fail13.json +1 -0
  73. data/vendor/json_pure/tests/fixtures/fail14.json +1 -0
  74. data/vendor/json_pure/tests/fixtures/fail18.json +1 -0
  75. data/vendor/json_pure/tests/fixtures/fail19.json +1 -0
  76. data/vendor/json_pure/tests/fixtures/fail2.json +1 -0
  77. data/vendor/json_pure/tests/fixtures/fail20.json +1 -0
  78. data/vendor/json_pure/tests/fixtures/fail21.json +1 -0
  79. data/vendor/json_pure/tests/fixtures/fail22.json +1 -0
  80. data/vendor/json_pure/tests/fixtures/fail23.json +1 -0
  81. data/vendor/json_pure/tests/fixtures/fail24.json +1 -0
  82. data/vendor/json_pure/tests/fixtures/fail25.json +1 -0
  83. data/vendor/json_pure/tests/fixtures/fail27.json +2 -0
  84. data/vendor/json_pure/tests/fixtures/fail28.json +2 -0
  85. data/vendor/json_pure/tests/fixtures/fail3.json +1 -0
  86. data/vendor/json_pure/tests/fixtures/fail4.json +1 -0
  87. data/vendor/json_pure/tests/fixtures/fail5.json +1 -0
  88. data/vendor/json_pure/tests/fixtures/fail6.json +1 -0
  89. data/vendor/json_pure/tests/fixtures/fail7.json +1 -0
  90. data/vendor/json_pure/tests/fixtures/fail8.json +1 -0
  91. data/vendor/json_pure/tests/fixtures/fail9.json +1 -0
  92. data/vendor/json_pure/tests/fixtures/pass1.json +56 -0
  93. data/vendor/json_pure/tests/fixtures/pass15.json +1 -0
  94. data/vendor/json_pure/tests/fixtures/pass16.json +1 -0
  95. data/vendor/json_pure/tests/fixtures/pass17.json +1 -0
  96. data/vendor/json_pure/tests/fixtures/pass2.json +1 -0
  97. data/vendor/json_pure/tests/fixtures/pass26.json +1 -0
  98. data/vendor/json_pure/tests/fixtures/pass3.json +6 -0
  99. data/vendor/json_pure/tests/setup_variant.rb +11 -0
  100. data/vendor/json_pure/tests/test_json.rb +545 -0
  101. data/vendor/json_pure/tests/test_json_addition.rb +196 -0
  102. data/vendor/json_pure/tests/test_json_encoding.rb +65 -0
  103. data/vendor/json_pure/tests/test_json_fixtures.rb +35 -0
  104. data/vendor/json_pure/tests/test_json_generate.rb +322 -0
  105. data/vendor/json_pure/tests/test_json_generic_object.rb +75 -0
  106. data/vendor/json_pure/tests/test_json_string_matching.rb +39 -0
  107. data/vendor/json_pure/tests/test_json_unicode.rb +72 -0
  108. data/vendor/json_pure/tools/fuzz.rb +139 -0
  109. data/vendor/json_pure/tools/server.rb +62 -0
  110. metadata +111 -4
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \x15"]
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \'"]
@@ -0,0 +1 @@
1
+ ["Illegal backslash escape: \017"]
@@ -0,0 +1 @@
1
+ [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
@@ -0,0 +1 @@
1
+ ["tab\ character\ in\ string\ "]
@@ -0,0 +1,6 @@
1
+ {
2
+ "JSON Test Pattern pass3": {
3
+ "The outermost value": "must be an object or array.",
4
+ "In this test": "It is an object."
5
+ }
6
+ }
@@ -0,0 +1,11 @@
1
+ case ENV['JSON']
2
+ when 'pure'
3
+ $:.unshift 'lib'
4
+ require 'json/pure'
5
+ when 'ext'
6
+ $:.unshift 'ext', 'lib'
7
+ require 'json/ext'
8
+ else
9
+ $:.unshift 'ext', 'lib'
10
+ require 'json'
11
+ end
@@ -0,0 +1,545 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'test/unit'
5
+ require File.join(File.dirname(__FILE__), 'setup_variant')
6
+ require 'stringio'
7
+ require 'tempfile'
8
+ require 'ostruct'
9
+
10
+ unless Array.method_defined?(:permutation)
11
+ begin
12
+ require 'enumerator'
13
+ require 'permutation'
14
+ class Array
15
+ def permutation
16
+ Permutation.for(self).to_enum.map { |x| x.project }
17
+ end
18
+ end
19
+ rescue LoadError
20
+ warn "Skipping permutation tests."
21
+ end
22
+ end
23
+
24
+ class TestJSON < Test::Unit::TestCase
25
+ include JSON
26
+
27
+ def setup
28
+ @ary = [1, "foo", 3.14, 4711.0, 2.718, nil, [1,-2,3], false, true].map do
29
+ |x| [x]
30
+ end
31
+ @ary_to_parse = ["1", '"foo"', "3.14", "4711.0", "2.718", "null",
32
+ "[1,-2,3]", "false", "true"].map do
33
+ |x| "[#{x}]"
34
+ end
35
+ @hash = {
36
+ 'a' => 2,
37
+ 'b' => 3.141,
38
+ 'c' => 'c',
39
+ 'd' => [ 1, "b", 3.14 ],
40
+ 'e' => { 'foo' => 'bar' },
41
+ 'g' => "\"\0\037",
42
+ 'h' => 1000.0,
43
+ 'i' => 0.001
44
+ }
45
+ @json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
46
+ '"g":"\\"\\u0000\\u001f","h":1.0E3,"i":1.0E-3}'
47
+ end
48
+
49
+ def test_construction
50
+ parser = JSON::Parser.new('test')
51
+ assert_equal 'test', parser.source
52
+ end
53
+
54
+ def assert_equal_float(expected, is)
55
+ assert_in_delta(expected.first, is.first, 1e-2)
56
+ end
57
+
58
+ def test_parse_simple_arrays
59
+ assert_equal([], parse('[]'))
60
+ assert_equal([], parse(' [ ] '))
61
+ assert_equal([nil], parse('[null]'))
62
+ assert_equal([false], parse('[false]'))
63
+ assert_equal([true], parse('[true]'))
64
+ assert_equal([-23], parse('[-23]'))
65
+ assert_equal([23], parse('[23]'))
66
+ assert_equal([0.23], parse('[0.23]'))
67
+ assert_equal([0.0], parse('[0e0]'))
68
+ assert_raises(JSON::ParserError) { parse('[+23.2]') }
69
+ assert_raises(JSON::ParserError) { parse('[+23]') }
70
+ assert_raises(JSON::ParserError) { parse('[.23]') }
71
+ assert_raises(JSON::ParserError) { parse('[023]') }
72
+ assert_equal_float [3.141], parse('[3.141]')
73
+ assert_equal_float [-3.141], parse('[-3.141]')
74
+ assert_equal_float [3.141], parse('[3141e-3]')
75
+ assert_equal_float [3.141], parse('[3141.1e-3]')
76
+ assert_equal_float [3.141], parse('[3141E-3]')
77
+ assert_equal_float [3.141], parse('[3141.0E-3]')
78
+ assert_equal_float [-3.141], parse('[-3141.0e-3]')
79
+ assert_equal_float [-3.141], parse('[-3141e-3]')
80
+ assert_raises(ParserError) { parse('[NaN]') }
81
+ assert parse('[NaN]', :allow_nan => true).first.nan?
82
+ assert_raises(ParserError) { parse('[Infinity]') }
83
+ assert_equal [1.0/0], parse('[Infinity]', :allow_nan => true)
84
+ assert_raises(ParserError) { parse('[-Infinity]') }
85
+ assert_equal [-1.0/0], parse('[-Infinity]', :allow_nan => true)
86
+ assert_equal([""], parse('[""]'))
87
+ assert_equal(["foobar"], parse('["foobar"]'))
88
+ assert_equal([{}], parse('[{}]'))
89
+ end
90
+
91
+ def test_parse_simple_objects
92
+ assert_equal({}, parse('{}'))
93
+ assert_equal({}, parse(' { } '))
94
+ assert_equal({ "a" => nil }, parse('{ "a" : null}'))
95
+ assert_equal({ "a" => nil }, parse('{"a":null}'))
96
+ assert_equal({ "a" => false }, parse('{ "a" : false } '))
97
+ assert_equal({ "a" => false }, parse('{"a":false}'))
98
+ assert_raises(JSON::ParserError) { parse('{false}') }
99
+ assert_equal({ "a" => true }, parse('{"a":true}'))
100
+ assert_equal({ "a" => true }, parse(' { "a" : true } '))
101
+ assert_equal({ "a" => -23 }, parse(' { "a" : -23 } '))
102
+ assert_equal({ "a" => -23 }, parse(' { "a" : -23 } '))
103
+ assert_equal({ "a" => 23 }, parse('{"a":23 } '))
104
+ assert_equal({ "a" => 23 }, parse(' { "a" : 23 } '))
105
+ assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
106
+ assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
107
+ end
108
+
109
+ def test_parse_json_primitive_values
110
+ assert_raise(JSON::ParserError) { JSON.parse('') }
111
+ assert_raise(JSON::ParserError) { JSON.parse('', :quirks_mode => true) }
112
+ assert_raise(TypeError) { JSON::Parser.new(nil).parse }
113
+ assert_raise(TypeError) { JSON::Parser.new(nil, :quirks_mode => true).parse }
114
+ assert_raise(TypeError) { JSON.parse(nil) }
115
+ assert_raise(TypeError) { JSON.parse(nil, :quirks_mode => true) }
116
+ assert_raise(JSON::ParserError) { JSON.parse(' /* foo */ ') }
117
+ assert_raise(JSON::ParserError) { JSON.parse(' /* foo */ ', :quirks_mode => true) }
118
+ parser = JSON::Parser.new('null')
119
+ assert_equal false, parser.quirks_mode?
120
+ assert_raise(JSON::ParserError) { parser.parse }
121
+ assert_raise(JSON::ParserError) { JSON.parse('null') }
122
+ assert_equal nil, JSON.parse('null', :quirks_mode => true)
123
+ parser = JSON::Parser.new('null', :quirks_mode => true)
124
+ assert_equal true, parser.quirks_mode?
125
+ assert_equal nil, parser.parse
126
+ assert_raise(JSON::ParserError) { JSON.parse('false') }
127
+ assert_equal false, JSON.parse('false', :quirks_mode => true)
128
+ assert_raise(JSON::ParserError) { JSON.parse('true') }
129
+ assert_equal true, JSON.parse('true', :quirks_mode => true)
130
+ assert_raise(JSON::ParserError) { JSON.parse('23') }
131
+ assert_equal 23, JSON.parse('23', :quirks_mode => true)
132
+ assert_raise(JSON::ParserError) { JSON.parse('1') }
133
+ assert_equal 1, JSON.parse('1', :quirks_mode => true)
134
+ assert_raise(JSON::ParserError) { JSON.parse('3.141') }
135
+ assert_in_delta 3.141, JSON.parse('3.141', :quirks_mode => true), 1E-3
136
+ assert_raise(JSON::ParserError) { JSON.parse('18446744073709551616') }
137
+ assert_equal 2 ** 64, JSON.parse('18446744073709551616', :quirks_mode => true)
138
+ assert_raise(JSON::ParserError) { JSON.parse('"foo"') }
139
+ assert_equal 'foo', JSON.parse('"foo"', :quirks_mode => true)
140
+ assert_raise(JSON::ParserError) { JSON.parse('NaN', :allow_nan => true) }
141
+ assert JSON.parse('NaN', :quirks_mode => true, :allow_nan => true).nan?
142
+ assert_raise(JSON::ParserError) { JSON.parse('Infinity', :allow_nan => true) }
143
+ assert JSON.parse('Infinity', :quirks_mode => true, :allow_nan => true).infinite?
144
+ assert_raise(JSON::ParserError) { JSON.parse('-Infinity', :allow_nan => true) }
145
+ assert JSON.parse('-Infinity', :quirks_mode => true, :allow_nan => true).infinite?
146
+ assert_raise(JSON::ParserError) { JSON.parse('[ 1, ]', :quirks_mode => true) }
147
+ end
148
+
149
+ if Array.method_defined?(:permutation)
150
+ def test_parse_more_complex_arrays
151
+ a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
152
+ a.permutation.each do |perm|
153
+ json = pretty_generate(perm)
154
+ assert_equal perm, parse(json)
155
+ end
156
+ end
157
+
158
+ def test_parse_complex_objects
159
+ a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
160
+ a.permutation.each do |perm|
161
+ s = "a"
162
+ orig_obj = perm.inject({}) { |h, x| h[s.dup] = x; s = s.succ; h }
163
+ json = pretty_generate(orig_obj)
164
+ assert_equal orig_obj, parse(json)
165
+ end
166
+ end
167
+ end
168
+
169
+ def test_parse_arrays
170
+ assert_equal([1,2,3], parse('[1,2,3]'))
171
+ assert_equal([1.2,2,3], parse('[1.2,2,3]'))
172
+ assert_equal([[],[[],[]]], parse('[[],[[],[]]]'))
173
+ end
174
+
175
+ def test_parse_values
176
+ assert_equal([""], parse('[""]'))
177
+ assert_equal(["\\"], parse('["\\\\"]'))
178
+ assert_equal(['"'], parse('["\""]'))
179
+ assert_equal(['\\"\\'], parse('["\\\\\\"\\\\"]'))
180
+ assert_equal(["\"\b\n\r\t\0\037"],
181
+ parse('["\"\b\n\r\t\u0000\u001f"]'))
182
+ for i in 0 ... @ary.size
183
+ assert_equal(@ary[i], parse(@ary_to_parse[i]))
184
+ end
185
+ end
186
+
187
+ def test_parse_array
188
+ assert_equal([], parse('[]'))
189
+ assert_equal([], parse(' [ ] '))
190
+ assert_equal([1], parse('[1]'))
191
+ assert_equal([1], parse(' [ 1 ] '))
192
+ assert_equal(@ary,
193
+ parse('[[1],["foo"],[3.14],[47.11e+2],[2718.0E-3],[null],[[1,-2,3]]'\
194
+ ',[false],[true]]'))
195
+ assert_equal(@ary, parse(%Q{ [ [1] , ["foo"] , [3.14] \t , [47.11e+2]\s
196
+ , [2718.0E-3 ],\r[ null] , [[1, -2, 3 ]], [false ],[ true]\n ] }))
197
+ end
198
+
199
+ class SubArray < Array
200
+ def <<(v)
201
+ @shifted = true
202
+ super
203
+ end
204
+
205
+ def shifted?
206
+ @shifted
207
+ end
208
+ end
209
+
210
+ class SubArray2 < Array
211
+ def to_json(*a)
212
+ {
213
+ JSON.create_id => self.class.name,
214
+ 'ary' => to_a,
215
+ }.to_json(*a)
216
+ end
217
+
218
+ def self.json_create(o)
219
+ o.delete JSON.create_id
220
+ o['ary']
221
+ end
222
+ end
223
+
224
+ class SubArrayWrapper
225
+ def initialize
226
+ @data = []
227
+ end
228
+
229
+ attr_reader :data
230
+
231
+ def [](index)
232
+ @data[index]
233
+ end
234
+
235
+ def <<(value)
236
+ @data << value
237
+ @shifted = true
238
+ end
239
+
240
+ def shifted?
241
+ @shifted
242
+ end
243
+ end
244
+
245
+ def test_parse_array_custom_array_derived_class
246
+ res = parse('[1,2]', :array_class => SubArray)
247
+ assert_equal([1,2], res)
248
+ assert_equal(SubArray, res.class)
249
+ assert res.shifted?
250
+ end
251
+
252
+ def test_parse_array_custom_non_array_derived_class
253
+ res = parse('[1,2]', :array_class => SubArrayWrapper)
254
+ assert_equal([1,2], res.data)
255
+ assert_equal(SubArrayWrapper, res.class)
256
+ assert res.shifted?
257
+ end
258
+
259
+ def test_parse_object
260
+ assert_equal({}, parse('{}'))
261
+ assert_equal({}, parse(' { } '))
262
+ assert_equal({'foo'=>'bar'}, parse('{"foo":"bar"}'))
263
+ assert_equal({'foo'=>'bar'}, parse(' { "foo" : "bar" } '))
264
+ end
265
+
266
+ class SubHash < Hash
267
+ def []=(k, v)
268
+ @item_set = true
269
+ super
270
+ end
271
+
272
+ def item_set?
273
+ @item_set
274
+ end
275
+ end
276
+
277
+ class SubHash2 < Hash
278
+ def to_json(*a)
279
+ {
280
+ JSON.create_id => self.class.name,
281
+ }.merge(self).to_json(*a)
282
+ end
283
+
284
+ def self.json_create(o)
285
+ o.delete JSON.create_id
286
+ self[o]
287
+ end
288
+ end
289
+
290
+ class SubOpenStruct < OpenStruct
291
+ def [](k)
292
+ __send__(k)
293
+ end
294
+
295
+ def []=(k, v)
296
+ @item_set = true
297
+ __send__("#{k}=", v)
298
+ end
299
+
300
+ def item_set?
301
+ @item_set
302
+ end
303
+ end
304
+
305
+ def test_parse_object_custom_hash_derived_class
306
+ res = parse('{"foo":"bar"}', :object_class => SubHash)
307
+ assert_equal({"foo" => "bar"}, res)
308
+ assert_equal(SubHash, res.class)
309
+ assert res.item_set?
310
+ end
311
+
312
+ def test_parse_object_custom_non_hash_derived_class
313
+ res = parse('{"foo":"bar"}', :object_class => SubOpenStruct)
314
+ assert_equal "bar", res.foo
315
+ assert_equal(SubOpenStruct, res.class)
316
+ assert res.item_set?
317
+ end
318
+
319
+ def test_parse_generic_object
320
+ res = parse('{"foo":"bar", "baz":{}}', :object_class => JSON::GenericObject)
321
+ assert_equal(JSON::GenericObject, res.class)
322
+ assert_equal "bar", res.foo
323
+ assert_equal "bar", res["foo"]
324
+ assert_equal "bar", res[:foo]
325
+ assert_equal "bar", res.to_hash[:foo]
326
+ assert_equal(JSON::GenericObject, res.baz.class)
327
+ end
328
+
329
+ def test_generate_core_subclasses_with_new_to_json
330
+ obj = SubHash2["foo" => SubHash2["bar" => true]]
331
+ obj_json = JSON(obj)
332
+ obj_again = JSON.parse(obj_json, :create_additions => true)
333
+ assert_kind_of SubHash2, obj_again
334
+ assert_kind_of SubHash2, obj_again['foo']
335
+ assert obj_again['foo']['bar']
336
+ assert_equal obj, obj_again
337
+ assert_equal ["foo"], JSON(JSON(SubArray2["foo"]), :create_additions => true)
338
+ end
339
+
340
+ def test_generate_core_subclasses_with_default_to_json
341
+ assert_equal '{"foo":"bar"}', JSON(SubHash["foo" => "bar"])
342
+ assert_equal '["foo"]', JSON(SubArray["foo"])
343
+ end
344
+
345
+ def test_generate_of_core_subclasses
346
+ obj = SubHash["foo" => SubHash["bar" => true]]
347
+ obj_json = JSON(obj)
348
+ obj_again = JSON(obj_json)
349
+ assert_kind_of Hash, obj_again
350
+ assert_kind_of Hash, obj_again['foo']
351
+ assert obj_again['foo']['bar']
352
+ assert_equal obj, obj_again
353
+ end
354
+
355
+ def test_parser_reset
356
+ parser = Parser.new(@json)
357
+ assert_equal(@hash, parser.parse)
358
+ assert_equal(@hash, parser.parse)
359
+ end
360
+
361
+ def test_comments
362
+ json = <<EOT
363
+ {
364
+ "key1":"value1", // eol comment
365
+ "key2":"value2" /* multi line
366
+ * comment */,
367
+ "key3":"value3" /* multi line
368
+ // nested eol comment
369
+ * comment */
370
+ }
371
+ EOT
372
+ assert_equal(
373
+ { "key1" => "value1", "key2" => "value2", "key3" => "value3" },
374
+ parse(json))
375
+ json = <<EOT
376
+ {
377
+ "key1":"value1" /* multi line
378
+ // nested eol comment
379
+ /* illegal nested multi line comment */
380
+ * comment */
381
+ }
382
+ EOT
383
+ assert_raises(ParserError) { parse(json) }
384
+ json = <<EOT
385
+ {
386
+ "key1":"value1" /* multi line
387
+ // nested eol comment
388
+ closed multi comment */
389
+ and again, throw an Error */
390
+ }
391
+ EOT
392
+ assert_raises(ParserError) { parse(json) }
393
+ json = <<EOT
394
+ {
395
+ "key1":"value1" /*/*/
396
+ }
397
+ EOT
398
+ assert_equal({ "key1" => "value1" }, parse(json))
399
+ end
400
+
401
+ def test_backslash
402
+ data = [ '\\.(?i:gif|jpe?g|png)$' ]
403
+ json = '["\\\\.(?i:gif|jpe?g|png)$"]'
404
+ assert_equal json, JSON.generate(data)
405
+ assert_equal data, JSON.parse(json)
406
+ #
407
+ data = [ '\\"' ]
408
+ json = '["\\\\\""]'
409
+ assert_equal json, JSON.generate(data)
410
+ assert_equal data, JSON.parse(json)
411
+ #
412
+ json = '["/"]'
413
+ data = JSON.parse(json)
414
+ assert_equal ['/'], data
415
+ assert_equal json, JSON.generate(data)
416
+ #
417
+ json = '["\""]'
418
+ data = JSON.parse(json)
419
+ assert_equal ['"'], data
420
+ assert_equal json, JSON.generate(data)
421
+ json = '["\\\'"]'
422
+ data = JSON.parse(json)
423
+ assert_equal ["'"], data
424
+ assert_equal '["\'"]', JSON.generate(data)
425
+ end
426
+
427
+ def test_wrong_inputs
428
+ assert_raises(ParserError) { JSON.parse('"foo"') }
429
+ assert_raises(ParserError) { JSON.parse('123') }
430
+ assert_raises(ParserError) { JSON.parse('[] bla') }
431
+ assert_raises(ParserError) { JSON.parse('[] 1') }
432
+ assert_raises(ParserError) { JSON.parse('[] []') }
433
+ assert_raises(ParserError) { JSON.parse('[] {}') }
434
+ assert_raises(ParserError) { JSON.parse('{} []') }
435
+ assert_raises(ParserError) { JSON.parse('{} {}') }
436
+ assert_raises(ParserError) { JSON.parse('[NULL]') }
437
+ assert_raises(ParserError) { JSON.parse('[FALSE]') }
438
+ assert_raises(ParserError) { JSON.parse('[TRUE]') }
439
+ assert_raises(ParserError) { JSON.parse('[07] ') }
440
+ assert_raises(ParserError) { JSON.parse('[0a]') }
441
+ assert_raises(ParserError) { JSON.parse('[1.]') }
442
+ assert_raises(ParserError) { JSON.parse(' ') }
443
+ end
444
+
445
+ def test_nesting
446
+ assert_raises(JSON::NestingError) { JSON.parse '[[]]', :max_nesting => 1 }
447
+ assert_raises(JSON::NestingError) { JSON.parser.new('[[]]', :max_nesting => 1).parse }
448
+ assert_equal [[]], JSON.parse('[[]]', :max_nesting => 2)
449
+ too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
450
+ too_deep_ary = eval too_deep
451
+ assert_raises(JSON::NestingError) { JSON.parse too_deep }
452
+ assert_raises(JSON::NestingError) { JSON.parser.new(too_deep).parse }
453
+ assert_raises(JSON::NestingError) { JSON.parse too_deep, :max_nesting => 100 }
454
+ ok = JSON.parse too_deep, :max_nesting => 101
455
+ assert_equal too_deep_ary, ok
456
+ ok = JSON.parse too_deep, :max_nesting => nil
457
+ assert_equal too_deep_ary, ok
458
+ ok = JSON.parse too_deep, :max_nesting => false
459
+ assert_equal too_deep_ary, ok
460
+ ok = JSON.parse too_deep, :max_nesting => 0
461
+ assert_equal too_deep_ary, ok
462
+ assert_raises(JSON::NestingError) { JSON.generate [[]], :max_nesting => 1 }
463
+ assert_equal '[[]]', JSON.generate([[]], :max_nesting => 2)
464
+ assert_raises(JSON::NestingError) { JSON.generate too_deep_ary }
465
+ assert_raises(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 100 }
466
+ ok = JSON.generate too_deep_ary, :max_nesting => 101
467
+ assert_equal too_deep, ok
468
+ ok = JSON.generate too_deep_ary, :max_nesting => nil
469
+ assert_equal too_deep, ok
470
+ ok = JSON.generate too_deep_ary, :max_nesting => false
471
+ assert_equal too_deep, ok
472
+ ok = JSON.generate too_deep_ary, :max_nesting => 0
473
+ assert_equal too_deep, ok
474
+ end
475
+
476
+ def test_symbolize_names
477
+ assert_equal({ "foo" => "bar", "baz" => "quux" },
478
+ JSON.parse('{"foo":"bar", "baz":"quux"}'))
479
+ assert_equal({ :foo => "bar", :baz => "quux" },
480
+ JSON.parse('{"foo":"bar", "baz":"quux"}', :symbolize_names => true))
481
+ end
482
+
483
+ def test_load
484
+ assert_equal @hash, JSON.load(@json)
485
+ tempfile = Tempfile.open('json')
486
+ tempfile.write @json
487
+ tempfile.rewind
488
+ assert_equal @hash, JSON.load(tempfile)
489
+ stringio = StringIO.new(@json)
490
+ stringio.rewind
491
+ assert_equal @hash, JSON.load(stringio)
492
+ assert_equal nil, JSON.load(nil)
493
+ assert_equal nil, JSON.load('')
494
+ end
495
+
496
+ def test_load_with_options
497
+ small_hash = JSON("foo" => 'bar')
498
+ symbol_hash = { :foo => 'bar' }
499
+ assert_equal symbol_hash, JSON.load(small_hash, nil, :symbolize_names => true)
500
+ end
501
+
502
+ def test_dump
503
+ too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
504
+ assert_equal too_deep, JSON.dump(eval(too_deep))
505
+ assert_kind_of String, Marshal.dump(eval(too_deep))
506
+ assert_raises(ArgumentError) { JSON.dump(eval(too_deep), 100) }
507
+ assert_raises(ArgumentError) { Marshal.dump(eval(too_deep), 100) }
508
+ assert_equal too_deep, JSON.dump(eval(too_deep), 101)
509
+ assert_kind_of String, Marshal.dump(eval(too_deep), 101)
510
+ output = StringIO.new
511
+ JSON.dump(eval(too_deep), output)
512
+ assert_equal too_deep, output.string
513
+ output = StringIO.new
514
+ JSON.dump(eval(too_deep), output, 101)
515
+ assert_equal too_deep, output.string
516
+ end
517
+
518
+ def test_big_integers
519
+ json1 = JSON([orig = (1 << 31) - 1])
520
+ assert_equal orig, JSON[json1][0]
521
+ json2 = JSON([orig = 1 << 31])
522
+ assert_equal orig, JSON[json2][0]
523
+ json3 = JSON([orig = (1 << 62) - 1])
524
+ assert_equal orig, JSON[json3][0]
525
+ json4 = JSON([orig = 1 << 62])
526
+ assert_equal orig, JSON[json4][0]
527
+ json5 = JSON([orig = 1 << 64])
528
+ assert_equal orig, JSON[json5][0]
529
+ end
530
+
531
+ if defined?(JSON::Ext::Parser)
532
+ def test_allocate
533
+ parser = JSON::Ext::Parser.new("{}")
534
+ assert_raise(TypeError, '[ruby-core:35079]') {parser.__send__(:initialize, "{}")}
535
+ parser = JSON::Ext::Parser.allocate
536
+ assert_raise(TypeError, '[ruby-core:35079]') {parser.source}
537
+ end
538
+ end
539
+
540
+ def test_argument_encoding
541
+ source = "{}".force_encoding("ascii-8bit")
542
+ JSON::Parser.new(source)
543
+ assert_equal Encoding::ASCII_8BIT, source.encoding
544
+ end if defined?(Encoding::ASCII_8BIT)
545
+ end