json_pure 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +16 -0
- data/Rakefile +80 -75
- data/TODO +1 -1
- data/VERSION +1 -1
- data/bin/edit_json.rb +11 -11
- data/data/prototype.js +2764 -1095
- data/ext/json/ext/generator/generator.c +17 -4
- data/ext/json/ext/parser/parser.c +95 -73
- data/ext/json/ext/parser/parser.rl +34 -12
- data/lib/json.rb +14 -12
- data/lib/json/add/core.rb +2 -1
- data/lib/json/add/rails.rb +6 -0
- data/lib/json/common.rb +9 -0
- data/lib/json/editor.rb +1363 -1293
- data/lib/json/pure/parser.rb +7 -3
- data/lib/json/version.rb +1 -1
- data/tests/runner.rb +2 -0
- data/tests/test_json_addition.rb +19 -0
- data/tests/test_json_rails.rb +114 -0
- metadata +87 -85
data/lib/json/pure/parser.rb
CHANGED
|
@@ -58,6 +58,9 @@ module JSON
|
|
|
58
58
|
# * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
|
|
59
59
|
# defiance of RFC 4627 to be parsed by the Parser. This option defaults
|
|
60
60
|
# to false.
|
|
61
|
+
# * *create_additions*: If set to false, the Parser doesn't create
|
|
62
|
+
# additions even if a matchin class and create_id was found. This option
|
|
63
|
+
# defaults to true.
|
|
61
64
|
def initialize(source, opts = {})
|
|
62
65
|
super
|
|
63
66
|
if !opts.key?(:max_nesting) # defaults to 19
|
|
@@ -68,7 +71,9 @@ module JSON
|
|
|
68
71
|
@max_nesting = 0
|
|
69
72
|
end
|
|
70
73
|
@allow_nan = !!opts[:allow_nan]
|
|
71
|
-
|
|
74
|
+
ca = true
|
|
75
|
+
ca = opts[:create_additions] if opts.key?(:create_additions)
|
|
76
|
+
@create_id = ca ? JSON.create_id : nil
|
|
72
77
|
end
|
|
73
78
|
|
|
74
79
|
alias source string
|
|
@@ -235,11 +240,10 @@ module JSON
|
|
|
235
240
|
if delim
|
|
236
241
|
raise ParserError, "expected next name, value pair in object at '#{peek(20)}'!"
|
|
237
242
|
end
|
|
238
|
-
if klassname = result[@create_id]
|
|
243
|
+
if @create_id and klassname = result[@create_id]
|
|
239
244
|
klass = JSON.deep_const_get klassname
|
|
240
245
|
break unless klass and klass.json_creatable?
|
|
241
246
|
result = klass.json_create(result)
|
|
242
|
-
result
|
|
243
247
|
end
|
|
244
248
|
break
|
|
245
249
|
when skip(IGNORE)
|
data/lib/json/version.rb
CHANGED
data/tests/runner.rb
CHANGED
|
@@ -8,6 +8,7 @@ require 'test_json'
|
|
|
8
8
|
require 'test_json_generate'
|
|
9
9
|
require 'test_json_unicode'
|
|
10
10
|
require 'test_json_addition'
|
|
11
|
+
require 'test_json_rails'
|
|
11
12
|
require 'test_json_fixtures'
|
|
12
13
|
|
|
13
14
|
class TS_AllTests
|
|
@@ -17,6 +18,7 @@ class TS_AllTests
|
|
|
17
18
|
suite << TC_JSON.suite
|
|
18
19
|
suite << TC_JSONUnicode.suite
|
|
19
20
|
suite << TC_JSONAddition.suite
|
|
21
|
+
suite << TC_JSONRails.suite
|
|
20
22
|
suite << TC_JSONFixtures.suite
|
|
21
23
|
end
|
|
22
24
|
end
|
data/tests/test_json_addition.rb
CHANGED
|
@@ -39,6 +39,10 @@ class TC_JSONAddition < Test::Unit::TestCase
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
class C
|
|
42
|
+
def self.json_creatable?
|
|
43
|
+
false
|
|
44
|
+
end
|
|
45
|
+
|
|
42
46
|
def to_json(*args)
|
|
43
47
|
{
|
|
44
48
|
'json_class' => 'TC_JSONAddition::Nix',
|
|
@@ -59,6 +63,21 @@ class TC_JSONAddition < Test::Unit::TestCase
|
|
|
59
63
|
assert_equal a, a_again
|
|
60
64
|
end
|
|
61
65
|
|
|
66
|
+
def test_extended_json_disabled
|
|
67
|
+
a = A.new(666)
|
|
68
|
+
assert A.json_creatable?
|
|
69
|
+
json = generate(a)
|
|
70
|
+
a_again = JSON.parse(json, :create_additions => true)
|
|
71
|
+
assert_kind_of a.class, a_again
|
|
72
|
+
assert_equal a, a_again
|
|
73
|
+
a_hash = JSON.parse(json, :create_additions => false)
|
|
74
|
+
assert_kind_of Hash, a_hash
|
|
75
|
+
assert_equal(
|
|
76
|
+
{"args"=>[666], "json_class"=>"TC_JSONAddition::A"}.sort_by { |k,| k },
|
|
77
|
+
a_hash.sort_by { |k,| k }
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
|
|
62
81
|
def test_extended_json_fail
|
|
63
82
|
b = B.new
|
|
64
83
|
assert !B.json_creatable?
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
require 'json/add/rails'
|
|
5
|
+
require 'date'
|
|
6
|
+
|
|
7
|
+
class TC_JSONRails < Test::Unit::TestCase
|
|
8
|
+
include JSON
|
|
9
|
+
|
|
10
|
+
class A
|
|
11
|
+
def initialize(a)
|
|
12
|
+
@a = a
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
attr_reader :a
|
|
16
|
+
|
|
17
|
+
def ==(other)
|
|
18
|
+
a == other.a
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.json_create(object)
|
|
22
|
+
new(*object['args'])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_json(*args)
|
|
26
|
+
{
|
|
27
|
+
'json_class' => self.class.name,
|
|
28
|
+
'args' => [ @a ],
|
|
29
|
+
}.to_json(*args)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class B
|
|
34
|
+
def to_json(*args)
|
|
35
|
+
{
|
|
36
|
+
'json_class' => self.class.name,
|
|
37
|
+
}.to_json(*args)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class C
|
|
42
|
+
def to_json(*args)
|
|
43
|
+
{
|
|
44
|
+
'json_class' => 'TC_JSONRails::Nix',
|
|
45
|
+
}.to_json(*args)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def setup
|
|
50
|
+
$KCODE = 'UTF8'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_extended_json
|
|
54
|
+
a = A.new(666)
|
|
55
|
+
assert A.json_creatable?
|
|
56
|
+
json = generate(a)
|
|
57
|
+
a_again = JSON.parse(json)
|
|
58
|
+
assert_kind_of a.class, a_again
|
|
59
|
+
assert_equal a, a_again
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_extended_json_disabled
|
|
63
|
+
a = A.new(666)
|
|
64
|
+
assert A.json_creatable?
|
|
65
|
+
json = generate(a)
|
|
66
|
+
a_again = JSON.parse(json, :create_additions => true)
|
|
67
|
+
assert_kind_of a.class, a_again
|
|
68
|
+
assert_equal a, a_again
|
|
69
|
+
a_hash = JSON.parse(json, :create_additions => false)
|
|
70
|
+
assert_kind_of Hash, a_hash
|
|
71
|
+
assert_equal(
|
|
72
|
+
{"args"=>[666], "json_class"=>"TC_JSONRails::A"}.sort_by { |k,| k },
|
|
73
|
+
a_hash.sort_by { |k,| k }
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_extended_json_fail
|
|
78
|
+
b = B.new
|
|
79
|
+
assert !B.json_creatable?
|
|
80
|
+
json = generate(b)
|
|
81
|
+
assert_equal({ 'json_class' => B.name }, JSON.parse(json))
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_extended_json_fail
|
|
85
|
+
c = C.new # with rails addition all objects are theoretically creatable
|
|
86
|
+
assert C.json_creatable?
|
|
87
|
+
json = generate(c)
|
|
88
|
+
assert_raises(ArgumentError) { JSON.parse(json) }
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_raw_strings
|
|
92
|
+
raw = ''
|
|
93
|
+
raw_array = []
|
|
94
|
+
for i in 0..255
|
|
95
|
+
raw << i
|
|
96
|
+
raw_array << i
|
|
97
|
+
end
|
|
98
|
+
json = raw.to_json_raw
|
|
99
|
+
json_raw_object = raw.to_json_raw_object
|
|
100
|
+
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
|
101
|
+
assert_equal hash, json_raw_object
|
|
102
|
+
json_raw = <<EOT.chomp
|
|
103
|
+
{\"json_class\":\"String\",\"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]}
|
|
104
|
+
EOT
|
|
105
|
+
# "
|
|
106
|
+
assert_equal json_raw, json
|
|
107
|
+
raw_again = JSON.parse(json)
|
|
108
|
+
assert_equal raw, raw_again
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_symbol
|
|
112
|
+
assert_equal '"foo"', JSON(:foo) # we don't want an object here
|
|
113
|
+
end
|
|
114
|
+
end
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
|
-
rubygems_version: 0.
|
|
2
|
+
rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: json_pure
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 1.1.
|
|
7
|
-
date: 2007-
|
|
6
|
+
version: 1.1.2
|
|
7
|
+
date: 2007-11-27 00:00:00 +01:00
|
|
8
8
|
summary: A JSON implementation in Ruby
|
|
9
9
|
require_paths:
|
|
10
10
|
- lib
|
|
@@ -25,109 +25,111 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
|
25
25
|
platform: ruby
|
|
26
26
|
signing_key:
|
|
27
27
|
cert_chain:
|
|
28
|
+
post_install_message:
|
|
28
29
|
authors:
|
|
29
30
|
- Florian Frank
|
|
30
31
|
files:
|
|
31
|
-
- bin
|
|
32
|
-
- VERSION
|
|
33
|
-
- TODO
|
|
34
|
-
- tests
|
|
35
|
-
- RUBY
|
|
36
|
-
- GPL
|
|
37
32
|
- install.rb
|
|
38
|
-
- ext
|
|
39
|
-
- diagrams
|
|
40
|
-
- benchmarks
|
|
41
|
-
- Rakefile
|
|
42
|
-
- data
|
|
43
33
|
- lib
|
|
34
|
+
- lib/json.rb
|
|
35
|
+
- lib/json
|
|
36
|
+
- lib/json/Array.xpm
|
|
37
|
+
- lib/json/FalseClass.xpm
|
|
38
|
+
- lib/json/json.xpm
|
|
39
|
+
- lib/json/editor.rb
|
|
40
|
+
- lib/json/Hash.xpm
|
|
41
|
+
- lib/json/Key.xpm
|
|
42
|
+
- lib/json/common.rb
|
|
43
|
+
- lib/json/String.xpm
|
|
44
|
+
- lib/json/pure
|
|
45
|
+
- lib/json/pure/generator.rb
|
|
46
|
+
- lib/json/pure/parser.rb
|
|
47
|
+
- lib/json/Numeric.xpm
|
|
48
|
+
- lib/json/ext.rb
|
|
49
|
+
- lib/json/pure.rb
|
|
50
|
+
- lib/json/NilClass.xpm
|
|
51
|
+
- lib/json/add
|
|
52
|
+
- lib/json/add/rails.rb
|
|
53
|
+
- lib/json/add/core.rb
|
|
54
|
+
- lib/json/TrueClass.xpm
|
|
55
|
+
- lib/json/version.rb
|
|
56
|
+
- ext
|
|
57
|
+
- ext/json
|
|
58
|
+
- ext/json/ext
|
|
59
|
+
- ext/json/ext/parser
|
|
60
|
+
- ext/json/ext/parser/unicode.h
|
|
61
|
+
- ext/json/ext/parser/parser.c
|
|
62
|
+
- ext/json/ext/parser/extconf.rb
|
|
63
|
+
- ext/json/ext/parser/unicode.c
|
|
64
|
+
- ext/json/ext/parser/parser.rl
|
|
65
|
+
- ext/json/ext/generator
|
|
66
|
+
- ext/json/ext/generator/unicode.h
|
|
67
|
+
- ext/json/ext/generator/extconf.rb
|
|
68
|
+
- ext/json/ext/generator/generator.c
|
|
69
|
+
- ext/json/ext/generator/unicode.c
|
|
44
70
|
- README
|
|
45
|
-
-
|
|
71
|
+
- diagrams
|
|
46
72
|
- CHANGES
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
- tests
|
|
73
|
+
- RUBY
|
|
74
|
+
- TODO
|
|
75
|
+
- VERSION
|
|
76
|
+
- tests
|
|
51
77
|
- tests/test_json.rb
|
|
52
|
-
- tests/fixtures
|
|
53
|
-
- tests/test_json_unicode.rb
|
|
54
|
-
- tests/test_json_generate.rb
|
|
55
78
|
- tests/test_json_addition.rb
|
|
56
|
-
- tests/fixtures
|
|
57
|
-
- tests/fixtures/
|
|
58
|
-
- tests/fixtures/
|
|
59
|
-
- tests/fixtures/pass17.json
|
|
60
|
-
- tests/fixtures/fail28.json
|
|
61
|
-
- tests/fixtures/fail25.json
|
|
62
|
-
- tests/fixtures/fail9.json
|
|
63
|
-
- tests/fixtures/fail20.json
|
|
64
|
-
- tests/fixtures/fail24.json
|
|
65
|
-
- tests/fixtures/fail14.json
|
|
66
|
-
- tests/fixtures/fail4.json
|
|
67
|
-
- tests/fixtures/fail7.json
|
|
79
|
+
- tests/fixtures
|
|
80
|
+
- tests/fixtures/fail11.json
|
|
81
|
+
- tests/fixtures/fail5.json
|
|
68
82
|
- tests/fixtures/fail10.json
|
|
83
|
+
- tests/fixtures/fail3.json
|
|
69
84
|
- tests/fixtures/pass15.json
|
|
70
|
-
- tests/fixtures/
|
|
71
|
-
- tests/fixtures/
|
|
85
|
+
- tests/fixtures/fail9.json
|
|
86
|
+
- tests/fixtures/fail22.json
|
|
72
87
|
- tests/fixtures/fail6.json
|
|
73
|
-
- tests/fixtures/
|
|
74
|
-
- tests/fixtures/
|
|
75
|
-
- tests/fixtures/
|
|
88
|
+
- tests/fixtures/pass2.json
|
|
89
|
+
- tests/fixtures/fail20.json
|
|
90
|
+
- tests/fixtures/fail19.json
|
|
91
|
+
- tests/fixtures/fail12.json
|
|
92
|
+
- tests/fixtures/fail7.json
|
|
93
|
+
- tests/fixtures/fail4.json
|
|
76
94
|
- tests/fixtures/fail1.json
|
|
77
|
-
- tests/fixtures/
|
|
78
|
-
- tests/fixtures/
|
|
95
|
+
- tests/fixtures/fail24.json
|
|
96
|
+
- tests/fixtures/fail21.json
|
|
79
97
|
- tests/fixtures/pass1.json
|
|
80
|
-
- tests/fixtures/
|
|
98
|
+
- tests/fixtures/fail2.json
|
|
99
|
+
- tests/fixtures/fail25.json
|
|
100
|
+
- tests/fixtures/pass16.json
|
|
81
101
|
- tests/fixtures/pass3.json
|
|
102
|
+
- tests/fixtures/fail18.json
|
|
103
|
+
- tests/fixtures/fail28.json
|
|
104
|
+
- tests/fixtures/fail13.json
|
|
105
|
+
- tests/fixtures/fail27.json
|
|
106
|
+
- tests/fixtures/pass17.json
|
|
107
|
+
- tests/fixtures/pass26.json
|
|
108
|
+
- tests/fixtures/fail23.json
|
|
109
|
+
- tests/fixtures/fail14.json
|
|
82
110
|
- tests/fixtures/fail8.json
|
|
83
|
-
- tests/
|
|
84
|
-
- tests/
|
|
85
|
-
- tests/
|
|
86
|
-
- tests/
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
- ext/json/ext/generator
|
|
90
|
-
- ext/json/ext/parser
|
|
91
|
-
- ext/json/ext/generator/unicode.c
|
|
92
|
-
- ext/json/ext/generator/unicode.h
|
|
93
|
-
- ext/json/ext/generator/extconf.rb
|
|
94
|
-
- ext/json/ext/generator/generator.c
|
|
95
|
-
- ext/json/ext/parser/unicode.c
|
|
96
|
-
- ext/json/ext/parser/parser.rl
|
|
97
|
-
- ext/json/ext/parser/unicode.h
|
|
98
|
-
- ext/json/ext/parser/extconf.rb
|
|
99
|
-
- benchmarks/benchmark_generator.rb
|
|
100
|
-
- benchmarks/benchmark.txt
|
|
111
|
+
- tests/runner.rb
|
|
112
|
+
- tests/test_json_generate.rb
|
|
113
|
+
- tests/test_json_rails.rb
|
|
114
|
+
- tests/test_json_unicode.rb
|
|
115
|
+
- tests/test_json_fixtures.rb
|
|
116
|
+
- benchmarks
|
|
101
117
|
- benchmarks/benchmark_parser.rb
|
|
118
|
+
- benchmarks/benchmark_generator.rb
|
|
102
119
|
- benchmarks/benchmark_rails.rb
|
|
120
|
+
- benchmarks/benchmark.txt
|
|
121
|
+
- Rakefile
|
|
122
|
+
- GPL
|
|
123
|
+
- data
|
|
103
124
|
- data/example.json
|
|
104
|
-
- data/prototype.js
|
|
105
125
|
- data/index.html
|
|
106
|
-
-
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
-
|
|
111
|
-
- lib/json/ext.rb
|
|
112
|
-
- lib/json/common.rb
|
|
113
|
-
- lib/json/Hash.xpm
|
|
114
|
-
- lib/json/pure
|
|
115
|
-
- lib/json/Key.xpm
|
|
116
|
-
- lib/json/Numeric.xpm
|
|
117
|
-
- lib/json/Array.xpm
|
|
118
|
-
- lib/json/editor.rb
|
|
119
|
-
- lib/json/String.xpm
|
|
120
|
-
- lib/json/pure.rb
|
|
121
|
-
- lib/json/NilClass.xpm
|
|
122
|
-
- lib/json/version.rb
|
|
123
|
-
- lib/json/json.xpm
|
|
124
|
-
- lib/json/add/core.rb
|
|
125
|
-
- lib/json/add/rails.rb
|
|
126
|
-
- lib/json/pure/parser.rb
|
|
127
|
-
- lib/json/pure/generator.rb
|
|
128
|
-
- tools/server.rb
|
|
126
|
+
- data/prototype.js
|
|
127
|
+
- bin
|
|
128
|
+
- bin/edit_json.rb
|
|
129
|
+
- bin/prettify_json.rb
|
|
130
|
+
- tools
|
|
129
131
|
- tools/fuzz.rb
|
|
130
|
-
-
|
|
132
|
+
- tools/server.rb
|
|
131
133
|
test_files:
|
|
132
134
|
- tests/runner.rb
|
|
133
135
|
rdoc_options:
|