json 2.0.4-java → 2.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ require 'test_helper'
4
4
  require 'stringio'
5
5
  require 'tempfile'
6
6
  require 'ostruct'
7
+ require 'bigdecimal'
7
8
 
8
9
  class JSONParserTest < Test::Unit::TestCase
9
10
  include JSON
@@ -90,22 +91,27 @@ class JSONParserTest < Test::Unit::TestCase
90
91
  assert_raise(JSON::ParserError) { parse('+23') }
91
92
  assert_raise(JSON::ParserError) { parse('.23') }
92
93
  assert_raise(JSON::ParserError) { parse('023') }
93
- assert_equal 23, parse('23')
94
- assert_equal -23, parse('-23')
95
- assert_equal_float 3.141, parse('3.141')
96
- assert_equal_float -3.141, parse('-3.141')
97
- assert_equal_float 3.141, parse('3141e-3')
98
- assert_equal_float 3.141, parse('3141.1e-3')
99
- assert_equal_float 3.141, parse('3141E-3')
100
- assert_equal_float 3.141, parse('3141.0E-3')
101
- assert_equal_float -3.141, parse('-3141.0e-3')
102
- assert_equal_float -3.141, parse('-3141e-3')
94
+ assert_equal(23, parse('23'))
95
+ assert_equal(-23, parse('-23'))
96
+ assert_equal_float(3.141, parse('3.141'))
97
+ assert_equal_float(-3.141, parse('-3.141'))
98
+ assert_equal_float(3.141, parse('3141e-3'))
99
+ assert_equal_float(3.141, parse('3141.1e-3'))
100
+ assert_equal_float(3.141, parse('3141E-3'))
101
+ assert_equal_float(3.141, parse('3141.0E-3'))
102
+ assert_equal_float(-3.141, parse('-3141.0e-3'))
103
+ assert_equal_float(-3.141, parse('-3141e-3'))
103
104
  assert_raise(ParserError) { parse('NaN') }
104
105
  assert parse('NaN', :allow_nan => true).nan?
105
106
  assert_raise(ParserError) { parse('Infinity') }
106
- assert_equal 1.0/0, parse('Infinity', :allow_nan => true)
107
+ assert_equal(1.0/0, parse('Infinity', :allow_nan => true))
107
108
  assert_raise(ParserError) { parse('-Infinity') }
108
- assert_equal -1.0/0, parse('-Infinity', :allow_nan => true)
109
+ assert_equal(-1.0/0, parse('-Infinity', :allow_nan => true))
110
+ end
111
+
112
+ def test_parse_bigdecimals
113
+ assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class)
114
+ assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
109
115
  end
110
116
 
111
117
  if Array.method_defined?(:permutation)
@@ -212,6 +218,17 @@ class JSONParserTest < Test::Unit::TestCase
212
218
  end
213
219
  end
214
220
 
221
+ def test_freeze
222
+ assert_predicate parse('{}', :freeze => true), :frozen?
223
+ assert_predicate parse('[]', :freeze => true), :frozen?
224
+ assert_predicate parse('"foo"', :freeze => true), :frozen?
225
+
226
+ if string_deduplication_available?
227
+ assert_same(-'foo', parse('"foo"', :freeze => true))
228
+ assert_same(-'foo', parse('{"foo": 1}', :freeze => true).keys.first)
229
+ end
230
+ end
231
+
215
232
  def test_parse_comments
216
233
  json = <<EOT
