json_pure 1.4.6 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGES +6 -0
  2. data/COPYING-json-jruby +57 -0
  3. data/README-json-jruby.markdown +33 -0
  4. data/Rakefile +224 -119
  5. data/VERSION +1 -1
  6. data/benchmarks/generator2_benchmark.rb +1 -1
  7. data/benchmarks/generator_benchmark.rb +1 -1
  8. data/ext/json/ext/generator/generator.c +20 -20
  9. data/ext/json/ext/generator/generator.h +7 -7
  10. data/ext/json/ext/parser/extconf.rb +1 -0
  11. data/ext/json/ext/parser/parser.c +122 -88
  12. data/ext/json/ext/parser/parser.h +7 -0
  13. data/ext/json/ext/parser/parser.rl +54 -20
  14. data/java/lib/bytelist-1.0.6.jar +0 -0
  15. data/java/lib/jcodings.jar +0 -0
  16. data/java/src/json/ext/ByteListTranscoder.java +167 -0
  17. data/java/src/json/ext/Generator.java +441 -0
  18. data/java/src/json/ext/GeneratorMethods.java +231 -0
  19. data/java/src/json/ext/GeneratorService.java +42 -0
  20. data/java/src/json/ext/GeneratorState.java +473 -0
  21. data/java/src/json/ext/OptionsReader.java +119 -0
  22. data/java/src/json/ext/Parser.java +2295 -0
  23. data/java/src/json/ext/Parser.rl +825 -0
  24. data/java/src/json/ext/ParserService.java +34 -0
  25. data/java/src/json/ext/RuntimeInfo.java +119 -0
  26. data/java/src/json/ext/StringDecoder.java +166 -0
  27. data/java/src/json/ext/StringEncoder.java +106 -0
  28. data/java/src/json/ext/Utils.java +89 -0
  29. data/json-java.gemspec +20 -0
  30. data/lib/json/add/core.rb +1 -2
  31. data/lib/json/add/rails.rb +4 -54
  32. data/lib/json/common.rb +36 -8
  33. data/lib/json/editor.rb +1 -3
  34. data/lib/json/ext.rb +2 -2
  35. data/lib/json/pure.rb +2 -64
  36. data/lib/json/pure/generator.rb +10 -8
  37. data/lib/json/pure/parser.rb +23 -12
  38. data/lib/json/version.rb +1 -1
  39. data/tests/setup_variant.rb +11 -0
  40. data/tests/test_json.rb +1 -5
  41. data/tests/test_json_addition.rb +14 -9
  42. data/tests/test_json_encoding.rb +9 -12
  43. data/tests/test_json_fixtures.rb +9 -8
  44. data/tests/test_json_generate.rb +3 -5
  45. data/tests/test_json_string_matching.rb +40 -0
  46. data/tests/test_json_unicode.rb +1 -5
  47. metadata +51 -13
  48. data/tests/test_json_rails.rb +0 -144
@@ -2,12 +2,8 @@
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
10
- require 'json/add/core'
5
+ require File.join(File.dirname(__FILE__), 'setup_variant')
6
+ load 'json/add/core.rb'
11
7
  require 'date'
12
8
 
13
9
  class TC_JSONAddition < Test::Unit::TestCase
@@ -36,6 +32,15 @@ class TC_JSONAddition < Test::Unit::TestCase
36
32
  end
37
33
  end
38
34
 
35
+ class A2 < A
36
+ def to_json(*args)
37
+ {
38
+ 'json_class' => self.class.name,
39
+ 'args' => [ @a ],
40
+ }.to_json(*args)
41
+ end
42
+ end
43
+
39
44
  class B
40
45
  def self.json_creatable?
41
46
  false
@@ -110,9 +115,9 @@ class TC_JSONAddition < Test::Unit::TestCase
110
115
  json_raw_object = raw.to_json_raw_object
111
116
  hash = { 'json_class' => 'String', 'raw'=> raw_array }
112
117
  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
118
+ assert_match(/\A\{.*\}\Z/, json)
119
+ assert_match(/"json_class":"String"/, json)
120
+ 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
121
  raw_again = JSON.parse(json)
117
122
  assert_equal raw, raw_again
118
123
  end
@@ -2,12 +2,7 @@
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
10
- require 'iconv'
5
+ require File.join(File.dirname(__FILE__), 'setup_variant')
11
6
 
12
7
  class TC_JSONEncoding < Test::Unit::TestCase
13
8
  include JSON
@@ -15,19 +10,21 @@ class TC_JSONEncoding < Test::Unit::TestCase
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
@@ -2,11 +2,7 @@
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
 
11
7
  class TC_JSONFixtures < Test::Unit::TestCase
