scout 5.6.7 → 5.6.8.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/CHANGELOG.markdown +4 -0
  2. data/lib/scout/version.rb +1 -1
  3. data/vendor/json_pure/.gitignore +12 -0
  4. data/vendor/json_pure/.travis.yml +20 -0
  5. data/vendor/json_pure/CHANGES +120 -0
  6. data/vendor/json_pure/COPYING-json-jruby +57 -0
  7. data/vendor/json_pure/Gemfile +11 -0
  8. data/vendor/json_pure/README-json-jruby.markdown +33 -0
  9. data/vendor/json_pure/{README → README.rdoc} +7 -7
  10. data/vendor/json_pure/Rakefile +305 -185
  11. data/vendor/json_pure/VERSION +1 -1
  12. data/vendor/json_pure/diagrams/.keep +0 -0
  13. data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +181 -0
  14. data/vendor/json_pure/ext/json/ext/generator/depend +1 -0
  15. data/vendor/json_pure/ext/json/ext/generator/extconf.rb +4 -6
  16. data/vendor/json_pure/ext/json/ext/generator/generator.c +463 -369
  17. data/vendor/json_pure/ext/json/ext/generator/generator.h +44 -66
  18. data/vendor/json_pure/ext/json/ext/parser/depend +1 -0
  19. data/vendor/json_pure/ext/json/ext/parser/extconf.rb +3 -5
  20. data/vendor/json_pure/ext/json/ext/parser/parser.c +580 -311
  21. data/vendor/json_pure/ext/json/ext/parser/parser.h +14 -8
  22. data/vendor/json_pure/ext/json/ext/parser/parser.rl +242 -107
  23. data/vendor/json_pure/install.rb +8 -11
  24. data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +167 -0
  25. data/vendor/json_pure/java/src/json/ext/Generator.java +444 -0
  26. data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +232 -0
  27. data/vendor/json_pure/java/src/json/ext/GeneratorService.java +43 -0
  28. data/vendor/json_pure/java/src/json/ext/GeneratorState.java +543 -0
  29. data/vendor/json_pure/java/src/json/ext/OptionsReader.java +114 -0
  30. data/vendor/json_pure/java/src/json/ext/Parser.java +2644 -0
  31. data/vendor/json_pure/java/src/json/ext/Parser.rl +968 -0
  32. data/vendor/json_pure/java/src/json/ext/ParserService.java +35 -0
  33. data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +121 -0
  34. data/vendor/json_pure/java/src/json/ext/StringDecoder.java +167 -0
  35. data/vendor/json_pure/java/src/json/ext/StringEncoder.java +106 -0
  36. data/vendor/json_pure/java/src/json/ext/Utils.java +89 -0
  37. data/vendor/json_pure/json-java.gemspec +23 -0
  38. data/vendor/json_pure/json.gemspec +37 -0
  39. data/vendor/json_pure/json_pure.gemspec +39 -0
  40. data/vendor/json_pure/lib/json.rb +52 -0
  41. data/vendor/json_pure/lib/json/add/bigdecimal.rb +28 -0
  42. data/vendor/json_pure/lib/json/add/complex.rb +22 -0
  43. data/vendor/json_pure/lib/json/add/core.rb +9 -146
  44. data/vendor/json_pure/lib/json/add/date.rb +34 -0
  45. data/vendor/json_pure/lib/json/add/date_time.rb +50 -0
  46. data/vendor/json_pure/lib/json/add/exception.rb +31 -0
  47. data/vendor/json_pure/lib/json/add/ostruct.rb +31 -0
  48. data/vendor/json_pure/lib/json/add/range.rb +29 -0
  49. data/vendor/json_pure/lib/json/add/rational.rb +22 -0
  50. data/vendor/json_pure/lib/json/add/regexp.rb +30 -0
  51. data/vendor/json_pure/lib/json/add/struct.rb +30 -0
  52. data/vendor/json_pure/lib/json/add/symbol.rb +25 -0
  53. data/vendor/json_pure/lib/json/add/time.rb +38 -0
  54. data/vendor/json_pure/lib/json/common.rb +157 -67
  55. data/vendor/json_pure/lib/json/ext.rb +8 -2
  56. data/vendor/json_pure/lib/json/ext/.keep +0 -0
  57. data/vendor/json_pure/lib/json/generic_object.rb +70 -0
  58. data/vendor/json_pure/lib/json/pure.rb +8 -64
  59. data/vendor/json_pure/lib/json/pure/generator.rb +183 -113
  60. data/vendor/json_pure/lib/json/pure/parser.rb +118 -66
  61. data/vendor/json_pure/lib/json/version.rb +1 -1
  62. data/vendor/json_pure/tests/fixtures/fail18.json +1 -1
  63. data/vendor/json_pure/tests/setup_variant.rb +11 -0
  64. data/vendor/json_pure/tests/test_json.rb +233 -28
  65. data/vendor/json_pure/tests/test_json_addition.rb +68 -34
  66. data/vendor/json_pure/tests/test_json_encoding.rb +11 -14
  67. data/vendor/json_pure/tests/test_json_fixtures.rb +11 -10
  68. data/vendor/json_pure/tests/test_json_generate.rb +207 -7
  69. data/vendor/json_pure/tests/test_json_generic_object.rb +75 -0
  70. data/vendor/json_pure/tests/test_json_string_matching.rb +39 -0
  71. data/vendor/json_pure/tests/test_json_unicode.rb +3 -7
  72. data/vendor/json_pure/tools/fuzz.rb +1 -1
  73. data/vendor/json_pure/tools/server.rb +1 -0
  74. metadata +87 -94
  75. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +0 -52
  76. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +0 -1000
  77. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +0 -1001
  78. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +0 -900
  79. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +0 -901
  80. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +0 -1000
  81. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +0 -1001
  82. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +0 -261
  83. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +0 -1000
  84. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +0 -1001
  85. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +0 -1000
  86. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +0 -1001
  87. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +0 -1000
  88. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +0 -1001
  89. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +0 -262
  90. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +0 -1000
  91. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +0 -1001
  92. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +0 -82
  93. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +0 -34
  94. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +0 -900
  95. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +0 -901
  96. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +0 -81
  97. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +0 -1000
  98. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +0 -1001
  99. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +0 -82
  100. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +0 -1000
  101. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +0 -1001
  102. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +0 -82
  103. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +0 -1000
  104. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +0 -1001
  105. data/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +0 -82
  106. data/vendor/json_pure/benchmarks/generator2_benchmark.rb +0 -222
  107. data/vendor/json_pure/benchmarks/generator_benchmark.rb +0 -224
  108. data/vendor/json_pure/benchmarks/ohai.json +0 -1216
  109. data/vendor/json_pure/benchmarks/ohai.ruby +0 -1
  110. data/vendor/json_pure/benchmarks/parser2_benchmark.rb +0 -251
  111. data/vendor/json_pure/benchmarks/parser_benchmark.rb +0 -259
  112. data/vendor/json_pure/bin/edit_json.rb +0 -9
  113. data/vendor/json_pure/bin/prettify_json.rb +0 -75
  114. data/vendor/json_pure/lib/json/Array.xpm +0 -21
  115. data/vendor/json_pure/lib/json/FalseClass.xpm +0 -21
  116. data/vendor/json_pure/lib/json/Hash.xpm +0 -21
  117. data/vendor/json_pure/lib/json/Key.xpm +0 -73
  118. data/vendor/json_pure/lib/json/NilClass.xpm +0 -21
  119. data/vendor/json_pure/lib/json/Numeric.xpm +0 -28
  120. data/vendor/json_pure/lib/json/String.xpm +0 -96
  121. data/vendor/json_pure/lib/json/TrueClass.xpm +0 -21
  122. data/vendor/json_pure/lib/json/add/rails.rb +0 -58
  123. data/vendor/json_pure/lib/json/editor.rb +0 -1371
  124. data/vendor/json_pure/lib/json/json.xpm +0 -1499
  125. data/vendor/json_pure/tests/test_json_rails.rb +0 -144