217
234
  {
@@ -287,6 +304,10 @@ EOT
287
304
  json = '["\\\'"]'
288
305
  data = ["'"]
289
306
  assert_equal data, parse(json)
307
+
308
+ json = '["\/"]'
309
+ data = [ '/' ]
310
+ assert_equal data, parse(json)
290
311
  end
291
312
 
292
313
  class SubArray < Array
@@ -458,6 +479,16 @@ EOT
458
479
 
459
480
  private
460
481
 
482
+ def string_deduplication_available?
483
+ r1 = rand.to_s
484
+ r2 = r1.dup
485
+ begin
486
+ (-r1).equal?(-r2)
487
+ rescue NoMethodError
488
+ false # No String#-@
489
+ end
490
+ end
491
+
461
492
  def assert_equal_float(expected, actual, delta = 1e-2)
462
493
  Array === expected and expected = expected.first
463
494
  Array === actual and actual = actual.first
@@ -1,12 +1,12 @@
1
1
  case ENV['JSON']
2
2
  when 'pure'
3
- $:.unshift 'lib'
3
+ $:.unshift File.join(__dir__, '../lib')
4
4
  require 'json/pure'
5
5
  when 'ext'
6
- $:.unshift 'ext', 'lib'
6
+ $:.unshift File.join(__dir__, '../ext'), File.join(__dir__, '../lib')
7
7
  require 'json/ext'
8
8
  else
9
- $:.unshift 'ext', 'lib'
9
+ $:.unshift File.join(__dir__, '../ext'), File.join(__dir__, '../lib')
10
10
  require 'json'
11
11
  end
12
12
 
@@ -15,7 +15,3 @@ begin
15
15
  require 'byebug'
16
16
  rescue LoadError
17
17
  end
18
- if ENV['START_SIMPLECOV'].to_i == 1
19
- require 'simplecov'
20
- SimpleCov.start
21
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.4.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: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -17,8 +17,8 @@ dependencies:
17
17
  - !ruby/object:Gem::Version
18
18
  version: '0'
19
19
  name: rake
20
- prerelease: false
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
@@ -27,23 +27,30 @@ dependencies:
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - "~>"
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '4.0'
33
36
  name: test-unit
34
- prerelease: false
35
37
  type: :development
38
+ prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '2.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
41
47
  description: A JSON implementation as a JRuby extension.
42
48
  email: dev+ruby@mernen.com
43
49
  executables: []
44
50
  extensions: []
45
51
  extra_rdoc_files: []
46
52
  files:
53
+ - LICENSE
47
54
  - lib/json.rb
48
55
  - lib/json/add/bigdecimal.rb
49
56
  - lib/json/add/complex.rb
@@ -55,6 +62,7 @@ files:
55
62
  - lib/json/add/range.rb
56
63
  - lib/json/add/rational.rb
57
64
  - lib/json/add/regexp.rb
65
+ - lib/json/add/set.rb
58
66
  - lib/json/add/struct.rb
59
67
  - lib/json/add/symbol.rb
60
68
  - lib/json/add/time.rb
@@ -83,7 +91,11 @@ files:
83
91
  - tests/fixtures/fail25.json
84
92
  - tests/fixtures/fail27.json
85
93
  - tests/fixtures/fail28.json
94
+ - tests/fixtures/fail29.json
86
95
  - tests/fixtures/fail3.json
96
+ - tests/fixtures/fail30.json
97
+ - tests/fixtures/fail31.json
98
+ - tests/fixtures/fail32.json
87
99
  - tests/fixtures/fail4.json
88
100
  - tests/fixtures/fail5.json
89
101
  - tests/fixtures/fail6.json
@@ -108,10 +120,16 @@ files:
108
120
  - tests/json_parser_test.rb
109
121
  - tests/json_string_matching_test.rb
110
122
  - tests/test_helper.rb
111
- homepage: http://json-jruby.rubyforge.org/
123
+ homepage: http://flori.github.com/json
112
124
  licenses:
113
125
  - Ruby
114
- metadata: {}
126
+ metadata:
127
+ bug_tracker_uri: https://github.com/flori/json/issues
128
+ changelog_uri: https://github.com/flori/json/blob/master/CHANGES.md
129
+ documentation_uri: http://flori.github.io/json/doc/index.html
130
+ homepage_uri: http://flori.github.io/json/
131
+ source_code_uri: https://github.com/flori/json
132
+ wiki_uri: https://github.com/flori/json/wiki
115
133
  post_install_message:
116
134
  rdoc_options: []
117
135
  require_paths:
@@ -120,16 +138,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
138
  requirements:
121
139
  - - ">="
122
140
  - !ruby/object:Gem::Version
123
- version: '0'
141
+ version: '2.0'
124
142
  required_rubygems_version: !ruby/object:Gem::Requirement
125
143
  requirements:
126
144
  - - ">="
127
145
  - !ruby/object:Gem::Version
128
146
  version: '0'
129
147
  requirements: []
130
- rubyforge_project: json-jruby
131
- rubygems_version: 2.6.8
148
+ rubygems_version: 3.0.6
132
149
  signing_key:
133
150
  specification_version: 4
134
- summary: JSON implementation for JRuby
135
- test_files: []
151
+ summary: JSON Implementation for Ruby
152
+ test_files:
153
+ - tests/test_helper.rb