12
8
  def setup
@@ -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
@@ -2,11 +2,7 @@
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
 
11
7
  class TC_JSONGenerate < Test::Unit::TestCase
12
8
  include JSON
@@ -84,6 +80,8 @@ EOT
84
80
  assert_raise(GeneratorError) { fast_generate(666) }
85
81
  end
86
82
 
83
+
84
+
87
85
  def test_states
88
86
  json = generate({1=>2}, nil)
89
87
  assert_equal('{"1":2}', json)
@@ -0,0 +1,40 @@
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 'stringio'
7
+ require 'time'
8
+
9
+ class TestJsonStringMatching < Test::Unit::TestCase
10
+ include JSON
11
+
12
+ class TestTime < ::Time
13
+ def self.json_create(string)
14
+ Time.parse(string)
15
+ end
16
+
17
+ def to_json(*)
18
+ %{"#{strftime('%FT%T%z')}"}
19
+ end
20
+
21
+ def ==(other)
22
+ to_i == other.to_i
23
+ end
24
+ end
25
+
26
+ def test_match_date
27
+ t = TestTime.new
28
+ t_json = [ t ].to_json
29
+ assert_equal [ t ],
30
+ JSON.parse(t_json,
31
+ :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
32
+ assert_equal [ t.strftime('%FT%T%z') ],
33
+ JSON.parse(t_json,
34
+ :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
35
+ assert_equal [ t.strftime('%FT%T%z') ],
36
+ JSON.parse(t_json,
37
+ :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime },
38
+ :create_additions => false)
39
+ end
40
+ end
@@ -2,11 +2,7 @@
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
 
11
7
  class TC_JSONUnicode < Test::Unit::TestCase
12
8
  include JSON
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_pure
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ hash: 3
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 5
9
+ - 0
10
+ version: 1.5.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Florian Frank
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-08-09 00:00:00 +02:00
18
+ date: 2011-01-22 00:00:00 +01:00
13
19
  default_executable: edit_json.rb
14
20
  dependencies: []
15
21
 
@@ -75,8 +81,25 @@ files:
75
81
  - ext/json/ext/parser/parser.h
76
82
  - ext/json/ext/parser/parser.c
77
83
  - Rakefile
84
+ - README-json-jruby.markdown
78
85
  - tools/fuzz.rb
79
86
  - tools/server.rb
87
+ - java/src/json/ext/Parser.rl
88
+ - java/src/json/ext/StringDecoder.java
89
+ - java/src/json/ext/GeneratorMethods.java
90
+ - java/src/json/ext/StringEncoder.java
91
+ - java/src/json/ext/Generator.java
92
+ - java/src/json/ext/GeneratorService.java
93
+ - java/src/json/ext/Utils.java
94
+ - java/src/json/ext/ByteListTranscoder.java
95
+ - java/src/json/ext/RuntimeInfo.java
96
+ - java/src/json/ext/ParserService.java
97
+ - java/src/json/ext/OptionsReader.java
98
+ - java/src/json/ext/GeneratorState.java
99
+ - java/src/json/ext/Parser.java
100
+ - java/lib/bytelist-1.0.6.jar
101
+ - java/lib/jcodings.jar
102
+ - COPYING-json-jruby
80
103
  - lib/json.rb
81
104
  - lib/json/json.xpm
82
105
  - lib/json/Key.xpm
@@ -132,13 +155,22 @@ files:
132
155
  - tests/fixtures/fail27.json
133
156
  - tests/fixtures/fail10.json
134
157
  - tests/fixtures/fail23.json
135
- - tests/test_json_rails.rb
136
158
  - tests/test_json.rb
159
+ - tests/test_json_string_matching.rb
137
160
  - tests/test_json_generate.rb
138
161
  - tests/test_json_unicode.rb
162
+ - tests/setup_variant.rb
139
163
  - tests/test_json_fixtures.rb
140
164
  - COPYING
165
+ - json-java.gemspec
141
166
  - install.rb
167
+ - ./tests/test_json_encoding.rb
168
+ - ./tests/test_json_addition.rb
169
+ - ./tests/test_json.rb
170
+ - ./tests/test_json_string_matching.rb
171
+ - ./tests/test_json_generate.rb
172
+ - ./tests/test_json_unicode.rb
173
+ - ./tests/test_json_fixtures.rb
142
174
  has_rdoc: true
143
175
  homepage: http://flori.github.com/json
144
176
  licenses: []
@@ -152,29 +184,35 @@ rdoc_options:
152
184
  require_paths:
153
185
  - lib
154
186
  required_ruby_version: !ruby/object:Gem::Requirement
187
+ none: false
155
188
  requirements:
156
189
  - - ">="
157
190
  - !ruby/object:Gem::Version
191
+ hash: 3
192
+ segments:
193
+ - 0
158
194
  version: "0"
159
- version:
160
195
  required_rubygems_version: !ruby/object:Gem::Requirement
196
+ none: false
161
197
  requirements:
162
198
  - - ">="
163
199
  - !ruby/object:Gem::Version
200
+ hash: 3
201
+ segments:
202
+ - 0
164
203
  version: "0"
165
- version:
166
204
  requirements: []
167
205
 
168
206
  rubyforge_project: json
169
- rubygems_version: 1.3.5
207
+ rubygems_version: 1.3.7
170
208
  signing_key:
171
209
  specification_version: 3
172
210
  summary: JSON Implementation for Ruby
173
211
  test_files:
174
- - tests/test_json_encoding.rb
175
- - tests/test_json_addition.rb
176
- - tests/test_json_rails.rb
177
- - tests/test_json.rb
178
- - tests/test_json_generate.rb
179
- - tests/test_json_unicode.rb
180
- - tests/test_json_fixtures.rb
212
+ - ./tests/test_json_encoding.rb
213
+ - ./tests/test_json_addition.rb
214
+ - ./tests/test_json.rb
215
+ - ./tests/test_json_string_matching.rb
216
+ - ./tests/test_json_generate.rb
217
+ - ./tests/test_json_unicode.rb
218
+ - ./tests/test_json_fixtures.rb
@@ -1,144 +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/rails'
11
- require 'date'
12
-
13
- class TC_JSONRails < 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 to_json(*args)
53
- {
54
- 'json_class' => 'TC_JSONRails::Nix',
55
- }.to_json(*args)
56
- end
57
- end
58
-
59
- class D
60
- def initialize
61
- @foo = 666
62
- end
63
-
64
- attr_reader :foo
65
-
66
- def ==(other)
67
- foo == other.foo
68
- end
69
- end
70
-
71
- def test_extended_json
72
- a = A.new(666)
73
- assert A.json_creatable?
74
- assert_equal 666, a.a
75
- json = generate(a)
76
- a_again = JSON.parse(json)
77
- assert_kind_of a.class, a_again
78
- assert_equal a, a_again
79
- assert_equal 666, a_again.a
80
- end
81
-
82
- def test_extended_json_generic_object
83
- d = D.new
84
- assert D.json_creatable?
85
- assert_equal 666, d.foo
86
- json = generate(d)
87
- d_again = JSON.parse(json)
88
- assert_kind_of d.class, d_again
89
- assert_equal d, d_again
90
- assert_equal 666, d_again.foo
91
- end
92
-
93
- def test_extended_json_disabled
94
- a = A.new(666)
95
- assert A.json_creatable?
96
- json = generate(a)
97
- a_again = JSON.parse(json, :create_additions => true)
98
- assert_kind_of a.class, a_again
99
- assert_equal a, a_again
100
- a_hash = JSON.parse(json, :create_additions => false)
101
- assert_kind_of Hash, a_hash
102
- assert_equal(
103
- {"args"=>[666], "json_class"=>"TC_JSONRails::A"}.sort_by { |k,| k },
104
- a_hash.sort_by { |k,| k }
105
- )
106
- end
107
-
108
- def test_extended_json_fail1
109
- b = B.new
110
- assert !B.json_creatable?
111
- json = generate(b)
112
- assert_equal({ 'json_class' => B.name }, JSON.parse(json))
113
- end
114
-
115
- def test_extended_json_fail2
116
- c = C.new # with rails addition all objects are theoretically creatable
117
- assert C.json_creatable?
118
- json = generate(c)
119
- assert_raises(ArgumentError, NameError) { JSON.parse(json) }
120
- end
121
-
122
- def test_raw_strings
123
- raw = ''
124
- raw.respond_to?(:encode!) and raw.encode!(Encoding::ASCII_8BIT)
125
- raw_array = []
126
- for i in 0..255
127
- raw << i
128
- raw_array << i
129
- end
130
- json = raw.to_json_raw
131
- json_raw_object = raw.to_json_raw_object
132
- hash = { 'json_class' => 'String', 'raw'=> raw_array }
133
- assert_equal hash, json_raw_object
134
- assert_match /\A\{.*\}\Z/, json
135
- assert_match /"json_class":"String"/, json
136
- assert_match /"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json
137
- raw_again = JSON.parse(json)
138
- assert_equal raw, raw_again
139
- end
140
-
141
- def test_symbol
142
- assert_equal '"foo"', :foo.to_json # we don't want an object here
143
- end
144
- end