@@ -2,15 +2,15 @@
2
2
  # -*- coding:utf-8 -*-
3
3
 
4
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
5
+ require File.join(File.dirname(__FILE__), 'setup_variant')
10
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
11
  require 'date'
12
12
 
13
- class TC_JSONAddition < Test::Unit::TestCase
13
+ class TestJSONAddition < Test::Unit::TestCase
14
14
  include JSON
15
15
 
16
16
  class A
@@ -23,7 +23,7 @@ class TC_JSONAddition < Test::Unit::TestCase
23
23
  def ==(other)
24
24
  a == other.a
25
25
  end
26
-
26
+
27
27
  def self.json_create(object)
28
28
  new(*object['args'])
29
29
  end
@@ -36,6 +36,15 @@ class TC_JSONAddition < Test::Unit::TestCase
36
36
  end
37
37
  end
38
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
+
39
48
  class B
40
49
  def self.json_creatable?
41
50
  false
@@ -55,7 +64,7 @@ class TC_JSONAddition < Test::Unit::TestCase
55
64
 
56
65
  def to_json(*args)
57
66
  {
58
- 'json_class' => 'TC_JSONAddition::Nix',
67
+ 'json_class' => 'TestJSONAddition::Nix',
59
68
  }.to_json(*args)
60
69
  end
