json 2.5.1-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/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 -85
- 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 -399
- 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/lib/core_assertions.rb +0 -763
- data/tests/lib/envutil.rb +0 -365
- data/tests/lib/find_executable.rb +0 -22
- data/tests/lib/helper.rb +0 -4
- data/tests/ractor_test.rb +0 -30
- data/tests/test_helper.rb +0 -17
@@ -1,169 +0,0 @@
|
|
1
|
-
#frozen_string_literal: false
|
2
|
-
require 'test_helper'
|
3
|
-
require 'stringio'
|
4
|
-
require 'tempfile'
|
5
|
-
|
6
|
-
class JSONCommonInterfaceTest < Test::Unit::TestCase
|
7
|
-
include JSON
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@hash = {
|
11
|
-
'a' => 2,
|
12
|
-
'b' => 3.141,
|
13
|
-
'c' => 'c',
|
14
|
-
'd' => [ 1, "b", 3.14 ],
|
15
|
-
'e' => { 'foo' => 'bar' },
|
16
|
-
'g' => "\"\0\037",
|
17
|
-
'h' => 1000.0,
|
18
|
-
'i' => 0.001
|
19
|
-
}
|
20
|
-
@json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
|
21
|
-
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_index
|
25
|
-
assert_equal @json, JSON[@hash]
|
26
|
-
assert_equal @hash, JSON[@json]
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_parser
|
30
|
-
assert_match(/::Parser\z/, JSON.parser.name)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_generator
|
34
|
-
assert_match(/::Generator\z/, JSON.generator.name)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_state
|
38
|
-
assert_match(/::Generator::State\z/, JSON.state.name)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_create_id
|
42
|
-
assert_equal 'json_class', JSON.create_id
|
43
|
-
JSON.create_id = 'foo_bar'
|
44
|
-
assert_equal 'foo_bar', JSON.create_id
|
45
|
-
ensure
|
46
|
-
JSON.create_id = 'json_class'
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_deep_const_get
|
50
|
-
assert_raise(ArgumentError) { JSON.deep_const_get('Nix::Da') }
|
51
|
-
assert_equal File::SEPARATOR, JSON.deep_const_get('File::SEPARATOR')
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_parse
|
55
|
-
assert_equal [ 1, 2, 3, ], JSON.parse('[ 1, 2, 3 ]')
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_parse_bang
|
59
|
-
assert_equal [ 1, Infinity, 3, ], JSON.parse!('[ 1, Infinity, 3 ]')
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_generate
|
63
|
-
assert_equal '[1,2,3]', JSON.generate([ 1, 2, 3 ])
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_fast_generate
|
67
|
-
assert_equal '[1,2,3]', JSON.generate([ 1, 2, 3 ])
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_pretty_generate
|
71
|
-
assert_equal "[\n 1,\n 2,\n 3\n]", JSON.pretty_generate([ 1, 2, 3 ])
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_load
|
75
|
-
assert_equal @hash, JSON.load(@json)
|
76
|
-
tempfile = Tempfile.open('@json')
|
77
|
-
tempfile.write @json
|
78
|
-
tempfile.rewind
|
79
|
-
assert_equal @hash, JSON.load(tempfile)
|
80
|
-
stringio = StringIO.new(@json)
|
81
|
-
stringio.rewind
|
82
|
-
assert_equal @hash, JSON.load(stringio)
|
83
|
-
assert_equal nil, JSON.load(nil)
|
84
|
-
assert_equal nil, JSON.load('')
|
85
|
-
ensure
|
86
|
-
tempfile.close!
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_load_with_options
|
90
|
-
json = '{ "foo": NaN }'
|
91
|
-
assert JSON.load(json, nil, :allow_nan => true)['foo'].nan?
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_load_null
|
95
|
-
assert_equal nil, JSON.load(nil, nil, :allow_blank => true)
|
96
|
-
assert_raise(TypeError) { JSON.load(nil, nil, :allow_blank => false) }
|
97
|
-
assert_raise(JSON::ParserError) { JSON.load('', nil, :allow_blank => false) }
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_dump
|
101
|
-
too_deep = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
102
|
-
assert_equal too_deep, dump(eval(too_deep))
|
103
|
-
assert_kind_of String, Marshal.dump(eval(too_deep))
|
104
|
-
assert_raise(ArgumentError) { dump(eval(too_deep), 100) }
|
105
|
-
assert_raise(ArgumentError) { Marshal.dump(eval(too_deep), 100) }
|
106
|
-
assert_equal too_deep, dump(eval(too_deep), 101)
|
107
|
-
assert_kind_of String, Marshal.dump(eval(too_deep), 101)
|
108
|
-
output = StringIO.new
|
109
|
-
dump(eval(too_deep), output)
|
110
|
-
assert_equal too_deep, output.string
|
111
|
-
output = StringIO.new
|
112
|
-
dump(eval(too_deep), output, 101)
|
113
|
-
assert_equal too_deep, output.string
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_dump_should_modify_defaults
|
117
|
-
max_nesting = JSON.dump_default_options[:max_nesting]
|
118
|
-
dump([], StringIO.new, 10)
|
119
|
-
assert_equal max_nesting, JSON.dump_default_options[:max_nesting]
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_JSON
|
123
|
-
assert_equal @json, JSON(@hash)
|
124
|
-
assert_equal @hash, JSON(@json)
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_load_file
|
128
|
-
test_load_shared(:load_file)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_load_file!
|
132
|
-
test_load_shared(:load_file!)
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_load_file_with_option
|
136
|
-
test_load_file_with_option_shared(:load_file)
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_load_file_with_option!
|
140
|
-
test_load_file_with_option_shared(:load_file!)
|
141
|
-
end
|
142
|
-
|
143
|
-
private
|
144
|
-
|
145
|
-
def test_load_shared(method_name)
|
146
|
-
temp_file_containing(@json) do |filespec|
|
147
|
-
assert_equal JSON.public_send(method_name, filespec), @hash
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_load_file_with_option_shared(method_name)
|
152
|
-
temp_file_containing(@json) do |filespec|
|
153
|
-
parsed_object = JSON.public_send(method_name, filespec, symbolize_names: true)
|
154
|
-
key_classes = parsed_object.keys.map(&:class)
|
155
|
-
assert_include(key_classes, Symbol)
|
156
|
-
assert_not_include(key_classes, String)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def temp_file_containing(text, file_prefix = '')
|
161
|
-
raise "This method must be called with a code block." unless block_given?
|
162
|
-
|
163
|
-
Tempfile.create(file_prefix) do |file|
|
164
|
-
file << text
|
165
|
-
file.close
|
166
|
-
yield file.path
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
data/tests/json_encoding_test.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#frozen_string_literal: false
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class JSONEncodingTest < Test::Unit::TestCase
|
6
|
-
include JSON
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@utf_8 = '"© ≠ €!"'
|
10
|
-
@ascii_8bit = @utf_8.dup.force_encoding('ascii-8bit')
|
11
|
-
@parsed = "© ≠ €!"
|
12
|
-
@generated = '"\u00a9 \u2260 \u20ac!"'
|
13
|
-
if String.method_defined?(:encode)
|
14
|
-
@utf_16_data = @parsed.encode('utf-16be', 'utf-8')
|
15
|
-
@utf_16be = @utf_8.encode('utf-16be', 'utf-8')
|
16
|
-
@utf_16le = @utf_8.encode('utf-16le', 'utf-8')
|
17
|
-
@utf_32be = @utf_8.encode('utf-32be', 'utf-8')
|
18
|
-
@utf_32le = @utf_8.encode('utf-32le', 'utf-8')
|
19
|
-
else
|
20
|
-
require 'iconv'
|
21
|
-
@utf_16_data, = Iconv.iconv('utf-16be', 'utf-8', @parsed)
|
22
|
-
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
|
23
|
-
@utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
|
24
|
-
@utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
|
25
|
-
@utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_parse
|
30
|
-
assert_equal @parsed, JSON.parse(@ascii_8bit)
|
31
|
-
assert_equal @parsed, JSON.parse(@utf_8)
|
32
|
-
assert_equal @parsed, JSON.parse(@utf_16be)
|
33
|
-
assert_equal @parsed, JSON.parse(@utf_16le)
|
34
|
-
assert_equal @parsed, JSON.parse(@utf_32be)
|
35
|
-
assert_equal @parsed, JSON.parse(@utf_32le)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_generate
|
39
|
-
assert_equal @generated, JSON.generate(@parsed, :ascii_only => true)
|
40
|
-
assert_equal @generated, JSON.generate(@utf_16_data, :ascii_only => true)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_unicode
|
44
|
-
assert_equal '""', ''.to_json
|
45
|
-
assert_equal '"\\b"', "\b".to_json
|
46
|
-
assert_equal '"\u0001"', 0x1.chr.to_json
|
47
|
-
assert_equal '"\u001f"', 0x1f.chr.to_json
|
48
|
-
assert_equal '" "', ' '.to_json
|
49
|
-
assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json
|
50
|
-
utf8 = [ "© ≠ €! \01" ]
|
51
|
-
json = '["© ≠ €! \u0001"]'
|
52
|
-
assert_equal json, utf8.to_json(:ascii_only => false)
|
53
|
-
assert_equal utf8, parse(json)
|
54
|
-
json = '["\u00a9 \u2260 \u20ac! \u0001"]'
|
55
|
-
assert_equal json, utf8.to_json(:ascii_only => true)
|
56
|
-
assert_equal utf8, parse(json)
|
57
|
-
utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
|
58
|
-
json = "[\"\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212\"]"
|
59
|
-
assert_equal utf8, parse(json)
|
60
|
-
assert_equal json, utf8.to_json(:ascii_only => false)
|
61
|
-
utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"]
|
62
|
-
assert_equal utf8, parse(json)
|
63
|
-
json = "[\"\\u3042\\u3044\\u3046\\u3048\\u304a\"]"
|
64
|
-
assert_equal json, utf8.to_json(:ascii_only => true)
|
65
|
-
assert_equal utf8, parse(json)
|
66
|
-
utf8 = ['საქართველო']
|
67
|
-
json = '["საქართველო"]'
|
68
|
-
assert_equal json, utf8.to_json(:ascii_only => false)
|
69
|
-
json = "[\"\\u10e1\\u10d0\\u10e5\\u10d0\\u10e0\\u10d7\\u10d5\\u10d4\\u10da\\u10dd\"]"
|
70
|
-
assert_equal json, utf8.to_json(:ascii_only => true)
|
71
|
-
assert_equal utf8, parse(json)
|
72
|
-
assert_equal '["Ã"]', generate(["Ã"], :ascii_only => false)
|
73
|
-
assert_equal '["\\u00c3"]', generate(["Ã"], :ascii_only => true)
|
74
|
-
assert_equal ["€"], parse('["\u20ac"]')
|
75
|
-
utf8 = ["\xf0\xa0\x80\x81"]
|
76
|
-
json = "[\"\xf0\xa0\x80\x81\"]"
|
77
|
-
assert_equal json, generate(utf8, :ascii_only => false)
|
78
|
-
assert_equal utf8, parse(json)
|
79
|
-
json = '["\ud840\udc01"]'
|
80
|
-
assert_equal json, generate(utf8, :ascii_only => true)
|
81
|
-
assert_equal utf8, parse(json)
|
82
|
-
assert_raise(JSON::ParserError) { parse('"\u"') }
|
83
|
-
assert_raise(JSON::ParserError) { parse('"\ud800"') }
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_chars
|
87
|
-
(0..0x7f).each do |i|
|
88
|
-
json = '["\u%04x"]' % i
|
89
|
-
if RUBY_VERSION >= "1.9."
|
90
|
-
i = i.chr
|
91
|
-
end
|
92
|
-
assert_equal i, parse(json).first[0]
|
93
|
-
if i == ?\b
|
94
|
-
generated = generate(["" << i])
|
95
|
-
assert '["\b"]' == generated || '["\10"]' == generated
|
96
|
-
elsif [?\n, ?\r, ?\t, ?\f].include?(i)
|
97
|
-
assert_equal '[' << ('' << i).dump << ']', generate(["" << i])
|
98
|
-
elsif i.chr < 0x20.chr
|
99
|
-
assert_equal json, generate(["" << i])
|
100
|
-
end
|
101
|
-
end
|
102
|
-
assert_raise(JSON::GeneratorError) do
|
103
|
-
generate(["\x80"], :ascii_only => true)
|
104
|
-
end
|
105
|
-
assert_equal "\302\200", parse('["\u0080"]').first
|
106
|
-
end
|
107
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
#frozen_string_literal: false
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class JSONExtParserTest < Test::Unit::TestCase
|
5
|
-
if defined?(JSON::Ext::Parser)
|
6
|
-
def test_allocate
|
7
|
-
parser = JSON::Ext::Parser.new("{}")
|
8
|
-
assert_raise(TypeError, '[ruby-core:35079]') do
|
9
|
-
parser.__send__(:initialize, "{}")
|
10
|
-
end
|
11
|
-
parser = JSON::Ext::Parser.allocate
|
12
|
-
assert_raise(TypeError, '[ruby-core:35079]') { parser.source }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/tests/json_fixtures_test.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
#frozen_string_literal: false
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class JSONFixturesTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
fixtures = File.join(File.dirname(__FILE__), 'fixtures/{fail,pass}*.json')
|
7
|
-
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
|
8
|
-
@passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
9
|
-
@failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_passing
|
13
|
-
verbose_bak, $VERBOSE = $VERBOSE, nil
|
14
|
-
for name, source in @passed
|
15
|
-
begin
|
16
|
-
assert JSON.parse(source),
|
17
|
-
"Did not pass for fixture '#{name}': #{source.inspect}"
|
18
|
-
rescue => e
|
19
|
-
warn "\nCaught #{e.class}(#{e}) for fixture '#{name}': #{source.inspect}\n#{e.backtrace * "\n"}"
|
20
|
-
raise e
|
21
|
-
end
|
22
|
-
end
|
23
|
-
ensure
|
24
|
-
$VERBOSE = verbose_bak
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_failing
|
28
|
-
for name, source in @failed
|
29
|
-
assert_raise(JSON::ParserError, JSON::NestingError,
|
30
|
-
"Did not fail for fixture '#{name}': #{source.inspect}") do
|
31
|
-
JSON.parse(source)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_sanity
|
37
|
-
assert(@passed.size > 5)
|
38
|
-
assert(@failed.size > 20)
|
39
|
-
end
|
40
|
-
end
|