oj 3.14.2 → 3.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +0 -1
- data/ext/oj/buf.h +2 -2
- data/ext/oj/cache.c +16 -16
- data/ext/oj/cache8.c +7 -7
- data/ext/oj/circarray.c +2 -1
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +2 -2
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +6 -14
- data/ext/oj/custom.c +1 -1
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +16 -16
- data/ext/oj/dump_compat.c +551 -576
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +35 -36
- data/ext/oj/dump_strict.c +2 -4
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +1 -1
- data/ext/oj/fast.c +24 -38
- data/ext/oj/intern.c +38 -42
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +211 -217
- data/ext/oj/mem.h +10 -10
- data/ext/oj/mimic_json.c +18 -24
- data/ext/oj/object.c +5 -5
- data/ext/oj/odd.c +2 -1
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +60 -81
- data/ext/oj/oj.h +53 -54
- data/ext/oj/parse.c +55 -118
- data/ext/oj/parse.h +5 -10
- data/ext/oj/parser.c +7 -8
- data/ext/oj/parser.h +7 -8
- data/ext/oj/rails.c +28 -59
- data/ext/oj/reader.c +5 -9
- data/ext/oj/reader.h +1 -1
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +1 -1
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +4 -4
- data/ext/oj/saj2.c +32 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +18 -67
- data/ext/oj/stream_writer.c +5 -18
- data/ext/oj/strict.c +7 -13
- data/ext/oj/string_writer.c +6 -14
- data/ext/oj/trace.h +27 -16
- data/ext/oj/usual.c +62 -61
- data/ext/oj/usual.h +6 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.h +4 -4
- data/ext/oj/wab.c +7 -9
- data/lib/oj/active_support_helper.rb +0 -1
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +0 -1
- data/lib/oj/json.rb +4 -2
- data/lib/oj/mimic.rb +4 -2
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +0 -1
- data/test/_test_active.rb +0 -1
- data/test/_test_active_mimic.rb +0 -1
- data/test/_test_mimic_rails.rb +0 -1
- data/test/activerecord/result_test.rb +5 -6
- data/test/bar.rb +3 -3
- data/test/files.rb +1 -1
- data/test/foo.rb +5 -48
- data/test/helper.rb +1 -4
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +4 -4
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +43 -32
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +46 -46
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/mem.rb +7 -7
- data/test/perf.rb +2 -2
- data/test/perf_compat.rb +1 -1
- data/test/perf_fast.rb +1 -1
- data/test/perf_file.rb +2 -2
- data/test/perf_object.rb +1 -2
- data/test/perf_once.rb +4 -4
- data/test/perf_parser.rb +1 -2
- data/test/perf_saj.rb +1 -2
- data/test/perf_scp.rb +1 -1
- data/test/perf_simple.rb +3 -3
- data/test/perf_strict.rb +1 -1
- data/test/perf_wab.rb +1 -1
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +2 -3
- data/test/sample_json.rb +0 -1
- data/test/test_compat.rb +11 -9
- data/test/test_custom.rb +5 -9
- data/test/test_debian.rb +1 -1
- data/test/test_fast.rb +10 -20
- data/test/test_file.rb +8 -8
- data/test/test_integer_range.rb +2 -2
- data/test/test_null.rb +5 -3
- data/test/test_object.rb +6 -5
- data/test/test_parser_saj.rb +23 -21
- data/test/test_parser_usual.rb +3 -3
- data/test/test_saj.rb +2 -0
- data/test/test_scp.rb +6 -6
- data/test/test_strict.rb +6 -4
- data/test/test_various.rb +21 -24
- data/test/test_wab.rb +6 -5
- data/test/test_writer.rb +1 -1
- metadata +17 -26
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
@@ -13,13 +13,12 @@ Oj.default_options = { mode: :rails }
|
|
13
13
|
|
14
14
|
class ActiveRecordResultTest < Minitest::Test
|
15
15
|
def test_hash_rows
|
16
|
-
|
17
16
|
result = ActiveRecord::Result.new(["one", "two"],
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
[
|
18
|
+
["row 1 col 1", "row 1 col 2"],
|
19
|
+
["row 2 col 1", "row 2 col 2"],
|
20
|
+
["row 3 col 1", "row 3 col 2"],
|
21
|
+
])
|
23
22
|
#puts "*** result: #{Oj.dump(result, indent: 2)}"
|
24
23
|
json_result = if ActiveRecord.version >= Gem::Version.new("6")
|
25
24
|
result.to_a
|
data/test/bar.rb
CHANGED
data/test/files.rb
CHANGED
@@ -7,7 +7,6 @@ if $0 == __FILE__
|
|
7
7
|
$: << '../ext'
|
8
8
|
end
|
9
9
|
|
10
|
-
require 'pp'
|
11
10
|
require 'sample/file'
|
12
11
|
require 'sample/dir'
|
13
12
|
|
@@ -15,6 +14,7 @@ def files(dir)
|
|
15
14
|
d = ::Sample::Dir.new(dir)
|
16
15
|
Dir.new(dir).each do |fn|
|
17
16
|
next if fn.start_with?('.')
|
17
|
+
|
18
18
|
filename = File.join(dir, fn)
|
19
19
|
#filename = '.' == dir ? fn : File.join(dir, fn)
|
20
20
|
if File.directory?(filename)
|
data/test/foo.rb
CHANGED
@@ -6,53 +6,10 @@ $: << File.join(File.dirname(__FILE__), "../ext")
|
|
6
6
|
|
7
7
|
require "oj"
|
8
8
|
|
9
|
-
|
10
|
-
attr_accessor :alpha, :bravo, :charlie, :delta, :echo, :foxtrot, :golf, :hotel, :india, :juliet
|
11
|
-
def self.json_create(arg)
|
12
|
-
obj = self.new
|
13
|
-
obj.alpha = arg["alpha"]
|
14
|
-
obj.bravo = arg["bravo"]
|
15
|
-
obj.charlie = arg["charlie"]
|
16
|
-
obj.delta = arg["delta"]
|
17
|
-
obj.echo = arg["echo"]
|
18
|
-
obj.foxtrot = arg["foxtrot"]
|
19
|
-
obj.golf = arg["golf"]
|
20
|
-
obj.hotel = arg["hotel"]
|
21
|
-
obj.india = arg["india"]
|
22
|
-
obj.juliet = arg["juliet"]
|
23
|
-
obj
|
24
|
-
end
|
25
|
-
end
|
9
|
+
GC.stress = true
|
26
10
|
|
27
|
-
|
28
|
-
|
29
|
-
"bravo": true,
|
30
|
-
"charlie": 123,
|
31
|
-
"delta": "some string",
|
32
|
-
"echo": null,
|
33
|
-
"^": "Stuff",
|
34
|
-
"foxtrot": false,
|
35
|
-
"golf": "gulp",
|
36
|
-
"hotel": {"x": true, "y": false},
|
37
|
-
"india": [null, true, 123],
|
38
|
-
"juliet": "junk"
|
39
|
-
}|
|
40
|
-
|
41
|
-
def parse(json)
|
42
|
-
p_usual = Oj::Parser.new(:usual)
|
43
|
-
p_usual.cache_keys = true
|
44
|
-
p_usual.cache_strings = (p_usual.cache_keys ? 6 : 0)
|
45
|
-
p_usual.symbol_keys = true
|
46
|
-
p_usual.create_id = '^'
|
47
|
-
p_usual.class_cache = true
|
48
|
-
p_usual.ignore_json_create = true
|
49
|
-
|
50
|
-
p_usual.parse(json)
|
51
|
-
nil
|
52
|
-
end
|
53
|
-
|
54
|
-
parse($obj_json)
|
55
|
-
|
56
|
-
Oj.mem_report()
|
11
|
+
require "oj"
|
12
|
+
Oj.mimic_JSON
|
57
13
|
|
58
|
-
Oj.
|
14
|
+
Oj.add_to_json(Hash)
|
15
|
+
pp JSON('{ "a": 1, "b": 2 }', :object_class => JSON::GenericObject)
|
data/test/helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
3
|
# Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
|
4
4
|
# required. That can be set in the RUBYOPT environment variable.
|
5
5
|
# export RUBYOPT=-w
|
@@ -15,10 +15,8 @@ require 'minitest/autorun'
|
|
15
15
|
require 'stringio'
|
16
16
|
require 'date'
|
17
17
|
require 'bigdecimal'
|
18
|
-
require 'pp'
|
19
18
|
require 'oj'
|
20
19
|
|
21
|
-
|
22
20
|
def verify_gc_compaction
|
23
21
|
# This method was added in Ruby 3.0.0. Calling it this way asks the GC to
|
24
22
|
# move objects around, helping to find object movement bugs.
|
@@ -31,7 +29,6 @@ def verify_gc_compaction
|
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
|
-
|
35
32
|
$ruby = RUBY_DESCRIPTION.split(' ')[0]
|
36
33
|
$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
|
37
34
|
|
data/test/isolated/shared.rb
CHANGED
@@ -21,7 +21,7 @@ class SharedMimicTest < Minitest::Test
|
|
21
21
|
alias == eql?
|
22
22
|
|
23
23
|
def as_json()
|
24
|
-
{"json_class" => self.class.to_s,"x" => @x,"y" => @y}
|
24
|
+
{"json_class" => self.class.to_s, "x" => @x, "y" => @y}
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.json_create(h)
|
@@ -207,7 +207,6 @@ class SharedMimicTest < Minitest::Test
|
|
207
207
|
--],#
|
208
208
|
--"a"~:*1#
|
209
209
|
}} == json)
|
210
|
-
|
211
210
|
end
|
212
211
|
|
213
212
|
# fast_generate
|
@@ -261,6 +260,8 @@ class SharedMimicTest < Minitest::Test
|
|
261
260
|
obj = JSON.parse(json, :create_additions => true)
|
262
261
|
JSON.create_id = 'json_class'
|
263
262
|
assert_equal(jam, obj)
|
263
|
+
|
264
|
+
assert_nothing_raised { JSON.create_id = nil }
|
264
265
|
end
|
265
266
|
def test_parse_bang
|
266
267
|
json = %{{"a":1,"b":[true,false]}}
|
@@ -191,9 +191,9 @@ class JSONAdditionTest < Test::Unit::TestCase
|
|
191
191
|
assert_equal d, JSON.parse(d.to_json, :create_additions => true)
|
192
192
|
d = DateTime.parse(now.utc.to_s) # of = 0
|
193
193
|
assert_equal d, JSON.parse(d.to_json, :create_additions => true)
|
194
|
-
d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(1,24))
|
194
|
+
d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(1, 24))
|
195
195
|
assert_equal d, JSON.parse(d.to_json, :create_additions => true)
|
196
|
-
d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(12,24))
|
196
|
+
d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(12, 24))
|
197
197
|
assert_equal d, JSON.parse(d.to_json, :create_additions => true)
|
198
198
|
end
|
199
199
|
|
@@ -29,7 +29,7 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
|
|
29
29
|
#@json = '{"a":2,"b":5.23683071,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
|
30
30
|
#'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
|
31
31
|
@json = '{"a":2,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},'\
|
32
|
-
|
32
|
+
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_index
|
@@ -43,15 +43,15 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
|
|
43
43
|
# functionality and perform better.
|
44
44
|
|
45
45
|
def test_parser
|
46
|
-
assert_match
|
46
|
+
assert_match(/::Parser\z/, JSON.parser.name)
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_generator
|
50
|
-
assert_match
|
50
|
+
assert_match(/::Generator\z/, JSON.generator.name)
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_state
|
54
|
-
assert_match
|
54
|
+
assert_match(/::Generator::State\z/, JSON.state.name)
|
55
55
|
end
|
56
56
|
|
57
57
|
# This doesn't have anything to do with JSON parsing or generation. It seems
|
File without changes
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
4
|
#frozen_string_literal: false
|
5
|
+
|
5
6
|
require 'json_gem/test_helper'
|
6
7
|
|
7
8
|
class JSONFixturesTest < Test::Unit::TestCase
|
@@ -16,7 +17,7 @@ class JSONFixturesTest < Test::Unit::TestCase
|
|
16
17
|
for name, source in @passed
|
17
18
|
begin
|
18
19
|
assert JSON.parse(source),
|
19
|
-
|
20
|
+
"Did not pass for fixture '#{name}': #{source.inspect}"
|
20
21
|
rescue => e
|
21
22
|
warn "\nCaught #{e.class}(#{e}) for fixture '#{name}': #{source.inspect}\n#{e.backtrace * "\n"}"
|
22
23
|
raise e
|
@@ -27,7 +28,7 @@ class JSONFixturesTest < Test::Unit::TestCase
|
|
27
28
|
def test_failing
|
28
29
|
for name, source in @failed
|
29
30
|
assert_raise(JSON::ParserError, JSON::NestingError,
|
30
|
-
|
31
|
+
"Did not fail for fixture '#{name}': #{source.inspect}") do
|
31
32
|
JSON.parse(source)
|
32
33
|
end
|
33
34
|
end
|
@@ -22,24 +22,24 @@ class JSONGeneratorTest < Test::Unit::TestCase
|
|
22
22
|
}
|
23
23
|
@json2 = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
|
24
24
|
'"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
|
25
|
-
@json3 =
|
26
|
-
{
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
42
|
-
EOT
|
25
|
+
@json3 = <<~'EOT'.chomp
|
26
|
+
{
|
27
|
+
"a": 2,
|
28
|
+
"b": 3.141,
|
29
|
+
"c": "c",
|
30
|
+
"d": [
|
31
|
+
1,
|
32
|
+
"b",
|
33
|
+
3.14
|
34
|
+
],
|
35
|
+
"e": {
|
36
|
+
"foo": "bar"
|
37
|
+
},
|
38
|
+
"g": "\"\u0000\u001f",
|
39
|
+
"h": 1000.0,
|
40
|
+
"i": 0.001
|
41
|
+
}
|
42
|
+
EOT
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_generate
|
@@ -64,11 +64,11 @@ EOT
|
|
64
64
|
parsed_json = JSON.parse(json)
|
65
65
|
assert_equal(@hash, parsed_json)
|
66
66
|
json = JSON.pretty_generate({1=>2})
|
67
|
-
assert_equal(
|
68
|
-
{
|
69
|
-
|
70
|
-
}
|
71
|
-
EOT
|
67
|
+
assert_equal(<<~'EOT'.chomp, json)
|
68
|
+
{
|
69
|
+
"1": 2
|
70
|
+
}
|
71
|
+
EOT
|
72
72
|
parsed_json = JSON.parse(json)
|
73
73
|
assert_equal({"1"=>2}, parsed_json)
|
74
74
|
assert_equal '666', JSON.pretty_generate(666)
|
@@ -78,15 +78,15 @@ EOT
|
|
78
78
|
|
79
79
|
def test_generate_custom
|
80
80
|
state = JSON::State.new(:space_before => " ", :space => " ", :indent => "<i>", :object_nl => "\n", :array_nl => "<a_nl>")
|
81
|
-
json = JSON.generate({1=>{2=>3,4=>[5,6]}}, state)
|
82
|
-
assert_equal(
|
83
|
-
{
|
84
|
-
<i>"1" : {
|
85
|
-
<i><i>"2" : 3,
|
86
|
-
<i><i>"4" : [<a_nl><i><i><i>5,<a_nl><i><i><i>6<a_nl><i><i>]
|
87
|
-
<i>}
|
88
|
-
}
|
89
|
-
EOT
|
81
|
+
json = JSON.generate({1=>{2=>3, 4=>[5, 6]}}, state)
|
82
|
+
assert_equal(<<~'EOT'.chomp, json)
|
83
|
+
{
|
84
|
+
<i>"1" : {
|
85
|
+
<i><i>"2" : 3,
|
86
|
+
<i><i>"4" : [<a_nl><i><i><i>5,<a_nl><i><i><i>6<a_nl><i><i>]
|
87
|
+
<i>}
|
88
|
+
}
|
89
|
+
EOT
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_fast_generate
|
@@ -393,4 +393,15 @@ EOT
|
|
393
393
|
assert_equal '["foo"]', JSON.generate([s.new('foo')])
|
394
394
|
end
|
395
395
|
end
|
396
|
+
|
397
|
+
def test_invalid_to_json
|
398
|
+
omit if REAL_JSON_GEM
|
399
|
+
|
400
|
+
data = Object.new
|
401
|
+
def data.to_json(*)
|
402
|
+
nil
|
403
|
+
end
|
404
|
+
|
405
|
+
assert_raises(TypeError) { JSON.generate(data) }
|
406
|
+
end
|
396
407
|
end
|
@@ -29,26 +29,26 @@ class JSONGenericObjectTest < Test::Unit::TestCase
|
|
29
29
|
|
30
30
|
def test_parse_json
|
31
31
|
x = JSON(
|
32
|
-
'{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }',
|
33
|
-
:create_additions => true
|
34
|
-
)
|
35
|
-
assert_kind_of Hash,
|
36
|
-
JSON(
|
37
32
|
'{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }',
|
38
33
|
:create_additions => true
|
39
34
|
)
|
35
|
+
assert_kind_of Hash,
|
36
|
+
JSON(
|
37
|
+
'{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }',
|
38
|
+
:create_additions => true
|
39
|
+
)
|
40
40
|
switch_json_creatable do
|
41
41
|
assert_equal @go, l =
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
JSON(
|
43
|
+
'{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }',
|
44
|
+
:create_additions => true
|
45
|
+
)
|
46
46
|
assert_equal 1, l.a
|
47
47
|
assert_equal @go,
|
48
|
-
|
48
|
+
l = JSON('{ "a": 1, "b": 2 }', :object_class => JSON::GenericObject)
|
49
49
|
assert_equal 1, l.a
|
50
50
|
assert_equal JSON::GenericObject[:a => JSON::GenericObject[:b => 2]],
|
51
|
-
|
51
|
+
l = JSON('{ "a": { "b": 2 } }', :object_class => JSON::GenericObject)
|
52
52
|
assert_equal 2, l.a.b
|
53
53
|
end
|
54
54
|
end
|
@@ -95,21 +95,21 @@ class JSONParserTest < Test::Unit::TestCase
|
|
95
95
|
assert_raise(JSON::ParserError) { JSON.parse('.23') }
|
96
96
|
assert_raise(JSON::ParserError) { JSON.parse('023') }
|
97
97
|
assert_equal 23, JSON.parse('23')
|
98
|
-
assert_equal
|
98
|
+
assert_equal(-23, JSON.parse('-23'))
|
99
99
|
assert_equal_float 3.141, JSON.parse('3.141')
|
100
|
-
assert_equal_float
|
100
|
+
assert_equal_float(-3.141, JSON.parse('-3.141'))
|
101
101
|
assert_equal_float 3.141, JSON.parse('3141e-3')
|
102
102
|
assert_equal_float 3.141, JSON.parse('3141.1e-3')
|
103
103
|
assert_equal_float 3.141, JSON.parse('3141E-3')
|
104
104
|
assert_equal_float 3.141, JSON.parse('3141.0E-3')
|
105
|
-
assert_equal_float
|
106
|
-
assert_equal_float
|
105
|
+
assert_equal_float(-3.141, JSON.parse('-3141.0e-3'))
|
106
|
+
assert_equal_float(-3.141, JSON.parse('-3141e-3'))
|
107
107
|
assert_raise(JSON::ParserError) { JSON.parse('NaN') }
|
108
108
|
assert JSON.parse('NaN', :allow_nan => true).nan?
|
109
109
|
assert_raise(JSON::ParserError) { JSON.parse('Infinity') }
|
110
110
|
assert_equal 1.0/0, JSON.parse('Infinity', :allow_nan => true)
|
111
111
|
assert_raise(JSON::ParserError) { JSON.parse('-Infinity') }
|
112
|
-
assert_equal
|
112
|
+
assert_equal(-1.0/0, JSON.parse('-Infinity', :allow_nan => true))
|
113
113
|
end
|
114
114
|
|
115
115
|
if Array.method_defined?(:permutation)
|
@@ -133,17 +133,17 @@ class JSONParserTest < Test::Unit::TestCase
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def test_parse_arrays
|
136
|
-
assert_equal([1,2,3], JSON.parse('[1,2,3]'))
|
137
|
-
assert_equal([1.2,2,3], JSON.parse('[1.2,2,3]'))
|
138
|
-
assert_equal([[],[[],[]]], JSON.parse('[[],[[],[]]]'))
|
136
|
+
assert_equal([1, 2, 3], JSON.parse('[1,2,3]'))
|
137
|
+
assert_equal([1.2, 2, 3], JSON.parse('[1.2,2,3]'))
|
138
|
+
assert_equal([[], [[], []]], JSON.parse('[[],[[],[]]]'))
|
139
139
|
assert_equal([], JSON.parse('[]'))
|
140
140
|
assert_equal([], JSON.parse(' [ ] '))
|
141
141
|
assert_equal([1], JSON.parse('[1]'))
|
142
142
|
assert_equal([1], JSON.parse(' [ 1 ] '))
|
143
143
|
ary = [[1], ["foo"], [3.14], [4711.0], [2.718], [nil],
|
144
|
-
|
144
|
+
[[1, -2, 3]], [false], [true]]
|
145
145
|
assert_equal(ary,
|
146
|
-
|
146
|
+
JSON.parse('[[1],["foo"],[3.14],[47.11e+2],[2718.0E-3],[null],[[1,-2,3]],[false],[true]]'))
|
147
147
|
assert_equal(ary, JSON.parse(%Q{ [ [1] , ["foo"] , [3.14] \t , [47.11e+2]\s
|
148
148
|
, [2718.0E-3 ],\r[ null] , [[1, -2, 3 ]], [false ],[ true]\n ] }))
|
149
149
|
end
|
@@ -208,51 +208,51 @@ class JSONParserTest < Test::Unit::TestCase
|
|
208
208
|
|
209
209
|
def test_symbolize_names
|
210
210
|
assert_equal({ "foo" => "bar", "baz" => "quux" },
|
211
|
-
|
211
|
+
JSON.parse('{"foo":"bar", "baz":"quux"}'))
|
212
212
|
assert_equal({ :foo => "bar", :baz => "quux" },
|
213
|
-
|
213
|
+
JSON.parse('{"foo":"bar", "baz":"quux"}', :symbolize_names => true))
|
214
214
|
assert_raise(ArgumentError) do
|
215
215
|
JSON.parse('{}', :symbolize_names => true, :create_additions => true)
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
219
219
|
def test_parse_comments
|
220
|
-
json =
|
221
|
-
{
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
}
|
229
|
-
EOT
|
220
|
+
json = <<~EOT
|
221
|
+
{
|
222
|
+
"key1":"value1", // eol comment
|
223
|
+
"key2":"value2" /* multi line
|
224
|
+
* comment */,
|
225
|
+
"key3":"value3" /* multi line
|
226
|
+
// nested eol comment
|
227
|
+
* comment */
|
228
|
+
}
|
229
|
+
EOT
|
230
230
|
assert_equal(
|
231
231
|
{ "key1" => "value1", "key2" => "value2", "key3" => "value3" },
|
232
232
|
JSON.parse(json))
|
233
|
-
json =
|
234
|
-
{
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
}
|
240
|
-
EOT
|
233
|
+
json = <<~EOT
|
234
|
+
{
|
235
|
+
"key1":"value1" /* multi line
|
236
|
+
// nested eol comment
|
237
|
+
/* illegal nested multi line comment */
|
238
|
+
* comment */
|
239
|
+
}
|
240
|
+
EOT
|
241
241
|
assert_raise(JSON::ParserError) { JSON.parse(json) }
|
242
|
-
json =
|
243
|
-
{
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
}
|
249
|
-
EOT
|
242
|
+
json = <<~EOT
|
243
|
+
{
|
244
|
+
"key1":"value1" /* multi line
|
245
|
+
// nested eol comment
|
246
|
+
closed multi comment */
|
247
|
+
and again, throw an Error */
|
248
|
+
}
|
249
|
+
EOT
|
250
250
|
assert_raise(JSON::ParserError) { JSON.parse(json) }
|
251
|
-
json =
|
252
|
-
{
|
253
|
-
|
254
|
-
}
|
255
|
-
EOT
|
251
|
+
json = <<~EOT
|
252
|
+
{
|
253
|
+
"key1":"value1" /*/*/
|
254
|
+
}
|
255
|
+
EOT
|
256
256
|
assert_equal({ "key1" => "value1" }, JSON.parse(json))
|
257
257
|
end
|
258
258
|
|
@@ -348,7 +348,7 @@ EOT
|
|
348
348
|
|
349
349
|
def test_parse_array_custom_array_derived_class
|
350
350
|
res = JSON.parse('[1,2]', :array_class => SubArray)
|
351
|
-
assert_equal([1,2], res)
|
351
|
+
assert_equal([1, 2], res)
|
352
352
|
assert_equal(SubArray, res.class)
|
353
353
|
assert res.shifted?
|
354
354
|
end
|
@@ -356,7 +356,7 @@ EOT
|
|
356
356
|
def test_parse_array_custom_non_array_derived_class
|
357
357
|
res = JSON.parse('[1,2]', :array_class => SubArrayWrapper)
|
358
358
|
assert_equal(SubArrayWrapper, res.class)
|
359
|
-
assert_equal([1,2], res.data)
|
359
|
+
assert_equal([1, 2], res.data)
|
360
360
|
assert res.shifted?
|
361
361
|
end
|
362
362
|
|
@@ -442,7 +442,7 @@ EOT
|
|
442
442
|
assert obj_again['foo']['bar']
|
443
443
|
assert_equal obj, obj_again
|
444
444
|
assert_equal ["foo"],
|
445
|
-
|
445
|
+
JSON(JSON(SubArray2["foo"]), :create_additions => true)
|
446
446
|
end
|
447
447
|
|
448
448
|
def test_generate_core_subclasses_with_default_to_json
|
@@ -28,15 +28,15 @@ class JSONStringMatchingTest < Test::Unit::TestCase
|
|
28
28
|
t_json = [ t ].to_json
|
29
29
|
time_regexp = /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/
|
30
30
|
assert_equal [ t ],
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
JSON.parse(
|
32
|
+
t_json,
|
33
|
+
:create_additions => true,
|
34
|
+
:match_string => { time_regexp => TestTime }
|
35
|
+
)
|
36
36
|
assert_equal [ t.strftime('%FT%T%z') ],
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
JSON.parse(
|
38
|
+
t_json,
|
39
|
+
:match_string => { time_regexp => TestTime }
|
40
|
+
)
|
41
41
|
end
|
42
42
|
end
|
data/test/mem.rb
CHANGED
@@ -17,13 +17,13 @@ end
|
|
17
17
|
('a'..'z').each { |b|
|
18
18
|
('a'..'z').each { |c|
|
19
19
|
('a'..'z').each { |d|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
('a'..'z').each { |e|
|
21
|
+
('a'..'z').each { |f|
|
22
|
+
key = "#{a}#{b}#{c}#{d}#{e}#{f}"
|
23
|
+
x = Oj.load(%|{ "#{key}": 101}|)
|
24
|
+
#Oj.dump(x)
|
25
|
+
}
|
26
|
+
}
|
27
27
|
}
|
28
28
|
}
|
29
29
|
puts "#{a}#{b} #{mem}"
|
data/test/perf.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
class Perf
|
3
2
|
|
4
3
|
def initialize()
|
@@ -38,6 +37,7 @@ class Perf
|
|
38
37
|
width = 6
|
39
38
|
@items.each do |i|
|
40
39
|
next if i.duration.nil?
|
40
|
+
|
41
41
|
width = i.title.size if width < i.title.size
|
42
42
|
end
|
43
43
|
iva = @items.clone
|
@@ -60,7 +60,7 @@ class Perf
|
|
60
60
|
iva.each do |i|
|
61
61
|
line = ["%*s" % [width, i.title]]
|
62
62
|
iva.each do |o|
|
63
|
-
line << "%*.2f" % [width, o.duration / i.duration]
|
63
|
+
line << ("%*.2f" % [width, o.duration / i.duration])
|
64
64
|
end
|
65
65
|
puts line.join(' ')
|
66
66
|
end
|
data/test/perf_compat.rb
CHANGED
data/test/perf_fast.rb
CHANGED
data/test/perf_file.rb
CHANGED
@@ -6,7 +6,7 @@ $: << '../ext'
|
|
6
6
|
|
7
7
|
if __FILE__ == $0
|
8
8
|
if (i = ARGV.index('-I'))
|
9
|
-
x,path = ARGV.slice!(i, 2)
|
9
|
+
x, path = ARGV.slice!(i, 2)
|
10
10
|
$: << path
|
11
11
|
end
|
12
12
|
end
|
@@ -42,7 +42,7 @@ $obj = {
|
|
42
42
|
}
|
43
43
|
|
44
44
|
json = Oj.dump($obj, :indent => $indent)
|
45
|
-
cnt = ($size * 1024 * 1024 + json.size) / json.size
|
45
|
+
cnt = (($size * 1024 * 1024) + json.size) / json.size
|
46
46
|
cnt = 1 if 0 == $size
|
47
47
|
|
48
48
|
filename = 'tmp.json'
|
data/test/perf_object.rb
CHANGED
@@ -6,7 +6,7 @@ $: << '../ext'
|
|
6
6
|
|
7
7
|
if __FILE__ == $0
|
8
8
|
if (i = ARGV.index('-I'))
|
9
|
-
x,path = ARGV.slice!(i, 2)
|
9
|
+
x, path = ARGV.slice!(i, 2)
|
10
10
|
$: << path
|
11
11
|
end
|
12
12
|
end
|
@@ -93,7 +93,6 @@ Oj.default_options = { :mode => :object, :indent => $indent, :circular => $circu
|
|
93
93
|
#puts "xml: #{$xml.size}"
|
94
94
|
#puts "marshal: #{$mars.size}"
|
95
95
|
|
96
|
-
|
97
96
|
if do_load
|
98
97
|
puts '-' * 80
|
99
98
|
puts "Load Performance"
|