61
70
  end
@@ -64,11 +73,19 @@ class TC_JSONAddition < Test::Unit::TestCase
64
73
  a = A.new(666)
65
74
  assert A.json_creatable?
66
75
  json = generate(a)
67
- a_again = JSON.parse(json)
76
+ a_again = JSON.parse(json, :create_additions => true)
68
77
  assert_kind_of a.class, a_again
69
78
  assert_equal a, a_again
70
79
  end
71
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
+
72
89
  def test_extended_json_disabled
73
90
  a = A.new(666)
74
91
  assert A.json_creatable?
@@ -79,7 +96,7 @@ class TC_JSONAddition < Test::Unit::TestCase
79
96
  a_hash = JSON.parse(json, :create_additions => false)
80
97
  assert_kind_of Hash, a_hash
81
98
  assert_equal(
82
- {"args"=>[666], "json_class"=>"TC_JSONAddition::A"}.sort_by { |k,| k },
99
+ {"args"=>[666], "json_class"=>"TestJSONAddition::A"}.sort_by { |k,| k },
83
100
  a_hash.sort_by { |k,| k }
84
101
  )
85
102
  end
@@ -88,14 +105,14 @@ class TC_JSONAddition < Test::Unit::TestCase
88
105
  b = B.new
89
106
  assert !B.json_creatable?
90
107
  json = generate(b)
91
- assert_equal({ "json_class"=>"TC_JSONAddition::B" }, JSON.parse(json))
108
+ assert_equal({ "json_class"=>"TestJSONAddition::B" }, JSON.parse(json))
92
109
  end
93
110
 
94
111
  def test_extended_json_fail2
95
112
  c = C.new
96
113
  assert !C.json_creatable?
97
114
  json = generate(c)
98
- assert_raises(ArgumentError, NameError) { JSON.parse(json) }
115
+ assert_raises(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) }
99
116
  end
100
117
 
101
118
  def test_raw_strings
@@ -110,10 +127,10 @@ class TC_JSONAddition < Test::Unit::TestCase
110
127
  json_raw_object = raw.to_json_raw_object
111
128
  hash = { 'json_class' => 'String', 'raw'=> raw_array }
112
129
  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)
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)
117
134
  assert_equal raw, raw_again
118
135
  end
119
136
 
@@ -121,17 +138,17 @@ class TC_JSONAddition < Test::Unit::TestCase
121
138
 
122
139
  def test_core
123
140
  t = Time.now
