json 1.0.0 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +503 -0
  3. data/LICENSE +56 -0
  4. data/README.md +416 -0
  5. data/ext/json/ext/fbuffer/fbuffer.h +187 -0
  6. data/ext/json/ext/generator/depend +1 -0
  7. data/ext/json/ext/generator/extconf.rb +2 -7
  8. data/ext/json/ext/generator/generator.c +1312 -338
  9. data/ext/json/ext/generator/generator.h +177 -0
  10. data/ext/json/ext/parser/depend +1 -0
  11. data/ext/json/ext/parser/extconf.rb +28 -5
  12. data/ext/json/ext/parser/parser.c +1349 -689
  13. data/ext/json/ext/parser/parser.h +96 -0
  14. data/ext/json/ext/parser/parser.rl +644 -188
  15. data/ext/json/extconf.rb +3 -0
  16. data/json.gemspec +68 -0
  17. data/lib/json/add/bigdecimal.rb +58 -0
  18. data/lib/json/add/complex.rb +51 -0
  19. data/lib/json/add/core.rb +12 -0
  20. data/lib/json/add/date.rb +54 -0
  21. data/lib/json/add/date_time.rb +67 -0
  22. data/lib/json/add/exception.rb +49 -0
  23. data/lib/json/add/ostruct.rb +54 -0
  24. data/lib/json/add/range.rb +54 -0
  25. data/lib/json/add/rational.rb +49 -0
  26. data/lib/json/add/regexp.rb +48 -0
  27. data/lib/json/add/set.rb +48 -0
  28. data/lib/json/add/struct.rb +52 -0
  29. data/lib/json/add/symbol.rb +48 -0
  30. data/lib/json/add/time.rb +59 -0
  31. data/lib/json/common.rb +588 -74
  32. data/lib/json/ext.rb +3 -1
  33. data/lib/json/generic_object.rb +75 -0
  34. data/lib/json/pure/generator.rb +311 -119
  35. data/lib/json/pure/parser.rb +182 -55
  36. data/lib/json/pure.rb +5 -65
  37. data/lib/json/version.rb +2 -1
  38. data/lib/json.rb +583 -196
  39. metadata +78 -137
  40. data/CHANGES +0 -25
  41. data/GPL +0 -340
  42. data/README +0 -77
  43. data/Rakefile +0 -250
  44. data/TODO +0 -1
  45. data/VERSION +0 -1
  46. data/benchmarks/benchmark.txt +0 -133
  47. data/benchmarks/benchmark_generator.rb +0 -44
  48. data/benchmarks/benchmark_parser.rb +0 -22
  49. data/benchmarks/benchmark_rails.rb +0 -26
  50. data/bin/edit_json.rb +0 -11
  51. data/data/example.json +0 -1
  52. data/data/index.html +0 -37
  53. data/data/prototype.js +0 -2515
  54. data/ext/json/ext/generator/Makefile +0 -149
  55. data/ext/json/ext/generator/unicode.c +0 -184
  56. data/ext/json/ext/generator/unicode.h +0 -40
  57. data/ext/json/ext/parser/Makefile +0 -149
  58. data/ext/json/ext/parser/unicode.c +0 -156
  59. data/ext/json/ext/parser/unicode.h +0 -44
  60. data/install.rb +0 -26
  61. data/lib/json/Array.xpm +0 -21
  62. data/lib/json/FalseClass.xpm +0 -21
  63. data/lib/json/Hash.xpm +0 -21
  64. data/lib/json/Key.xpm +0 -73
  65. data/lib/json/NilClass.xpm +0 -21
  66. data/lib/json/Numeric.xpm +0 -28
  67. data/lib/json/String.xpm +0 -96
  68. data/lib/json/TrueClass.xpm +0 -21
  69. data/lib/json/editor.rb +0 -1207
  70. data/lib/json/json.xpm +0 -1499
  71. data/tests/fixtures/fail1.json +0 -1
  72. data/tests/fixtures/fail10.json +0 -1
  73. data/tests/fixtures/fail11.json +0 -1
  74. data/tests/fixtures/fail12.json +0 -1
  75. data/tests/fixtures/fail13.json +0 -1
  76. data/tests/fixtures/fail14.json +0 -1
  77. data/tests/fixtures/fail15.json +0 -1
  78. data/tests/fixtures/fail16.json +0 -1
  79. data/tests/fixtures/fail17.json +0 -1
  80. data/tests/fixtures/fail19.json +0 -1
  81. data/tests/fixtures/fail2.json +0 -1
  82. data/tests/fixtures/fail20.json +0 -1
  83. data/tests/fixtures/fail21.json +0 -1
  84. data/tests/fixtures/fail22.json +0 -1
  85. data/tests/fixtures/fail23.json +0 -1
  86. data/tests/fixtures/fail24.json +0 -1
  87. data/tests/fixtures/fail25.json +0 -1
  88. data/tests/fixtures/fail26.json +0 -1
  89. data/tests/fixtures/fail27.json +0 -2
  90. data/tests/fixtures/fail28.json +0 -2
  91. data/tests/fixtures/fail3.json +0 -1
  92. data/tests/fixtures/fail4.json +0 -1
  93. data/tests/fixtures/fail5.json +0 -1
  94. data/tests/fixtures/fail6.json +0 -1
  95. data/tests/fixtures/fail7.json +0 -1
  96. data/tests/fixtures/fail8.json +0 -1
  97. data/tests/fixtures/fail9.json +0 -1
  98. data/tests/fixtures/pass1.json +0 -56
  99. data/tests/fixtures/pass18.json +0 -1
  100. data/tests/fixtures/pass2.json +0 -1
  101. data/tests/fixtures/pass3.json +0 -6
  102. data/tests/runner.rb +0 -24
  103. data/tests/test_json.rb +0 -235
  104. data/tests/test_json_addition.rb +0 -94
  105. data/tests/test_json_fixtures.rb +0 -30
  106. data/tests/test_json_generate.rb +0 -81
  107. data/tests/test_json_unicode.rb +0 -55
  108. data/tools/fuzz.rb +0 -133
  109. data/tools/server.rb +0 -62
