es-scout 5.3.0.es1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +4 -0
- data/CHANGELOG +225 -0
- data/COPYING +340 -0
- data/INSTALL +18 -0
- data/LICENSE +6 -0
- data/README +66 -0
- data/Rakefile +74 -0
- data/TODO +6 -0
- data/bin/es-scout +10 -0
- data/data/cacert.pem +3154 -0
- data/data/code_key.pub +13 -0
- data/data/gpl-2.0.txt +339 -0
- data/data/lgpl-2.1.txt +504 -0
- data/lib/es-scout/command/install.rb +68 -0
- data/lib/es-scout/command/run.rb +56 -0
- data/lib/es-scout/command/test.rb +62 -0
- data/lib/es-scout/command/troubleshoot.rb +142 -0
- data/lib/es-scout/command.rb +258 -0
- data/lib/es-scout/plugin.rb +237 -0
- data/lib/es-scout/plugin_options.rb +80 -0
- data/lib/es-scout/scout_logger.rb +19 -0
- data/lib/es-scout/server.rb +578 -0
- data/lib/es-scout.rb +11 -0
- data/vendor/json_pure/CHANGES +162 -0
- data/vendor/json_pure/COPYING +58 -0
- data/vendor/json_pure/GPL +340 -0
- data/vendor/json_pure/README +358 -0
- data/vendor/json_pure/Rakefile +292 -0
- data/vendor/json_pure/TODO +1 -0
- data/vendor/json_pure/VERSION +1 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +52 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +900 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +901 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +261 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +262 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +82 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +34 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +900 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +901 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +81 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +82 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +82 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +1000 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +1001 -0
- data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +82 -0
- data/vendor/json_pure/benchmarks/generator2_benchmark.rb +222 -0
- data/vendor/json_pure/benchmarks/generator_benchmark.rb +224 -0
- 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 +259 -0
- data/vendor/json_pure/bin/edit_json.rb +9 -0
- data/vendor/json_pure/bin/prettify_json.rb +75 -0
- data/vendor/json_pure/data/example.json +1 -0
- data/vendor/json_pure/data/index.html +38 -0
- data/vendor/json_pure/data/prototype.js +4184 -0
- data/vendor/json_pure/ext/json/ext/generator/extconf.rb +16 -0
- data/vendor/json_pure/ext/json/ext/generator/generator.c +1341 -0
- data/vendor/json_pure/ext/json/ext/generator/generator.h +170 -0
- data/vendor/json_pure/ext/json/ext/parser/extconf.rb +15 -0
- data/vendor/json_pure/ext/json/ext/parser/parser.c +1935 -0
- data/vendor/json_pure/ext/json/ext/parser/parser.h +71 -0
- data/vendor/json_pure/ext/json/ext/parser/parser.rl +792 -0
- data/vendor/json_pure/install.rb +26 -0
- data/vendor/json_pure/lib/json/Array.xpm +21 -0
- data/vendor/json_pure/lib/json/FalseClass.xpm +21 -0
- data/vendor/json_pure/lib/json/Hash.xpm +21 -0
- data/vendor/json_pure/lib/json/Key.xpm +73 -0
- data/vendor/json_pure/lib/json/NilClass.xpm +21 -0
- data/vendor/json_pure/lib/json/Numeric.xpm +28 -0
- data/vendor/json_pure/lib/json/String.xpm +96 -0
- data/vendor/json_pure/lib/json/TrueClass.xpm +21 -0
- data/vendor/json_pure/lib/json/add/core.rb +148 -0
- data/vendor/json_pure/lib/json/add/rails.rb +58 -0
- data/vendor/json_pure/lib/json/common.rb +397 -0
- data/vendor/json_pure/lib/json/editor.rb +1371 -0
- data/vendor/json_pure/lib/json/ext.rb +15 -0
- data/vendor/json_pure/lib/json/json.xpm +1499 -0
- data/vendor/json_pure/lib/json/pure/generator.rb +452 -0
- data/vendor/json_pure/lib/json/pure/parser.rb +307 -0
- data/vendor/json_pure/lib/json/pure.rb +77 -0
- data/vendor/json_pure/lib/json/version.rb +8 -0
- data/vendor/json_pure/lib/json.rb +10 -0
- data/vendor/json_pure/tests/fixtures/fail1.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail10.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail11.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail12.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail13.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail14.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail18.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail19.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail2.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail20.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail21.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail22.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail23.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail24.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail25.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail27.json +2 -0
- data/vendor/json_pure/tests/fixtures/fail28.json +2 -0
- data/vendor/json_pure/tests/fixtures/fail3.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail4.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail5.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail6.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail7.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail8.json +1 -0
- data/vendor/json_pure/tests/fixtures/fail9.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass1.json +56 -0
- data/vendor/json_pure/tests/fixtures/pass15.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass16.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass17.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass2.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass26.json +1 -0
- data/vendor/json_pure/tests/fixtures/pass3.json +6 -0
- data/vendor/json_pure/tests/test_json.rb +340 -0
- data/vendor/json_pure/tests/test_json_addition.rb +162 -0
- data/vendor/json_pure/tests/test_json_encoding.rb +68 -0
- data/vendor/json_pure/tests/test_json_fixtures.rb +34 -0
- data/vendor/json_pure/tests/test_json_generate.rb +122 -0
- data/vendor/json_pure/tests/test_json_rails.rb +144 -0
- data/vendor/json_pure/tests/test_json_unicode.rb +76 -0
- data/vendor/json_pure/tools/fuzz.rb +139 -0
- data/vendor/json_pure/tools/server.rb +61 -0
- metadata +233 -0
@@ -0,0 +1,340 @@
|
|
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 'stringio'
|
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
|
+
|
26
|
+
class TC_JSON < Test::Unit::TestCase
|
27
|
+
include JSON
|
28
|
+
|
29
|
+
def setup
|
30
|
+
@ary = [1, "foo", 3.14, 4711.0, 2.718, nil, [1,-2,3], false, true].map do
|
31
|
+
|x| [x]
|
32
|
+
end
|
33
|
+
@ary_to_parse = ["1", '"foo"', "3.14", "4711.0", "2.718", "null",
|
34
|
+
"[1,-2,3]", "false", "true"].map do
|
35
|
+
|x| "[#{x}]"
|
36
|
+
end
|
37
|
+
@hash = {
|
38
|
+
'a' => 2,
|
39
|
+
'b' => 3.141,
|
40
|
+
'c' => 'c',
|
41
|
+
'd' => [ 1, "b", 3.14 ],
|
42
|
+
'e' => { 'foo' => 'bar' },
|
43
|
+
'g' => "\"\0\037",
|
44
|
+
'h' => 1000.0,
|
45
|
+
'i' => 0.001
|
46
|
+
}
|
47
|
+
@json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
|
48
|
+
'"g":"\\"\\u0000\\u001f","h":1.0E3,"i":1.0E-3}'
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_construction
|
52
|
+
parser = JSON::Parser.new('test')
|
53
|
+
assert_equal 'test', parser.source
|
54
|
+
end
|
55
|
+
|
56
|
+
def assert_equal_float(expected, is)
|
57
|
+
assert_in_delta(expected.first, is.first, 1e-2)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_parse_simple_arrays
|
61
|
+
assert_equal([], parse('[]'))
|
62
|
+
assert_equal([], parse(' [ ] '))
|
63
|
+
assert_equal([nil], parse('[null]'))
|
64
|
+
assert_equal([false], parse('[false]'))
|
65
|
+
assert_equal([true], parse('[true]'))
|
66
|
+
assert_equal([-23], parse('[-23]'))
|
67
|
+
assert_equal([23], parse('[23]'))
|
68
|
+
assert_equal([0.23], parse('[0.23]'))
|
69
|
+
assert_equal([0.0], parse('[0e0]'))
|
70
|
+
assert_raises(JSON::ParserError) { parse('[+23.2]') }
|
71
|
+
assert_raises(JSON::ParserError) { parse('[+23]') }
|
72
|
+
assert_raises(JSON::ParserError) { parse('[.23]') }
|
73
|
+
assert_raises(JSON::ParserError) { parse('[023]') }
|
74
|
+
assert_equal_float [3.141], parse('[3.141]')
|
75
|
+
assert_equal_float [-3.141], parse('[-3.141]')
|
76
|
+
assert_equal_float [3.141], parse('[3141e-3]')
|
77
|
+
assert_equal_float [3.141], parse('[3141.1e-3]')
|
78
|
+
assert_equal_float [3.141], parse('[3141E-3]')
|
79
|
+
assert_equal_float [3.141], parse('[3141.0E-3]')
|
80
|
+
assert_equal_float [-3.141], parse('[-3141.0e-3]')
|
81
|
+
assert_equal_float [-3.141], parse('[-3141e-3]')
|
82
|
+
assert_raises(ParserError) { parse('[NaN]') }
|
83
|
+
assert parse('[NaN]', :allow_nan => true).first.nan?
|
84
|
+
assert_raises(ParserError) { parse('[Infinity]') }
|
85
|
+
assert_equal [1.0/0], parse('[Infinity]', :allow_nan => true)
|
86
|
+
assert_raises(ParserError) { parse('[-Infinity]') }
|
87
|
+
assert_equal [-1.0/0], parse('[-Infinity]', :allow_nan => true)
|
88
|
+
assert_equal([""], parse('[""]'))
|
89
|
+
assert_equal(["foobar"], parse('["foobar"]'))
|
90
|
+
assert_equal([{}], parse('[{}]'))
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_parse_simple_objects
|
94
|
+
assert_equal({}, parse('{}'))
|
95
|
+
assert_equal({}, parse(' { } '))
|
96
|
+
assert_equal({ "a" => nil }, parse('{ "a" : null}'))
|
97
|
+
assert_equal({ "a" => nil }, parse('{"a":null}'))
|
98
|
+
assert_equal({ "a" => false }, parse('{ "a" : false } '))
|
99
|
+
assert_equal({ "a" => false }, parse('{"a":false}'))
|
100
|
+
assert_raises(JSON::ParserError) { parse('{false}') }
|
101
|
+
assert_equal({ "a" => true }, parse('{"a":true}'))
|
102
|
+
assert_equal({ "a" => true }, parse(' { "a" : true } '))
|
103
|
+
assert_equal({ "a" => -23 }, parse(' { "a" : -23 } '))
|
104
|
+
assert_equal({ "a" => -23 }, parse(' { "a" : -23 } '))
|
105
|
+
assert_equal({ "a" => 23 }, parse('{"a":23 } '))
|
106
|
+
assert_equal({ "a" => 23 }, parse(' { "a" : 23 } '))
|
107
|
+
assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
|
108
|
+
assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
|
109
|
+
end
|
110
|
+
|
111
|
+
if Array.method_defined?(:permutation)
|
112
|
+
def test_parse_more_complex_arrays
|
113
|
+
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
|
114
|
+
a.permutation.each do |perm|
|
115
|
+
json = pretty_generate(perm)
|
116
|
+
assert_equal perm, parse(json)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_parse_complex_objects
|
121
|
+
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
|
122
|
+
a.permutation.each do |perm|
|
123
|
+
s = "a"
|
124
|
+
orig_obj = perm.inject({}) { |h, x| h[s.dup] = x; s = s.succ; h }
|
125
|
+
json = pretty_generate(orig_obj)
|
126
|
+
assert_equal orig_obj, parse(json)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_parse_arrays
|
132
|
+
assert_equal([1,2,3], parse('[1,2,3]'))
|
133
|
+
assert_equal([1.2,2,3], parse('[1.2,2,3]'))
|
134
|
+
assert_equal([[],[[],[]]], parse('[[],[[],[]]]'))
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_parse_values
|
138
|
+
assert_equal([""], parse('[""]'))
|
139
|
+
assert_equal(["\\"], parse('["\\\\"]'))
|
140
|
+
assert_equal(['"'], parse('["\""]'))
|
141
|
+
assert_equal(['\\"\\'], parse('["\\\\\\"\\\\"]'))
|
142
|
+
assert_equal(["\"\b\n\r\t\0\037"],
|
143
|
+
parse('["\"\b\n\r\t\u0000\u001f"]'))
|
144
|
+
for i in 0 ... @ary.size
|
145
|
+
assert_equal(@ary[i], parse(@ary_to_parse[i]))
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_parse_array
|
150
|
+
assert_equal([], parse('[]'))
|
151
|
+
assert_equal([], parse(' [ ] '))
|
152
|
+
assert_equal([1], parse('[1]'))
|
153
|
+
assert_equal([1], parse(' [ 1 ] '))
|
154
|
+
assert_equal(@ary,
|
155
|
+
parse('[[1],["foo"],[3.14],[47.11e+2],[2718.0E-3],[null],[[1,-2,3]]'\
|
156
|
+
',[false],[true]]'))
|
157
|
+
assert_equal(@ary, parse(%Q{ [ [1] , ["foo"] , [3.14] \t , [47.11e+2]
|
158
|
+
, [2718.0E-3 ],\r[ null] , [[1, -2, 3 ]], [false ],[ true]\n ] }))
|
159
|
+
end
|
160
|
+
|
161
|
+
class SubArray < Array; end
|
162
|
+
|
163
|
+
def test_parse_array_custom_class
|
164
|
+
res = parse('[]', :array_class => SubArray)
|
165
|
+
assert_equal([], res)
|
166
|
+
assert_equal(SubArray, res.class)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_parse_object
|
170
|
+
assert_equal({}, parse('{}'))
|
171
|
+
assert_equal({}, parse(' { } '))
|
172
|
+
assert_equal({'foo'=>'bar'}, parse('{"foo":"bar"}'))
|
173
|
+
assert_equal({'foo'=>'bar'}, parse(' { "foo" : "bar" } '))
|
174
|
+
end
|
175
|
+
|
176
|
+
class SubHash < Hash; end
|
177
|
+
|
178
|
+
def test_parse_object_custom_class
|
179
|
+
res = parse('{}', :object_class => SubHash)
|
180
|
+
assert_equal({}, res)
|
181
|
+
assert_equal(SubHash, res.class)
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_parser_reset
|
185
|
+
parser = Parser.new(@json)
|
186
|
+
assert_equal(@hash, parser.parse)
|
187
|
+
assert_equal(@hash, parser.parse)
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_comments
|
191
|
+
json = <<EOT
|
192
|
+
{
|
193
|
+
"key1":"value1", // eol comment
|
194
|
+
"key2":"value2" /* multi line
|
195
|
+
* comment */,
|
196
|
+
"key3":"value3" /* multi line
|
197
|
+
// nested eol comment
|
198
|
+
* comment */
|
199
|
+
}
|
200
|
+
EOT
|
201
|
+
assert_equal(
|
202
|
+
{ "key1" => "value1", "key2" => "value2", "key3" => "value3" },
|
203
|
+
parse(json))
|
204
|
+
json = <<EOT
|
205
|
+
{
|
206
|
+
"key1":"value1" /* multi line
|
207
|
+
// nested eol comment
|
208
|
+
/* illegal nested multi line comment */
|
209
|
+
* comment */
|
210
|
+
}
|
211
|
+
EOT
|
212
|
+
assert_raises(ParserError) { parse(json) }
|
213
|
+
json = <<EOT
|
214
|
+
{
|
215
|
+
"key1":"value1" /* multi line
|
216
|
+
// nested eol comment
|
217
|
+
closed multi comment */
|
218
|
+
and again, throw an Error */
|
219
|
+
}
|
220
|
+
EOT
|
221
|
+
assert_raises(ParserError) { parse(json) }
|
222
|
+
json = <<EOT
|
223
|
+
{
|
224
|
+
"key1":"value1" /*/*/
|
225
|
+
}
|
226
|
+
EOT
|
227
|
+
assert_equal({ "key1" => "value1" }, parse(json))
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_backslash
|
231
|
+
data = [ '\\.(?i:gif|jpe?g|png)$' ]
|
232
|
+
json = '["\\\\.(?i:gif|jpe?g|png)$"]'
|
233
|
+
assert_equal json, JSON.generate(data)
|
234
|
+
assert_equal data, JSON.parse(json)
|
235
|
+
#
|
236
|
+
data = [ '\\"' ]
|
237
|
+
json = '["\\\\\""]'
|
238
|
+
assert_equal json, JSON.generate(data)
|
239
|
+
assert_equal data, JSON.parse(json)
|
240
|
+
#
|
241
|
+
json = '["/"]'
|
242
|
+
data = JSON.parse(json)
|
243
|
+
assert_equal ['/'], data
|
244
|
+
assert_equal json, JSON.generate(data)
|
245
|
+
#
|
246
|
+
json = '["\""]'
|
247
|
+
data = JSON.parse(json)
|
248
|
+
assert_equal ['"'], data
|
249
|
+
assert_equal json, JSON.generate(data)
|
250
|
+
json = '["\\\'"]'
|
251
|
+
data = JSON.parse(json)
|
252
|
+
assert_equal ["'"], data
|
253
|
+
assert_equal '["\'"]', JSON.generate(data)
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_wrong_inputs
|
257
|
+
assert_raises(ParserError) { JSON.parse('"foo"') }
|
258
|
+
assert_raises(ParserError) { JSON.parse('123') }
|
259
|
+
assert_raises(ParserError) { JSON.parse('[] bla') }
|
260
|
+
assert_raises(ParserError) { JSON.parse('[] 1') }
|
261
|
+
assert_raises(ParserError) { JSON.parse('[] []') }
|
262
|
+
assert_raises(ParserError) { JSON.parse('[] {}') }
|
263
|
+
assert_raises(ParserError) { JSON.parse('{} []') }
|
264
|
+
assert_raises(ParserError) { JSON.parse('{} {}') }
|
265
|
+
assert_raises(ParserError) { JSON.parse('[NULL]') }
|
266
|
+
assert_raises(ParserError) { JSON.parse('[FALSE]') }
|
267
|
+
assert_raises(ParserError) { JSON.parse('[TRUE]') }
|
268
|
+
assert_raises(ParserError) { JSON.parse('[07] ') }
|
269
|
+
assert_raises(ParserError) { JSON.parse('[0a]') }
|
270
|
+
assert_raises(ParserError) { JSON.parse('[1.]') }
|
271
|
+
assert_raises(ParserError) { JSON.parse(' ') }
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_nesting
|
275
|
+
assert_raises(JSON::NestingError) { JSON.parse '[[]]', :max_nesting => 1 }
|
276
|
+
assert_raises(JSON::NestingError) { JSON.parser.new('[[]]', :max_nesting => 1).parse }
|
277
|
+
assert_equal [[]], JSON.parse('[[]]', :max_nesting => 2)
|
278
|
+
too_deep = '[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]'
|
279
|
+
too_deep_ary = eval too_deep
|
280
|
+
assert_raises(JSON::NestingError) { JSON.parse too_deep }
|
281
|
+
assert_raises(JSON::NestingError) { JSON.parser.new(too_deep).parse }
|
282
|
+
assert_raises(JSON::NestingError) { JSON.parse too_deep, :max_nesting => 19 }
|
283
|
+
ok = JSON.parse too_deep, :max_nesting => 20
|
284
|
+
assert_equal too_deep_ary, ok
|
285
|
+
ok = JSON.parse too_deep, :max_nesting => nil
|
286
|
+
assert_equal too_deep_ary, ok
|
287
|
+
ok = JSON.parse too_deep, :max_nesting => false
|
288
|
+
assert_equal too_deep_ary, ok
|
289
|
+
ok = JSON.parse too_deep, :max_nesting => 0
|
290
|
+
assert_equal too_deep_ary, ok
|
291
|
+
assert_raises(JSON::NestingError) { JSON.generate [[]], :max_nesting => 1 }
|
292
|
+
assert_equal '[[]]', JSON.generate([[]], :max_nesting => 2)
|
293
|
+
assert_raises(JSON::NestingError) { JSON.generate too_deep_ary }
|
294
|
+
assert_raises(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 19 }
|
295
|
+
ok = JSON.generate too_deep_ary, :max_nesting => 20
|
296
|
+
assert_equal too_deep, ok
|
297
|
+
ok = JSON.generate too_deep_ary, :max_nesting => nil
|
298
|
+
assert_equal too_deep, ok
|
299
|
+
ok = JSON.generate too_deep_ary, :max_nesting => false
|
300
|
+
assert_equal too_deep, ok
|
301
|
+
ok = JSON.generate too_deep_ary, :max_nesting => 0
|
302
|
+
assert_equal too_deep, ok
|
303
|
+
end
|
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
|
+
|
312
|
+
def test_load_dump
|
313
|
+
too_deep = '[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]'
|
314
|
+
assert_equal too_deep, JSON.dump(eval(too_deep))
|
315
|
+
assert_kind_of String, Marshal.dump(eval(too_deep))
|
316
|
+
assert_raises(ArgumentError) { JSON.dump(eval(too_deep), 19) }
|
317
|
+
assert_raises(ArgumentError) { Marshal.dump(eval(too_deep), 19) }
|
318
|
+
assert_equal too_deep, JSON.dump(eval(too_deep), 20)
|
319
|
+
assert_kind_of String, Marshal.dump(eval(too_deep), 20)
|
320
|
+
output = StringIO.new
|
321
|
+
JSON.dump(eval(too_deep), output)
|
322
|
+
assert_equal too_deep, output.string
|
323
|
+
output = StringIO.new
|
324
|
+
JSON.dump(eval(too_deep), output, 20)
|
325
|
+
assert_equal too_deep, output.string
|
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
|
340
|
+
end
|
@@ -0,0 +1,162 @@
|
|
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 'json/add/core'
|
11
|
+
require 'date'
|
12
|
+
|
13
|
+
class TC_JSONAddition < Test::Unit::TestCase
|
14
|
+
include JSON
|
15
|
+
|
16
|
+
class A
|
17
|
+
def initialize(a)
|
18
|
+
@a = a
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :a
|
22
|
+
|
23
|
+
def ==(other)
|
24
|
+
a == other.a
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.json_create(object)
|
28
|
+
new(*object['args'])
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_json(*args)
|
32
|
+
{
|
33
|
+
'json_class' => self.class.name,
|
34
|
+
'args' => [ @a ],
|
35
|
+
}.to_json(*args)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class B
|
40
|
+
def self.json_creatable?
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_json(*args)
|
45
|
+
{
|
46
|
+
'json_class' => self.class.name,
|
47
|
+
}.to_json(*args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class C
|
52
|
+
def self.json_creatable?
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_json(*args)
|
57
|
+
{
|
58
|
+
'json_class' => 'TC_JSONAddition::Nix',
|
59
|
+
}.to_json(*args)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_extended_json
|
64
|
+
a = A.new(666)
|
65
|
+
assert A.json_creatable?
|
66
|
+
json = generate(a)
|
67
|
+
a_again = JSON.parse(json)
|
68
|
+
assert_kind_of a.class, a_again
|
69
|
+
assert_equal a, a_again
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_extended_json_disabled
|
73
|
+
a = A.new(666)
|
74
|
+
assert A.json_creatable?
|
75
|
+
json = generate(a)
|
76
|
+
a_again = JSON.parse(json, :create_additions => true)
|
77
|
+
assert_kind_of a.class, a_again
|
78
|
+
assert_equal a, a_again
|
79
|
+
a_hash = JSON.parse(json, :create_additions => false)
|
80
|
+
assert_kind_of Hash, a_hash
|
81
|
+
assert_equal(
|
82
|
+
{"args"=>[666], "json_class"=>"TC_JSONAddition::A"}.sort_by { |k,| k },
|
83
|
+
a_hash.sort_by { |k,| k }
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_extended_json_fail1
|
88
|
+
b = B.new
|
89
|
+
assert !B.json_creatable?
|
90
|
+
json = generate(b)
|
91
|
+
assert_equal({ "json_class"=>"TC_JSONAddition::B" }, JSON.parse(json))
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_extended_json_fail2
|
95
|
+
c = C.new
|
96
|
+
assert !C.json_creatable?
|
97
|
+
json = generate(c)
|
98
|
+
assert_raises(ArgumentError, NameError) { JSON.parse(json) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_raw_strings
|
102
|
+
raw = ''
|
103
|
+
raw.respond_to?(:encode!) and raw.encode!(Encoding::ASCII_8BIT)
|
104
|
+
raw_array = []
|
105
|
+
for i in 0..255
|
106
|
+
raw << i
|
107
|
+
raw_array << i
|
108
|
+
end
|
109
|
+
json = raw.to_json_raw
|
110
|
+
json_raw_object = raw.to_json_raw_object
|
111
|
+
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
112
|
+
assert_equal hash, json_raw_object
|
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
|
116
|
+
raw_again = JSON.parse(json)
|
117
|
+
assert_equal raw, raw_again
|
118
|
+
end
|
119
|
+
|
120
|
+
MyJsonStruct = Struct.new 'MyJsonStruct', :foo, :bar
|
121
|
+
|
122
|
+
def test_core
|
123
|
+
t = Time.now
|
124
|
+
assert_equal t.inspect, JSON(JSON(t)).inspect
|
125
|
+
d = Date.today
|
126
|
+
assert_equal d, JSON(JSON(d))
|
127
|
+
d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161)
|
128
|
+
assert_equal d, JSON(JSON(d))
|
129
|
+
assert_equal 1..10, JSON(JSON(1..10))
|
130
|
+
assert_equal 1...10, JSON(JSON(1...10))
|
131
|
+
assert_equal "a".."c", JSON(JSON("a".."c"))
|
132
|
+
assert_equal "a"..."c", JSON(JSON("a"..."c"))
|
133
|
+
s = MyJsonStruct.new 4711, 'foot'
|
134
|
+
assert_equal s, JSON(JSON(s))
|
135
|
+
struct = Struct.new :foo, :bar
|
136
|
+
s = struct.new 4711, 'foot'
|
137
|
+
assert_raises(JSONError) { JSON(s) }
|
138
|
+
begin
|
139
|
+
raise TypeError, "test me"
|
140
|
+
rescue TypeError => e
|
141
|
+
e_json = JSON.generate e
|
142
|
+
e_again = JSON e_json
|
143
|
+
assert_kind_of TypeError, e_again
|
144
|
+
assert_equal e.message, e_again.message
|
145
|
+
assert_equal e.backtrace, e_again.backtrace
|
146
|
+
end
|
147
|
+
assert_equal(/foo/, JSON(JSON(/foo/)))
|
148
|
+
assert_equal(/foo/i, JSON(JSON(/foo/i)))
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_utc_datetime
|
152
|
+
now = Time.now
|
153
|
+
d = DateTime.parse(now.to_s) # usual case
|
154
|
+
assert d, JSON.parse(d.to_json)
|
155
|
+
d = DateTime.parse(now.utc.to_s) # of = 0
|
156
|
+
assert d, JSON.parse(d.to_json)
|
157
|
+
d = DateTime.civil(2008, 6, 17, 11, 48, 32, 1) # of = 1 / 12 => 1/12
|
158
|
+
assert d, JSON.parse(d.to_json)
|
159
|
+
d = DateTime.civil(2008, 6, 17, 11, 48, 32, 12) # of = 12 / 12 => 12
|
160
|
+
assert d, JSON.parse(d.to_json)
|
161
|
+
end
|
162
|
+
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
|
@@ -0,0 +1,34 @@
|
|
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
|
+
|
11
|
+
class TC_JSONFixtures < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
|
14
|
+
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
|
15
|
+
@passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
16
|
+
@failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_passing
|
20
|
+
for name, source in @passed
|
21
|
+
assert JSON.parse(source),
|
22
|
+
"Did not pass for fixture '#{name}'"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_failing
|
27
|
+
for name, source in @failed
|
28
|
+
assert_raises(JSON::ParserError, JSON::NestingError,
|
29
|
+
"Did not fail for fixture '#{name}'") do
|
30
|
+
JSON.parse(source)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|