124
- assert_equal t.inspect, JSON(JSON(t)).inspect
141
+ assert_equal t, JSON(JSON(t), :create_additions => true)
125
142
  d = Date.today
126
- assert_equal d, JSON(JSON(d))
143
+ assert_equal d, JSON(JSON(d), :create_additions => true)
127
144
  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"))
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)
133
150
  s = MyJsonStruct.new 4711, 'foot'
134
- assert_equal s, JSON(JSON(s))
151
+ assert_equal s, JSON(JSON(s), :create_additions => true)
135
152
  struct = Struct.new :foo, :bar
136
153
  s = struct.new 4711, 'foot'
137
154
  assert_raises(JSONError) { JSON(s) }
@@ -139,24 +156,41 @@ class TC_JSONAddition < Test::Unit::TestCase
139
156
  raise TypeError, "test me"
140
157
  rescue TypeError => e
141
158
  e_json = JSON.generate e
142
- e_again = JSON e_json
159
+ e_again = JSON e_json, :create_additions => true
143
160
  assert_kind_of TypeError, e_again
144
161
  assert_equal e.message, e_again.message
145
162
  assert_equal e.backtrace, e_again.backtrace
146
163
  end
147
- assert_equal(/foo/, JSON(JSON(/foo/)))
148
- assert_equal(/foo/i, JSON(JSON(/foo/i)))
164
+ assert_equal(/foo/, JSON(JSON(/foo/), :create_additions => true))
165
+ assert_equal(/foo/i, JSON(JSON(/foo/i), :create_additions => true))
149
166
  end
150
167
 
151
168
  def test_utc_datetime
152
169
  now = Time.now
153
- d = DateTime.parse(now.to_s) # usual case
154
- assert d, JSON.parse(d.to_json)
170
+ d = DateTime.parse(now.to_s, :create_additions => true) # usual case
171
+ assert_equal d, JSON.parse(d.to_json, :create_additions => true)
155
172
  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)
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)
161
195
  end
162
196
  end
@@ -1,33 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
2
+ # encoding: utf-8
3
3
 
4
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'
5
+ require File.join(File.dirname(__FILE__), 'setup_variant')
11
6
 
12
- class TC_JSONEncoding < Test::Unit::TestCase
7
+ class TestJSONEncoding < Test::Unit::TestCase
13
8
  include JSON
14
9
 
15
10
  def setup
16
11
  @utf_8 = '["© ≠ €!"]'
17
12
  @parsed = [ "© ≠ €!" ]
18
- @utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
19
13
  @generated = '["\u00a9 \u2260 \u20ac!"]'
20
- if defined?(::Encoding)
14
+ if String.method_defined?(:encode)
15
+ @utf_16_data = [@parsed.first.encode('utf-16be', 'utf-8')]
21
16
  @utf_8_ascii_8bit = @utf_8.dup.force_encoding(Encoding::ASCII_8BIT)
22
- @utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
17
+ @utf_16be = @utf_8.encode('utf-16be', 'utf-8')
23
18
  @utf_16be_ascii_8bit = @utf_16be.dup.force_encoding(Encoding::ASCII_8BIT)
24
- @utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
19
+ @utf_16le = @utf_8.encode('utf-16le', 'utf-8')
25
20
  @utf_16le_ascii_8bit = @utf_16le.dup.force_encoding(Encoding::ASCII_8BIT)
26
- @utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
21
+ @utf_32be = @utf_8.encode('utf-32be', 'utf-8')
27
22
  @utf_32be_ascii_8bit = @utf_32be.dup.force_encoding(Encoding::ASCII_8BIT)
28
- @utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
23
+ @utf_32le = @utf_8.encode('utf-32le', 'utf-8')
29
24
  @utf_32le_ascii_8bit = @utf_32le.dup.force_encoding(Encoding::ASCII_8BIT)
30
25
  else
26
+ require 'iconv'
27
+ @utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
31
28
  @utf_8_ascii_8bit = @utf_8.dup
32
29
  @utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