@@ -1 +0,0 @@
1
- "A JSON payload should be an object or array, not a string."
@@ -1 +0,0 @@
1
- {"Extra value after close": true} "misplaced quoted value"
@@ -1 +0,0 @@
1
- {"Illegal expression": 1 + 2}
@@ -1 +0,0 @@
1
- {"Illegal invocation": alert()}
@@ -1 +0,0 @@
1
- {"Numbers cannot have leading zeroes": 013}
@@ -1 +0,0 @@
1
- {"Numbers cannot be hex": 0x14}
@@ -1 +0,0 @@
1
- ["Illegal backslash escape: \x15"]
@@ -1 +0,0 @@
1
- ["Illegal backslash escape: \'"]
@@ -1 +0,0 @@
1
- ["Illegal backslash escape: \017"]
@@ -1 +0,0 @@
1
- {"Missing colon" null}
@@ -1 +0,0 @@
1
- ["Unclosed array"
@@ -1 +0,0 @@
1
- {"Double colon":: null}
@@ -1 +0,0 @@
1
- {"Comma instead of colon", null}
@@ -1 +0,0 @@
1
- ["Colon instead of comma": false]
@@ -1 +0,0 @@
1
- ["Bad value", truth]
@@ -1 +0,0 @@
1
- ['single quote']
@@ -1 +0,0 @@
1
- ["tab character in string "]
@@ -1 +0,0 @@
1
- ["tab\ character\ in\ string\ "]
@@ -1,2 +0,0 @@
1
- ["line
2
- break"]
@@ -1,2 +0,0 @@
1
- ["line\
2
- break"]
@@ -1 +0,0 @@
1
- {unquoted_key: "keys must be quoted"}
@@ -1 +0,0 @@
1
- ["extra comma",]
@@ -1 +0,0 @@
1
- ["double extra comma",,]
@@ -1 +0,0 @@
1
- [ , "<-- missing value"]
@@ -1 +0,0 @@
1
- ["Comma after the close"],
@@ -1 +0,0 @@
1
- ["Extra close"]]
@@ -1 +0,0 @@
1
- {"Extra comma": true,}
@@ -1,56 +0,0 @@
1
- [
2
- "JSON Test Pattern pass1",
3
- {"object with 1 member":["array with 1 element"]},
4
- {},
5
- [],
6
- -42,
7
- true,
8
- false,
9
- null,
10
- {
11
- "integer": 1234567890,
12
- "real": -9876.543210,
13
- "e": 0.123456789e-12,
14
- "E": 1.234567890E+34,
15
- "": 23456789012E666,
16
- "zero": 0,
17
- "one": 1,
18
- "space": " ",
19
- "quote": "\"",
20
- "backslash": "\\",
21
- "controls": "\b\f\n\r\t",
22
- "slash": "/ & \/",
23
- "alpha": "abcdefghijklmnopqrstuvwyz",
24
- "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
25
- "digit": "0123456789",
26
- "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
27
- "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
28
- "true": true,
29
- "false": false,
30
- "null": null,
31
- "array":[ ],
32
- "object":{ },
33
- "address": "50 St. James Street",
34
- "url": "http://www.JSON.org/",
35
- "comment": "// /* <!-- --",
36
- "# -- --> */": " ",
37
- " s p a c e d " :[1,2 , 3
38
-
39
- ,
40
-
41
- 4 , 5 , 6 ,7 ],
42
- "compact": [1,2,3,4,5,6,7],
43
- "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
44
- "quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
45
- "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
46
- : "A key can be any string"
47
- },
48
- 0.5 ,98.6
49
- ,
50
- 99.44
51
- ,
52
-
53
- 1066
54
-
55
-
56
- ,"rosebud"]
@@ -1 +0,0 @@
1
- [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] // No, we don't limit our depth: Moved to pass...
@@ -1 +0,0 @@
1
- [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
@@ -1,6 +0,0 @@
1
- {
2
- "JSON Test Pattern pass3": {
3
- "The outermost value": "must be an object or array.",
4
- "In this test": "It is an object."
5
- }
6
- }
data/tests/runner.rb DELETED
@@ -1,24 +0,0 @@
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 'tests'
7
- require 'test_json'
8
- require 'test_json_generate'
9
- require 'test_json_unicode'
10
- require 'test_json_addition'
11
- require 'test_json_fixtures'
12
-
13
- class TS_AllTests
14
- def self.suite
15
- suite = Test::Unit::TestSuite.new name
16
- suite << TC_JSONGenerate.suite
17
- suite << TC_JSON.suite
18
- suite << TC_JSONUnicode.suite
19
- suite << TC_JSONAddition.suite
20
- suite << TC_JSONFixtures.suite
21
- end
22
- end
23
- Test::Unit::UI::Console::TestRunner.run(TS_AllTests)
24
- # vim: set et sw=2 ts=2:
data/tests/test_json.rb DELETED
@@ -1,235 +0,0 @@
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
- def setup
10
- $KCODE = 'UTF8'
11
- @ary = [1, "foo", 3.14, 4711.0, 2.718, nil, [1,-2,3], false, true].map do
12
- |x| [x]
13
- end
14
- @ary_to_parse = ["1", '"foo"', "3.14", "4711.0", "2.718", "null",
15
- "[1,-2,3]", "false", "true"].map do
16
- |x| "[#{x}]"
17
- end
18
- @hash = {
19
- 'a' => 2,
20
- 'b' => 3.141,
21
- 'c' => 'c',
22
- 'd' => [ 1, "b", 3.14 ],
23
- 'e' => { 'foo' => 'bar' },
24
- 'g' => "\"\0\037",
25
- 'h' => 1000.0,
26
- 'i' => 0.001
27
- }
28
- @json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
29
- '"g":"\\"\\u0000\\u001f","h":1.0E3,"i":1.0E-3}'
30
- end
31
- suite << TC_JSON.suite
32
-
33
- def test_construction
34
- parser = JSON::Parser.new('test')
35
- assert_equal 'test', parser.source
36
- end
37
-
38
- def assert_equal_float(expected, is)
39
- assert_in_delta(expected.first, is.first, 1e-2)
40
- end
41
-
42
- def test_parse_simple_arrays
43
- assert_equal([], parse('[]'))
44
- assert_equal([], parse(' [ ] '))
45
- assert_equal([nil], parse('[null]'))
46
- assert_equal([false], parse('[false]'))
47
- assert_equal([true], parse('[true]'))
48
- assert_equal([-23], parse('[-23]'))
49
- assert_equal([23], parse('[23]'))
50
- assert_equal([0.23], parse('[0.23]'))
51
- assert_raises(JSON::ParserError) { parse('[+23.2]') }
52
- assert_raises(JSON::ParserError) { parse('[+23]') }
53
- assert_raises(JSON::ParserError) { parse('[.23]') }
54
- assert_raises(JSON::ParserError) { parse('[023]') }
55
- assert_equal_float [3.141], parse('[3.141]')
56
- assert_equal_float [-3.141], parse('[-3.141]')
57
- assert_equal_float [3.141], parse('[3141e-3]')
58
- assert_equal_float [3.141], parse('[3141.1e-3]')
59
- assert_equal_float [3.141], parse('[3141E-3]')
60
- assert_equal_float [3.141], parse('[3141.0E-3]')
61
- assert_equal_float [-3.141], parse('[-3141.0e-3]')
62
- assert_equal_float [-3.141], parse('[-3141e-3]')
63
- assert_equal([""], parse('[""]'))
64
- assert_equal(["foobar"], parse('["foobar"]'))
65
- assert_equal([{}], parse('[{}]'))
66
- end
67
-
68
- def test_parse_simple_objects
69
- assert_equal({}, parse('{}'))
70
- assert_equal({}, parse(' { } '))
71
- assert_equal({ "a" => nil }, parse('{ "a" : null}'))
72
- assert_equal({ "a" => nil }, parse('{"a":null}'))
73
- assert_equal({ "a" => false }, parse('{ "a" : false } '))
74
- assert_equal({ "a" => false }, parse('{"a":false}'))
75
- assert_raises(JSON::ParserError) { parse('{false}') }
76
- assert_equal({ "a" => true }, parse('{"a":true}'))
77
- assert_equal({ "a" => true }, parse(' { "a" : true } '))
78
- assert_equal({ "a" => -23 }, parse(' { "a" : -23 } '))
79
- assert_equal({ "a" => -23 }, parse(' { "a" : -23 } '))
80
- assert_equal({ "a" => 23 }, parse('{"a":23 } '))
81
- assert_equal({ "a" => 23 }, parse(' { "a" : 23 } '))
82
- assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
83
- assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
84
- end
85
-
86
- begin
87
- require 'permutation'
88
- def test_parse_more_complex_arrays
89
- a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
90
- perms = Permutation.for a
91
- perms.each do |perm|
92
- orig_ary = perm.project
93
- json = pretty_generate(orig_ary)
94
- assert_equal orig_ary, parse(json)
95
- end
96
- end
97
-
98
- def test_parse_complex_objects
99
- a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
100
- perms = Permutation.for a
101
- perms.each do |perm|
102
- s = "a"
103
- orig_obj = perm.project.inject({}) { |h, x| h[s.dup] = x; s = s.succ; h }
104
- json = pretty_generate(orig_obj)
105
- assert_equal orig_obj, parse(json)
106
- end
107
- end
108
- rescue LoadError
109
- warn "Skipping permutation tests."
110
- end
111
-
112
- def test_parse_arrays
113
- assert_equal([1,2,3], parse('[1,2,3]'))
114
- assert_equal([1.2,2,3], parse('[1.2,2,3]'))
115
- assert_equal([[],[[],[]]], parse('[[],[[],[]]]'))
116
- end
117
-
118
- def test_parse_values
119
- assert_equal([""], parse('[""]'))
120
- assert_equal(["\\"], parse('["\\\\"]'))
121
- assert_equal(['"'], parse('["\""]'))
122
- assert_equal(['\\"\\'], parse('["\\\\\\"\\\\"]'))
123
- assert_equal(["\"\b\n\r\t\0\037"],
124
- parse('["\"\b\n\r\t\u0000\u001f"]'))
125
- for i in 0 ... @ary.size
126
- assert_equal(@ary[i], parse(@ary_to_parse[i]))
127
- end
128
- end
129
-
130
- def test_parse_array
131
- assert_equal([], parse('[]'))
132
- assert_equal([], parse(' [ ] '))
133
- assert_equal([1], parse('[1]'))
134
- assert_equal([1], parse(' [ 1 ] '))
135
- assert_equal(@ary,
136
- parse('[[1],["foo"],[3.14],[47.11e+2],[2718.0E-3],[null],[[1,-2,3]]'\
137
- ',[false],[true]]'))
138
- assert_equal(@ary, parse(%Q{ [ [1] , ["foo"] , [3.14] \t , [47.11e+2]
139
- , [2718.0E-3 ],\r[ null] , [[1, -2, 3 ]], [false ],[ true]\n ] }))
140
- end
141
-
142
- def test_parse_object
143
- assert_equal({}, parse('{}'))
144
- assert_equal({}, parse(' { } '))
145
- assert_equal({'foo'=>'bar'}, parse('{"foo":"bar"}'))
146
- assert_equal({'foo'=>'bar'}, parse(' { "foo" : "bar" } '))
147
- end
148
-
149
- def test_parser_reset
150
- parser = Parser.new(@json)
151
- assert_equal(@hash, parser.parse)
152
- assert_equal(@hash, parser.parse)
153
- end
154
-
155
- def test_comments
156
- json = <<EOT
157
- {
158
- "key1":"value1", // eol comment
159
- "key2":"value2" /* multi line
160
- * comment */,
161
- "key3":"value3" /* multi line
162
- // nested eol comment
163
- * comment */
164
- }
165
- EOT
166
- assert_equal(
167
- { "key1" => "value1", "key2" => "value2", "key3" => "value3" },
168
- parse(json))
169
- json = <<EOT
170
- {
171
- "key1":"value1" /* multi line
172
- // nested eol comment
173
- /* illegal nested multi line comment */
174
- * comment */
175
- }
176
- EOT
177
- assert_raises(ParserError) { parse(json) }
178
- json = <<EOT
179
- {
180
- "key1":"value1" /* multi line
181
- // nested eol comment
182
- closed multi comment */
183
- and again, throw an Error */
184
- }
185
- EOT
186
- assert_raises(ParserError) { parse(json) }
187
- json = <<EOT
188
- {
189
- "key1":"value1" /*/*/
190
- }
191
- EOT
192
- assert_equal({ "key1" => "value1" }, parse(json))
193
- end
194
-
195
- def test_backslash
196
- data = [ '\\.(?i:gif|jpe?g|png)$' ]
197
- json = '["\\\\.(?i:gif|jpe?g|png)$"]'
198
- assert_equal json, JSON.unparse(data)
199
- assert_equal data, JSON.parse(json)
200
- #
201
- data = [ '\\"' ]
202
- json = '["\\\\\""]'
203
- assert_equal json, JSON.unparse(data)
204
- assert_equal data, JSON.parse(json)
205
- #
206
- json = '["\/"]'
207
- data = JSON.parse(json)
208
- assert_equal ['/'], data
209
- assert_equal json, JSON.unparse(data)
210
- #
211
- json = '["\""]'
212
- data = JSON.parse(json)
213
- assert_equal ['"'], data
214
- assert_equal json, JSON.unparse(data)
215
- end
216
-
217
- def test_wrong_inputs
218
- assert_raises(ParserError) { JSON.parse('"foo"') }
219
- assert_raises(ParserError) { JSON.parse('123') }
220
- assert_raises(ParserError) { JSON.parse('[] bla') }
221
- assert_raises(ParserError) { JSON.parse('[] 1') }
222
- assert_raises(ParserError) { JSON.parse('[] []') }
223
- assert_raises(ParserError) { JSON.parse('[] {}') }
224
- assert_raises(ParserError) { JSON.parse('{} []') }
225
- assert_raises(ParserError) { JSON.parse('{} {}') }
226
- assert_raises(ParserError) { JSON.parse('[NULL]') }
227
- assert_raises(ParserError) { JSON.parse('[FALSE]') }
228
- assert_raises(ParserError) { JSON.parse('[TRUE]') }
229
- assert_raises(ParserError) { JSON.parse('[07] ') }
230
- assert_raises(ParserError) { JSON.parse('[0a]') }
231
- assert_raises(ParserError) { JSON.parse('[1.]') }
232
- assert_raises(ParserError) { JSON.parse(' ') }
233
- end
234
- end
235
- # vim: set et sw=2 ts=2:
@@ -1,94 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'json'
5
-
6
- class TC_JSONAddition < 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
- class B
33
- def to_json(*args)
34
- {
35
- 'json_class' => self.class,
36
- }.to_json(*args)
37
- end
38
- end
39
-
40
- class C
41
- def to_json(*args)
42
- {
43
- 'json_class' => 'TC_JSONAddition::Nix',
44
- }.to_json(*args)
45
- end
46
- end
47
-
48
- def setup
49
- $KCODE = 'UTF8'
50
- end
51
-
52
- def test_extended_json
53
- a = A.new(666)
54
- assert A.json_creatable?
55
- json = generate(a)
56
- a_again = JSON.parse(json)
57
- assert_kind_of a.class, a_again
58
- assert_equal a, a_again
59
- end
60
-
61
- def test_extended_json_fail
62
- b = B.new
63
- assert !B.json_creatable?
64
- json = generate(b)
65
- assert_equal({ 'json_class' => B.name }, JSON.parse(json))
66
- end
67
-
68
- def test_extended_json_fail
69
- c = C.new
70
- assert !C.json_creatable?
71
- json = generate(c)
72
- assert_raises(ArgumentError) { JSON.parse(json) }
73
- end
74
-
75
- def test_raw_strings
76
- raw = ''
77
- raw_array = []
78
- for i in 0..255
79
- raw << i
80
- raw_array << i
81
- end
82
- json = raw.to_json_raw
83
- json_raw_object = raw.to_json_raw_object
84
- hash = { 'json_class' => 'String', 'raw'=> raw_array }
85
- assert_equal hash, json_raw_object
86
- json_raw = <<EOT.chomp
87
- {\"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]}
88
- EOT
89
- # "
90
- assert_equal json_raw, json
91
- raw_again = JSON.parse(json)
92
- assert_equal raw, raw_again
93
- end
94
- end
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'json'
5
-
6
- class TC_JSONFixtures < Test::Unit::TestCase
7
- def setup
8
- $KCODE = 'UTF8'
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
- assert JSON.parse(source),
18
- "Did not pass for fixture '#{name}'"
19
- end
20
- end
21
-
22
- def test_failing
23
- for (name, source) in @failed
24
- assert_raises(JSON::ParserError,
25
- "Did not fail for fixture '#{name}'") do
26
- JSON.parse(source)
27
- end
28
- end
29
- end
30
- end
@@ -1,81 +0,0 @@
1
- require 'test/unit'
2
- require 'json'
3
-
4
- class TC_JSONGenerate < Test::Unit::TestCase
5
- include JSON
6
-
7
- def setup
8
- $KCODE = 'UTF8'
9
- @hash = {
10
- 'a' => 2,
11
- 'b' => 3.141,
12
- 'c' => 'c',
13
- 'd' => [ 1, "b", 3.14 ],
14
- 'e' => { 'foo' => 'bar' },
15
- 'g' => "\"\0\037",
16
- 'h' => 1000.0,
17
- 'i' => 0.001
18
- }
19
- @json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
20
- '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
21
- @json3 = <<'EOT'.chomp
22
- {
23
- "a": 2,
24
- "b": 3.141,
25
- "c": "c",
26
- "d": [
27
- 1,
28
- "b",
29
- 3.14
30
- ],
31
- "e": {
32
- "foo": "bar"
33
- },
34
- "g": "\"\u0000\u001f",
35
- "h": 1000.0,
36
- "i": 0.001
37
- }
38
- EOT
39
- end
40
-
41
- def test_unparse
42
- json = unparse(@hash)
43
- assert_equal(@json2, json)
44
- parsed_json = parse(json)
45
- assert_equal(@hash, parsed_json)
46
- json = generate({1=>2})
47
- assert_equal('{"1":2}', json)
48
- parsed_json = parse(json)
49
- assert_equal({"1"=>2}, parsed_json)
50
- end
51
-
52
- def test_unparse_pretty
53
- json = pretty_unparse(@hash)
54
- assert_equal(@json3, json)
55
- parsed_json = parse(json)
56
- assert_equal(@hash, parsed_json)
57
- json = pretty_generate({1=>2})
58
- assert_equal(<<'EOT'.chomp, json)
59
- {
60
- "1": 2
61
- }
62
- EOT
63
- parsed_json = parse(json)
64
- assert_equal({"1"=>2}, parsed_json)
65
- end
66
-
67
- def test_states
68
- json = generate({1=>2}, nil)
69
- assert_equal('{"1":2}', json)
70
- s = JSON.state.new(:check_circular => true)
71
- #assert s.check_circular
72
- h = { 1=>2 }
73
- h[3] = h
74
- assert_raises(JSON::CircularDatastructure) { generate(h, s) }
75
- s = JSON.state.new(:check_circular => true)
76
- #assert s.check_circular
77
- a = [ 1, 2 ]
78
- a << a
79
- assert_raises(JSON::CircularDatastructure) { generate(a, s) }
80
- end
81
- end