oj 3.13.23 → 3.16.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +86 -0
- data/README.md +2 -2
- data/ext/oj/buf.h +7 -6
- data/ext/oj/cache.c +29 -26
- data/ext/oj/cache.h +3 -2
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +7 -5
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +5 -12
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +20 -60
- data/ext/oj/custom.c +26 -59
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +103 -53
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +557 -592
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +42 -48
- data/ext/oj/dump_strict.c +10 -22
- 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 +16 -7
- data/ext/oj/fast.c +63 -98
- data/ext/oj/intern.c +62 -47
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +54 -38
- data/ext/oj/object.c +33 -43
- data/ext/oj/odd.c +8 -6
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +245 -216
- data/ext/oj/oj.h +83 -81
- data/ext/oj/parse.c +109 -153
- data/ext/oj/parse.h +21 -24
- data/ext/oj/parser.c +80 -67
- data/ext/oj/parser.h +9 -8
- data/ext/oj/rails.c +71 -94
- data/ext/oj/reader.c +9 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +6 -5
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +13 -15
- data/ext/oj/saj2.c +37 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +6 -20
- data/ext/oj/sparse.c +22 -70
- data/ext/oj/stream_writer.c +46 -48
- data/ext/oj/strict.c +22 -56
- data/ext/oj/string_writer.c +64 -40
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +125 -114
- data/ext/oj/usual.h +7 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +13 -2
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/wab.c +25 -57
- 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 +0 -1
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +7 -7
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/InstallOptions.md +20 -0
- data/pages/Options.md +4 -0
- metadata +46 -121
- data/test/_test_active.rb +0 -76
- data/test/_test_active_mimic.rb +0 -96
- data/test/_test_mimic_rails.rb +0 -126
- data/test/activerecord/result_test.rb +0 -32
- 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
- data/test/activesupport6/abstract_unit.rb +0 -44
- data/test/activesupport6/decoding_test.rb +0 -133
- data/test/activesupport6/encoding_test.rb +0 -507
- data/test/activesupport6/encoding_test_cases.rb +0 -98
- data/test/activesupport6/test_common.rb +0 -17
- data/test/activesupport6/test_helper.rb +0 -163
- data/test/activesupport6/time_zone_test_helpers.rb +0 -39
- data/test/activesupport7/abstract_unit.rb +0 -49
- data/test/activesupport7/decoding_test.rb +0 -125
- data/test/activesupport7/encoding_test.rb +0 -486
- data/test/activesupport7/encoding_test_cases.rb +0 -104
- data/test/activesupport7/time_zone_test_helpers.rb +0 -47
- data/test/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -77
- data/test/helper.rb +0 -42
- data/test/isolated/shared.rb +0 -308
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/json_gem/json_addition_test.rb +0 -216
- data/test/json_gem/json_common_interface_test.rb +0 -153
- data/test/json_gem/json_encoding_test.rb +0 -107
- data/test/json_gem/json_ext_parser_test.rb +0 -20
- data/test/json_gem/json_fixtures_test.rb +0 -35
- data/test/json_gem/json_generator_test.rb +0 -396
- data/test/json_gem/json_generic_object_test.rb +0 -90
- data/test/json_gem/json_parser_test.rb +0 -477
- data/test/json_gem/json_string_matching_test.rb +0 -42
- data/test/json_gem/test_helper.rb +0 -30
- data/test/mem.rb +0 -33
- data/test/perf.rb +0 -107
- data/test/perf_compat.rb +0 -130
- data/test/perf_dump.rb +0 -50
- data/test/perf_fast.rb +0 -164
- data/test/perf_file.rb +0 -64
- data/test/perf_object.rb +0 -138
- data/test/perf_once.rb +0 -58
- data/test/perf_parser.rb +0 -189
- data/test/perf_saj.rb +0 -109
- data/test/perf_scp.rb +0 -152
- data/test/perf_simple.rb +0 -287
- data/test/perf_strict.rb +0 -139
- data/test/perf_wab.rb +0 -131
- data/test/prec.rb +0 -23
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sample.rb +0 -54
- data/test/sample_json.rb +0 -37
- data/test/test_compat.rb +0 -540
- data/test/test_custom.rb +0 -544
- data/test/test_debian.rb +0 -53
- data/test/test_fast.rb +0 -530
- data/test/test_file.rb +0 -255
- data/test/test_gc.rb +0 -60
- data/test/test_generate.rb +0 -21
- data/test/test_hash.rb +0 -39
- data/test/test_integer_range.rb +0 -72
- data/test/test_null.rb +0 -376
- data/test/test_object.rb +0 -1025
- data/test/test_parser.rb +0 -11
- data/test/test_parser_debug.rb +0 -27
- data/test/test_parser_saj.rb +0 -335
- data/test/test_parser_usual.rb +0 -217
- data/test/test_rails.rb +0 -35
- data/test/test_saj.rb +0 -186
- data/test/test_scp.rb +0 -431
- data/test/test_strict.rb +0 -435
- data/test/test_various.rb +0 -752
- data/test/test_wab.rb +0 -309
- data/test/test_writer.rb +0 -380
- data/test/tests.rb +0 -33
- data/test/tests_mimic.rb +0 -23
- data/test/tests_mimic_addition.rb +0 -16
- data/test/zoo.rb +0 -13
data/test/test_file.rb
DELETED
@@ -1,255 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class FileJuice < Minitest::Test
|
9
|
-
class Jam
|
10
|
-
attr_accessor :x, :y
|
11
|
-
|
12
|
-
def initialize(x, y)
|
13
|
-
@x = x
|
14
|
-
@y = y
|
15
|
-
end
|
16
|
-
|
17
|
-
def eql?(o)
|
18
|
-
self.class == o.class && @x == o.x && @y == o.y
|
19
|
-
end
|
20
|
-
alias == eql?
|
21
|
-
|
22
|
-
end# Jam
|
23
|
-
|
24
|
-
class Jeez < Jam
|
25
|
-
def initialize(x, y)
|
26
|
-
super
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_json()
|
30
|
-
%{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.json_create(h)
|
34
|
-
self.new(h['x'], h['y'])
|
35
|
-
end
|
36
|
-
end# Jeez
|
37
|
-
|
38
|
-
class Orange < Jam
|
39
|
-
def initialize(x, y)
|
40
|
-
super
|
41
|
-
end
|
42
|
-
|
43
|
-
def as_json()
|
44
|
-
{ :json_class => self.class,
|
45
|
-
:x => @x,
|
46
|
-
:y => @y }
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.json_create(h)
|
50
|
-
self.new(h['x'], h['y'])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def setup
|
55
|
-
@default_options = Oj.default_options
|
56
|
-
end
|
57
|
-
|
58
|
-
def teardown
|
59
|
-
Oj.default_options = @default_options
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_nil
|
63
|
-
dump_and_load(nil, false)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_true
|
67
|
-
dump_and_load(true, false)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_false
|
71
|
-
dump_and_load(false, false)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_fixnum
|
75
|
-
dump_and_load(0, false)
|
76
|
-
dump_and_load(12345, false)
|
77
|
-
dump_and_load(-54321, false)
|
78
|
-
dump_and_load(1, false)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_float
|
82
|
-
mode = Oj.default_options()[:mode]
|
83
|
-
Oj.default_options = {:mode => :object}
|
84
|
-
dump_and_load(0.0, false)
|
85
|
-
dump_and_load(12345.6789, false)
|
86
|
-
dump_and_load(70.35, false)
|
87
|
-
dump_and_load(-54321.012, false)
|
88
|
-
dump_and_load(1.7775, false)
|
89
|
-
dump_and_load(2.5024, false)
|
90
|
-
dump_and_load(2.48e16, false)
|
91
|
-
dump_and_load(2.48e100 * 1.0e10, false)
|
92
|
-
dump_and_load(-2.48e100 * 1.0e10, false)
|
93
|
-
dump_and_load(1/0.0, false)
|
94
|
-
Oj.default_options = {:mode => mode}
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_string
|
98
|
-
dump_and_load('', false)
|
99
|
-
dump_and_load('abc', false)
|
100
|
-
dump_and_load("abc\ndef", false)
|
101
|
-
dump_and_load("a\u0041", false)
|
102
|
-
assert_equal("a\u0000a", dump_and_load("a\u0000a", false))
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_string_object
|
106
|
-
dump_and_load('abc', false)
|
107
|
-
dump_and_load(':abc', false)
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_array
|
111
|
-
dump_and_load([], false)
|
112
|
-
dump_and_load([true, false], false)
|
113
|
-
dump_and_load(['a', 1, nil], false)
|
114
|
-
dump_and_load([[nil]], false)
|
115
|
-
dump_and_load([[nil], 58], false)
|
116
|
-
end
|
117
|
-
|
118
|
-
# Symbol
|
119
|
-
def test_symbol_object
|
120
|
-
Oj.default_options = { :mode => :object }
|
121
|
-
#dump_and_load(''.to_sym, false)
|
122
|
-
dump_and_load(:abc, false)
|
123
|
-
dump_and_load(':xyz'.to_sym, false)
|
124
|
-
end
|
125
|
-
|
126
|
-
# Time
|
127
|
-
def test_time_object
|
128
|
-
t = Time.now()
|
129
|
-
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
|
130
|
-
dump_and_load(t, false)
|
131
|
-
end
|
132
|
-
def test_time_object_early
|
133
|
-
skip 'Windows does not support dates before 1970.' if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
134
|
-
|
135
|
-
t = Time.xmlschema("1954-01-05T00:00:00.123456")
|
136
|
-
Oj.default_options = { :mode => :object, :time_format => :unix_zone }
|
137
|
-
dump_and_load(t, false)
|
138
|
-
end
|
139
|
-
|
140
|
-
# Hash
|
141
|
-
def test_hash
|
142
|
-
Oj.default_options = { :mode => :strict }
|
143
|
-
dump_and_load({}, false)
|
144
|
-
dump_and_load({ 'true' => true, 'false' => false}, false)
|
145
|
-
dump_and_load({ 'true' => true, 'array' => [], 'hash' => { }}, false)
|
146
|
-
end
|
147
|
-
|
148
|
-
# Object with to_json()
|
149
|
-
def test_json_object_compat
|
150
|
-
Oj.default_options = { :mode => :compat, :use_to_json => true, :create_additions => true }
|
151
|
-
obj = Jeez.new(true, 58)
|
152
|
-
json = Oj.dump(obj, :indent => 2)
|
153
|
-
assert(%{{"json_class":"FileJuice::Jeez","x":true,"y":58}
|
154
|
-
} == json ||
|
155
|
-
%{{"json_class":"FileJuice::Jeez","y":58,"x":true}
|
156
|
-
} == json)
|
157
|
-
dump_and_load(obj, false)
|
158
|
-
Oj.default_options = { :mode => :compat, :use_to_json => false }
|
159
|
-
end
|
160
|
-
|
161
|
-
# Range
|
162
|
-
def test_range_object
|
163
|
-
Oj.default_options = { :mode => :object }
|
164
|
-
json = Oj.dump(1..7, :mode => :object, :indent => 0)
|
165
|
-
if $ruby == 'ruby'
|
166
|
-
assert_equal(%{{"^u":["Range",1,7,false]}}, json)
|
167
|
-
else
|
168
|
-
assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
|
169
|
-
end
|
170
|
-
dump_and_load(1..7, false)
|
171
|
-
dump_and_load(1..1, false)
|
172
|
-
dump_and_load(1...7, false)
|
173
|
-
end
|
174
|
-
|
175
|
-
# BigNum
|
176
|
-
def test_bignum_object
|
177
|
-
Oj.default_options = { :mode => :compat }
|
178
|
-
dump_and_load(7 ** 55, false)
|
179
|
-
end
|
180
|
-
|
181
|
-
# BigDecimal
|
182
|
-
def test_bigdecimal_strict
|
183
|
-
mode = Oj.default_options[:mode]
|
184
|
-
Oj.default_options = {:mode => :strict}
|
185
|
-
dump_and_load(BigDecimal('3.14159265358979323846'), false)
|
186
|
-
Oj.default_options = {:mode => mode}
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_bigdecimal_null
|
190
|
-
mode = Oj.default_options[:mode]
|
191
|
-
Oj.default_options = {:mode => :null}
|
192
|
-
dump_and_load(BigDecimal('3.14159265358979323846'), false)
|
193
|
-
Oj.default_options = {:mode => mode}
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_bigdecimal_object
|
197
|
-
Oj.default_options = {:mode => :object}
|
198
|
-
dump_and_load(BigDecimal('3.14159265358979323846'), false)
|
199
|
-
end
|
200
|
-
|
201
|
-
# Date
|
202
|
-
def test_date_object
|
203
|
-
Oj.default_options = { :mode => :object }
|
204
|
-
dump_and_load(Date.new(2012, 6, 19), false)
|
205
|
-
end
|
206
|
-
|
207
|
-
# DateTime
|
208
|
-
def test_datetime_object
|
209
|
-
Oj.default_options = { :mode => :object }
|
210
|
-
dump_and_load(DateTime.new(2012, 6, 19), false)
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_load_unicode_path
|
214
|
-
json =<<~JSON
|
215
|
-
{
|
216
|
-
"x":true,
|
217
|
-
"y":58,
|
218
|
-
"z": [1,2,3]
|
219
|
-
}
|
220
|
-
JSON
|
221
|
-
|
222
|
-
Tempfile.create('file_test_conceição1.json') do |f|
|
223
|
-
f.write(json)
|
224
|
-
f.close
|
225
|
-
|
226
|
-
objects = Oj.load_file(f.path)
|
227
|
-
assert_equal(Oj.load(json), objects)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
def dump_and_load(obj, trace=false)
|
232
|
-
filename = File.join(File.dirname(__FILE__), 'file_test.json')
|
233
|
-
File.open(filename, "w") { |f|
|
234
|
-
Oj.to_stream(f, obj, :indent => 2)
|
235
|
-
}
|
236
|
-
puts "\n*** file: '#{File.read(filename)}'" if trace
|
237
|
-
loaded = Oj.load_file(filename)
|
238
|
-
if obj.is_a?(Time) && loaded.is_a?(Time)
|
239
|
-
assert_equal(obj.tv_sec, loaded.tv_sec)
|
240
|
-
if obj.respond_to?(:tv_nsec)
|
241
|
-
assert_equal(obj.tv_nsec, loaded.tv_nsec)
|
242
|
-
else
|
243
|
-
assert_equal(obj.tv_usec, loaded.tv_usec)
|
244
|
-
end
|
245
|
-
assert_equal(obj.utc?, loaded.utc?)
|
246
|
-
assert_equal(obj.utc_offset, loaded.utc_offset)
|
247
|
-
elsif obj.nil?
|
248
|
-
assert_nil(loaded)
|
249
|
-
else
|
250
|
-
assert_equal(obj, loaded)
|
251
|
-
end
|
252
|
-
loaded
|
253
|
-
end
|
254
|
-
|
255
|
-
end
|
data/test/test_gc.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class GCTest < Minitest::Test
|
9
|
-
class Goo
|
10
|
-
attr_accessor :x, :child
|
11
|
-
|
12
|
-
def initialize(x, child)
|
13
|
-
@x = x
|
14
|
-
@child = child
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_hash()
|
18
|
-
{ 'json_class' => "#{self.class}", 'x' => x, 'child' => child }
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.json_create(h)
|
22
|
-
GC.start
|
23
|
-
self.new(h['x'], h['child'])
|
24
|
-
end
|
25
|
-
end # Goo
|
26
|
-
|
27
|
-
def setup
|
28
|
-
@default_options = Oj.default_options
|
29
|
-
GC.stress = true
|
30
|
-
end
|
31
|
-
|
32
|
-
def teardown
|
33
|
-
Oj.default_options = @default_options
|
34
|
-
GC.stress = false
|
35
|
-
end
|
36
|
-
|
37
|
-
# if no crash then the GC marking is working
|
38
|
-
def test_parse_compat_gc
|
39
|
-
g = Goo.new(0, nil)
|
40
|
-
100.times { |i| g = Goo.new(i, g) }
|
41
|
-
json = Oj.dump(g, :mode => :compat)
|
42
|
-
Oj.compat_load(json)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_parse_object_gc
|
46
|
-
g = Goo.new(0, nil)
|
47
|
-
100.times { |i| g = Goo.new(i, g) }
|
48
|
-
json = Oj.dump(g, :mode => :object)
|
49
|
-
Oj.object_load(json)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_parse_gc
|
53
|
-
json = '{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}'
|
54
|
-
|
55
|
-
50.times do
|
56
|
-
data = Oj.load(json)
|
57
|
-
assert_equal(json, Oj.dump(data))
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/test/test_generate.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
6
|
-
%w(lib ext).each do |dir|
|
7
|
-
$: << File.join($oj_dir, dir)
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'minitest'
|
11
|
-
require 'minitest/autorun'
|
12
|
-
require 'oj'
|
13
|
-
|
14
|
-
class Generator < Minitest::Test
|
15
|
-
|
16
|
-
def test_before
|
17
|
-
json = Oj.generate({})
|
18
|
-
assert_equal("{}", json)
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
data/test/test_hash.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class HashTest < Minitest::Test
|
9
|
-
|
10
|
-
module TestModule
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_dump
|
14
|
-
h = Oj::EasyHash.new()
|
15
|
-
h['abc'] = 3
|
16
|
-
out = Oj.dump(h, :mode => :compat)
|
17
|
-
assert_equal(%|{"abc":3}|, out)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_load
|
21
|
-
obj = Oj.load(%|{"abc":3}|, :mode => :compat, :hash_class => Oj::EasyHash)
|
22
|
-
|
23
|
-
assert_equal(Oj::EasyHash, obj.class)
|
24
|
-
assert_equal(3, obj['abc'])
|
25
|
-
assert_equal(3, obj[:abc])
|
26
|
-
assert_equal(3, obj.abc())
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_marshal
|
30
|
-
h = Oj::EasyHash.new()
|
31
|
-
h['abc'] = 3
|
32
|
-
out = Marshal.dump(h)
|
33
|
-
|
34
|
-
obj = Marshal.load(out)
|
35
|
-
assert_equal(Oj::EasyHash, obj.class)
|
36
|
-
assert_equal(3, obj[:abc])
|
37
|
-
end
|
38
|
-
|
39
|
-
end # HashTest
|
data/test/test_integer_range.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
$oj_dir = File.dirname(File.expand_path(File.dirname(__FILE__)))
|
6
|
-
%w(lib ext).each do |dir|
|
7
|
-
$: << File.join($oj_dir, dir)
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'minitest'
|
11
|
-
require 'minitest/autorun'
|
12
|
-
require 'oj'
|
13
|
-
|
14
|
-
class IntegerRangeTest < Minitest::Test
|
15
|
-
def setup
|
16
|
-
@default_options = Oj.default_options
|
17
|
-
# in null mode other options other than the number formats are not used.
|
18
|
-
Oj.default_options = { :mode => :null, bigdecimal_as_decimal: true }
|
19
|
-
end
|
20
|
-
|
21
|
-
def teardown
|
22
|
-
Oj.default_options = @default_options
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_range
|
26
|
-
test = {s: 0, s2: -1, s3: 1, u: -2, u2: 2, u3: 9007199254740993}
|
27
|
-
exp = '{"s":0,"s2":-1,"s3":1,"u":"-2","u2":"2","u3":"9007199254740993"}'
|
28
|
-
assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_bignum
|
32
|
-
test = {u: -10000000000000000000, u2: 10000000000000000000}
|
33
|
-
exp = '{"u":"-10000000000000000000","u2":"10000000000000000000"}'
|
34
|
-
assert_equal(exp, Oj.dump(test, integer_range: (-1..1)))
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_valid_modes
|
38
|
-
test = {safe: 0, unsafe: 9007199254740993}
|
39
|
-
exp = '{"safe":0,"unsafe":"9007199254740993"}'
|
40
|
-
|
41
|
-
[:strict, :null, :compat, :rails, :custom].each do |mode|
|
42
|
-
assert_equal(exp, Oj.dump(test, mode: mode, integer_range: (-1..1)), "Invalid mode #{mode}")
|
43
|
-
end
|
44
|
-
|
45
|
-
exp = '{":safe":0,":unsafe":"9007199254740993"}'
|
46
|
-
[:object].each do |mode|
|
47
|
-
assert_equal(exp, Oj.dump(test, mode: mode, integer_range: (-1..1)), "Invalid mode #{mode}")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_modes_without_opt
|
52
|
-
test = {safe:0, unsafe: 10000000000000000000}
|
53
|
-
exp = '{"safe":0,"unsafe":10000000000000000000}'
|
54
|
-
|
55
|
-
[:strict, :null, :compat, :rails, :custom].each do |mode|
|
56
|
-
assert_equal(exp, Oj.dump(test, mode: mode), "Invalid mode #{mode}")
|
57
|
-
end
|
58
|
-
|
59
|
-
exp = '{":safe":0,":unsafe":10000000000000000000}'
|
60
|
-
[:object].each do |mode|
|
61
|
-
assert_equal(exp, Oj.dump(test, mode: mode), "Invalid mode #{mode}")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_accept_nil_and_false
|
66
|
-
test = {safe:0, unsafe: 10000000000000000000}
|
67
|
-
exp = '{"safe":0,"unsafe":10000000000000000000}'
|
68
|
-
|
69
|
-
assert_equal(exp, Oj.dump(test, integer_range: nil))
|
70
|
-
assert_equal(exp, Oj.dump(test, integer_range: false))
|
71
|
-
end
|
72
|
-
end
|