scout 5.1.2 → 5.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/scout.rb +1 -1
- data/lib/scout/server.rb +4 -1
- data/vendor/json_pure/CHANGES +43 -0
- data/vendor/json_pure/{RUBY → COPYING} +1 -1
- data/vendor/json_pure/GPL +7 -7
- data/vendor/json_pure/README +319 -39
- data/vendor/json_pure/Rakefile +69 -47
- data/vendor/json_pure/VERSION +1 -1
- data/vendor/json_pure/benchmarks/generator2_benchmark.rb +222 -0
- data/vendor/json_pure/benchmarks/generator_benchmark.rb +64 -5
- data/vendor/json_pure/benchmarks/ohai.json +1216 -0
- data/vendor/json_pure/benchmarks/ohai.ruby +1 -0
- data/vendor/json_pure/benchmarks/parser2_benchmark.rb +251 -0
- data/vendor/json_pure/benchmarks/parser_benchmark.rb +67 -5
- data/vendor/json_pure/ext/json/ext/generator/extconf.rb +9 -4
- data/vendor/json_pure/ext/json/ext/generator/generator.c +831 -409
- data/vendor/json_pure/ext/json/ext/generator/generator.h +170 -0
- data/vendor/json_pure/ext/json/ext/parser/extconf.rb +8 -4
- data/vendor/json_pure/ext/json/ext/parser/parser.c +292 -186
- data/vendor/json_pure/ext/json/ext/parser/parser.h +71 -0
- data/vendor/json_pure/ext/json/ext/parser/parser.rl +218 -112
- data/vendor/json_pure/lib/json/add/core.rb +20 -7
- data/vendor/json_pure/lib/json/add/rails.rb +2 -2
- data/vendor/json_pure/lib/json/common.rb +85 -42
- data/vendor/json_pure/lib/json/pure.rb +3 -3
- data/vendor/json_pure/lib/json/pure/generator.rb +112 -90
- data/vendor/json_pure/lib/json/pure/parser.rb +42 -4
- data/vendor/json_pure/lib/json/version.rb +1 -1
- data/vendor/json_pure/tests/test_json.rb +46 -18
- data/vendor/json_pure/tests/test_json_addition.rb +4 -6
- data/vendor/json_pure/tests/test_json_encoding.rb +68 -0
- data/vendor/json_pure/tests/test_json_generate.rb +30 -14
- data/vendor/json_pure/tests/test_json_rails.rb +5 -7
- data/vendor/json_pure/tests/test_json_unicode.rb +20 -6
- metadata +26 -15
- data/vendor/json_pure/doc-templates/main.txt +0 -283
- data/vendor/json_pure/ext/json/ext/generator/unicode.c +0 -182
- data/vendor/json_pure/ext/json/ext/generator/unicode.h +0 -53
- data/vendor/json_pure/ext/json/ext/parser/unicode.c +0 -154
- data/vendor/json_pure/ext/json/ext/parser/unicode.h +0 -58
@@ -60,13 +60,50 @@ module JSON
|
|
60
60
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
61
61
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
62
62
|
# to false.
|
63
|
+
# * *symbolize_names*: If set to true, returns symbols for the names
|
64
|
+
# (keys) in a JSON object. Otherwise strings are returned, which is also
|
65
|
+
# the default.
|
63
66
|
# * *create_additions*: If set to false, the Parser doesn't create
|
64
67
|
# additions even if a matchin class and create_id was found. This option
|
65
68
|
# defaults to true.
|
66
69
|
# * *object_class*: Defaults to Hash
|
67
70
|
# * *array_class*: Defaults to Array
|
68
71
|
def initialize(source, opts = {})
|
69
|
-
|
72
|
+
if defined?(::Encoding)
|
73
|
+
if source.encoding == Encoding::ASCII_8BIT
|
74
|
+
b = source[0, 4].bytes.to_a
|
75
|
+
source = case
|
76
|
+
when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
|
77
|
+
source.dup.force_encoding(Encoding::UTF_32BE).encode!(Encoding::UTF_8)
|
78
|
+
when b.size >= 4 && b[0] == 0 && b[2] == 0
|
79
|
+
source.dup.force_encoding(Encoding::UTF_16BE).encode!(Encoding::UTF_8)
|
80
|
+
when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
|
81
|
+
source.dup.force_encoding(Encoding::UTF_32LE).encode!(Encoding::UTF_8)
|
82
|
+
when b.size >= 4 && b[1] == 0 && b[3] == 0
|
83
|
+
source.dup.force_encoding(Encoding::UTF_16LE).encode!(Encoding::UTF_8)
|
84
|
+
else
|
85
|
+
source.dup
|
86
|
+
end
|
87
|
+
else
|
88
|
+
source = source.encode(Encoding::UTF_8)
|
89
|
+
end
|
90
|
+
source.force_encoding(Encoding::ASCII_8BIT)
|
91
|
+
else
|
92
|
+
b = source
|
93
|
+
source = case
|
94
|
+
when b.size >= 4 && b[0] == 0 && b[1] == 0 && b[2] == 0
|
95
|
+
JSON.iconv('utf-8', 'utf-32be', b)
|
96
|
+
when b.size >= 4 && b[0] == 0 && b[2] == 0
|
97
|
+
JSON.iconv('utf-8', 'utf-16be', b)
|
98
|
+
when b.size >= 4 && b[1] == 0 && b[2] == 0 && b[3] == 0
|
99
|
+
JSON.iconv('utf-8', 'utf-32le', b)
|
100
|
+
when b.size >= 4 && b[1] == 0 && b[3] == 0
|
101
|
+
JSON.iconv('utf-8', 'utf-16le', b)
|
102
|
+
else
|
103
|
+
b
|
104
|
+
end
|
105
|
+
end
|
106
|
+
super source
|
70
107
|
if !opts.key?(:max_nesting) # defaults to 19
|
71
108
|
@max_nesting = 19
|
72
109
|
elsif opts[:max_nesting]
|
@@ -75,6 +112,7 @@ module JSON
|
|
75
112
|
@max_nesting = 0
|
76
113
|
end
|
77
114
|
@allow_nan = !!opts[:allow_nan]
|
115
|
+
@symbolize_names = !!opts[:symbolize_names]
|
78
116
|
ca = true
|
79
117
|
ca = opts[:create_additions] if opts.key?(:create_additions)
|
80
118
|
@create_id = ca ? JSON.create_id : nil
|
@@ -188,7 +226,7 @@ module JSON
|
|
188
226
|
end
|
189
227
|
|
190
228
|
def parse_array
|
191
|
-
raise NestingError, "nesting of #@current_nesting is
|
229
|
+
raise NestingError, "nesting of #@current_nesting is too deep" if
|
192
230
|
@max_nesting.nonzero? && @current_nesting > @max_nesting
|
193
231
|
result = @array_class.new
|
194
232
|
delim = false
|
@@ -220,7 +258,7 @@ module JSON
|
|
220
258
|
end
|
221
259
|
|
222
260
|
def parse_object
|
223
|
-
raise NestingError, "nesting of #@current_nesting is
|
261
|
+
raise NestingError, "nesting of #@current_nesting is too deep" if
|
224
262
|
@max_nesting.nonzero? && @current_nesting > @max_nesting
|
225
263
|
result = @object_class.new
|
226
264
|
delim = false
|
@@ -233,7 +271,7 @@ module JSON
|
|
233
271
|
end
|
234
272
|
skip(IGNORE)
|
235
273
|
unless (value = parse_value).equal? UNPARSED
|
236
|
-
result[string] = value
|
274
|
+
result[@symbolize_names ? string.to_sym : string] = value
|
237
275
|
delim = false
|
238
276
|
skip(IGNORE)
|
239
277
|
if scan(COLLECTION_DELIMITER)
|
@@ -9,6 +9,20 @@ else require 'json'
|
|
9
9
|
end
|
10
10
|
require 'stringio'
|
11
11
|
|
12
|
+
unless Array.method_defined?(:permutation)
|
13
|
+
begin
|
14
|
+
require 'enumerator'
|
15
|
+
require 'permutation'
|
16
|
+
class Array
|
17
|
+
def permutation
|
18
|
+
Permutation.for(self).to_enum.map { |x| x.project }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
rescue LoadError
|
22
|
+
warn "Skipping permutation tests."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
12
26
|
class TC_JSON < Test::Unit::TestCase
|
13
27
|
include JSON
|
14
28
|
|
@@ -94,30 +108,24 @@ class TC_JSON < Test::Unit::TestCase
|
|
94
108
|
assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
|
95
109
|
end
|
96
110
|
|
97
|
-
|
98
|
-
require 'permutation'
|
111
|
+
if Array.method_defined?(:permutation)
|
99
112
|
def test_parse_more_complex_arrays
|
100
113
|
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
json = pretty_generate(orig_ary)
|
105
|
-
assert_equal orig_ary, parse(json)
|
114
|
+
a.permutation.each do |perm|
|
115
|
+
json = pretty_generate(perm)
|
116
|
+
assert_equal perm, parse(json)
|
106
117
|
end
|
107
118
|
end
|
108
119
|
|
109
120
|
def test_parse_complex_objects
|
110
121
|
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
|
111
|
-
|
112
|
-
perms.each do |perm|
|
122
|
+
a.permutation.each do |perm|
|
113
123
|
s = "a"
|
114
|
-
orig_obj = perm.
|
124
|
+
orig_obj = perm.inject({}) { |h, x| h[s.dup] = x; s = s.succ; h }
|
115
125
|
json = pretty_generate(orig_obj)
|
116
126
|
assert_equal orig_obj, parse(json)
|
117
127
|
end
|
118
128
|
end
|
119
|
-
rescue LoadError
|
120
|
-
warn "Skipping permutation tests."
|
121
129
|
end
|
122
130
|
|
123
131
|
def test_parse_arrays
|
@@ -222,27 +230,27 @@ EOT
|
|
222
230
|
def test_backslash
|
223
231
|
data = [ '\\.(?i:gif|jpe?g|png)$' ]
|
224
232
|
json = '["\\\\.(?i:gif|jpe?g|png)$"]'
|
225
|
-
assert_equal json, JSON.
|
233
|
+
assert_equal json, JSON.generate(data)
|
226
234
|
assert_equal data, JSON.parse(json)
|
227
235
|
#
|
228
236
|
data = [ '\\"' ]
|
229
237
|
json = '["\\\\\""]'
|
230
|
-
assert_equal json, JSON.
|
238
|
+
assert_equal json, JSON.generate(data)
|
231
239
|
assert_equal data, JSON.parse(json)
|
232
240
|
#
|
233
|
-
json = '["
|
241
|
+
json = '["/"]'
|
234
242
|
data = JSON.parse(json)
|
235
243
|
assert_equal ['/'], data
|
236
|
-
assert_equal json, JSON.
|
244
|
+
assert_equal json, JSON.generate(data)
|
237
245
|
#
|
238
246
|
json = '["\""]'
|
239
247
|
data = JSON.parse(json)
|
240
248
|
assert_equal ['"'], data
|
241
|
-
assert_equal json, JSON.
|
249
|
+
assert_equal json, JSON.generate(data)
|
242
250
|
json = '["\\\'"]'
|
243
251
|
data = JSON.parse(json)
|
244
252
|
assert_equal ["'"], data
|
245
|
-
assert_equal '["\'"]', JSON.
|
253
|
+
assert_equal '["\'"]', JSON.generate(data)
|
246
254
|
end
|
247
255
|
|
248
256
|
def test_wrong_inputs
|
@@ -294,6 +302,13 @@ EOT
|
|
294
302
|
assert_equal too_deep, ok
|
295
303
|
end
|
296
304
|
|
305
|
+
def test_symbolize_names
|
306
|
+
assert_equal({ "foo" => "bar", "baz" => "quux" },
|
307
|
+
JSON.parse('{"foo":"bar", "baz":"quux"}'))
|
308
|
+
assert_equal({ :foo => "bar", :baz => "quux" },
|
309
|
+
JSON.parse('{"foo":"bar", "baz":"quux"}', :symbolize_names => true))
|
310
|
+
end
|
311
|
+
|
297
312
|
def test_load_dump
|
298
313
|
too_deep = '[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]'
|
299
314
|
assert_equal too_deep, JSON.dump(eval(too_deep))
|
@@ -309,4 +324,17 @@ EOT
|
|
309
324
|
JSON.dump(eval(too_deep), output, 20)
|
310
325
|
assert_equal too_deep, output.string
|
311
326
|
end
|
327
|
+
|
328
|
+
def test_big_integers
|
329
|
+
json1 = JSON([orig = (1 << 31) - 1])
|
330
|
+
assert_equal orig, JSON[json1][0]
|
331
|
+
json2 = JSON([orig = 1 << 31])
|
332
|
+
assert_equal orig, JSON[json2][0]
|
333
|
+
json3 = JSON([orig = (1 << 62) - 1])
|
334
|
+
assert_equal orig, JSON[json3][0]
|
335
|
+
json4 = JSON([orig = 1 << 62])
|
336
|
+
assert_equal orig, JSON[json4][0]
|
337
|
+
json5 = JSON([orig = 1 << 64])
|
338
|
+
assert_equal orig, JSON[json5][0]
|
339
|
+
end
|
312
340
|
end
|
@@ -95,7 +95,7 @@ class TC_JSONAddition < Test::Unit::TestCase
|
|
95
95
|
c = C.new
|
96
96
|
assert !C.json_creatable?
|
97
97
|
json = generate(c)
|
98
|
-
assert_raises(ArgumentError) { JSON.parse(json) }
|
98
|
+
assert_raises(ArgumentError, NameError) { JSON.parse(json) }
|
99
99
|
end
|
100
100
|
|
101
101
|
def test_raw_strings
|
@@ -110,11 +110,9 @@ class TC_JSONAddition < Test::Unit::TestCase
|
|
110
110
|
json_raw_object = raw.to_json_raw_object
|
111
111
|
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
112
112
|
assert_equal hash, json_raw_object
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
# "
|
117
|
-
assert_equal json_raw, json
|
113
|
+
assert_match /\A\{.*\}\Z/, json
|
114
|
+
assert_match /"json_class":"String"/, json
|
115
|
+
assert_match /"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json
|
118
116
|
raw_again = JSON.parse(json)
|
119
117
|
assert_equal raw, raw_again
|
120
118
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
case ENV['JSON']
|
6
|
+
when 'pure' then require 'json/pure'
|
7
|
+
when 'ext' then require 'json/ext'
|
8
|
+
else require 'json'
|
9
|
+
end
|
10
|
+
require 'iconv'
|
11
|
+
|
12
|
+
class TC_JSONEncoding < Test::Unit::TestCase
|
13
|
+
include JSON
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@utf_8 = '["© ≠ €!"]'
|
17
|
+
@parsed = [ "© ≠ €!" ]
|
18
|
+
@utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
|
19
|
+
@generated = '["\u00a9 \u2260 \u20ac!"]'
|
20
|
+
if defined?(::Encoding)
|
21
|
+
@utf_8_ascii_8bit = @utf_8.dup.force_encoding(Encoding::ASCII_8BIT)
|
22
|
+
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
|
23
|
+
@utf_16be_ascii_8bit = @utf_16be.dup.force_encoding(Encoding::ASCII_8BIT)
|
24
|
+
@utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
|
25
|
+
@utf_16le_ascii_8bit = @utf_16le.dup.force_encoding(Encoding::ASCII_8BIT)
|
26
|
+
@utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
|
27
|
+
@utf_32be_ascii_8bit = @utf_32be.dup.force_encoding(Encoding::ASCII_8BIT)
|
28
|
+
@utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
|
29
|
+
@utf_32le_ascii_8bit = @utf_32le.dup.force_encoding(Encoding::ASCII_8BIT)
|
30
|
+
else
|
31
|
+
@utf_8_ascii_8bit = @utf_8.dup
|
32
|
+
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
|
33
|
+
@utf_16be_ascii_8bit = @utf_16be.dup
|
34
|
+
@utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
|
35
|
+
@utf_16le_ascii_8bit = @utf_16le.dup
|
36
|
+
@utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
|
37
|
+
@utf_32be_ascii_8bit = @utf_32be.dup
|
38
|
+
@utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
|
39
|
+
@utf_32le_ascii_8bit = @utf_32le.dup
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_parse
|
44
|
+
assert_equal @parsed, JSON.parse(@utf_8)
|
45
|
+
assert_equal @parsed, JSON.parse(@utf_16be)
|
46
|
+
assert_equal @parsed, JSON.parse(@utf_16le)
|
47
|
+
assert_equal @parsed, JSON.parse(@utf_32be)
|
48
|
+
assert_equal @parsed, JSON.parse(@utf_32le)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_parse_ascii_8bit
|
52
|
+
assert_equal @parsed, JSON.parse(@utf_8_ascii_8bit)
|
53
|
+
assert_equal @parsed, JSON.parse(@utf_16be_ascii_8bit)
|
54
|
+
assert_equal @parsed, JSON.parse(@utf_16le_ascii_8bit)
|
55
|
+
assert_equal @parsed, JSON.parse(@utf_32be_ascii_8bit)
|
56
|
+
assert_equal @parsed, JSON.parse(@utf_32le_ascii_8bit)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_generate
|
60
|
+
assert_equal @generated, JSON.generate(@parsed, :ascii_only => true)
|
61
|
+
if defined?(::Encoding)
|
62
|
+
assert_equal @generated, JSON.generate(@utf_16_data, :ascii_only => true)
|
63
|
+
else
|
64
|
+
# XXX checking of correct utf8 data is not as strict (yet?) without :ascii_only
|
65
|
+
assert_raises(JSON::GeneratorError) { JSON.generate(@utf_16_data, :ascii_only => true) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -44,8 +44,8 @@ class TC_JSONGenerate < Test::Unit::TestCase
|
|
44
44
|
EOT
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
json =
|
47
|
+
def test_generate
|
48
|
+
json = generate(@hash)
|
49
49
|
assert_equal(JSON.parse(@json2), JSON.parse(json))
|
50
50
|
parsed_json = parse(json)
|
51
51
|
assert_equal(@hash, parsed_json)
|
@@ -53,10 +53,11 @@ EOT
|
|
53
53
|
assert_equal('{"1":2}', json)
|
54
54
|
parsed_json = parse(json)
|
55
55
|
assert_equal({"1"=>2}, parsed_json)
|
56
|
+
assert_raise(GeneratorError) { generate(666) }
|
56
57
|
end
|
57
58
|
|
58
|
-
def
|
59
|
-
json =
|
59
|
+
def test_generate_pretty
|
60
|
+
json = pretty_generate(@hash)
|
60
61
|
assert_equal(JSON.parse(@json3), JSON.parse(json))
|
61
62
|
parsed_json = parse(json)
|
62
63
|
assert_equal(@hash, parsed_json)
|
@@ -68,38 +69,53 @@ EOT
|
|
68
69
|
EOT
|
69
70
|
parsed_json = parse(json)
|
70
71
|
assert_equal({"1"=>2}, parsed_json)
|
72
|
+
assert_raise(GeneratorError) { pretty_generate(666) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_fast_generate
|
76
|
+
json = fast_generate(@hash)
|
77
|
+
assert_equal(JSON.parse(@json2), JSON.parse(json))
|
78
|
+
parsed_json = parse(json)
|
79
|
+
assert_equal(@hash, parsed_json)
|
80
|
+
json = fast_generate({1=>2})
|
81
|
+
assert_equal('{"1":2}', json)
|
82
|
+
parsed_json = parse(json)
|
83
|
+
assert_equal({"1"=>2}, parsed_json)
|
84
|
+
assert_raise(GeneratorError) { fast_generate(666) }
|
71
85
|
end
|
72
86
|
|
73
87
|
def test_states
|
74
88
|
json = generate({1=>2}, nil)
|
75
89
|
assert_equal('{"1":2}', json)
|
76
|
-
s = JSON.state.new
|
77
|
-
|
90
|
+
s = JSON.state.new
|
91
|
+
assert s.check_circular?
|
92
|
+
assert s[:check_circular?]
|
78
93
|
h = { 1=>2 }
|
79
94
|
h[3] = h
|
80
|
-
assert_raises(JSON::
|
81
|
-
assert_raises(JSON::
|
82
|
-
s = JSON.state.new
|
83
|
-
#assert s.check_circular
|
95
|
+
assert_raises(JSON::NestingError) { generate(h) }
|
96
|
+
assert_raises(JSON::NestingError) { generate(h, s) }
|
97
|
+
s = JSON.state.new
|
84
98
|
a = [ 1, 2 ]
|
85
99
|
a << a
|
86
|
-
assert_raises(JSON::
|
100
|
+
assert_raises(JSON::NestingError) { generate(a, s) }
|
101
|
+
assert s.check_circular?
|
102
|
+
assert s[:check_circular?]
|
87
103
|
end
|
88
104
|
|
89
105
|
def test_allow_nan
|
90
106
|
assert_raises(GeneratorError) { generate([JSON::NaN]) }
|
91
107
|
assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true)
|
92
|
-
|
108
|
+
assert_raises(GeneratorError) { fast_generate([JSON::NaN]) }
|
93
109
|
assert_raises(GeneratorError) { pretty_generate([JSON::NaN]) }
|
94
110
|
assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true)
|
95
111
|
assert_raises(GeneratorError) { generate([JSON::Infinity]) }
|
96
112
|
assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true)
|
97
|
-
|
113
|
+
assert_raises(GeneratorError) { fast_generate([JSON::Infinity]) }
|
98
114
|
assert_raises(GeneratorError) { pretty_generate([JSON::Infinity]) }
|
99
115
|
assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true)
|
100
116
|
assert_raises(GeneratorError) { generate([JSON::MinusInfinity]) }
|
101
117
|
assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true)
|
102
|
-
|
118
|
+
assert_raises(GeneratorError) { fast_generate([JSON::MinusInfinity]) }
|
103
119
|
assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
|
104
120
|
assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
|
105
121
|
end
|
@@ -116,7 +116,7 @@ class TC_JSONRails < Test::Unit::TestCase
|
|
116
116
|
c = C.new # with rails addition all objects are theoretically creatable
|
117
117
|
assert C.json_creatable?
|
118
118
|
json = generate(c)
|
119
|
-
assert_raises(ArgumentError) { JSON.parse(json) }
|
119
|
+
assert_raises(ArgumentError, NameError) { JSON.parse(json) }
|
120
120
|
end
|
121
121
|
|
122
122
|
def test_raw_strings
|
@@ -131,16 +131,14 @@ class TC_JSONRails < Test::Unit::TestCase
|
|
131
131
|
json_raw_object = raw.to_json_raw_object
|
132
132
|
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
133
133
|
assert_equal hash, json_raw_object
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# "
|
138
|
-
assert_equal json_raw, json
|
134
|
+
assert_match /\A\{.*\}\Z/, json
|
135
|
+
assert_match /"json_class":"String"/, json
|
136
|
+
assert_match /"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json
|
139
137
|
raw_again = JSON.parse(json)
|
140
138
|
assert_equal raw, raw_again
|
141
139
|
end
|
142
140
|
|
143
141
|
def test_symbol
|
144
|
-
assert_equal '"foo"',
|
142
|
+
assert_equal '"foo"', :foo.to_json # we don't want an object here
|
145
143
|
end
|
146
144
|
end
|
@@ -19,22 +19,36 @@ class TC_JSONUnicode < Test::Unit::TestCase
|
|
19
19
|
assert_equal '" "', ' '.to_json
|
20
20
|
assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
|
21
21
|
utf8 = [ "© ≠ €! \01" ]
|
22
|
+
json = '["© ≠ €! \u0001"]'
|
23
|
+
assert_equal json, utf8.to_json(:ascii_only => false)
|
24
|
+
assert_equal utf8, parse(json)
|
22
25
|
json = '["\u00a9 \u2260 \u20ac! \u0001"]'
|
23
|
-
assert_equal json, utf8.to_json
|
26
|
+
assert_equal json, utf8.to_json(:ascii_only => true)
|
27
|
+
assert_equal utf8, parse(json)
|
28
|
+
utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
|
29
|
+
json = "[\"\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212\"]"
|
24
30
|
assert_equal utf8, parse(json)
|
31
|
+
assert_equal json, utf8.to_json(:ascii_only => false)
|
25
32
|
utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
|
33
|
+
assert_equal utf8, parse(json)
|
26
34
|
json = "[\"\\u3042\\u3044\\u3046\\u3048\\u304a\"]"
|
27
|
-
assert_equal json, utf8.to_json
|
35
|
+
assert_equal json, utf8.to_json(:ascii_only => true)
|
28
36
|
assert_equal utf8, parse(json)
|
29
37
|
utf8 = ['საქართველო']
|
38
|
+
json = '["საქართველო"]'
|
39
|
+
assert_equal json, utf8.to_json(:ascii_only => false)
|
30
40
|
json = "[\"\\u10e1\\u10d0\\u10e5\\u10d0\\u10e0\\u10d7\\u10d5\\u10d4\\u10da\\u10dd\"]"
|
31
|
-
assert_equal json, utf8.to_json
|
41
|
+
assert_equal json, utf8.to_json(:ascii_only => true)
|
32
42
|
assert_equal utf8, parse(json)
|
33
|
-
assert_equal '["
|
43
|
+
assert_equal '["Ã"]', JSON.generate(["Ã"], :ascii_only => false)
|
44
|
+
assert_equal '["\\u00c3"]', JSON.generate(["Ã"], :ascii_only => true)
|
34
45
|
assert_equal ["€"], JSON.parse('["\u20ac"]')
|
35
46
|
utf8 = ["\xf0\xa0\x80\x81"]
|
47
|
+
json = "[\"\xf0\xa0\x80\x81\"]"
|
48
|
+
assert_equal json, JSON.generate(utf8, :ascii_only => false)
|
49
|
+
assert_equal utf8, JSON.parse(json)
|
36
50
|
json = '["\ud840\udc01"]'
|
37
|
-
assert_equal json, JSON.generate(utf8)
|
51
|
+
assert_equal json, JSON.generate(utf8, :ascii_only => true)
|
38
52
|
assert_equal utf8, JSON.parse(json)
|
39
53
|
end
|
40
54
|
|
@@ -55,7 +69,7 @@ class TC_JSONUnicode < Test::Unit::TestCase
|
|
55
69
|
end
|
56
70
|
end
|
57
71
|
assert_raise(JSON::GeneratorError) do
|
58
|
-
JSON.generate(["\x80"])
|
72
|
+
JSON.generate(["\x80"], :ascii_only => true)
|
59
73
|
end
|
60
74
|
assert_equal "\302\200", JSON.parse('["\u0080"]').first
|
61
75
|
end
|