scout 5.7.1 → 5.7.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/CHANGELOG.markdown +5 -0
  2. data/lib/scout/command/run.rb +1 -1
  3. data/lib/scout/server.rb +2 -1
  4. data/lib/scout/streamer.rb +3 -2
  5. data/lib/scout/streamer_daemon.rb +4 -4
  6. data/lib/scout/version.rb +1 -1
  7. data/test/scout_test.rb +7 -8
  8. data/vendor/httpclient/README.txt +759 -0
  9. data/vendor/httpclient/bin/httpclient +65 -0
  10. data/vendor/httpclient/lib/hexdump.rb +50 -0
  11. data/vendor/httpclient/lib/http-access2.rb +55 -0
  12. data/vendor/httpclient/lib/http-access2/cookie.rb +1 -0
  13. data/vendor/httpclient/lib/http-access2/http.rb +1 -0
  14. data/vendor/httpclient/lib/httpclient.rb +1156 -0
  15. data/vendor/httpclient/lib/httpclient/auth.rb +899 -0
  16. data/vendor/httpclient/lib/httpclient/cacert.p7s +1912 -0
  17. data/vendor/httpclient/lib/httpclient/connection.rb +88 -0
  18. data/vendor/httpclient/lib/httpclient/cookie.rb +438 -0
  19. data/vendor/httpclient/lib/httpclient/http.rb +1046 -0
  20. data/vendor/httpclient/lib/httpclient/include_client.rb +83 -0
  21. data/vendor/httpclient/lib/httpclient/session.rb +1025 -0
  22. data/vendor/httpclient/lib/httpclient/ssl_config.rb +403 -0
  23. data/vendor/httpclient/lib/httpclient/timeout.rb +140 -0
  24. data/vendor/httpclient/lib/httpclient/util.rb +178 -0
  25. data/vendor/httpclient/lib/httpclient/version.rb +3 -0
  26. data/vendor/httpclient/lib/oauthclient.rb +110 -0
  27. data/vendor/httpclient/sample/async.rb +8 -0
  28. data/vendor/httpclient/sample/auth.rb +11 -0
  29. data/vendor/httpclient/sample/cookie.rb +18 -0
  30. data/vendor/httpclient/sample/dav.rb +103 -0
  31. data/vendor/httpclient/sample/howto.rb +49 -0
  32. data/vendor/httpclient/sample/oauth_buzz.rb +57 -0
  33. data/vendor/httpclient/sample/oauth_friendfeed.rb +59 -0
  34. data/vendor/httpclient/sample/oauth_salesforce_10.rb +63 -0
  35. data/vendor/httpclient/sample/oauth_twitter.rb +61 -0
  36. data/vendor/httpclient/sample/ssl/0cert.pem +22 -0
  37. data/vendor/httpclient/sample/ssl/0key.pem +30 -0
  38. data/vendor/httpclient/sample/ssl/1000cert.pem +19 -0
  39. data/vendor/httpclient/sample/ssl/1000key.pem +18 -0
  40. data/vendor/httpclient/sample/ssl/htdocs/index.html +10 -0
  41. data/vendor/httpclient/sample/ssl/ssl_client.rb +22 -0
  42. data/vendor/httpclient/sample/ssl/webrick_httpsd.rb +29 -0
  43. data/vendor/httpclient/sample/stream.rb +21 -0
  44. data/vendor/httpclient/sample/thread.rb +27 -0
  45. data/vendor/httpclient/sample/wcat.rb +21 -0
  46. data/vendor/httpclient/test/ca-chain.cert +44 -0
  47. data/vendor/httpclient/test/ca.cert +23 -0
  48. data/vendor/httpclient/test/client.cert +19 -0
  49. data/vendor/httpclient/test/client.key +15 -0
  50. data/vendor/httpclient/test/helper.rb +129 -0
  51. data/vendor/httpclient/test/htdigest +1 -0
  52. data/vendor/httpclient/test/htpasswd +2 -0
  53. data/vendor/httpclient/test/runner.rb +2 -0
  54. data/vendor/httpclient/test/server.cert +19 -0
  55. data/vendor/httpclient/test/server.key +15 -0
  56. data/vendor/httpclient/test/sslsvr.rb +65 -0
  57. data/vendor/httpclient/test/subca.cert +21 -0
  58. data/vendor/httpclient/test/test_auth.rb +321 -0
  59. data/vendor/httpclient/test/test_cookie.rb +391 -0
  60. data/vendor/httpclient/test/test_hexdump.rb +14 -0
  61. data/vendor/httpclient/test/test_http-access2.rb +507 -0
  62. data/vendor/httpclient/test/test_httpclient.rb +1783 -0
  63. data/vendor/httpclient/test/test_include_client.rb +52 -0
  64. data/vendor/httpclient/test/test_ssl.rb +235 -0
  65. data/vendor/multi_json/.document +5 -0
  66. data/vendor/multi_json/.rspec +3 -0
  67. data/vendor/multi_json/.travis.yml +11 -0
  68. data/vendor/multi_json/.yardopts +6 -0
  69. data/vendor/multi_json/CHANGELOG.md +169 -0
  70. data/vendor/multi_json/CONTRIBUTING.md +46 -0
  71. data/vendor/multi_json/Gemfile +31 -0
  72. data/vendor/multi_json/LICENSE.md +20 -0
  73. data/vendor/multi_json/README.md +109 -0
  74. data/vendor/multi_json/Rakefile +12 -0
  75. data/vendor/multi_json/lib/multi_json.rb +157 -0
  76. data/vendor/multi_json/lib/multi_json/adapter.rb +48 -0
  77. data/vendor/multi_json/lib/multi_json/adapters/gson.rb +19 -0
  78. data/vendor/multi_json/lib/multi_json/adapters/jr_jackson.rb +19 -0
  79. data/vendor/multi_json/lib/multi_json/adapters/json_common.rb +25 -0
  80. data/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +11 -0
  81. data/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +11 -0
  82. data/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +34 -0
  83. data/vendor/multi_json/lib/multi_json/adapters/oj.rb +24 -0
  84. data/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +22 -0
  85. data/vendor/multi_json/lib/multi_json/adapters/yajl.rb +19 -0
  86. data/vendor/multi_json/lib/multi_json/convertible_hash_keys.rb +43 -0
  87. data/vendor/multi_json/lib/multi_json/load_error.rb +11 -0
  88. data/vendor/multi_json/lib/multi_json/options.rb +48 -0
  89. data/vendor/multi_json/lib/multi_json/vendor/okjson.rb +606 -0
  90. data/vendor/multi_json/lib/multi_json/version.rb +20 -0
  91. data/vendor/multi_json/multi_json.gemspec +22 -0
  92. data/vendor/multi_json/spec/adapter_shared_example.rb +235 -0
  93. data/vendor/multi_json/spec/has_options.rb +119 -0
  94. data/vendor/multi_json/spec/helper.rb +35 -0
  95. data/vendor/multi_json/spec/json_common_shared_example.rb +30 -0
  96. data/vendor/multi_json/spec/multi_json_spec.rb +226 -0
  97. data/vendor/{signature → pusher}/.document +0 -0
  98. data/vendor/{json_pure/diagrams/.keep → pusher/.gemtest} +0 -0
  99. data/vendor/pusher/.gitignore +23 -0
  100. data/vendor/pusher/.travis.yml +15 -0
  101. data/vendor/pusher/Gemfile +2 -0
  102. data/vendor/{pusher-gem → pusher}/LICENSE +1 -1
  103. data/vendor/pusher/README.md +186 -0
  104. data/vendor/{pusher-gem → pusher}/Rakefile +0 -0
  105. data/vendor/{pusher-gem → pusher}/examples/async_message.rb +0 -0
  106. data/vendor/pusher/lib/pusher.rb +60 -0
  107. data/vendor/{pusher-gem → pusher}/lib/pusher/channel.rb +47 -54
  108. data/vendor/pusher/lib/pusher/client.rb +306 -0
  109. data/vendor/pusher/lib/pusher/request.rb +107 -0
  110. data/vendor/pusher/lib/pusher/resource.rb +36 -0
  111. data/vendor/pusher/lib/pusher/webhook.rb +110 -0
  112. data/vendor/{pusher-gem → pusher}/pusher.gemspec +6 -5
  113. data/vendor/pusher/spec/channel_spec.rb +127 -0
  114. data/vendor/pusher/spec/client_spec.rb +464 -0
  115. data/vendor/{pusher-gem → pusher}/spec/spec_helper.rb +12 -0
  116. data/vendor/pusher/spec/web_hook_spec.rb +117 -0
  117. data/vendor/signature/.travis.yml +15 -0
  118. data/vendor/signature/Gemfile +1 -1
  119. data/vendor/signature/README.md +38 -28
  120. data/vendor/signature/lib/signature.rb +97 -15
  121. data/vendor/signature/lib/signature/query_encoder.rb +47 -0
  122. data/vendor/signature/lib/signature/version.rb +1 -1
  123. data/vendor/signature/signature.gemspec +3 -2
  124. data/vendor/signature/spec/signature_spec.rb +164 -55
  125. data/vendor/signature/spec/spec_helper.rb +2 -3
  126. metadata +120 -145
  127. data/vendor/json_pure/.gitignore +0 -12
  128. data/vendor/json_pure/.travis.yml +0 -20
  129. data/vendor/json_pure/CHANGES +0 -282
  130. data/vendor/json_pure/COPYING +0 -58
  131. data/vendor/json_pure/COPYING-json-jruby +0 -57
  132. data/vendor/json_pure/GPL +0 -340
  133. data/vendor/json_pure/Gemfile +0 -11
  134. data/vendor/json_pure/README-json-jruby.markdown +0 -33
  135. data/vendor/json_pure/README.rdoc +0 -358
  136. data/vendor/json_pure/Rakefile +0 -412
  137. data/vendor/json_pure/TODO +0 -1
  138. data/vendor/json_pure/VERSION +0 -1
  139. data/vendor/json_pure/data/example.json +0 -1
  140. data/vendor/json_pure/data/index.html +0 -38
  141. data/vendor/json_pure/data/prototype.js +0 -4184
  142. data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +0 -181
  143. data/vendor/json_pure/ext/json/ext/generator/depend +0 -1
  144. data/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -14
  145. data/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1435
  146. data/vendor/json_pure/ext/json/ext/generator/generator.h +0 -148
  147. data/vendor/json_pure/ext/json/ext/parser/depend +0 -1
  148. data/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -13
  149. data/vendor/json_pure/ext/json/ext/parser/parser.c +0 -2204
  150. data/vendor/json_pure/ext/json/ext/parser/parser.h +0 -77
  151. data/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -927
  152. data/vendor/json_pure/install.rb +0 -23
  153. data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +0 -167
  154. data/vendor/json_pure/java/src/json/ext/Generator.java +0 -444
  155. data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +0 -232
  156. data/vendor/json_pure/java/src/json/ext/GeneratorService.java +0 -43
  157. data/vendor/json_pure/java/src/json/ext/GeneratorState.java +0 -543
  158. data/vendor/json_pure/java/src/json/ext/OptionsReader.java +0 -114
  159. data/vendor/json_pure/java/src/json/ext/Parser.java +0 -2644
  160. data/vendor/json_pure/java/src/json/ext/Parser.rl +0 -968
  161. data/vendor/json_pure/java/src/json/ext/ParserService.java +0 -35
  162. data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +0 -121
  163. data/vendor/json_pure/java/src/json/ext/StringDecoder.java +0 -167
  164. data/vendor/json_pure/java/src/json/ext/StringEncoder.java +0 -106
  165. data/vendor/json_pure/java/src/json/ext/Utils.java +0 -89
  166. data/vendor/json_pure/json-java.gemspec +0 -23
  167. data/vendor/json_pure/json.gemspec +0 -37
  168. data/vendor/json_pure/json_pure.gemspec +0 -39
  169. data/vendor/json_pure/lib/json.rb +0 -62
  170. data/vendor/json_pure/lib/json/add/bigdecimal.rb +0 -28
  171. data/vendor/json_pure/lib/json/add/complex.rb +0 -22
  172. data/vendor/json_pure/lib/json/add/core.rb +0 -11
  173. data/vendor/json_pure/lib/json/add/date.rb +0 -34
  174. data/vendor/json_pure/lib/json/add/date_time.rb +0 -50
  175. data/vendor/json_pure/lib/json/add/exception.rb +0 -31
  176. data/vendor/json_pure/lib/json/add/ostruct.rb +0 -31
  177. data/vendor/json_pure/lib/json/add/range.rb +0 -29
  178. data/vendor/json_pure/lib/json/add/rational.rb +0 -22
  179. data/vendor/json_pure/lib/json/add/regexp.rb +0 -30
  180. data/vendor/json_pure/lib/json/add/struct.rb +0 -30
  181. data/vendor/json_pure/lib/json/add/symbol.rb +0 -25
  182. data/vendor/json_pure/lib/json/add/time.rb +0 -38
  183. data/vendor/json_pure/lib/json/common.rb +0 -487
  184. data/vendor/json_pure/lib/json/ext.rb +0 -21
  185. data/vendor/json_pure/lib/json/ext/.keep +0 -0
  186. data/vendor/json_pure/lib/json/generic_object.rb +0 -70
  187. data/vendor/json_pure/lib/json/pure.rb +0 -21
  188. data/vendor/json_pure/lib/json/pure/generator.rb +0 -522
  189. data/vendor/json_pure/lib/json/pure/parser.rb +0 -359
  190. data/vendor/json_pure/lib/json/version.rb +0 -8
  191. data/vendor/json_pure/tests/fixtures/fail1.json +0 -1
  192. data/vendor/json_pure/tests/fixtures/fail10.json +0 -1
  193. data/vendor/json_pure/tests/fixtures/fail11.json +0 -1
  194. data/vendor/json_pure/tests/fixtures/fail12.json +0 -1
  195. data/vendor/json_pure/tests/fixtures/fail13.json +0 -1
  196. data/vendor/json_pure/tests/fixtures/fail14.json +0 -1
  197. data/vendor/json_pure/tests/fixtures/fail18.json +0 -1
  198. data/vendor/json_pure/tests/fixtures/fail19.json +0 -1
  199. data/vendor/json_pure/tests/fixtures/fail2.json +0 -1
  200. data/vendor/json_pure/tests/fixtures/fail20.json +0 -1
  201. data/vendor/json_pure/tests/fixtures/fail21.json +0 -1
  202. data/vendor/json_pure/tests/fixtures/fail22.json +0 -1
  203. data/vendor/json_pure/tests/fixtures/fail23.json +0 -1
  204. data/vendor/json_pure/tests/fixtures/fail24.json +0 -1
  205. data/vendor/json_pure/tests/fixtures/fail25.json +0 -1
  206. data/vendor/json_pure/tests/fixtures/fail27.json +0 -2
  207. data/vendor/json_pure/tests/fixtures/fail28.json +0 -2
  208. data/vendor/json_pure/tests/fixtures/fail3.json +0 -1
  209. data/vendor/json_pure/tests/fixtures/fail4.json +0 -1
  210. data/vendor/json_pure/tests/fixtures/fail5.json +0 -1
  211. data/vendor/json_pure/tests/fixtures/fail6.json +0 -1
  212. data/vendor/json_pure/tests/fixtures/fail7.json +0 -1
  213. data/vendor/json_pure/tests/fixtures/fail8.json +0 -1
  214. data/vendor/json_pure/tests/fixtures/fail9.json +0 -1
  215. data/vendor/json_pure/tests/fixtures/pass1.json +0 -56
  216. data/vendor/json_pure/tests/fixtures/pass15.json +0 -1
  217. data/vendor/json_pure/tests/fixtures/pass16.json +0 -1
  218. data/vendor/json_pure/tests/fixtures/pass17.json +0 -1
  219. data/vendor/json_pure/tests/fixtures/pass2.json +0 -1
  220. data/vendor/json_pure/tests/fixtures/pass26.json +0 -1
  221. data/vendor/json_pure/tests/fixtures/pass3.json +0 -6
  222. data/vendor/json_pure/tests/setup_variant.rb +0 -11
  223. data/vendor/json_pure/tests/test_json.rb +0 -545
  224. data/vendor/json_pure/tests/test_json_addition.rb +0 -196
  225. data/vendor/json_pure/tests/test_json_encoding.rb +0 -65
  226. data/vendor/json_pure/tests/test_json_fixtures.rb +0 -35
  227. data/vendor/json_pure/tests/test_json_generate.rb +0 -322
  228. data/vendor/json_pure/tests/test_json_generic_object.rb +0 -75
  229. data/vendor/json_pure/tests/test_json_string_matching.rb +0 -39
  230. data/vendor/json_pure/tests/test_json_unicode.rb +0 -72
  231. data/vendor/json_pure/tools/fuzz.rb +0 -139
  232. data/vendor/json_pure/tools/server.rb +0 -62
  233. data/vendor/pusher-gem/Gemfile +0 -2
  234. data/vendor/pusher-gem/README.md +0 -80
  235. data/vendor/pusher-gem/lib/pusher.rb +0 -107
  236. data/vendor/pusher-gem/lib/pusher/request.rb +0 -107
  237. data/vendor/pusher-gem/spec/channel_spec.rb +0 -274
  238. data/vendor/pusher-gem/spec/pusher_spec.rb +0 -87
  239. data/vendor/ruby-hmac/History.txt +0 -15
  240. data/vendor/ruby-hmac/Manifest.txt +0 -11
  241. data/vendor/ruby-hmac/README.md +0 -41
  242. data/vendor/ruby-hmac/Rakefile +0 -23
  243. data/vendor/ruby-hmac/lib/hmac-md5.rb +0 -11
  244. data/vendor/ruby-hmac/lib/hmac-rmd160.rb +0 -11
  245. data/vendor/ruby-hmac/lib/hmac-sha1.rb +0 -11
  246. data/vendor/ruby-hmac/lib/hmac-sha2.rb +0 -25
  247. data/vendor/ruby-hmac/lib/hmac.rb +0 -118
  248. data/vendor/ruby-hmac/lib/ruby_hmac.rb +0 -2
  249. data/vendor/ruby-hmac/ruby-hmac.gemspec +0 -33
  250. data/vendor/ruby-hmac/test/test_hmac.rb +0 -89
  251. data/vendor/signature/VERSION +0 -1
