json 2.4.0-java → 2.6.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json/common.rb +34 -13
- data/lib/json/ext/generator.jar +0 -0
- data/lib/json/ext/parser.jar +0 -0
- data/lib/json/pure/parser.rb +1 -1
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +1 -1
- metadata +6 -86
- data/tests/fixtures/fail10.json +0 -1
- data/tests/fixtures/fail11.json +0 -1
- data/tests/fixtures/fail12.json +0 -1
- data/tests/fixtures/fail13.json +0 -1
- data/tests/fixtures/fail14.json +0 -1
- data/tests/fixtures/fail18.json +0 -1
- data/tests/fixtures/fail19.json +0 -1
- data/tests/fixtures/fail2.json +0 -1
- data/tests/fixtures/fail20.json +0 -1
- data/tests/fixtures/fail21.json +0 -1
- data/tests/fixtures/fail22.json +0 -1
- data/tests/fixtures/fail23.json +0 -1
- data/tests/fixtures/fail24.json +0 -1
- data/tests/fixtures/fail25.json +0 -1
- data/tests/fixtures/fail27.json +0 -2
- data/tests/fixtures/fail28.json +0 -2
- data/tests/fixtures/fail29.json +0 -1
- data/tests/fixtures/fail3.json +0 -1
- data/tests/fixtures/fail30.json +0 -1
- data/tests/fixtures/fail31.json +0 -1
- data/tests/fixtures/fail32.json +0 -1
- data/tests/fixtures/fail4.json +0 -1
- data/tests/fixtures/fail5.json +0 -1
- data/tests/fixtures/fail6.json +0 -1
- data/tests/fixtures/fail7.json +0 -1
- data/tests/fixtures/fail8.json +0 -1
- data/tests/fixtures/fail9.json +0 -1
- data/tests/fixtures/obsolete_fail1.json +0 -1
- data/tests/fixtures/pass1.json +0 -56
- data/tests/fixtures/pass15.json +0 -1
- data/tests/fixtures/pass16.json +0 -1
- data/tests/fixtures/pass17.json +0 -1
- data/tests/fixtures/pass2.json +0 -1
- data/tests/fixtures/pass26.json +0 -1
- data/tests/fixtures/pass3.json +0 -6
- data/tests/json_addition_test.rb +0 -199
- data/tests/json_common_interface_test.rb +0 -169
- data/tests/json_encoding_test.rb +0 -107
- data/tests/json_ext_parser_test.rb +0 -15
- data/tests/json_fixtures_test.rb +0 -40
- data/tests/json_generator_test.rb +0 -432
- data/tests/json_generic_object_test.rb +0 -82
- data/tests/json_parser_test.rb +0 -497
- data/tests/json_string_matching_test.rb +0 -38
- data/tests/test_helper.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08d64ed0d9aa72d181203add925545e460e68ab0c9589cc50186ff2ef85211a7'
|
4
|
+
data.tar.gz: 98c567e47395cb39adb38629d5d139f77e7d5c884c96e9dee4c3e5d90ee6f842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffc1cd18ab2cdbce97ccb592eaf87876e1aff224de2533bbcdea16e530d22a9d02ace8b268dd16a19e4e3a358893da588e9191e1440aec20c16e6f5adff94b02
|
7
|
+
data.tar.gz: 13859869ef94c1ff854df0ca2781dffd9a0473a40f8cf3ec0457df20356329c16d4af987b74f6607a2dedf414c22ce668ea92eff12ff6386546b6c6b006d39df
|
data/lib/json/common.rb
CHANGED
@@ -71,22 +71,30 @@ module JSON
|
|
71
71
|
end
|
72
72
|
self.state = generator::State
|
73
73
|
const_set :State, self.state
|
74
|
-
const_set :SAFE_STATE_PROTOTYPE, State.new
|
75
|
-
const_set :FAST_STATE_PROTOTYPE,
|
74
|
+
const_set :SAFE_STATE_PROTOTYPE, State.new # for JRuby
|
75
|
+
const_set :FAST_STATE_PROTOTYPE, create_fast_state
|
76
|
+
const_set :PRETTY_STATE_PROTOTYPE, create_pretty_state
|
77
|
+
ensure
|
78
|
+
$VERBOSE = old
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_fast_state
|
82
|
+
State.new(
|
76
83
|
:indent => '',
|
77
84
|
:space => '',
|
78
85
|
:object_nl => "",
|
79
86
|
:array_nl => "",
|
80
87
|
:max_nesting => false
|
81
88
|
)
|
82
|
-
|
89
|
+
end
|
90
|
+
|
91
|
+
def create_pretty_state
|
92
|
+
State.new(
|
83
93
|
:indent => ' ',
|
84
94
|
:space => ' ',
|
85
95
|
:object_nl => "\n",
|
86
96
|
:array_nl => "\n"
|
87
97
|
)
|
88
|
-
ensure
|
89
|
-
$VERBOSE = old
|
90
98
|
end
|
91
99
|
|
92
100
|
# Returns the JSON generator module that is used by JSON. This is
|
@@ -98,13 +106,26 @@ module JSON
|
|
98
106
|
# either JSON::Ext::Generator::State or JSON::Pure::Generator::State:
|
99
107
|
# JSON.state # => JSON::Ext::Generator::State
|
100
108
|
attr_accessor :state
|
109
|
+
end
|
110
|
+
|
111
|
+
DEFAULT_CREATE_ID = 'json_class'.freeze
|
112
|
+
private_constant :DEFAULT_CREATE_ID
|
113
|
+
|
114
|
+
CREATE_ID_TLS_KEY = "JSON.create_id".freeze
|
115
|
+
private_constant :CREATE_ID_TLS_KEY
|
116
|
+
|
117
|
+
# Sets create identifier, which is used to decide if the _json_create_
|
118
|
+
# hook of a class should be called; initial value is +json_class+:
|
119
|
+
# JSON.create_id # => 'json_class'
|
120
|
+
def self.create_id=(new_value)
|
121
|
+
Thread.current[CREATE_ID_TLS_KEY] = new_value.dup.freeze
|
122
|
+
end
|
101
123
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
124
|
+
# Returns the current create identifier.
|
125
|
+
# See also JSON.create_id=.
|
126
|
+
def self.create_id
|
127
|
+
Thread.current[CREATE_ID_TLS_KEY] || DEFAULT_CREATE_ID
|
106
128
|
end
|
107
|
-
self.create_id = 'json_class'
|
108
129
|
|
109
130
|
NaN = 0.0/0
|
110
131
|
|
@@ -276,7 +297,7 @@ module JSON
|
|
276
297
|
if State === opts
|
277
298
|
state, opts = opts, nil
|
278
299
|
else
|
279
|
-
state =
|
300
|
+
state = State.new
|
280
301
|
end
|
281
302
|
if opts
|
282
303
|
if opts.respond_to? :to_hash
|
@@ -315,7 +336,7 @@ module JSON
|
|
315
336
|
if State === opts
|
316
337
|
state, opts = opts, nil
|
317
338
|
else
|
318
|
-
state =
|
339
|
+
state = JSON.create_fast_state
|
319
340
|
end
|
320
341
|
if opts
|
321
342
|
if opts.respond_to? :to_hash
|
@@ -370,7 +391,7 @@ module JSON
|
|
370
391
|
if State === opts
|
371
392
|
state, opts = opts, nil
|
372
393
|
else
|
373
|
-
state =
|
394
|
+
state = JSON.create_pretty_state
|
374
395
|
end
|
375
396
|
if opts
|
376
397
|
if opts.respond_to? :to_hash
|
data/lib/json/ext/generator.jar
CHANGED
Binary file
|
data/lib/json/ext/parser.jar
CHANGED
Binary file
|
data/lib/json/pure/parser.rb
CHANGED
data/lib/json/version.rb
CHANGED
data/lib/json.rb
CHANGED
@@ -493,7 +493,7 @@ require 'json/common'
|
|
493
493
|
# json = JSON.generate(ruby0) # {"json_class":"Customer","v":["Dave","123 Main"]}
|
494
494
|
# ruby1 = JSON.parse(json, create_additions: true) # #<struct Customer name="Dave", address="123 Main">
|
495
495
|
# ruby1.class # Customer
|
496
|
-
|
496
|
+
#
|
497
497
|
# \Symbol:
|
498
498
|
# require 'json/add/symbol'
|
499
499
|
# ruby0 = :foo # foo
|
metadata
CHANGED
@@ -1,49 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Daniel Luz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
15
|
-
requirements:
|
16
|
-
- - ">="
|
17
|
-
- !ruby/object:Gem::Version
|
18
|
-
version: '0'
|
19
|
-
name: rake
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
29
|
-
requirements:
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '2.0'
|
33
|
-
- - "<"
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '4.0'
|
36
|
-
name: test-unit
|
37
|
-
type: :development
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '2.0'
|
44
|
-
- - "<"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '4.0'
|
11
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
47
13
|
description: A JSON implementation as a JRuby extension.
|
48
14
|
email: dev+ruby@mernen.com
|
49
15
|
executables: []
|
@@ -75,51 +41,6 @@ files:
|
|
75
41
|
- lib/json/pure/generator.rb
|
76
42
|
- lib/json/pure/parser.rb
|
77
43
|
- lib/json/version.rb
|
78
|
-
- tests/fixtures/fail10.json
|
79
|
-
- tests/fixtures/fail11.json
|
80
|
-
- tests/fixtures/fail12.json
|
81
|
-
- tests/fixtures/fail13.json
|
82
|
-
- tests/fixtures/fail14.json
|
83
|
-
- tests/fixtures/fail18.json
|
84
|
-
- tests/fixtures/fail19.json
|
85
|
-
- tests/fixtures/fail2.json
|
86
|
-
- tests/fixtures/fail20.json
|
87
|
-
- tests/fixtures/fail21.json
|
88
|
-
- tests/fixtures/fail22.json
|
89
|
-
- tests/fixtures/fail23.json
|
90
|
-
- tests/fixtures/fail24.json
|
91
|
-
- tests/fixtures/fail25.json
|
92
|
-
- tests/fixtures/fail27.json
|
93
|
-
- tests/fixtures/fail28.json
|
94
|
-
- tests/fixtures/fail29.json
|
95
|
-
- tests/fixtures/fail3.json
|
96
|
-
- tests/fixtures/fail30.json
|
97
|
-
- tests/fixtures/fail31.json
|
98
|
-
- tests/fixtures/fail32.json
|
99
|
-
- tests/fixtures/fail4.json
|
100
|
-
- tests/fixtures/fail5.json
|
101
|
-
- tests/fixtures/fail6.json
|
102
|
-
- tests/fixtures/fail7.json
|
103
|
-
- tests/fixtures/fail8.json
|
104
|
-
- tests/fixtures/fail9.json
|
105
|
-
- tests/fixtures/obsolete_fail1.json
|
106
|
-
- tests/fixtures/pass1.json
|
107
|
-
- tests/fixtures/pass15.json
|
108
|
-
- tests/fixtures/pass16.json
|
109
|
-
- tests/fixtures/pass17.json
|
110
|
-
- tests/fixtures/pass2.json
|
111
|
-
- tests/fixtures/pass26.json
|
112
|
-
- tests/fixtures/pass3.json
|
113
|
-
- tests/json_addition_test.rb
|
114
|
-
- tests/json_common_interface_test.rb
|
115
|
-
- tests/json_encoding_test.rb
|
116
|
-
- tests/json_ext_parser_test.rb
|
117
|
-
- tests/json_fixtures_test.rb
|
118
|
-
- tests/json_generator_test.rb
|
119
|
-
- tests/json_generic_object_test.rb
|
120
|
-
- tests/json_parser_test.rb
|
121
|
-
- tests/json_string_matching_test.rb
|
122
|
-
- tests/test_helper.rb
|
123
44
|
homepage: http://flori.github.com/json
|
124
45
|
licenses:
|
125
46
|
- Ruby
|
@@ -138,16 +59,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
59
|
requirements:
|
139
60
|
- - ">="
|
140
61
|
- !ruby/object:Gem::Version
|
141
|
-
version: '2.
|
62
|
+
version: '2.3'
|
142
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
64
|
requirements:
|
144
65
|
- - ">="
|
145
66
|
- !ruby/object:Gem::Version
|
146
67
|
version: '0'
|
147
68
|
requirements: []
|
148
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.2.29
|
149
70
|
signing_key:
|
150
71
|
specification_version: 4
|
151
72
|
summary: JSON Implementation for Ruby
|
152
|
-
test_files:
|
153
|
-
- tests/test_helper.rb
|
73
|
+
test_files: []
|
data/tests/fixtures/fail10.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Extra value after close": true} "misplaced quoted value"
|
data/tests/fixtures/fail11.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Illegal expression": 1 + 2}
|
data/tests/fixtures/fail12.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Illegal invocation": alert()}
|
data/tests/fixtures/fail13.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Numbers cannot have leading zeroes": 013}
|
data/tests/fixtures/fail14.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Numbers cannot be hex": 0x14}
|
data/tests/fixtures/fail18.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
|
data/tests/fixtures/fail19.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Missing colon" null}
|
data/tests/fixtures/fail2.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["Unclosed array"
|
data/tests/fixtures/fail20.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Double colon":: null}
|
data/tests/fixtures/fail21.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Comma instead of colon", null}
|
data/tests/fixtures/fail22.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["Colon instead of comma": false]
|
data/tests/fixtures/fail23.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["Bad value", truth]
|
data/tests/fixtures/fail24.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
['single quote']
|
data/tests/fixtures/fail25.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["tab character in string "]
|
data/tests/fixtures/fail27.json
DELETED
data/tests/fixtures/fail28.json
DELETED
data/tests/fixtures/fail29.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{
|
data/tests/fixtures/fail3.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{unquoted_key: "keys must be quoted"}
|
data/tests/fixtures/fail30.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
[
|
data/tests/fixtures/fail31.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
[1, 2, 3,
|
data/tests/fixtures/fail32.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"foo": "bar"
|
data/tests/fixtures/fail4.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["extra comma",]
|
data/tests/fixtures/fail5.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["double extra comma",,]
|
data/tests/fixtures/fail6.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
[ , "<-- missing value"]
|
data/tests/fixtures/fail7.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["Comma after the close"],
|
data/tests/fixtures/fail8.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["Extra close"]]
|
data/tests/fixtures/fail9.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"Extra comma": true,}
|
@@ -1 +0,0 @@
|
|
1
|
-
"A JSON payload should be an object or array, not a string."
|
data/tests/fixtures/pass1.json
DELETED
@@ -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": "" \u0022 %22 0x22 034 "",
|
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"]
|
data/tests/fixtures/pass15.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["Illegal backslash escape: \x15"]
|
data/tests/fixtures/pass16.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["Illegal backslash escape: \'"]
|
data/tests/fixtures/pass17.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["Illegal backslash escape: \017"]
|
data/tests/fixtures/pass2.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
|
data/tests/fixtures/pass26.json
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
["tab\ character\ in\ string\ "]
|
data/tests/fixtures/pass3.json
DELETED
data/tests/json_addition_test.rb
DELETED
@@ -1,199 +0,0 @@
|
|
1
|
-
#frozen_string_literal: false
|
2
|
-
require 'test_helper'
|
3
|
-
require 'json/add/core'
|
4
|
-
require 'json/add/complex'
|
5
|
-
require 'json/add/rational'
|
6
|
-
require 'json/add/bigdecimal'
|
7
|
-
require 'json/add/ostruct'
|
8
|
-
require 'json/add/set'
|
9
|
-
require 'date'
|
10
|
-
|
11
|
-
class JSONAdditionTest < Test::Unit::TestCase
|
12
|
-
include JSON
|
13
|
-
|
14
|
-
class A
|
15
|
-
def initialize(a)
|
16
|
-
@a = a
|
17
|
-
end
|
18
|
-
|
19
|
-
attr_reader :a
|
20
|
-
|
21
|
-
def ==(other)
|
22
|
-
a == other.a
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.json_create(object)
|
26
|
-
new(*object['args'])
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_json(*args)
|
30
|
-
{
|
31
|
-
'json_class' => self.class.name,
|
32
|
-
'args' => [ @a ],
|
33
|
-
}.to_json(*args)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class A2 < A
|
38
|
-
def to_json(*args)
|
39
|
-
{
|
40
|
-
'json_class' => self.class.name,
|
41
|
-
'args' => [ @a ],
|
42
|
-
}.to_json(*args)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class B
|
47
|
-
def self.json_creatable?
|
48
|
-
false
|
49
|
-
end
|
50
|
-
|
51
|
-
def to_json(*args)
|
52
|
-
{
|
53
|
-
'json_class' => self.class.name,
|
54
|
-
}.to_json(*args)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class C
|
59
|
-
def self.json_creatable?
|
60
|
-
false
|
61
|
-
end
|
62
|
-
|
63
|
-
def to_json(*args)
|
64
|
-
{
|
65
|
-
'json_class' => 'JSONAdditionTest::Nix',
|
66
|
-
}.to_json(*args)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_extended_json
|
71
|
-
a = A.new(666)
|
72
|
-
assert A.json_creatable?
|
73
|
-
json = generate(a)
|
74
|
-
a_again = parse(json, :create_additions => true)
|
75
|
-
assert_kind_of a.class, a_again
|
76
|
-
assert_equal a, a_again
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_extended_json_default
|
80
|
-
a = A.new(666)
|
81
|
-
assert A.json_creatable?
|
82
|
-
json = generate(a)
|
83
|
-
a_hash = parse(json)
|
84
|
-
assert_kind_of Hash, a_hash
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_extended_json_disabled
|
88
|
-
a = A.new(666)
|
89
|
-
assert A.json_creatable?
|
90
|
-
json = generate(a)
|
91
|
-
a_again = parse(json, :create_additions => true)
|
92
|
-
assert_kind_of a.class, a_again
|
93
|
-
assert_equal a, a_again
|
94
|
-
a_hash = parse(json, :create_additions => false)
|
95
|
-
assert_kind_of Hash, a_hash
|
96
|
-
assert_equal(
|
97
|
-
{"args"=>[666], "json_class"=>"JSONAdditionTest::A"}.sort_by { |k,| k },
|
98
|
-
a_hash.sort_by { |k,| k }
|
99
|
-
)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_extended_json_fail1
|
103
|
-
b = B.new
|
104
|
-
assert !B.json_creatable?
|
105
|
-
json = generate(b)
|
106
|
-
assert_equal({ "json_class"=>"JSONAdditionTest::B" }, parse(json))
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_extended_json_fail2
|
110
|
-
c = C.new
|
111
|
-
assert !C.json_creatable?
|
112
|
-
json = generate(c)
|
113
|
-
assert_raise(ArgumentError, NameError) { parse(json, :create_additions => true) }
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_raw_strings
|
117
|
-
raw = ''
|
118
|
-
raw.respond_to?(:encode!) and raw.encode!(Encoding::ASCII_8BIT)
|
119
|
-
raw_array = []
|
120
|
-
for i in 0..255
|
121
|
-
raw << i
|
122
|
-
raw_array << i
|
123
|
-
end
|
124
|
-
json = raw.to_json_raw
|
125
|
-
json_raw_object = raw.to_json_raw_object
|
126
|
-
hash = { 'json_class' => 'String', 'raw'=> raw_array }
|
127
|
-
assert_equal hash, json_raw_object
|
128
|
-
assert_match(/\A\{.*\}\z/, json)
|
129
|
-
assert_match(/"json_class":"String"/, json)
|
130
|
-
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)
|
131
|
-
raw_again = parse(json, :create_additions => true)
|
132
|
-
assert_equal raw, raw_again
|
133
|
-
end
|
134
|
-
|
135
|
-
MyJsonStruct = Struct.new 'MyJsonStruct', :foo, :bar
|
136
|
-
|
137
|
-
def test_core
|
138
|
-
t = Time.now
|
139
|
-
assert_equal t, JSON(JSON(t), :create_additions => true)
|
140
|
-
d = Date.today
|
141
|
-
assert_equal d, JSON(JSON(d), :create_additions => true)
|
142
|
-
d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161)
|
143
|
-
assert_equal d, JSON(JSON(d), :create_additions => true)
|
144
|
-
assert_equal 1..10, JSON(JSON(1..10), :create_additions => true)
|
145
|
-
assert_equal 1...10, JSON(JSON(1...10), :create_additions => true)
|
146
|
-
assert_equal "a".."c", JSON(JSON("a".."c"), :create_additions => true)
|
147
|
-
assert_equal "a"..."c", JSON(JSON("a"..."c"), :create_additions => true)
|
148
|
-
s = MyJsonStruct.new 4711, 'foot'
|
149
|
-
assert_equal s, JSON(JSON(s), :create_additions => true)
|
150
|
-
struct = Struct.new :foo, :bar
|
151
|
-
s = struct.new 4711, 'foot'
|
152
|
-
assert_raise(JSONError) { JSON(s) }
|
153
|
-
begin
|
154
|
-
raise TypeError, "test me"
|
155
|
-
rescue TypeError => e
|
156
|
-
e_json = JSON.generate e
|
157
|
-
e_again = JSON e_json, :create_additions => true
|
158
|
-
assert_kind_of TypeError, e_again
|
159
|
-
assert_equal e.message, e_again.message
|
160
|
-
assert_equal e.backtrace, e_again.backtrace
|
161
|
-
end
|
162
|
-
assert_equal(/foo/, JSON(JSON(/foo/), :create_additions => true))
|
163
|
-
assert_equal(/foo/i, JSON(JSON(/foo/i), :create_additions => true))
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_utc_datetime
|
167
|
-
now = Time.now
|
168
|
-
d = DateTime.parse(now.to_s, :create_additions => true) # usual case
|
169
|
-
assert_equal d, parse(d.to_json, :create_additions => true)
|
170
|
-
d = DateTime.parse(now.utc.to_s) # of = 0
|
171
|
-
assert_equal d, parse(d.to_json, :create_additions => true)
|
172
|
-
d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(1,24))
|
173
|
-
assert_equal d, parse(d.to_json, :create_additions => true)
|
174
|
-
d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(12,24))
|
175
|
-
assert_equal d, parse(d.to_json, :create_additions => true)
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_rational_complex
|
179
|
-
assert_equal Rational(2, 9), parse(JSON(Rational(2, 9)), :create_additions => true)
|
180
|
-
assert_equal Complex(2, 9), parse(JSON(Complex(2, 9)), :create_additions => true)
|
181
|
-
end
|
182
|
-
|
183
|
-
def test_bigdecimal
|
184
|
-
assert_equal BigDecimal('3.141', 23), JSON(JSON(BigDecimal('3.141', 23)), :create_additions => true)
|
185
|
-
assert_equal BigDecimal('3.141', 666), JSON(JSON(BigDecimal('3.141', 666)), :create_additions => true)
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_ostruct
|
189
|
-
o = OpenStruct.new
|
190
|
-
# XXX this won't work; o.foo = { :bar => true }
|
191
|
-
o.foo = { 'bar' => true }
|
192
|
-
assert_equal o, parse(JSON(o), :create_additions => true)
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_set
|
196
|
-
s = Set.new([:a, :b, :c, :a])
|
197
|
-
assert_equal s, JSON.parse(JSON(s), :create_additions => true)
|
198
|
-
end
|
199
|
-
end
|