33
30
  @utf_16be_ascii_8bit = @utf_16be.dup
@@ -1,14 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
2
+ # encoding: utf-8
3
3
 
4
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
5
+ require File.join(File.dirname(__FILE__), 'setup_variant')
10
6
 
11
- class TC_JSONFixtures < Test::Unit::TestCase
7
+ class TestJSONFixtures < Test::Unit::TestCase
12
8
  def setup
13
9
  fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
14
10
  passed, failed = Dir[fixtures].partition { |f| f['pass'] }
@@ -18,15 +14,20 @@ class TC_JSONFixtures < Test::Unit::TestCase
18
14
 
19
15
  def test_passing
20
16
  for name, source in @passed
21
- assert JSON.parse(source),
22
- "Did not pass for fixture '#{name}'"
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
23
24
  end
24
25
  end
25
26
 
26
27
  def test_failing
27
28
  for name, source in @failed
28
29
  assert_raises(JSON::ParserError, JSON::NestingError,
29
- "Did not fail for fixture '#{name}'") do
30
+ "Did not fail for fixture '#{name}': #{source.inspect}") do
30
31
  JSON.parse(source)
31
32
  end
32
33
  end
@@ -1,14 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
2
+ # encoding: utf-8
3
3
 
4
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
5
+ require File.join(File.dirname(__FILE__), 'setup_variant')
10
6
 
11
- class TC_JSONGenerate < Test::Unit::TestCase
7
+ class TestJSONGenerate < Test::Unit::TestCase
12
8
  include JSON
13
9
 
14
10
  def setup
@@ -47,6 +43,8 @@ EOT
47
43
  def test_generate
48
44
  json = generate(@hash)
49
45
  assert_equal(JSON.parse(@json2), JSON.parse(json))
46
+ json = JSON[@hash]
47
+ assert_equal(JSON.parse(@json2), JSON.parse(json))
50
48
  parsed_json = parse(json)
51
49
  assert_equal(@hash, parsed_json)
52
50
  json = generate({1=>2})
@@ -54,10 +52,12 @@ EOT
54
52
  parsed_json = parse(json)
55
53
  assert_equal({"1"=>2}, parsed_json)
56
54
  assert_raise(GeneratorError) { generate(666) }
55
+ assert_equal '666', generate(666, :quirks_mode => true)
57
56
  end
58
57
 
59
58
  def test_generate_pretty
60
59
  json = pretty_generate(@hash)
60
+ # hashes aren't (insertion) ordered on every ruby implementation assert_equal(@json3, json)
61
61
  assert_equal(JSON.parse(@json3), JSON.parse(json))
62
62
  parsed_json = parse(json)
63
63
  assert_equal(@hash, parsed_json)
@@ -70,6 +70,7 @@ EOT
70
70
  parsed_json = parse(json)
71
71
  assert_equal({"1"=>2}, parsed_json)
72
72
  assert_raise(GeneratorError) { pretty_generate(666) }
73
+ assert_equal '666', pretty_generate(666, :quirks_mode => true)
73
74
  end
74
75
 
75
76
  def test_fast_generate
@@ -82,6 +83,23 @@ EOT
82
83
  parsed_json = parse(json)
83
84
  assert_equal({"1"=>2}, parsed_json)
84
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)
85
103
  end
86
104
 
87
105
  def test_states
@@ -102,6 +120,57 @@ EOT
102
120
  assert s[:check_circular?]
103
121
  end
104
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
+
105
174
  def test_allow_nan
106
175
  assert_raises(GeneratorError) { generate([JSON::NaN]) }
107
176
  assert_equal '[NaN]', generate([JSON::NaN], :allow_nan => true)
@@ -119,4 +188,135 @@ EOT
119
188
  assert_raises(GeneratorError) { pretty_generate([JSON::MinusInfinity]) }
120
189
  assert_equal "[\n -Infinity\n]", pretty_generate([JSON::MinusInfinity], :allow_nan => true)
121
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
122
322
  end