@@ -1,196 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding:utf-8 -*-
3
-
4
- require 'test/unit'
5
- require File.join(File.dirname(__FILE__), 'setup_variant')
6
- require 'json/add/core'
7
- require 'json/add/complex'
8
- require 'json/add/rational'
9
- require 'json/add/bigdecimal'
10
- require 'json/add/ostruct'
11
- require 'date'
12
-
13
- class TestJSONAddition < 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 A2 < A
40
- def to_json(*args)
41
- {
42
- 'json_class' => self.class.name,
43
- 'args' => [ @a ],
44
- }.to_json(*args)
45
- end
46
- end
47
-
48
- class B
49
- def self.json_creatable?
50
- false
51
- end
52
-
53
- def to_json(*args)
54
- {
55
- 'json_class' => self.class.name,
56
- }.to_json(*args)
57
- end
58
- end
59
-
60
- class C
61
- def self.json_creatable?
62
- false
63
- end
64
-
65
- def to_json(*args)
66
- {
67
- 'json_class' => 'TestJSONAddition::Nix',
68
- }.to_json(*args)
69
- end
70
- end
71
-
72
- def test_extended_json
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
- end
80
-
81
- def test_extended_json_default
82
- a = A.new(666)
83
- assert A.json_creatable?
84
- json = generate(a)
85
- a_hash = JSON.parse(json)
86
- assert_kind_of Hash, a_hash
87
- end
88
-
89
- def test_extended_json_disabled
90
- a = A.new(666)
91
- assert A.json_creatable?
92
- json = generate(a)
93
- a_again = JSON.parse(json, :create_additions => true)
94
- assert_kind_of a.class, a_again
95
- assert_equal a, a_again
96
- a_hash = JSON.parse(json, :create_additions => false)
97
- assert_kind_of Hash, a_hash
98
- assert_equal(
99
- {"args"=>[666], "json_class"=>"TestJSONAddition::A"}.sort_by { |k,| k },
100
- a_hash.sort_by { |k,| k }
101
- )
102
- end
103
-
104
- def test_extended_json_fail1
105
- b = B.new
106
- assert !B.json_creatable?
107
- json = generate(b)
108
- assert_equal({ "json_class"=>"TestJSONAddition::B" }, JSON.parse(json))
109
- end
110
-
111
- def test_extended_json_fail2
112
- c = C.new
113
- assert !C.json_creatable?
114
- json = generate(c)
115
- assert_raises(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) }
116
- end
117
-
118
- def test_raw_strings
119
- raw = ''
120
- raw.respond_to?(:encode!) and raw.encode!(Encoding::ASCII_8BIT)
121
- raw_array = []
122
- for i in 0..255
123
- raw << i
124
- raw_array << i
125
- end
126
- json = raw.to_json_raw
127
- json_raw_object = raw.to_json_raw_object
128
- hash = { 'json_class' => 'String', 'raw'=> raw_array }
129
- assert_equal hash, json_raw_object
130
- assert_match(/\A\{.*\}\z/, json)
131
- assert_match(/"json_class":"String"/, json)
132
- 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)
133
- raw_again = JSON.parse(json, :create_additions => true)
134
- assert_equal raw, raw_again
135
- end
136
-
137
- MyJsonStruct = Struct.new 'MyJsonStruct', :foo, :bar
138
-
139
- def test_core
140
- t = Time.now
141
- assert_equal t, JSON(JSON(t), :create_additions => true)
142
- d = Date.today
143
- assert_equal d, JSON(JSON(d), :create_additions => true)
144
- d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161)
145
- assert_equal d, JSON(JSON(d), :create_additions => true)
146
- assert_equal 1..10, JSON(JSON(1..10), :create_additions => true)
147
- assert_equal 1...10, JSON(JSON(1...10), :create_additions => true)
148
- assert_equal "a".."c", JSON(JSON("a".."c"), :create_additions => true)
149
- assert_equal "a"..."c", JSON(JSON("a"..."c"), :create_additions => true)
150
- s = MyJsonStruct.new 4711, 'foot'
151
- assert_equal s, JSON(JSON(s), :create_additions => true)
152
- struct = Struct.new :foo, :bar
153
- s = struct.new 4711, 'foot'
154
- assert_raises(JSONError) { JSON(s) }
155
- begin
156
- raise TypeError, "test me"
157
- rescue TypeError => e
158
- e_json = JSON.generate e
159
- e_again = JSON e_json, :create_additions => true
160
- assert_kind_of TypeError, e_again
161
- assert_equal e.message, e_again.message
162
- assert_equal e.backtrace, e_again.backtrace
163
- end
164
- assert_equal(/foo/, JSON(JSON(/foo/), :create_additions => true))
165
- assert_equal(/foo/i, JSON(JSON(/foo/i), :create_additions => true))
166
- end
167
-
168
- def test_utc_datetime
169
- now = Time.now
170
- d = DateTime.parse(now.to_s, :create_additions => true) # usual case
171
- assert_equal d, JSON.parse(d.to_json, :create_additions => true)
172
- d = DateTime.parse(now.utc.to_s) # of = 0
173
- assert_equal d, JSON.parse(d.to_json, :create_additions => true)
174
- d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(1,24))
175
- assert_equal d, JSON.parse(d.to_json, :create_additions => true)
176
- d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(12,24))
177
- assert_equal d, JSON.parse(d.to_json, :create_additions => true)
178
- end
179
-
180
- def test_rational_complex
181
- assert_equal Rational(2, 9), JSON.parse(JSON(Rational(2, 9)), :create_additions => true)
182
- assert_equal Complex(2, 9), JSON.parse(JSON(Complex(2, 9)), :create_additions => true)
183
- end
184
-
185
- def test_bigdecimal
186
- assert_equal BigDecimal('3.141', 23), JSON(JSON(BigDecimal('3.141', 23)), :create_additions => true)
187
- assert_equal BigDecimal('3.141', 666), JSON(JSON(BigDecimal('3.141', 666)), :create_additions => true)
188
- end
189
-
190
- def test_ostruct
191
- o = OpenStruct.new
192
- # XXX this won't work; o.foo = { :bar => true }
193
- o.foo = { 'bar' => true }
194
- assert_equal o, JSON.parse(JSON(o), :create_additions => true)
195
- end
196
- end
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'test/unit'
5
- require File.join(File.dirname(__FILE__), 'setup_variant')
6
-
7
- class TestJSONEncoding < Test::Unit::TestCase
8
- include JSON
9
-
10
- def setup
11
- @utf_8 = '["© ≠ €!"]'
12
- @parsed = [ "© ≠ €!" ]
13
- @generated = '["\u00a9 \u2260 \u20ac!"]'
14
- if String.method_defined?(:encode)
15
- @utf_16_data = [@parsed.first.encode('utf-16be', 'utf-8')]
16
- @utf_8_ascii_8bit = @utf_8.dup.force_encoding(Encoding::ASCII_8BIT)
17
- @utf_16be = @utf_8.encode('utf-16be', 'utf-8')
18
- @utf_16be_ascii_8bit = @utf_16be.dup.force_encoding(Encoding::ASCII_8BIT)
19
- @utf_16le = @utf_8.encode('utf-16le', 'utf-8')
20
- @utf_16le_ascii_8bit = @utf_16le.dup.force_encoding(Encoding::ASCII_8BIT)
21
- @utf_32be = @utf_8.encode('utf-32be', 'utf-8')
22
- @utf_32be_ascii_8bit = @utf_32be.dup.force_encoding(Encoding::ASCII_8BIT)
23
- @utf_32le = @utf_8.encode('utf-32le', 'utf-8')
24
- @utf_32le_ascii_8bit = @utf_32le.dup.force_encoding(Encoding::ASCII_8BIT)
25
- else
26
- require 'iconv'
27
- @utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
28
- @utf_8_ascii_8bit = @utf_8.dup
29
- @utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
30
- @utf_16be_ascii_8bit = @utf_16be.dup
31
- @utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
32
- @utf_16le_ascii_8bit = @utf_16le.dup
33
- @utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
34
- @utf_32be_ascii_8bit = @utf_32be.dup
35
- @utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
36
- @utf_32le_ascii_8bit = @utf_32le.dup
37
- end
38
- end
39
-
40
- def test_parse
41
- assert_equal @parsed, JSON.parse(@utf_8)
42
- assert_equal @parsed, JSON.parse(@utf_16be)
43
- assert_equal @parsed, JSON.parse(@utf_16le)
44
- assert_equal @parsed, JSON.parse(@utf_32be)
45
- assert_equal @parsed, JSON.parse(@utf_32le)
46
- end
47
-
48
- def test_parse_ascii_8bit
49
- assert_equal @parsed, JSON.parse(@utf_8_ascii_8bit)
50
- assert_equal @parsed, JSON.parse(@utf_16be_ascii_8bit)
51
- assert_equal @parsed, JSON.parse(@utf_16le_ascii_8bit)
52
- assert_equal @parsed, JSON.parse(@utf_32be_ascii_8bit)
53
- assert_equal @parsed, JSON.parse(@utf_32le_ascii_8bit)
54
- end
55
-
56
- def test_generate
57
- assert_equal @generated, JSON.generate(@parsed, :ascii_only => true)
58
- if defined?(::Encoding)
59
- assert_equal @generated, JSON.generate(@utf_16_data, :ascii_only => true)
60
- else
61
- # XXX checking of correct utf8 data is not as strict (yet?) without :ascii_only
62
- assert_raises(JSON::GeneratorError) { JSON.generate(@utf_16_data, :ascii_only => true) }
63
- end
64
- end
65
- end
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'test/unit'
5
- require File.join(File.dirname(__FILE__), 'setup_variant')
6
-
7
- class TestJSONFixtures < Test::Unit::TestCase
8
- def setup
9
- fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
10
- passed, failed = Dir[fixtures].partition { |f| f['pass'] }
11
- @passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
12
- @failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
13
- end
14
-
15
- def test_passing
16
- for name, source in @passed
17
- begin
18
- assert JSON.parse(source),
19
- "Did not pass for fixture '#{name}': #{source.inspect}"
20
- rescue => e
21
- warn "\nCaught #{e.class}(#{e}) for fixture '#{name}': #{source.inspect}\n#{e.backtrace * "\n"}"
22
- raise e
23
- end
24
- end
25
- end
26
-
27
- def test_failing
28
- for name, source in @failed
29
- assert_raises(JSON::ParserError, JSON::NestingError,
30
- "Did not fail for fixture '#{name}': #{source.inspect}") do
31
- JSON.parse(source)
32
- end
33
- end
34
- end
35
- end
@@ -1,322 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'test/unit'
5
- require File.join(File.dirname(__FILE__), 'setup_variant')
6
-
7
- class TestJSONGenerate < Test::Unit::TestCase
8
- include JSON
9
-
10
- def setup
11
- @hash = {
12
- 'a' => 2,
13
- 'b' => 3.141,
14
- 'c' => 'c',
15
- 'd' => [ 1, "b", 3.14 ],
16
- 'e' => { 'foo' => 'bar' },
17
- 'g' => "\"\0\037",
18
- 'h' => 1000.0,
19
- 'i' => 0.001
20
- }
21
- @json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
22
- '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
23
- @json3 = <<'EOT'.chomp
24
- {
25
- "a": 2,
26
- "b": 3.141,
27
- "c": "c",
28
- "d": [
29
- 1,
30
- "b",
31
- 3.14
32
- ],
33
- "e": {
34
- "foo": "bar"
35
- },
36
- "g": "\"\u0000\u001f",
37
- "h": 1000.0,
38
- "i": 0.001
39
- }
40
- EOT
41
- end
42
-
43
- def test_generate
44
- json = generate(@hash)
45
- assert_equal(JSON.parse(@json2), JSON.parse(json))
46
- json = JSON[@hash]
47
- assert_equal(JSON.parse(@json2), JSON.parse(json))
48
- parsed_json = parse(json)
49
- assert_equal(@hash, parsed_json)
50
- json = generate({1=>2})
51
- assert_equal('{"1":2}', json)
52
- parsed_json = parse(json)
53
- assert_equal({"1"=>2}, parsed_json)
54
- assert_raise(GeneratorError) { generate(666) }
55
- assert_equal '666', generate(666, :quirks_mode => true)
56
- end
57
-
58
- def test_generate_pretty
59
- json = pretty_generate(@hash)
60
- # hashes aren't (insertion) ordered on every ruby implementation assert_equal(@json3, json)
61
- assert_equal(JSON.parse(@json3), JSON.parse(json))
62
- parsed_json = parse(json)
63
- assert_equal(@hash, parsed_json)
64
- json = pretty_generate({1=>2})
65
- assert_equal(<<'EOT'.chomp, json)
66
- {
67
- "1": 2
68
- }
69
- EOT
70
- parsed_json = parse(json)
71
- assert_equal({"1"=>2}, parsed_json)
72
- assert_raise(GeneratorError) { pretty_generate(666) }
73
- assert_equal '666', pretty_generate(666, :quirks_mode => true)
74
- end
75
-
76
- def test_fast_generate
77
- json = fast_generate(@hash)
78
- assert_equal(JSON.parse(@json2), JSON.parse(json))
79
- parsed_json = parse(json)
80
- assert_equal(@hash, parsed_json)
81
- json = fast_generate({1=>2})
82
- assert_equal('{"1":2}', json)
83
- parsed_json = parse(json)
84
- assert_equal({"1"=>2}, parsed_json)
85
- assert_raise(GeneratorError) { fast_generate(666) }
86
- assert_equal '666', fast_generate(666, :quirks_mode => true)
87
- end
88
-
89
- def test_own_state
90
- state = State.new
91
- json = generate(@hash, state)
92
- assert_equal(JSON.parse(@json2), JSON.parse(json))
93
- parsed_json = parse(json)
94
- assert_equal(@hash, parsed_json)
95
- json = generate({1=>2}, state)
96
- assert_equal('{"1":2}', json)
97
- parsed_json = parse(json)
98
- assert_equal({"1"=>2}, parsed_json)
99
- assert_raise(GeneratorError) { generate(666, state) }
100
- state.quirks_mode = true
101
- assert state.quirks_mode?
102
- assert_equal '666', generate(666, state)
103
- end
104
-
105
- def test_states
106
- json = generate({1=>2}, nil)
107
- assert_equal('{"1":2}', json)
108
- s = JSON.state.new
109
- assert s.check_circular?
110
- assert s[:check_circular?]
111
- h = { 1=>2 }
112
- h[3] = h
113
- assert_raises(JSON::NestingError) { generate(h) }
114
- assert_raises(JSON::NestingError) { generate(h, s) }
115
- s = JSON.state.new
116
- a = [ 1, 2 ]
117
- a << a
118
- assert_raises(JSON::NestingError) { generate(a, s) }
119
- assert s.check_circular?
120
- assert s[:check_circular?]
121
- end
122
-
123
- def test_pretty_state
124
- state = PRETTY_STATE_PROTOTYPE.dup
125
- assert_equal({
126
- :allow_nan => false,
127
- :array_nl => "\n",
128
- :ascii_only => false,
129
- :buffer_initial_length => 1024,
130
- :quirks_mode => false,
131
- :depth => 0,
132
- :indent => " ",
133
- :max_nesting => 100,
134
- :object_nl => "\n",
135
- :space => " ",
136
- :space_before => "",
137
- }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s })
138
- end
139
-
140
- def test_safe_state
141
- state = SAFE_STATE_PROTOTYPE.dup
142
- assert_equal({
143
- :allow_nan => false,
144
- :array_nl => "",
145
- :ascii_only => false,
146
- :buffer_initial_length => 1024,
147
- :quirks_mode => false,
148
- :depth => 0,
149
- :indent => "",
150
- :max_nesting => 100,
151
- :object_nl => "",
152
- :space => "",
153
- :space_before => "",
154
- }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s })
155
- end
156
-
157
- def test_fast_state
158
- state = FAST_STATE_PROTOTYPE.dup
159
- assert_equal({
160
- :allow_nan => false,
161
- :array_nl => "",
162
- :ascii_only => false,
163
- :buffer_initial_length => 1024,
164
- :quirks_mode => false,
165
- :depth => 0,
166
- :indent => "",
167
- :max_nesting => 0,
168
- :object_nl => "",
169
- :space => "",
170
- :space_before => "",
171
- }.sort_by { |n,| n.to_s }, state.to_h.sort_by { |n,| n.to_s })
172
- end
173
-
174
- def test_allow_nan
175
- assert_raises(GeneratorError) { generate([JSON::NaN]) }
176
- assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true)
177
- assert_raises(GeneratorError) { fast_generate([JSON::NaN]) }
178
- assert_raises(GeneratorError) { pretty_generate([JSON::NaN]) }
179
- assert_equal "[\n NaN\n]", pretty_generate([JSON::NaN], :allow_nan => true)
180
- assert_raises(GeneratorError) { generate([JSON::Infinity]) }
181
- assert_equal '[Infinity]', generate([JSON::Infinity], :allow_nan => true)
182
- assert_raises(GeneratorError) { fast_generate([JSON::Infinity]) }
183
- assert_raises(GeneratorError) { pretty_generate([JSON::Infinity]) }
184
- assert_equal "[\n Infinity\n]", pretty_generate([JSON::Infinity], :allow_nan => true)
185
- assert_raises(GeneratorError) { generate([JSON::MinusInfinity]) }
186
- assert_equal '[-Infinity]', generate([JSON::MinusInfinity], :allow_nan => true)
187
- assert_raises(GeneratorError) { fast_generate([JSON::MinusInfinity]) }
188
- assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
189
- assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
190
- end
191
-
192
- def test_depth
193
- ary = []; ary << ary
194
- assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
195
- assert_raises(JSON::NestingError) { JSON.generate(ary) }
196
- assert_equal 0, JSON::SAFE_STATE_PROTOTYPE.depth
197
- assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
198
- assert_raises(JSON::NestingError) { JSON.pretty_generate(ary) }
199
- assert_equal 0, JSON::PRETTY_STATE_PROTOTYPE.depth
200
- s = JSON.state.new
201
- assert_equal 0, s.depth
202
- assert_raises(JSON::NestingError) { ary.to_json(s) }
203
- assert_equal 100, s.depth
204
- end
205
-
206
- def test_buffer_initial_length
207
- s = JSON.state.new
208
- assert_equal 1024, s.buffer_initial_length
209
- s.buffer_initial_length = 0
210
- assert_equal 1024, s.buffer_initial_length
211
- s.buffer_initial_length = -1
212
- assert_equal 1024, s.buffer_initial_length
213
- s.buffer_initial_length = 128
214
- assert_equal 128, s.buffer_initial_length
215
- end
216
-
217
- def test_gc
218
- bignum_too_long_to_embed_as_string = 1234567890123456789012345
219
- expect = bignum_too_long_to_embed_as_string.to_s
220
- stress, GC.stress = GC.stress, true
221
-
222
- 10.times do |i|
223
- tmp = bignum_too_long_to_embed_as_string.to_json
224
- assert_equal expect, tmp
225
- end
226
- ensure
227
- GC.stress = stress
228
- end if GC.respond_to?(:stress=)
229
-
230
- def test_configure_using_configure_and_merge
231
- numbered_state = {
232
- :indent => "1",
233
- :space => '2',
234
- :space_before => '3',
235
- :object_nl => '4',
236
- :array_nl => '5'
237
- }
238
- state1 = JSON.state.new
239
- state1.merge(numbered_state)
240
- assert_equal '1', state1.indent
241
- assert_equal '2', state1.space
242
- assert_equal '3', state1.space_before
243
- assert_equal '4', state1.object_nl
244
- assert_equal '5', state1.array_nl
245
- state2 = JSON.state.new
246
- state2.configure(numbered_state)
247
- assert_equal '1', state2.indent
248
- assert_equal '2', state2.space
249
- assert_equal '3', state2.space_before
250
- assert_equal '4', state2.object_nl
251
- assert_equal '5', state2.array_nl
252
- end
253
-
254
- def test_configure_hash_conversion
255
- state = JSON.state.new
256
- state.configure(:indent => '1')
257
- assert_equal '1', state.indent
258
- state = JSON.state.new
259
- foo = 'foo'
260
- assert_raise(TypeError) do
261
- state.configure(foo)
262
- end
263
- def foo.to_h
264
- { :indent => '2' }
265
- end
266
- state.configure(foo)
267
- assert_equal '2', state.indent
268
- end
269
-
270
- if defined?(JSON::Ext::Generator)
271
- def test_broken_bignum # [ruby-core:38867]
272
- pid = fork do
273
- Bignum.class_eval do
274
- def to_s
275
- end
276
- end
277
- begin
278
- JSON::Ext::Generator::State.new.generate(1<<64)
279
- exit 1
280
- rescue TypeError
281
- exit 0
282
- end
283
- end
284
- _, status = Process.waitpid2(pid)
285
- assert status.success?
286
- rescue NotImplementedError
287
- # forking to avoid modifying core class of a parent process and
288
- # introducing race conditions of tests are run in parallel
289
- end
290
- end
291
-
292
- def test_hash_likeness_set_symbol
293
- state = JSON.state.new
294
- assert_equal nil, state[:foo]
295
- assert_equal nil.class, state[:foo].class
296
- assert_equal nil, state['foo']
297
- state[:foo] = :bar
298
- assert_equal :bar, state[:foo]
299
- assert_equal :bar, state['foo']
300
- state_hash = state.to_hash
301
- assert_kind_of Hash, state_hash
302
- assert_equal :bar, state_hash[:foo]
303
- end
304
-
305
- def test_hash_likeness_set_string
306
- state = JSON.state.new
307
- assert_equal nil, state[:foo]
308
- assert_equal nil, state['foo']
309
- state['foo'] = :bar
310
- assert_equal :bar, state[:foo]
311
- assert_equal :bar, state['foo']
312
- state_hash = state.to_hash
313
- assert_kind_of Hash, state_hash
314
- assert_equal :bar, state_hash[:foo]
315
- end
316
-
317
- def test_json_generate
318
- assert_raise JSON::GeneratorError do
319
- assert_equal true, JSON.generate(["\xea"])
320
- end
321
- end
322
- end