json 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of json might be problematic. Click here for more details.
- data/GPL +340 -0
- data/README +27 -0
- data/Rakefile +85 -0
- data/TODO +0 -0
- data/VERSION +1 -0
- data/bin/edit_json.rb +11 -0
- data/install.rb +21 -0
- data/lib/json.rb +652 -0
- data/lib/json/Array.xpm +21 -0
- data/lib/json/FalseClass.xpm +21 -0
- data/lib/json/Hash.xpm +21 -0
- data/lib/json/Key.xpm +73 -0
- data/lib/json/NilClass.xpm +21 -0
- data/lib/json/Numeric.xpm +28 -0
- data/lib/json/String.xpm +96 -0
- data/lib/json/TrueClass.xpm +21 -0
- data/lib/json/editor.rb +1195 -0
- data/lib/json/json.xpm +1499 -0
- data/tests/runner.rb +18 -0
- data/tests/test_json.rb +209 -0
- metadata +64 -0
data/tests/runner.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit/ui/console/testrunner'
|
4
|
+
require 'test/unit/testsuite'
|
5
|
+
$:.unshift File.expand_path(File.dirname($0))
|
6
|
+
$:.unshift 'lib'
|
7
|
+
$:.unshift '../lib'
|
8
|
+
#require 'coverage'
|
9
|
+
require 'test_json'
|
10
|
+
|
11
|
+
class TS_AllTests
|
12
|
+
def self.suite
|
13
|
+
suite = Test::Unit::TestSuite.new
|
14
|
+
suite << TC_JSON.suite
|
15
|
+
end
|
16
|
+
end
|
17
|
+
Test::Unit::UI::Console::TestRunner.run(TS_AllTests)
|
18
|
+
# vim: set et sw=2 ts=2:
|
data/tests/test_json.rb
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class TC_JSON < Test::Unit::TestCase
|
7
|
+
include JSON
|
8
|
+
|
9
|
+
class A
|
10
|
+
def initialize(a)
|
11
|
+
@a = a
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :a
|
15
|
+
|
16
|
+
def ==(other)
|
17
|
+
a == other.a
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.json_create(object)
|
21
|
+
new(*object['args'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json(*args)
|
25
|
+
{
|
26
|
+
'json_class' => self.class,
|
27
|
+
'args' => [ @a ],
|
28
|
+
}.to_json(*args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
$KCODE = 'UTF8'
|
34
|
+
@ary = [1, "foo", 3.14, 4711.0, 2.718, nil, [1,-2,3], false, true]
|
35
|
+
@ary_to_parse = ["1", '"foo"', "3.14", "4711.0", "2.718", "null",
|
36
|
+
"[1,-2,3]", "false", "true"]
|
37
|
+
@hash = {
|
38
|
+
'a' => 2,
|
39
|
+
'b' => 3.141,
|
40
|
+
'c' => 'c',
|
41
|
+
'd' => [ 1, "b", 3.14 ],
|
42
|
+
'e' => { 'foo' => 'bar' },
|
43
|
+
'g' => "\"\0\037",
|
44
|
+
'h' => 1000.0,
|
45
|
+
'i' => 0.001
|
46
|
+
}
|
47
|
+
@json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
|
48
|
+
'"g":"\\"\\u0000\\u001f","h":1.0E3,"i":1.0E-3}'
|
49
|
+
@json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
|
50
|
+
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_parse_value
|
54
|
+
assert_equal("", parse('""'))
|
55
|
+
assert_equal("\\", parse('"\\\\"'))
|
56
|
+
assert_equal('"', parse('"\""'))
|
57
|
+
assert_equal('\\"\\', parse('"\\\\\\"\\\\"'))
|
58
|
+
assert_equal("\\a\"\b\f\n\r\t\0\037",
|
59
|
+
parse('"\\a\"\b\f\n\r\t\u0000\u001f"'))
|
60
|
+
for i in 0 ... @ary.size
|
61
|
+
assert_equal(@ary[i], parse(@ary_to_parse[i]))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_parse_array
|
66
|
+
assert_equal([], parse('[]'))
|
67
|
+
assert_equal([], parse(' [ ] '))
|
68
|
+
assert_equal([1], parse('[1]'))
|
69
|
+
assert_equal([1], parse(' [ 1 ] '))
|
70
|
+
assert_equal(@ary,
|
71
|
+
parse('[1,"foo",3.14,47.11e+2,2718.E-3,null,[1,-2,3],false,true]'))
|
72
|
+
assert_equal(@ary, parse(%Q{ [ 1 , "foo" , 3.14 \t , 47.11e+2
|
73
|
+
, 2718.E-3 ,\n null , [1, -2, 3 ], false , true\n ] }))
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_parse_object
|
77
|
+
assert_equal({}, parse('{}'))
|
78
|
+
assert_equal({}, parse(' { } '))
|
79
|
+
assert_equal({'foo'=>'bar'}, parse('{"foo":"bar"}'))
|
80
|
+
assert_equal({'foo'=>'bar'}, parse(' { "foo" : "bar" } '))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_unparse
|
84
|
+
json = unparse(@hash)
|
85
|
+
assert_equal(@json2, json)
|
86
|
+
parsed_json = parse(json)
|
87
|
+
assert_equal(@hash, parsed_json)
|
88
|
+
json = unparse({1=>2})
|
89
|
+
assert_equal('{"1":2}', json)
|
90
|
+
parsed_json = parse(json)
|
91
|
+
assert_equal({"1"=>2}, parsed_json)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_parser_reset
|
95
|
+
parser = Parser.new(@json)
|
96
|
+
assert_equal(@hash, parser.parse)
|
97
|
+
assert_equal(@hash, parser.parse)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_unicode
|
101
|
+
assert_equal '""', ''.to_json
|
102
|
+
assert_equal '"\\b"', "\b".to_json
|
103
|
+
assert_equal '"\u0001"', 0x1.chr.to_json
|
104
|
+
assert_equal '"\u001f"', 0x1f.chr.to_json
|
105
|
+
assert_equal '" "', ' '.to_json
|
106
|
+
assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
|
107
|
+
utf8 = '© ≠ €!'
|
108
|
+
json = '"\u00a9 \u2260 \u20ac!"'
|
109
|
+
assert_equal json, utf8.to_json
|
110
|
+
assert_equal utf8, parse(json)
|
111
|
+
utf8 = "\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"
|
112
|
+
json = '"\u3042\u3044\u3046\u3048\u304a"'
|
113
|
+
assert_equal json, utf8.to_json
|
114
|
+
assert_equal utf8, parse(json)
|
115
|
+
utf8 = 'საქართველო'
|
116
|
+
json = '"\u10e1\u10d0\u10e5\u10d0\u10e0\u10d7\u10d5\u10d4\u10da\u10dd"'
|
117
|
+
assert_equal json, utf8.to_json
|
118
|
+
assert_equal utf8, parse(json)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_comments
|
122
|
+
json = <<EOT
|
123
|
+
{
|
124
|
+
"key1":"value1", // eol comment
|
125
|
+
"key2":"value2" /* multi line
|
126
|
+
* comment */,
|
127
|
+
"key3":"value3" /* multi line
|
128
|
+
// nested eol comment
|
129
|
+
* comment */
|
130
|
+
}
|
131
|
+
EOT
|
132
|
+
assert_equal(
|
133
|
+
{ "key1" => "value1", "key2" => "value2", "key3" => "value3" },
|
134
|
+
parse(json))
|
135
|
+
json = <<EOT
|
136
|
+
{
|
137
|
+
"key1":"value1" /* multi line
|
138
|
+
// nested eol comment
|
139
|
+
/* illegal nested multi line comment */
|
140
|
+
* comment */
|
141
|
+
}
|
142
|
+
EOT
|
143
|
+
assert_raises(ParserError) { parse(json) }
|
144
|
+
json = <<EOT
|
145
|
+
{
|
146
|
+
"key1":"value1" /* multi line
|
147
|
+
// nested eol comment
|
148
|
+
closed multi comment */
|
149
|
+
and again, throw an Error */
|
150
|
+
}
|
151
|
+
EOT
|
152
|
+
assert_raises(ParserError) { parse(json) }
|
153
|
+
json = <<EOT
|
154
|
+
{
|
155
|
+
"key1":"value1" /*/*/
|
156
|
+
}
|
157
|
+
EOT
|
158
|
+
assert_equal({ "key1" => "value1" }, parse(json))
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_extended_json
|
162
|
+
a = A.new(666)
|
163
|
+
json = a.to_json
|
164
|
+
a_again = JSON.parse(json)
|
165
|
+
assert_kind_of a.class, a_again
|
166
|
+
assert_equal a, a_again
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_raw_strings
|
170
|
+
raw = ''
|
171
|
+
raw_array = []
|
172
|
+
for i in 0..255
|
173
|
+
raw << i
|
174
|
+
raw_array << i
|
175
|
+
end
|
176
|
+
json = raw.to_json_raw
|
177
|
+
json_raw_object = raw.to_json_raw_object
|
178
|
+
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
179
|
+
assert_equal hash, json_raw_object
|
180
|
+
json_raw = <<EOT.chomp
|
181
|
+
{\"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]}
|
182
|
+
EOT
|
183
|
+
# "
|
184
|
+
assert_equal json_raw, json
|
185
|
+
raw_again = JSON.parse(json)
|
186
|
+
assert_equal raw, raw_again
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_utf8_mode
|
190
|
+
$KCODE = 'NONE'
|
191
|
+
utf8 = "© ≠ €! - \001"
|
192
|
+
json = "\"© ≠ €! - \\u0001\""
|
193
|
+
assert_equal json, utf8.to_json
|
194
|
+
assert_equal utf8, parse(json)
|
195
|
+
assert JSON.support_unicode?
|
196
|
+
$KCODE = 'UTF8'
|
197
|
+
utf8 = '© ≠ €!'
|
198
|
+
json = '"\u00a9 \u2260 \u20ac!"'
|
199
|
+
assert_equal json, utf8.to_json
|
200
|
+
assert_equal utf8, parse(json)
|
201
|
+
JSON.support_unicode = false
|
202
|
+
assert !JSON.support_unicode?
|
203
|
+
utf8 = "© ≠ €! - \001"
|
204
|
+
json = "\"© ≠ €! - \\u0001\""
|
205
|
+
assert_equal json, utf8.to_json
|
206
|
+
assert_equal utf8, parse(json)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
# vim: set et sw=2 ts=2:
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: json
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.4.0
|
7
|
+
date: 2005-09-30 00:00:00 +02:00
|
8
|
+
summary: A JSON implementation in Ruby
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: flori@ping.de
|
12
|
+
homepage: http://json.rubyforge.org
|
13
|
+
rubyforge_project: json
|
14
|
+
description: ''
|
15
|
+
autorequire: json
|
16
|
+
default_executable: edit_json.rb
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
authors:
|
30
|
+
- Florian Frank
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- GPL
|
34
|
+
- bin
|
35
|
+
- lib
|
36
|
+
- Rakefile
|
37
|
+
- TODO
|
38
|
+
- VERSION
|
39
|
+
- install.rb
|
40
|
+
- tests
|
41
|
+
- bin/edit_json.rb
|
42
|
+
- lib/json
|
43
|
+
- lib/json.rb
|
44
|
+
- lib/json/Array.xpm
|
45
|
+
- lib/json/FalseClass.xpm
|
46
|
+
- lib/json/Hash.xpm
|
47
|
+
- lib/json/Key.xpm
|
48
|
+
- lib/json/NilClass.xpm
|
49
|
+
- lib/json/Numeric.xpm
|
50
|
+
- lib/json/String.xpm
|
51
|
+
- lib/json/TrueClass.xpm
|
52
|
+
- lib/json/editor.rb
|
53
|
+
- lib/json/json.xpm
|
54
|
+
- tests/runner.rb
|
55
|
+
- tests/test_json.rb
|
56
|
+
test_files:
|
57
|
+
- tests/runner.rb
|
58
|
+
rdoc_options: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
executables:
|
61
|
+
- edit_json.rb
|
62
|
+
extensions: []
|
63
|
+
requirements: []
|
64
|
+
dependencies: []
|