oj 3.11.5 → 3.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1421 -0
- data/README.md +19 -5
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +20 -6
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +8 -6
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +19 -33
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +27 -77
- data/ext/oj/custom.c +86 -179
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +256 -249
- data/ext/oj/dump.h +26 -12
- data/ext/oj/dump_compat.c +565 -642
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +65 -187
- data/ext/oj/dump_strict.c +27 -51
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +24 -8
- data/ext/oj/extconf.rb +21 -6
- data/ext/oj/fast.c +149 -149
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +121 -106
- data/ext/oj/object.c +85 -162
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +542 -411
- data/ext/oj/oj.h +99 -73
- data/ext/oj/parse.c +175 -187
- data/ext/oj/parse.h +26 -24
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +101 -0
- data/ext/oj/rails.c +112 -159
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +11 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +5 -24
- data/ext/oj/rxclass.c +7 -6
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +22 -33
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +5 -28
- data/ext/oj/sparse.c +28 -72
- data/ext/oj/stream_writer.c +50 -40
- data/ext/oj/strict.c +56 -61
- data/ext/oj/string_writer.c +72 -39
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +14 -3
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +63 -88
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +1 -2
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +9 -7
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +12 -8
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/Compatibility.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +8 -3
- data/pages/Options.md +43 -5
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +14 -2
- data/test/_test_active.rb +8 -9
- data/test/_test_active_mimic.rb +7 -8
- data/test/_test_mimic_rails.rb +17 -20
- data/test/activerecord/result_test.rb +5 -6
- data/test/activesupport6/encoding_test.rb +63 -28
- data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
- data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
- data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
- data/test/files.rb +15 -15
- data/test/foo.rb +16 -45
- data/test/helper.rb +11 -8
- 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 +8 -6
- 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 +56 -38
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +54 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +7 -3
- data/test/mem.rb +34 -0
- data/test/perf.rb +22 -27
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +50 -0
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -69
- data/test/perf_once.rb +59 -0
- data/test/perf_parser.rb +183 -0
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +58 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +74 -82
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +5 -5
- 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 +16 -16
- data/test/sample_json.rb +8 -8
- data/test/test_compat.rb +95 -43
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +135 -79
- data/test/test_file.rb +41 -30
- data/test/test_gc.rb +16 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +5 -5
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +99 -96
- data/test/test_parser.rb +11 -0
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +337 -0
- data/test/test_parser_usual.rb +251 -0
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +37 -39
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +165 -84
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -5
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +74 -128
- data/ext/oj/hash.c +0 -131
- data/ext/oj/hash.h +0 -19
- data/ext/oj/hash_test.c +0 -491
- 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/test_helper.rb +0 -72
- data/test/bar.rb +0 -35
- data/test/baz.rb +0 -16
- data/test/zoo.rb +0 -13
data/test/test_integer_range.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
|
+
@oj_dir = File.dirname(File.expand_path(__dir__))
|
6
6
|
%w(lib ext).each do |dir|
|
7
|
-
|
7
|
+
$LOAD_PATH << File.join(@oj_dir, dir)
|
8
8
|
end
|
9
9
|
|
10
10
|
require 'minitest'
|
@@ -23,19 +23,19 @@ class IntegerRangeTest < Minitest::Test
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_range
|
26
|
-
test = {s: 0, s2: -1, s3: 1, u: -2, u2: 2, u3:
|
26
|
+
test = {s: 0, s2: -1, s3: 1, u: -2, u2: 2, u3: 9_007_199_254_740_993}
|
27
27
|
exp = '{"s":0,"s2":-1,"s3":1,"u":"-2","u2":"2","u3":"9007199254740993"}'
|
28
28
|
assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_bignum
|
32
|
-
test = {u: -
|
32
|
+
test = {u: -10_000_000_000_000_000_000, u2: 10_000_000_000_000_000_000}
|
33
33
|
exp = '{"u":"-10000000000000000000","u2":"10000000000000000000"}'
|
34
34
|
assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_valid_modes
|
38
|
-
test = {safe: 0, unsafe:
|
38
|
+
test = {safe: 0, unsafe: 9_007_199_254_740_993}
|
39
39
|
exp = '{"safe":0,"unsafe":"9007199254740993"}'
|
40
40
|
|
41
41
|
[:strict, :null, :compat, :rails, :custom].each do |mode|
|
@@ -49,7 +49,7 @@ class IntegerRangeTest < Minitest::Test
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_modes_without_opt
|
52
|
-
test = {safe:0, unsafe:
|
52
|
+
test = {safe: 0, unsafe: 10_000_000_000_000_000_000}
|
53
53
|
exp = '{"safe":0,"unsafe":10000000000000000000}'
|
54
54
|
|
55
55
|
[:strict, :null, :compat, :rails, :custom].each do |mode|
|
@@ -63,7 +63,7 @@ class IntegerRangeTest < Minitest::Test
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_accept_nil_and_false
|
66
|
-
test = {safe:0, unsafe:
|
66
|
+
test = {safe: 0, unsafe: 10_000_000_000_000_000_000}
|
67
67
|
exp = '{"safe":0,"unsafe":10000000000000000000}'
|
68
68
|
|
69
69
|
assert_equal(exp, Oj.dump(test, integer_range: nil))
|
data/test/test_null.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
|
+
@oj_dir = File.dirname(File.expand_path(__dir__))
|
6
6
|
%w(lib ext).each do |dir|
|
7
|
-
|
7
|
+
$LOAD_PATH << File.join(@oj_dir, dir)
|
8
8
|
end
|
9
9
|
|
10
10
|
require 'minitest'
|
@@ -52,16 +52,16 @@ class NullJuice < Minitest::Test
|
|
52
52
|
|
53
53
|
def test_fixnum
|
54
54
|
dump_and_load(0, false)
|
55
|
-
dump_and_load(
|
56
|
-
dump_and_load(-
|
55
|
+
dump_and_load(12_345, false)
|
56
|
+
dump_and_load(-54_321, false)
|
57
57
|
dump_and_load(1, false)
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_float
|
61
61
|
dump_and_load(0.0, false)
|
62
|
-
dump_and_load(
|
62
|
+
dump_and_load(12_345.6789, false)
|
63
63
|
dump_and_load(70.35, false)
|
64
|
-
dump_and_load(-
|
64
|
+
dump_and_load(-54_321.012, false)
|
65
65
|
dump_and_load(1.7775, false)
|
66
66
|
dump_and_load(2.5024, false)
|
67
67
|
dump_and_load(2.48e16, false)
|
@@ -78,7 +78,7 @@ class NullJuice < Minitest::Test
|
|
78
78
|
assert(true)
|
79
79
|
return
|
80
80
|
end
|
81
|
-
assert(false,
|
81
|
+
assert(false, '*** expected an exception')
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_infinity_dump
|
@@ -90,7 +90,7 @@ class NullJuice < Minitest::Test
|
|
90
90
|
assert(true)
|
91
91
|
return
|
92
92
|
end
|
93
|
-
assert(false,
|
93
|
+
assert(false, '*** expected an exception')
|
94
94
|
end
|
95
95
|
|
96
96
|
def test_neg_infinity_dump
|
@@ -102,7 +102,7 @@ class NullJuice < Minitest::Test
|
|
102
102
|
assert(true)
|
103
103
|
return
|
104
104
|
end
|
105
|
-
assert(false,
|
105
|
+
assert(false, '*** expected an exception')
|
106
106
|
end
|
107
107
|
|
108
108
|
def test_string
|
@@ -116,13 +116,13 @@ class NullJuice < Minitest::Test
|
|
116
116
|
opts = Oj.default_options
|
117
117
|
Oj.default_options = { :ascii_only => false }
|
118
118
|
unless 'jruby' == $ruby
|
119
|
-
dump_and_load(
|
119
|
+
dump_and_load('ぴーたー', false)
|
120
120
|
end
|
121
121
|
Oj.default_options = { :ascii_only => true }
|
122
|
-
json = Oj.dump(
|
122
|
+
json = Oj.dump('ぴーたー')
|
123
123
|
assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
|
124
124
|
unless 'jruby' == $ruby
|
125
|
-
dump_and_load(
|
125
|
+
dump_and_load('ぴーたー', false)
|
126
126
|
end
|
127
127
|
Oj.default_options = opts
|
128
128
|
end
|
@@ -152,7 +152,7 @@ class NullJuice < Minitest::Test
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def test_array_deep
|
155
|
-
dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
|
155
|
+
dump_and_load([1, [2, [3, [4, [5, [6, [7, [8, [9, [10, [11, [12, [13, [14, [15, [16, [17, [18, [19, [20]]]]]]]]]]]]]]]]]]]], false)
|
156
156
|
end
|
157
157
|
|
158
158
|
# Hash
|
@@ -198,7 +198,7 @@ class NullJuice < Minitest::Test
|
|
198
198
|
assert(true)
|
199
199
|
return
|
200
200
|
end
|
201
|
-
assert(false,
|
201
|
+
assert(false, '*** expected an exception')
|
202
202
|
end
|
203
203
|
|
204
204
|
def test_bignum_object
|
@@ -244,13 +244,13 @@ class NullJuice < Minitest::Test
|
|
244
244
|
end
|
245
245
|
|
246
246
|
def test_io_file
|
247
|
-
filename = File.join(
|
248
|
-
File.
|
247
|
+
filename = File.join(__dir__, 'open_file_test.json')
|
248
|
+
File.write(filename, %{{
|
249
249
|
"x":true,
|
250
250
|
"y":58,
|
251
251
|
"z": [1,2,3]
|
252
252
|
}
|
253
|
-
})
|
253
|
+
})
|
254
254
|
f = File.new(filename)
|
255
255
|
obj = Oj.strict_load(f)
|
256
256
|
f.close()
|
@@ -364,7 +364,7 @@ class NullJuice < Minitest::Test
|
|
364
364
|
def dump_and_load(obj, trace=false)
|
365
365
|
json = Oj.dump(obj, :indent => 2)
|
366
366
|
puts json if trace
|
367
|
-
loaded = Oj.strict_load(json)
|
367
|
+
loaded = Oj.strict_load(json)
|
368
368
|
if obj.nil?
|
369
369
|
assert_nil(loaded)
|
370
370
|
else
|
data/test/test_object.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
@@ -20,12 +20,12 @@ class ObjectJuice < Minitest::Test
|
|
20
20
|
end
|
21
21
|
alias == eql?
|
22
22
|
|
23
|
-
def to_json(*
|
23
|
+
def to_json(*_a)
|
24
24
|
%{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.json_create(h)
|
28
|
-
|
28
|
+
new(h['x'], h['y'])
|
29
29
|
end
|
30
30
|
end # Jeez
|
31
31
|
|
@@ -45,30 +45,26 @@ class ObjectJuice < Minitest::Test
|
|
45
45
|
end # Jam
|
46
46
|
|
47
47
|
class Jazz < Jam
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
def to_hash()
|
48
|
+
|
49
|
+
def to_hash
|
52
50
|
{ 'json_class' => self.class.to_s, 'x' => @x, 'y' => @y }
|
53
51
|
end
|
52
|
+
|
54
53
|
def self.json_create(h)
|
55
|
-
|
54
|
+
new(h['x'], h['y'])
|
56
55
|
end
|
57
56
|
end # Jazz
|
58
57
|
|
59
58
|
class Orange < Jam
|
60
|
-
def initialize(x, y)
|
61
|
-
super
|
62
|
-
end
|
63
59
|
|
64
|
-
def as_json
|
60
|
+
def as_json
|
65
61
|
{ :json_class => self.class,
|
66
62
|
:x => @x,
|
67
63
|
:y => @y }
|
68
64
|
end
|
69
65
|
|
70
66
|
def self.json_create(h)
|
71
|
-
|
67
|
+
new(h['x'], h['y'])
|
72
68
|
end
|
73
69
|
end
|
74
70
|
|
@@ -77,24 +73,21 @@ class ObjectJuice < Minitest::Test
|
|
77
73
|
module Three
|
78
74
|
class Deep
|
79
75
|
|
80
|
-
def initialize()
|
81
|
-
end
|
82
|
-
|
83
76
|
def eql?(o)
|
84
77
|
self.class == o.class
|
85
78
|
end
|
86
79
|
alias == eql?
|
87
80
|
|
88
|
-
def to_hash
|
89
|
-
{'json_class' =>
|
81
|
+
def to_hash
|
82
|
+
{'json_class' => self.class.name.to_s}
|
90
83
|
end
|
91
84
|
|
92
|
-
def to_json(*
|
85
|
+
def to_json(*_a)
|
93
86
|
%{{"json_class":"#{self.class.name}"}}
|
94
87
|
end
|
95
88
|
|
96
|
-
def self.json_create(
|
97
|
-
|
89
|
+
def self.json_create(_h)
|
90
|
+
new()
|
98
91
|
end
|
99
92
|
end # Deep
|
100
93
|
end # Three
|
@@ -102,7 +95,6 @@ class ObjectJuice < Minitest::Test
|
|
102
95
|
|
103
96
|
class Stuck2 < Struct.new(:a, :b)
|
104
97
|
end
|
105
|
-
|
106
98
|
end # One
|
107
99
|
|
108
100
|
class Stuck < Struct.new(:a, :b)
|
@@ -115,7 +107,7 @@ class ObjectJuice < Minitest::Test
|
|
115
107
|
@safe = safe
|
116
108
|
end
|
117
109
|
|
118
|
-
def safe?
|
110
|
+
def safe?
|
119
111
|
@safe
|
120
112
|
end
|
121
113
|
|
@@ -128,8 +120,8 @@ class ObjectJuice < Minitest::Test
|
|
128
120
|
end
|
129
121
|
alias == eql?
|
130
122
|
|
131
|
-
def inspect
|
132
|
-
|
123
|
+
def inspect
|
124
|
+
super + '(' + @safe + ')'
|
133
125
|
end
|
134
126
|
end
|
135
127
|
|
@@ -182,7 +174,7 @@ class ObjectJuice < Minitest::Test
|
|
182
174
|
@json = j
|
183
175
|
end
|
184
176
|
|
185
|
-
def to_json(*
|
177
|
+
def to_json(*_a)
|
186
178
|
@json
|
187
179
|
end
|
188
180
|
|
@@ -206,7 +198,7 @@ class ObjectJuice < Minitest::Test
|
|
206
198
|
@hash = h
|
207
199
|
end
|
208
200
|
|
209
|
-
def dump
|
201
|
+
def dump
|
210
202
|
@hash
|
211
203
|
end
|
212
204
|
|
@@ -237,16 +229,16 @@ class ObjectJuice < Minitest::Test
|
|
237
229
|
|
238
230
|
def test_fixnum
|
239
231
|
dump_and_load(0, false)
|
240
|
-
dump_and_load(
|
241
|
-
dump_and_load(-
|
232
|
+
dump_and_load(12_345, false)
|
233
|
+
dump_and_load(-54_321, false)
|
242
234
|
dump_and_load(1, false)
|
243
235
|
end
|
244
236
|
|
245
237
|
def test_float
|
246
238
|
dump_and_load(0.0, false)
|
247
|
-
dump_and_load(
|
239
|
+
dump_and_load(12_345.6789, false)
|
248
240
|
dump_and_load(70.35, false)
|
249
|
-
dump_and_load(-
|
241
|
+
dump_and_load(-54_321.012, false)
|
250
242
|
dump_and_load(1.7775, false)
|
251
243
|
dump_and_load(2.5024, false)
|
252
244
|
dump_and_load(2.48e16, false)
|
@@ -256,8 +248,8 @@ class ObjectJuice < Minitest::Test
|
|
256
248
|
# NaN does not always == NaN
|
257
249
|
json = Oj.dump(0/0.0, :mode => :object)
|
258
250
|
assert_equal('3.3e14159265358979323846', json)
|
259
|
-
loaded = Oj.load(json)
|
260
|
-
|
251
|
+
loaded = Oj.load(json)
|
252
|
+
assert_predicate(loaded, :nan?)
|
261
253
|
end
|
262
254
|
|
263
255
|
def test_string
|
@@ -269,18 +261,18 @@ class ObjectJuice < Minitest::Test
|
|
269
261
|
|
270
262
|
def test_symbol
|
271
263
|
dump_and_load(:abc, false)
|
272
|
-
dump_and_load(
|
273
|
-
dump_and_load(
|
264
|
+
dump_and_load(':abc', false)
|
265
|
+
dump_and_load(:":xyz", false)
|
274
266
|
end
|
275
267
|
|
276
268
|
def test_encode
|
277
269
|
opts = Oj.default_options
|
278
270
|
Oj.default_options = { :ascii_only => false }
|
279
|
-
dump_and_load(
|
271
|
+
dump_and_load('ぴーたー', false)
|
280
272
|
Oj.default_options = { :ascii_only => true }
|
281
|
-
json = Oj.dump(
|
273
|
+
json = Oj.dump('ぴーたー')
|
282
274
|
assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
|
283
|
-
dump_and_load(
|
275
|
+
dump_and_load('ぴーたー', false)
|
284
276
|
Oj.default_options = opts
|
285
277
|
end
|
286
278
|
|
@@ -301,7 +293,7 @@ class ObjectJuice < Minitest::Test
|
|
301
293
|
end
|
302
294
|
|
303
295
|
def test_array_deep
|
304
|
-
dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
|
296
|
+
dump_and_load([1, [2, [3, [4, [5, [6, [7, [8, [9, [10, [11, [12, [13, [14, [15, [16, [17, [18, [19, [20]]]]]]]]]]]]]]]]]]]], false)
|
305
297
|
end
|
306
298
|
|
307
299
|
# Hash
|
@@ -376,13 +368,13 @@ class ObjectJuice < Minitest::Test
|
|
376
368
|
end
|
377
369
|
|
378
370
|
def test_io_file
|
379
|
-
filename = File.join(
|
380
|
-
File.
|
371
|
+
filename = File.join(__dir__, 'open_file_test.json')
|
372
|
+
File.write(filename, %{{
|
381
373
|
"x":true,
|
382
374
|
"y":58,
|
383
375
|
"z": [1,2,3]
|
384
376
|
}
|
385
|
-
})
|
377
|
+
})
|
386
378
|
f = File.new(filename)
|
387
379
|
obj = Oj.object_load(f)
|
388
380
|
f.close()
|
@@ -412,7 +404,7 @@ class ObjectJuice < Minitest::Test
|
|
412
404
|
def test_non_str_hash_object
|
413
405
|
json = Oj.dump({ 1 => true, :sim => nil }, :mode => :object)
|
414
406
|
h = Oj.load(json, :mode => :strict)
|
415
|
-
assert_equal({
|
407
|
+
assert_equal({'^#1' => [1, true], ':sim' => nil}, h)
|
416
408
|
h = Oj.load(json, :mode => :object)
|
417
409
|
assert_equal({ 1 => true, :sim => nil }, h)
|
418
410
|
end
|
@@ -464,8 +456,8 @@ class ObjectJuice < Minitest::Test
|
|
464
456
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
465
457
|
# separately along with utc.
|
466
458
|
json = Oj.dump(t, :mode => :object, :time_format => :xmlschema)
|
467
|
-
#puts "*** json for test_xml_time '#{json}'"
|
468
|
-
loaded = Oj.object_load(json)
|
459
|
+
# puts "*** json for test_xml_time '#{json}'"
|
460
|
+
loaded = Oj.object_load(json)
|
469
461
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
470
462
|
if t.respond_to?(:tv_nsec)
|
471
463
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -482,7 +474,7 @@ class ObjectJuice < Minitest::Test
|
|
482
474
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
483
475
|
# separately along with utc.
|
484
476
|
json = Oj.dump(t, :mode => :object, :time_format => :xmlschema)
|
485
|
-
loaded = Oj.object_load(json)
|
477
|
+
loaded = Oj.object_load(json)
|
486
478
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
487
479
|
if t.respond_to?(:tv_nsec)
|
488
480
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -499,8 +491,8 @@ class ObjectJuice < Minitest::Test
|
|
499
491
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
500
492
|
# separately along with utc.
|
501
493
|
json = Oj.dump(t, :mode => :object, :time_format => :ruby)
|
502
|
-
#puts "*** json for test_ruby_time '#{json}'"
|
503
|
-
loaded = Oj.object_load(json)
|
494
|
+
# puts "*** json for test_ruby_time '#{json}'"
|
495
|
+
loaded = Oj.object_load(json)
|
504
496
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
505
497
|
if t.respond_to?(:tv_nsec)
|
506
498
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -512,14 +504,14 @@ class ObjectJuice < Minitest::Test
|
|
512
504
|
end
|
513
505
|
|
514
506
|
def test_ruby_time_12345
|
515
|
-
t = Time.new(2015, 1, 5, 21, 37, 7.123456789,
|
507
|
+
t = Time.new(2015, 1, 5, 21, 37, 7.123456789, 12_345/60*60)
|
516
508
|
# The fractional seconds are not always recreated exactly which causes a
|
517
509
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
518
510
|
# separately along with utc.
|
519
511
|
json = Oj.dump(t, :mode => :object, :time_format => :ruby)
|
520
|
-
#puts "*** json for test_ruby_time '#{json}'"
|
521
|
-
loaded = Oj.object_load(json)
|
522
|
-
#puts "*** loaded: #{loaded}"
|
512
|
+
# puts "*** json for test_ruby_time '#{json}'"
|
513
|
+
loaded = Oj.object_load(json)
|
514
|
+
# puts "*** loaded: #{loaded}"
|
523
515
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
524
516
|
if t.respond_to?(:tv_nsec)
|
525
517
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -536,8 +528,8 @@ class ObjectJuice < Minitest::Test
|
|
536
528
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
537
529
|
# separately along with utc.
|
538
530
|
json = Oj.dump(t, :mode => :object, :time_format => :ruby)
|
539
|
-
#puts json
|
540
|
-
loaded = Oj.object_load(json)
|
531
|
+
# puts json
|
532
|
+
loaded = Oj.object_load(json)
|
541
533
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
542
534
|
if t.respond_to?(:tv_nsec)
|
543
535
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -557,8 +549,8 @@ class ObjectJuice < Minitest::Test
|
|
557
549
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
558
550
|
# separately along with utc.
|
559
551
|
json = Oj.dump(t, :mode => :object, :time_format => :unix_zone)
|
560
|
-
#puts json
|
561
|
-
loaded = Oj.object_load(json)
|
552
|
+
# puts json
|
553
|
+
loaded = Oj.object_load(json)
|
562
554
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
563
555
|
if t.respond_to?(:tv_nsec)
|
564
556
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -575,8 +567,8 @@ class ObjectJuice < Minitest::Test
|
|
575
567
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
576
568
|
# separately along with utc.
|
577
569
|
json = Oj.dump(t, :mode => :object, :time_format => :unix_zone)
|
578
|
-
#puts json
|
579
|
-
loaded = Oj.object_load(json)
|
570
|
+
# puts json
|
571
|
+
loaded = Oj.object_load(json)
|
580
572
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
581
573
|
if t.respond_to?(:tv_nsec)
|
582
574
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -588,13 +580,13 @@ class ObjectJuice < Minitest::Test
|
|
588
580
|
end
|
589
581
|
|
590
582
|
def test_time_unix_zone_12345
|
591
|
-
t = Time.new(2015, 1, 5, 21, 37, 7.123456789,
|
583
|
+
t = Time.new(2015, 1, 5, 21, 37, 7.123456789, 12_345)
|
592
584
|
# The fractional seconds are not always recreated exactly which causes a
|
593
585
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
594
586
|
# separately along with utc.
|
595
587
|
json = Oj.dump(t, :mode => :object, :time_format => :unix_zone)
|
596
|
-
#puts json
|
597
|
-
loaded = Oj.object_load(json)
|
588
|
+
# puts json
|
589
|
+
loaded = Oj.object_load(json)
|
598
590
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
599
591
|
if t.respond_to?(:tv_nsec)
|
600
592
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -611,8 +603,8 @@ class ObjectJuice < Minitest::Test
|
|
611
603
|
# mismatch so instead the seconds, nsecs, and gmt_offset are checked
|
612
604
|
# separately along with utc.
|
613
605
|
json = Oj.dump(t, :mode => :object, :time_format => :unix_zone)
|
614
|
-
#puts json
|
615
|
-
loaded = Oj.object_load(json)
|
606
|
+
# puts json
|
607
|
+
loaded = Oj.object_load(json)
|
616
608
|
assert_equal(t.tv_sec, loaded.tv_sec)
|
617
609
|
if t.respond_to?(:tv_nsec)
|
618
610
|
assert_equal(t.tv_nsec, loaded.tv_nsec)
|
@@ -638,20 +630,20 @@ class ObjectJuice < Minitest::Test
|
|
638
630
|
begin
|
639
631
|
Oj.object_load(json)
|
640
632
|
rescue Exception => e
|
641
|
-
assert_equal(
|
633
|
+
assert_equal('ArgumentError', e.class().name)
|
642
634
|
return
|
643
635
|
end
|
644
|
-
assert(false,
|
636
|
+
assert(false, '*** expected an exception')
|
645
637
|
end
|
646
638
|
|
647
639
|
def test_json_object_not_hat_hash
|
648
640
|
json = %{{"^#x":[1,2]}}
|
649
641
|
h = Oj.object_load(json)
|
650
|
-
assert_equal({1 => 2}, h)
|
642
|
+
assert_equal({1 => 2}, h)
|
651
643
|
|
652
644
|
json = %{{"~#x":[1,2]}}
|
653
645
|
h = Oj.object_load(json)
|
654
|
-
assert_equal({'~#x' => [1,2]}, h)
|
646
|
+
assert_equal({'~#x' => [1, 2]}, h)
|
655
647
|
end
|
656
648
|
|
657
649
|
def test_json_struct
|
@@ -668,14 +660,14 @@ class ObjectJuice < Minitest::Test
|
|
668
660
|
s = Struct.new(:x, :y)
|
669
661
|
obj = s.new(1, 2)
|
670
662
|
json = Oj.dump(obj, :indent => 2, :mode => :object)
|
671
|
-
#puts json
|
672
|
-
loaded = Oj.object_load(json)
|
663
|
+
# puts json
|
664
|
+
loaded = Oj.object_load(json)
|
673
665
|
assert_equal(obj.members, loaded.members)
|
674
666
|
assert_equal(obj.values, loaded.values)
|
675
667
|
end
|
676
668
|
|
677
669
|
def test_json_non_str_hash
|
678
|
-
obj = { 59 =>
|
670
|
+
obj = { 59 => 'young', false => true }
|
679
671
|
dump_and_load(obj, false)
|
680
672
|
end
|
681
673
|
|
@@ -779,24 +771,24 @@ class ObjectJuice < Minitest::Test
|
|
779
771
|
err = e
|
780
772
|
end
|
781
773
|
json = Oj.dump(err, :mode => :object, :indent => 2)
|
782
|
-
#puts "*** #{json}"
|
774
|
+
# puts "*** #{json}"
|
783
775
|
e2 = Oj.load(json, :mode => :strict)
|
784
776
|
assert_equal(err.class.to_s, e2['^o'])
|
785
777
|
assert_equal(err.message, e2['~mesg'])
|
786
778
|
assert_equal(err.backtrace, e2['~bt'])
|
787
779
|
e2 = Oj.load(json, :mode => :object)
|
788
780
|
if 'rubinius' == $ruby
|
789
|
-
assert_equal(e.class, e2.class)
|
790
|
-
assert_equal(e.message, e2.message)
|
791
|
-
assert_equal(e.backtrace, e2.backtrace)
|
781
|
+
assert_equal(e.class, e2.class)
|
782
|
+
assert_equal(e.message, e2.message)
|
783
|
+
assert_equal(e.backtrace, e2.backtrace)
|
792
784
|
else
|
793
|
-
assert_equal(e, e2)
|
785
|
+
assert_equal(e, e2)
|
794
786
|
end
|
795
787
|
end
|
796
788
|
|
797
|
-
class SubX <
|
789
|
+
class SubX < StandardError
|
798
790
|
def initialize
|
799
|
-
super(
|
791
|
+
super('sub')
|
800
792
|
@xyz = 123
|
801
793
|
end
|
802
794
|
end
|
@@ -809,22 +801,22 @@ class ObjectJuice < Minitest::Test
|
|
809
801
|
err = e
|
810
802
|
end
|
811
803
|
json = Oj.dump(err, :mode => :object, :indent => 2)
|
812
|
-
#puts "*** #{json}"
|
804
|
+
# puts "*** #{json}"
|
813
805
|
e2 = Oj.load(json, :mode => :strict)
|
814
806
|
assert_equal(err.class.to_s, e2['^o'])
|
815
807
|
assert_equal(err.message, e2['~mesg'])
|
816
808
|
assert_equal(err.backtrace, e2['~bt'])
|
817
809
|
e2 = Oj.load(json, :mode => :object)
|
818
|
-
assert_equal(e, e2)
|
810
|
+
assert_equal(e, e2)
|
819
811
|
end
|
820
812
|
|
821
813
|
def test_range_object
|
822
814
|
Oj.default_options = { :mode => :object }
|
823
815
|
json = Oj.dump(1..7, :mode => :object, :indent => 0)
|
824
|
-
if '
|
825
|
-
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
826
|
-
else
|
816
|
+
if 'ruby' == $ruby
|
827
817
|
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
|
818
|
+
else
|
819
|
+
assert_equal(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}}, json)
|
828
820
|
end
|
829
821
|
dump_and_load(1..7, false)
|
830
822
|
dump_and_load(1..1, false)
|
@@ -839,7 +831,6 @@ class ObjectJuice < Minitest::Test
|
|
839
831
|
assert_equal(h2['b'].__id__, h2.__id__)
|
840
832
|
end
|
841
833
|
|
842
|
-
|
843
834
|
def test_json_object_missing_fields
|
844
835
|
json = %{{ "^u": [ "ObjectJuice::Stuck",1]}}
|
845
836
|
|
@@ -948,11 +939,30 @@ class ObjectJuice < Minitest::Test
|
|
948
939
|
|
949
940
|
def test_odd_date
|
950
941
|
dump_and_load(Date.new(2012, 6, 19), false)
|
942
|
+
|
943
|
+
Oj.register_odd(Date, Date, :jd, :jd)
|
944
|
+
json = Oj.dump(Date.new(2015, 3, 7), :mode => :object)
|
945
|
+
assert_equal(%|{"^O":"Date","jd":2457089}|, json)
|
946
|
+
dump_and_load(Date.new(2012, 6, 19), false)
|
951
947
|
end
|
952
948
|
|
953
949
|
def test_odd_datetime
|
954
950
|
dump_and_load(DateTime.new(2012, 6, 19, 13, 5, Rational(4, 3)), false)
|
955
|
-
dump_and_load(DateTime.new(2012, 6, 19, 13, 5, Rational(
|
951
|
+
dump_and_load(DateTime.new(2012, 6, 19, 13, 5, Rational(7_123_456_789, 1_000_000_000)), false)
|
952
|
+
end
|
953
|
+
|
954
|
+
def test_odd_xml_time
|
955
|
+
str = "2023-01-01T00:00:00Z"
|
956
|
+
assert_equal(Time.parse(str), Oj.load('{"^t":"' + str + '"}', mode: :object))
|
957
|
+
|
958
|
+
str = "2023-01-01T00:00:00.3Z"
|
959
|
+
assert_equal(Time.parse(str), Oj.load('{"^t":"' + str + '"}', mode: :object))
|
960
|
+
|
961
|
+
str = "2023-01-01T00:00:00.123456789123456789Z"
|
962
|
+
assert_equal(Time.parse(str), Oj.load('{"^t":"' + str + '"}', mode: :object))
|
963
|
+
|
964
|
+
str = "2023-01-01T00:00:00.123456789123456789123456789Z"
|
965
|
+
assert_equal(Time.parse(str), Oj.load('{"^t":"' + str + '"}', mode: :object))
|
956
966
|
end
|
957
967
|
|
958
968
|
def test_bag
|
@@ -962,23 +972,16 @@ class ObjectJuice < Minitest::Test
|
|
962
972
|
"y":58 }}
|
963
973
|
obj = Oj.load(json, :mode => :object, :auto_define => true)
|
964
974
|
assert_equal('ObjectJuice::Jem', obj.class.name)
|
965
|
-
|
975
|
+
assert(obj.x)
|
966
976
|
assert_equal(58, obj.y)
|
967
977
|
end
|
968
978
|
|
969
979
|
def test_odd_string
|
970
980
|
Oj.register_odd(Strung, Strung, :create, :to_s, 'safe?')
|
971
|
-
s = Strung.new(
|
981
|
+
s = Strung.new('Pete', true)
|
972
982
|
dump_and_load(s, false)
|
973
983
|
end
|
974
984
|
|
975
|
-
def test_odd_date_replaced
|
976
|
-
Oj.register_odd(Date, Date, :jd, :jd)
|
977
|
-
json = Oj.dump(Date.new(2015, 3, 7), :mode => :object)
|
978
|
-
assert_equal(%|{"^O":"Date","jd":2457089}|, json)
|
979
|
-
dump_and_load(Date.new(2012, 6, 19), false)
|
980
|
-
end
|
981
|
-
|
982
985
|
def test_odd_raw
|
983
986
|
Oj.register_odd_raw(Raw, Raw, :create, :to_json)
|
984
987
|
json = Oj.dump(Raw.new(%|{"a":1}|), :mode => :object)
|
@@ -996,7 +999,7 @@ class ObjectJuice < Minitest::Test
|
|
996
999
|
end
|
997
1000
|
|
998
1001
|
def test_auto_string
|
999
|
-
s = AutoStrung.new(
|
1002
|
+
s = AutoStrung.new('Pete', true)
|
1000
1003
|
dump_and_load(s, false)
|
1001
1004
|
end
|
1002
1005
|
|
@@ -1015,7 +1018,7 @@ class ObjectJuice < Minitest::Test
|
|
1015
1018
|
def dump_and_load(obj, trace=false)
|
1016
1019
|
json = Oj.dump(obj, :indent => 2, :mode => :object)
|
1017
1020
|
puts json if trace
|
1018
|
-
loaded = Oj.object_load(json)
|
1021
|
+
loaded = Oj.object_load(json)
|
1019
1022
|
if obj.nil?
|
1020
1023
|
assert_nil(loaded)
|
1021
1024
|
else
|