engineyard-serverside 2.0.5 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/engineyard-serverside.rb +3 -3
- data/lib/engineyard-serverside/configuration.rb +6 -6
- data/lib/engineyard-serverside/deploy.rb +11 -7
- data/lib/engineyard-serverside/version.rb +1 -1
- data/lib/vendor/multi_json/CHANGELOG.md +121 -0
- data/lib/vendor/multi_json/CONTRIBUTING.md +46 -0
- data/lib/vendor/multi_json/Gemfile +31 -0
- data/lib/vendor/multi_json/LICENSE.md +20 -0
- data/lib/vendor/multi_json/README.md +105 -0
- data/lib/vendor/multi_json/Rakefile +12 -0
- data/lib/vendor/multi_json/lib/multi_json.rb +137 -0
- data/lib/vendor/multi_json/lib/multi_json/adapters/gson.rb +20 -0
- data/lib/vendor/multi_json/lib/multi_json/adapters/json_common.rb +35 -0
- data/lib/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +12 -0
- data/lib/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +12 -0
- data/lib/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +35 -0
- data/lib/vendor/multi_json/lib/multi_json/adapters/oj.rb +29 -0
- data/lib/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +58 -0
- data/lib/vendor/multi_json/lib/multi_json/adapters/yajl.rb +20 -0
- data/lib/vendor/multi_json/lib/multi_json/vendor/okjson.rb +602 -0
- data/lib/vendor/multi_json/lib/multi_json/version.rb +3 -0
- data/lib/vendor/multi_json/multi_json.gemspec +22 -0
- data/lib/vendor/multi_json/spec/adapter_shared_example.rb +162 -0
- data/lib/vendor/multi_json/spec/helper.rb +45 -0
- data/lib/vendor/multi_json/spec/json_common_shared_example.rb +36 -0
- data/lib/vendor/multi_json/spec/multi_json_spec.rb +151 -0
- data/spec/configuration_spec.rb +79 -1
- data/spec/deploy_hook_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +26 -120
- data/lib/vendor/json_pure/CHANGES +0 -166
- data/lib/vendor/json_pure/COPYING +0 -58
- data/lib/vendor/json_pure/GPL +0 -340
- data/lib/vendor/json_pure/README +0 -358
- data/lib/vendor/json_pure/Rakefile +0 -292
- data/lib/vendor/json_pure/TODO +0 -1
- data/lib/vendor/json_pure/VERSION +0 -1
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +0 -52
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +0 -900
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +0 -901
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +0 -261
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +0 -262
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +0 -82
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +0 -34
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +0 -900
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +0 -901
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +0 -81
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +0 -82
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +0 -82
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +0 -1000
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +0 -1001
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +0 -82
- data/lib/vendor/json_pure/benchmarks/generator2_benchmark.rb +0 -222
- data/lib/vendor/json_pure/benchmarks/generator_benchmark.rb +0 -224
- data/lib/vendor/json_pure/benchmarks/ohai.json +0 -1216
- data/lib/vendor/json_pure/benchmarks/ohai.ruby +0 -1
- data/lib/vendor/json_pure/benchmarks/parser2_benchmark.rb +0 -251
- data/lib/vendor/json_pure/benchmarks/parser_benchmark.rb +0 -259
- data/lib/vendor/json_pure/bin/edit_json.rb +0 -9
- data/lib/vendor/json_pure/bin/prettify_json.rb +0 -75
- data/lib/vendor/json_pure/data/example.json +0 -1
- data/lib/vendor/json_pure/data/index.html +0 -38
- data/lib/vendor/json_pure/data/prototype.js +0 -4184
- data/lib/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -16
- data/lib/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1323
- data/lib/vendor/json_pure/ext/json/ext/generator/generator.h +0 -170
- data/lib/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -15
- data/lib/vendor/json_pure/ext/json/ext/parser/parser.c +0 -1935
- data/lib/vendor/json_pure/ext/json/ext/parser/parser.h +0 -71
- data/lib/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -792
- data/lib/vendor/json_pure/install.rb +0 -26
- data/lib/vendor/json_pure/lib/json.rb +0 -10
- data/lib/vendor/json_pure/lib/json/Array.xpm +0 -21
- data/lib/vendor/json_pure/lib/json/FalseClass.xpm +0 -21
- data/lib/vendor/json_pure/lib/json/Hash.xpm +0 -21
- data/lib/vendor/json_pure/lib/json/Key.xpm +0 -73
- data/lib/vendor/json_pure/lib/json/NilClass.xpm +0 -21
- data/lib/vendor/json_pure/lib/json/Numeric.xpm +0 -28
- data/lib/vendor/json_pure/lib/json/String.xpm +0 -96
- data/lib/vendor/json_pure/lib/json/TrueClass.xpm +0 -21
- data/lib/vendor/json_pure/lib/json/add/core.rb +0 -148
- data/lib/vendor/json_pure/lib/json/add/rails.rb +0 -58
- data/lib/vendor/json_pure/lib/json/common.rb +0 -397
- data/lib/vendor/json_pure/lib/json/editor.rb +0 -1371
- data/lib/vendor/json_pure/lib/json/ext.rb +0 -15
- data/lib/vendor/json_pure/lib/json/json.xpm +0 -1499
- data/lib/vendor/json_pure/lib/json/pure.rb +0 -77
- data/lib/vendor/json_pure/lib/json/pure/generator.rb +0 -452
- data/lib/vendor/json_pure/lib/json/pure/parser.rb +0 -307
- data/lib/vendor/json_pure/lib/json/version.rb +0 -8
- data/lib/vendor/json_pure/tests/fixtures/fail1.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail10.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail11.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail12.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail13.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail14.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail18.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail19.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail2.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail20.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail21.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail22.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail23.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail24.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail25.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail27.json +0 -2
- data/lib/vendor/json_pure/tests/fixtures/fail28.json +0 -2
- data/lib/vendor/json_pure/tests/fixtures/fail3.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail4.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail5.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail6.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail7.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail8.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/fail9.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/pass1.json +0 -56
- data/lib/vendor/json_pure/tests/fixtures/pass15.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/pass16.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/pass17.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/pass2.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/pass26.json +0 -1
- data/lib/vendor/json_pure/tests/fixtures/pass3.json +0 -6
- data/lib/vendor/json_pure/tests/test_json.rb +0 -361
- data/lib/vendor/json_pure/tests/test_json_addition.rb +0 -162
- data/lib/vendor/json_pure/tests/test_json_encoding.rb +0 -68
- data/lib/vendor/json_pure/tests/test_json_fixtures.rb +0 -34
- data/lib/vendor/json_pure/tests/test_json_generate.rb +0 -122
- data/lib/vendor/json_pure/tests/test_json_rails.rb +0 -144
- data/lib/vendor/json_pure/tests/test_json_unicode.rb +0 -76
- data/lib/vendor/json_pure/tools/fuzz.rb +0 -139
- data/lib/vendor/json_pure/tools/server.rb +0 -61
@@ -1 +0,0 @@
|
|
1
|
-
["Illegal backslash escape: \x15"]
|
@@ -1 +0,0 @@
|
|
1
|
-
["Illegal backslash escape: \'"]
|
@@ -1 +0,0 @@
|
|
1
|
-
["Illegal backslash escape: \017"]
|
@@ -1 +0,0 @@
|
|
1
|
-
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
|
@@ -1 +0,0 @@
|
|
1
|
-
["tab\ character\ in\ string\ "]
|
@@ -1,361 +0,0 @@
|
|
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
|
177
|
-
def to_json(*a)
|
178
|
-
{
|
179
|
-
JSON.create_id => self.class.name,
|
180
|
-
}.merge(self).to_json(*a)
|
181
|
-
end
|
182
|
-
|
183
|
-
def self.json_create(o)
|
184
|
-
o.delete JSON.create_id
|
185
|
-
new.merge(o)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_parse_object_custom_class
|
190
|
-
res = parse('{}', :object_class => SubHash)
|
191
|
-
assert_equal({}, res)
|
192
|
-
assert_equal(SubHash, res.class)
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_generation_of_core_subclasses
|
196
|
-
obj = SubHash.new.merge( "foo" => SubHash.new.merge("bar" => true))
|
197
|
-
obj_json = JSON(obj)
|
198
|
-
obj_again = JSON(obj_json)
|
199
|
-
assert_kind_of SubHash, obj_again
|
200
|
-
assert_kind_of SubHash, obj_again['foo']
|
201
|
-
assert obj_again['foo']['bar']
|
202
|
-
assert_equal obj, obj_again
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_parser_reset
|
206
|
-
parser = Parser.new(@json)
|
207
|
-
assert_equal(@hash, parser.parse)
|
208
|
-
assert_equal(@hash, parser.parse)
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_comments
|
212
|
-
json = <<EOT
|
213
|
-
{
|
214
|
-
"key1":"value1", // eol comment
|
215
|
-
"key2":"value2" /* multi line
|
216
|
-
* comment */,
|
217
|
-
"key3":"value3" /* multi line
|
218
|
-
// nested eol comment
|
219
|
-
* comment */
|
220
|
-
}
|
221
|
-
EOT
|
222
|
-
assert_equal(
|
223
|
-
{ "key1" => "value1", "key2" => "value2", "key3" => "value3" },
|
224
|
-
parse(json))
|
225
|
-
json = <<EOT
|
226
|
-
{
|
227
|
-
"key1":"value1" /* multi line
|
228
|
-
// nested eol comment
|
229
|
-
/* illegal nested multi line comment */
|
230
|
-
* comment */
|
231
|
-
}
|
232
|
-
EOT
|
233
|
-
assert_raises(ParserError) { parse(json) }
|
234
|
-
json = <<EOT
|
235
|
-
{
|
236
|
-
"key1":"value1" /* multi line
|
237
|
-
// nested eol comment
|
238
|
-
closed multi comment */
|
239
|
-
and again, throw an Error */
|
240
|
-
}
|
241
|
-
EOT
|
242
|
-
assert_raises(ParserError) { parse(json) }
|
243
|
-
json = <<EOT
|
244
|
-
{
|
245
|
-
"key1":"value1" /*/*/
|
246
|
-
}
|
247
|
-
EOT
|
248
|
-
assert_equal({ "key1" => "value1" }, parse(json))
|
249
|
-
end
|
250
|
-
|
251
|
-
def test_backslash
|
252
|
-
data = [ '\\.(?i:gif|jpe?g|png)$' ]
|
253
|
-
json = '["\\\\.(?i:gif|jpe?g|png)$"]'
|
254
|
-
assert_equal json, JSON.generate(data)
|
255
|
-
assert_equal data, JSON.parse(json)
|
256
|
-
#
|
257
|
-
data = [ '\\"' ]
|
258
|
-
json = '["\\\\\""]'
|
259
|
-
assert_equal json, JSON.generate(data)
|
260
|
-
assert_equal data, JSON.parse(json)
|
261
|
-
#
|
262
|
-
json = '["/"]'
|
263
|
-
data = JSON.parse(json)
|
264
|
-
assert_equal ['/'], data
|
265
|
-
assert_equal json, JSON.generate(data)
|
266
|
-
#
|
267
|
-
json = '["\""]'
|
268
|
-
data = JSON.parse(json)
|
269
|
-
assert_equal ['"'], data
|
270
|
-
assert_equal json, JSON.generate(data)
|
271
|
-
json = '["\\\'"]'
|
272
|
-
data = JSON.parse(json)
|
273
|
-
assert_equal ["'"], data
|
274
|
-
assert_equal '["\'"]', JSON.generate(data)
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_wrong_inputs
|
278
|
-
assert_raises(ParserError) { JSON.parse('"foo"') }
|
279
|
-
assert_raises(ParserError) { JSON.parse('123') }
|
280
|
-
assert_raises(ParserError) { JSON.parse('[] bla') }
|
281
|
-
assert_raises(ParserError) { JSON.parse('[] 1') }
|
282
|
-
assert_raises(ParserError) { JSON.parse('[] []') }
|
283
|
-
assert_raises(ParserError) { JSON.parse('[] {}') }
|
284
|
-
assert_raises(ParserError) { JSON.parse('{} []') }
|
285
|
-
assert_raises(ParserError) { JSON.parse('{} {}') }
|
286
|
-
assert_raises(ParserError) { JSON.parse('[NULL]') }
|
287
|
-
assert_raises(ParserError) { JSON.parse('[FALSE]') }
|
288
|
-
assert_raises(ParserError) { JSON.parse('[TRUE]') }
|
289
|
-
assert_raises(ParserError) { JSON.parse('[07] ') }
|
290
|
-
assert_raises(ParserError) { JSON.parse('[0a]') }
|
291
|
-
assert_raises(ParserError) { JSON.parse('[1.]') }
|
292
|
-
assert_raises(ParserError) { JSON.parse(' ') }
|
293
|
-
end
|
294
|
-
|
295
|
-
def test_nesting
|
296
|
-
assert_raises(JSON::NestingError) { JSON.parse '[[]]', :max_nesting => 1 }
|
297
|
-
assert_raises(JSON::NestingError) { JSON.parser.new('[[]]', :max_nesting => 1).parse }
|
298
|
-
assert_equal [[]], JSON.parse('[[]]', :max_nesting => 2)
|
299
|
-
too_deep = '[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]'
|
300
|
-
too_deep_ary = eval too_deep
|
301
|
-
assert_raises(JSON::NestingError) { JSON.parse too_deep }
|
302
|
-
assert_raises(JSON::NestingError) { JSON.parser.new(too_deep).parse }
|
303
|
-
assert_raises(JSON::NestingError) { JSON.parse too_deep, :max_nesting => 19 }
|
304
|
-
ok = JSON.parse too_deep, :max_nesting => 20
|
305
|
-
assert_equal too_deep_ary, ok
|
306
|
-
ok = JSON.parse too_deep, :max_nesting => nil
|
307
|
-
assert_equal too_deep_ary, ok
|
308
|
-
ok = JSON.parse too_deep, :max_nesting => false
|
309
|
-
assert_equal too_deep_ary, ok
|
310
|
-
ok = JSON.parse too_deep, :max_nesting => 0
|
311
|
-
assert_equal too_deep_ary, ok
|
312
|
-
assert_raises(JSON::NestingError) { JSON.generate [[]], :max_nesting => 1 }
|
313
|
-
assert_equal '[[]]', JSON.generate([[]], :max_nesting => 2)
|
314
|
-
assert_raises(JSON::NestingError) { JSON.generate too_deep_ary }
|
315
|
-
assert_raises(JSON::NestingError) { JSON.generate too_deep_ary, :max_nesting => 19 }
|
316
|
-
ok = JSON.generate too_deep_ary, :max_nesting => 20
|
317
|
-
assert_equal too_deep, ok
|
318
|
-
ok = JSON.generate too_deep_ary, :max_nesting => nil
|
319
|
-
assert_equal too_deep, ok
|
320
|
-
ok = JSON.generate too_deep_ary, :max_nesting => false
|
321
|
-
assert_equal too_deep, ok
|
322
|
-
ok = JSON.generate too_deep_ary, :max_nesting => 0
|
323
|
-
assert_equal too_deep, ok
|
324
|
-
end
|
325
|
-
|
326
|
-
def test_symbolize_names
|
327
|
-
assert_equal({ "foo" => "bar", "baz" => "quux" },
|
328
|
-
JSON.parse('{"foo":"bar", "baz":"quux"}'))
|
329
|
-
assert_equal({ :foo => "bar", :baz => "quux" },
|
330
|
-
JSON.parse('{"foo":"bar", "baz":"quux"}', :symbolize_names => true))
|
331
|
-
end
|
332
|
-
|
333
|
-
def test_load_dump
|
334
|
-
too_deep = '[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]'
|
335
|
-
assert_equal too_deep, JSON.dump(eval(too_deep))
|
336
|
-
assert_kind_of String, Marshal.dump(eval(too_deep))
|
337
|
-
assert_raises(ArgumentError) { JSON.dump(eval(too_deep), 19) }
|
338
|
-
assert_raises(ArgumentError) { Marshal.dump(eval(too_deep), 19) }
|
339
|
-
assert_equal too_deep, JSON.dump(eval(too_deep), 20)
|
340
|
-
assert_kind_of String, Marshal.dump(eval(too_deep), 20)
|
341
|
-
output = StringIO.new
|
342
|
-
JSON.dump(eval(too_deep), output)
|
343
|
-
assert_equal too_deep, output.string
|
344
|
-
output = StringIO.new
|
345
|
-
JSON.dump(eval(too_deep), output, 20)
|
346
|
-
assert_equal too_deep, output.string
|
347
|
-
end
|
348
|
-
|
349
|
-
def test_big_integers
|
350
|
-
json1 = JSON([orig = (1 << 31) - 1])
|
351
|
-
assert_equal orig, JSON[json1][0]
|
352
|
-
json2 = JSON([orig = 1 << 31])
|
353
|
-
assert_equal orig, JSON[json2][0]
|
354
|
-
json3 = JSON([orig = (1 << 62) - 1])
|
355
|
-
assert_equal orig, JSON[json3][0]
|
356
|
-
json4 = JSON([orig = 1 << 62])
|
357
|
-
assert_equal orig, JSON[json4][0]
|
358
|
-
json5 = JSON([orig = 1 << 64])
|
359
|
-
assert_equal orig, JSON[json5][0]
|
360
|
-
end
|
361
|
-
end
|
@@ -1,162 +0,0 @@
|
|
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
|