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_parser.rb
DELETED
@@ -1,11 +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 'test_parser_usual'
|
11
|
-
require 'test_parser_saj'
|
data/test/test_parser_debug.rb
DELETED
@@ -1,27 +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 'stringio'
|
13
|
-
require 'date'
|
14
|
-
require 'bigdecimal'
|
15
|
-
require 'oj'
|
16
|
-
|
17
|
-
class ParserJuice < Minitest::Test
|
18
|
-
|
19
|
-
def test_array
|
20
|
-
p = Oj::Parser.new(:debug)
|
21
|
-
out = p.parse(%|[true, false, null, 123, -1.23, "abc"]|)
|
22
|
-
puts out
|
23
|
-
out = p.parse(%|{"abc": []}|)
|
24
|
-
puts out
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
data/test/test_parser_saj.rb
DELETED
@@ -1,335 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
$json = %|{
|
9
|
-
"array": [
|
10
|
-
{
|
11
|
-
"num" : 3,
|
12
|
-
"string": "message",
|
13
|
-
"hash" : {
|
14
|
-
"h2" : {
|
15
|
-
"a" : [ 1, 2, 3 ]
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
19
|
-
],
|
20
|
-
"boolean" : true
|
21
|
-
}|
|
22
|
-
|
23
|
-
class AllSaj < Oj::Saj
|
24
|
-
attr_accessor :calls
|
25
|
-
|
26
|
-
def initialize()
|
27
|
-
@calls = []
|
28
|
-
end
|
29
|
-
|
30
|
-
def hash_start(key)
|
31
|
-
@calls << [:hash_start, key]
|
32
|
-
end
|
33
|
-
|
34
|
-
def hash_end(key)
|
35
|
-
@calls << [:hash_end, key]
|
36
|
-
end
|
37
|
-
|
38
|
-
def array_start(key)
|
39
|
-
@calls << [:array_start, key]
|
40
|
-
end
|
41
|
-
|
42
|
-
def array_end(key)
|
43
|
-
@calls << [:array_end, key]
|
44
|
-
end
|
45
|
-
|
46
|
-
def add_value(value, key)
|
47
|
-
@calls << [:add_value, value, key]
|
48
|
-
end
|
49
|
-
|
50
|
-
def error(message, line, column)
|
51
|
-
@calls << [:error, message, line, column]
|
52
|
-
end
|
53
|
-
|
54
|
-
end # AllSaj
|
55
|
-
|
56
|
-
class LocSaj
|
57
|
-
attr_accessor :calls
|
58
|
-
|
59
|
-
def initialize()
|
60
|
-
@calls = []
|
61
|
-
end
|
62
|
-
|
63
|
-
def hash_start(key, line, column)
|
64
|
-
@calls << [:hash_start, key, line, column]
|
65
|
-
end
|
66
|
-
|
67
|
-
def hash_end(key, line, column)
|
68
|
-
@calls << [:hash_end, key, line, column]
|
69
|
-
end
|
70
|
-
|
71
|
-
def array_start(key, line, column)
|
72
|
-
@calls << [:array_start, key, line, column]
|
73
|
-
end
|
74
|
-
|
75
|
-
def array_end(key, line, column)
|
76
|
-
@calls << [:array_end, key, line, column]
|
77
|
-
end
|
78
|
-
|
79
|
-
def add_value(value, key, line, column)
|
80
|
-
@calls << [:add_value, value, key, line, column]
|
81
|
-
end
|
82
|
-
|
83
|
-
end # LocSaj
|
84
|
-
|
85
|
-
class SajTest < Minitest::Test
|
86
|
-
|
87
|
-
def test_nil
|
88
|
-
handler = AllSaj.new()
|
89
|
-
json = %{null}
|
90
|
-
p = Oj::Parser.new(:saj)
|
91
|
-
p.handler = handler
|
92
|
-
p.parse(json)
|
93
|
-
assert_equal([[:add_value, nil, nil]], handler.calls)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_true
|
97
|
-
handler = AllSaj.new()
|
98
|
-
json = %{true}
|
99
|
-
p = Oj::Parser.new(:saj)
|
100
|
-
p.handler = handler
|
101
|
-
p.parse(json)
|
102
|
-
assert_equal([[:add_value, true, nil]], handler.calls)
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_false
|
106
|
-
handler = AllSaj.new()
|
107
|
-
json = %{false}
|
108
|
-
p = Oj::Parser.new(:saj)
|
109
|
-
p.handler = handler
|
110
|
-
p.parse(json)
|
111
|
-
assert_equal([[:add_value, false, nil]], handler.calls)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_string
|
115
|
-
handler = AllSaj.new()
|
116
|
-
json = %{"a string"}
|
117
|
-
p = Oj::Parser.new(:saj)
|
118
|
-
p.handler = handler
|
119
|
-
p.parse(json)
|
120
|
-
assert_equal([[:add_value, 'a string', nil]], handler.calls)
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_fixnum
|
124
|
-
handler = AllSaj.new()
|
125
|
-
json = %{12345}
|
126
|
-
p = Oj::Parser.new(:saj)
|
127
|
-
p.handler = handler
|
128
|
-
p.parse(json)
|
129
|
-
assert_equal([[:add_value, 12345, nil]], handler.calls)
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_float
|
133
|
-
handler = AllSaj.new()
|
134
|
-
json = %{12345.6789}
|
135
|
-
p = Oj::Parser.new(:saj)
|
136
|
-
p.handler = handler
|
137
|
-
p.parse(json)
|
138
|
-
assert_equal([[:add_value, 12345.6789, nil]], handler.calls)
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_float_exp
|
142
|
-
handler = AllSaj.new()
|
143
|
-
json = %{12345.6789e7}
|
144
|
-
p = Oj::Parser.new(:saj)
|
145
|
-
p.handler = handler
|
146
|
-
p.parse(json)
|
147
|
-
assert_equal(1, handler.calls.size)
|
148
|
-
assert_equal(:add_value, handler.calls[0][0])
|
149
|
-
assert_equal((12345.6789e7 * 10000).to_i, (handler.calls[0][1] * 10000).to_i)
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_bignum
|
153
|
-
handler = AllSaj.new()
|
154
|
-
json = %{-11.899999999999999}
|
155
|
-
p = Oj::Parser.new(:saj)
|
156
|
-
p.handler = handler
|
157
|
-
p.parse(json)
|
158
|
-
assert_equal(1, handler.calls.size)
|
159
|
-
assert_equal(:add_value, handler.calls[0][0])
|
160
|
-
assert_equal(-118999, (handler.calls[0][1] * 10000).to_i)
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_bignum_loc
|
164
|
-
handler = LocSaj.new()
|
165
|
-
json = <<~JSON
|
166
|
-
{
|
167
|
-
"width": 192.33800000000002,
|
168
|
-
"xaxis": {
|
169
|
-
"anchor": "y"
|
170
|
-
}
|
171
|
-
}
|
172
|
-
JSON
|
173
|
-
|
174
|
-
p = Oj::Parser.new(:saj)
|
175
|
-
p.handler = handler
|
176
|
-
p.parse(json)
|
177
|
-
assert_equal(6, handler.calls.size)
|
178
|
-
assert_equal(1_923_380, (handler.calls[1][1] * 10000).to_i)
|
179
|
-
handler.calls[1][1] = 1_923_380
|
180
|
-
assert_equal([[:hash_start, nil, 1, 1],
|
181
|
-
[:add_value, 1923380, 'width', 2, 30],
|
182
|
-
[:hash_start, 'xaxis', 3, 12],
|
183
|
-
[:add_value, 'y', 'anchor', 4, 17],
|
184
|
-
[:hash_end, 'xaxis', 5, 3],
|
185
|
-
[:hash_end, nil, 6, 1]],
|
186
|
-
handler.calls)
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_array_empty
|
190
|
-
handler = AllSaj.new()
|
191
|
-
json = %{[]}
|
192
|
-
p = Oj::Parser.new(:saj)
|
193
|
-
p.handler = handler
|
194
|
-
p.parse(json)
|
195
|
-
assert_equal([[:array_start, nil],
|
196
|
-
[:array_end, nil]], handler.calls)
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_array
|
200
|
-
handler = AllSaj.new()
|
201
|
-
json = %{[true,false]}
|
202
|
-
p = Oj::Parser.new(:saj)
|
203
|
-
p.handler = handler
|
204
|
-
p.parse(json)
|
205
|
-
assert_equal([[:array_start, nil],
|
206
|
-
[:add_value, true, nil],
|
207
|
-
[:add_value, false, nil],
|
208
|
-
[:array_end, nil]], handler.calls)
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_hash_empty
|
212
|
-
handler = AllSaj.new()
|
213
|
-
json = %{{}}
|
214
|
-
p = Oj::Parser.new(:saj)
|
215
|
-
p.handler = handler
|
216
|
-
p.parse(json)
|
217
|
-
assert_equal([[:hash_start, nil],
|
218
|
-
[:hash_end, nil]], handler.calls)
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_hash
|
222
|
-
handler = AllSaj.new()
|
223
|
-
json = %{{"one":true,"two":false}}
|
224
|
-
p = Oj::Parser.new(:saj)
|
225
|
-
p.handler = handler
|
226
|
-
p.parse(json)
|
227
|
-
assert_equal([[:hash_start, nil],
|
228
|
-
[:add_value, true, 'one'],
|
229
|
-
[:add_value, false, 'two'],
|
230
|
-
[:hash_end, nil]], handler.calls)
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_full
|
234
|
-
handler = AllSaj.new()
|
235
|
-
Oj.saj_parse(handler, $json)
|
236
|
-
assert_equal([[:hash_start, nil],
|
237
|
-
[:array_start, 'array'],
|
238
|
-
[:hash_start, nil],
|
239
|
-
[:add_value, 3, 'num'],
|
240
|
-
[:add_value, 'message', 'string'],
|
241
|
-
[:hash_start, 'hash'],
|
242
|
-
[:hash_start, 'h2'],
|
243
|
-
[:array_start, 'a'],
|
244
|
-
[:add_value, 1, nil],
|
245
|
-
[:add_value, 2, nil],
|
246
|
-
[:add_value, 3, nil],
|
247
|
-
[:array_end, 'a'],
|
248
|
-
[:hash_end, 'h2'],
|
249
|
-
[:hash_end, 'hash'],
|
250
|
-
[:hash_end, nil],
|
251
|
-
[:array_end, 'array'],
|
252
|
-
[:add_value, true, 'boolean'],
|
253
|
-
[:hash_end, nil]], handler.calls)
|
254
|
-
end
|
255
|
-
|
256
|
-
def test_multiple
|
257
|
-
handler = AllSaj.new()
|
258
|
-
json = %|[true][false]|
|
259
|
-
p = Oj::Parser.new(:saj)
|
260
|
-
p.handler = handler
|
261
|
-
p.parse(json)
|
262
|
-
assert_equal([
|
263
|
-
[:array_start, nil],
|
264
|
-
[:add_value, true, nil],
|
265
|
-
[:array_end, nil],
|
266
|
-
[:array_start, nil],
|
267
|
-
[:add_value, false, nil],
|
268
|
-
[:array_end, nil],
|
269
|
-
], handler.calls)
|
270
|
-
end
|
271
|
-
|
272
|
-
def test_io
|
273
|
-
handler = AllSaj.new()
|
274
|
-
json = %| [true,false] |
|
275
|
-
p = Oj::Parser.new(:saj)
|
276
|
-
p.handler = handler
|
277
|
-
p.load(StringIO.new(json))
|
278
|
-
assert_equal([
|
279
|
-
[:array_start, nil],
|
280
|
-
[:add_value, true, nil],
|
281
|
-
[:add_value, false, nil],
|
282
|
-
[:array_end, nil],
|
283
|
-
], handler.calls)
|
284
|
-
end
|
285
|
-
|
286
|
-
def test_file
|
287
|
-
handler = AllSaj.new()
|
288
|
-
p = Oj::Parser.new(:saj)
|
289
|
-
p.handler = handler
|
290
|
-
p.file('saj_test.json')
|
291
|
-
assert_equal([
|
292
|
-
[:array_start, nil],
|
293
|
-
[:add_value, true, nil],
|
294
|
-
[:add_value, false, nil],
|
295
|
-
[:array_end, nil],
|
296
|
-
], handler.calls)
|
297
|
-
end
|
298
|
-
|
299
|
-
def test_default
|
300
|
-
handler = AllSaj.new()
|
301
|
-
json = %|[true]|
|
302
|
-
Oj::Parser.saj.handler = handler
|
303
|
-
Oj::Parser.saj.parse(json)
|
304
|
-
assert_equal([
|
305
|
-
[:array_start, nil],
|
306
|
-
[:add_value, true, nil],
|
307
|
-
[:array_end, nil],
|
308
|
-
], handler.calls)
|
309
|
-
end
|
310
|
-
|
311
|
-
def test_loc
|
312
|
-
handler = LocSaj.new()
|
313
|
-
Oj::Parser.saj.handler = handler
|
314
|
-
Oj::Parser.saj.parse($json)
|
315
|
-
assert_equal([[:hash_start, nil, 1, 1],
|
316
|
-
[:array_start, 'array', 2, 12],
|
317
|
-
[:hash_start, nil, 3, 5],
|
318
|
-
[:add_value, 3, 'num', 4, 18],
|
319
|
-
[:add_value, 'message', 'string', 5, 25],
|
320
|
-
[:hash_start, 'hash', 6, 17],
|
321
|
-
[:hash_start, 'h2', 7, 17],
|
322
|
-
[:array_start, 'a', 8, 17],
|
323
|
-
[:add_value, 1, nil, 8, 20],
|
324
|
-
[:add_value, 2, nil, 8, 23],
|
325
|
-
[:add_value, 3, nil, 8, 26],
|
326
|
-
[:array_end, 'a', 8, 27],
|
327
|
-
[:hash_end, 'h2', 9, 9],
|
328
|
-
[:hash_end, 'hash', 10, 7],
|
329
|
-
[:hash_end, nil, 11, 5],
|
330
|
-
[:array_end, 'array', 12, 3],
|
331
|
-
[:add_value, true, 'boolean', 13, 18],
|
332
|
-
[:hash_end, nil, 14, 1]], handler.calls)
|
333
|
-
end
|
334
|
-
|
335
|
-
end
|
data/test/test_parser_usual.rb
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class UsualTest < Minitest::Test
|
9
|
-
|
10
|
-
def test_nil
|
11
|
-
p = Oj::Parser.new(:usual)
|
12
|
-
doc = p.parse('nil')
|
13
|
-
assert_nil(doc)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_primitive
|
17
|
-
p = Oj::Parser.new(:usual)
|
18
|
-
[
|
19
|
-
['true', true],
|
20
|
-
['false', false],
|
21
|
-
['123', 123],
|
22
|
-
['1.25', 1.25],
|
23
|
-
['"abc"', 'abc'],
|
24
|
-
].each { |x|
|
25
|
-
doc = p.parse(x[0])
|
26
|
-
assert_equal(x[1], doc)
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_big
|
31
|
-
p = Oj::Parser.new(:usual)
|
32
|
-
doc = p.parse('12345678901234567890123456789')
|
33
|
-
assert_equal(BigDecimal, doc.class)
|
34
|
-
doc = p.parse('1234567890.1234567890123456789')
|
35
|
-
assert_equal(BigDecimal, doc.class)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_array
|
39
|
-
p = Oj::Parser.new(:usual)
|
40
|
-
[
|
41
|
-
['[]', []],
|
42
|
-
['[false]', [false]],
|
43
|
-
['[true,false]', [true,false]],
|
44
|
-
['[[]]', [[]]],
|
45
|
-
['[true,[],false]', [true,[],false]],
|
46
|
-
['[true,[true],false]', [true,[true],false]],
|
47
|
-
].each { |x|
|
48
|
-
doc = p.parse(x[0])
|
49
|
-
assert_equal(x[1], doc)
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_hash
|
54
|
-
p = Oj::Parser.new(:usual)
|
55
|
-
[
|
56
|
-
['{}', {}],
|
57
|
-
['{"a": null}', {'a' => nil}],
|
58
|
-
['{"t": true, "f": false, "s": "abc"}', {'t' => true, 'f' => false, 's' => 'abc'}],
|
59
|
-
['{"a": {}}', {'a' => {}}],
|
60
|
-
['{"a": {"b": 2}}', {'a' => {'b' => 2}}],
|
61
|
-
['{"a": [true]}', {'a' => [true]}],
|
62
|
-
].each { |x|
|
63
|
-
doc = p.parse(x[0])
|
64
|
-
assert_equal(x[1], doc)
|
65
|
-
}
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_symbol_keys
|
69
|
-
p = Oj::Parser.new(:usual)
|
70
|
-
assert_equal(false, p.symbol_keys)
|
71
|
-
p.symbol_keys = true
|
72
|
-
doc = p.parse('{"a": true, "b": false}')
|
73
|
-
assert_equal({a: true, b: false}, doc)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_strings
|
77
|
-
p = Oj::Parser.new(:usual)
|
78
|
-
doc = p.parse('{"ぴ": "", "ぴ ": "x", "c": "ぴーたー", "d": " ぴーたー "}')
|
79
|
-
assert_equal({'ぴ' => '', 'ぴ ' => 'x', 'c' => 'ぴーたー', 'd' => ' ぴーたー '}, doc)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_capacity
|
83
|
-
p = Oj::Parser.new(:usual, capacity: 1000)
|
84
|
-
assert_equal(4096, p.capacity)
|
85
|
-
p.capacity = 5000
|
86
|
-
assert_equal(5000, p.capacity)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_decimal
|
90
|
-
p = Oj::Parser.new(:usual)
|
91
|
-
assert_equal(:auto, p.decimal)
|
92
|
-
doc = p.parse('1.234567890123456789')
|
93
|
-
assert_equal(BigDecimal, doc.class)
|
94
|
-
assert_equal('0.1234567890123456789e1', doc.to_s)
|
95
|
-
doc = p.parse('1.25')
|
96
|
-
assert_equal(Float, doc.class)
|
97
|
-
|
98
|
-
p.decimal = :float
|
99
|
-
assert_equal(:float, p.decimal)
|
100
|
-
doc = p.parse('1.234567890123456789')
|
101
|
-
assert_equal(Float, doc.class)
|
102
|
-
|
103
|
-
p.decimal = :bigdecimal
|
104
|
-
assert_equal(:bigdecimal, p.decimal)
|
105
|
-
doc = p.parse('1.234567890123456789')
|
106
|
-
assert_equal(BigDecimal, doc.class)
|
107
|
-
doc = p.parse('1.25')
|
108
|
-
assert_equal(BigDecimal, doc.class)
|
109
|
-
assert_equal('0.125e1', doc.to_s)
|
110
|
-
|
111
|
-
p.decimal = :ruby
|
112
|
-
assert_equal(:ruby, p.decimal)
|
113
|
-
doc = p.parse('1.234567890123456789')
|
114
|
-
assert_equal(Float, doc.class)
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_omit_null
|
118
|
-
p = Oj::Parser.new(:usual)
|
119
|
-
p.omit_null = true
|
120
|
-
doc = p.parse('{"a":true,"b":null}')
|
121
|
-
assert_equal({'a'=>true}, doc)
|
122
|
-
|
123
|
-
p.omit_null = false
|
124
|
-
doc = p.parse('{"a":true,"b":null}')
|
125
|
-
assert_equal({'a'=>true, 'b'=>nil}, doc)
|
126
|
-
end
|
127
|
-
|
128
|
-
class MyArray < Array
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_array_class
|
132
|
-
p = Oj::Parser.new(:usual)
|
133
|
-
p.array_class = MyArray
|
134
|
-
assert_equal(MyArray, p.array_class)
|
135
|
-
doc = p.parse('[true]')
|
136
|
-
assert_equal(MyArray, doc.class)
|
137
|
-
end
|
138
|
-
|
139
|
-
class MyHash < Hash
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_hash_class
|
143
|
-
p = Oj::Parser.new(:usual)
|
144
|
-
p.hash_class = MyHash
|
145
|
-
assert_equal(MyHash, p.hash_class)
|
146
|
-
doc = p.parse('{"a":true}')
|
147
|
-
assert_equal(MyHash, doc.class)
|
148
|
-
end
|
149
|
-
|
150
|
-
class MyClass
|
151
|
-
attr_accessor :a
|
152
|
-
attr_accessor :b
|
153
|
-
|
154
|
-
def to_s
|
155
|
-
"#{self.class}{a: #{@a} b: #{b}}"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
class MyClass2 < MyClass
|
160
|
-
def self.json_create(arg)
|
161
|
-
obj = new
|
162
|
-
obj.a = arg['a']
|
163
|
-
obj.b = arg['b']
|
164
|
-
obj
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_create_id
|
169
|
-
p = Oj::Parser.new(:usual)
|
170
|
-
p.create_id = '^'
|
171
|
-
doc = p.parse('{"a":true}')
|
172
|
-
assert_equal(Hash, doc.class)
|
173
|
-
doc = p.parse('{"a":true,"^":"UsualTest::MyClass","b":false}')
|
174
|
-
assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
|
175
|
-
|
176
|
-
doc = p.parse('{"a":true,"^":"UsualTest::MyClass2","b":false}')
|
177
|
-
assert_equal('UsualTest::MyClass2{a: true b: false}', doc.to_s)
|
178
|
-
|
179
|
-
p.hash_class = MyHash
|
180
|
-
assert_equal(MyHash, p.hash_class)
|
181
|
-
doc = p.parse('{"a":true}')
|
182
|
-
assert_equal(MyHash, doc.class)
|
183
|
-
|
184
|
-
doc = p.parse('{"a":true,"^":"UsualTest::MyClass","b":false}')
|
185
|
-
assert_equal('UsualTest::MyClass{a: true b: false}', doc.to_s)
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_missing_class
|
189
|
-
p = Oj::Parser.new(:usual, create_id: '^')
|
190
|
-
json = '{"a":true,"^":"Auto","b":false}'
|
191
|
-
doc = p.parse(json)
|
192
|
-
assert_equal(Hash, doc.class)
|
193
|
-
|
194
|
-
p.missing_class = :auto
|
195
|
-
doc = p.parse(json)
|
196
|
-
# Auto should be defined after parsing
|
197
|
-
assert_equal(Auto, doc.class)
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_class_cache
|
201
|
-
p = Oj::Parser.new(:usual)
|
202
|
-
p.create_id = '^'
|
203
|
-
p.class_cache = true
|
204
|
-
p.missing_class = :auto
|
205
|
-
json = '{"a":true,"^":"Auto2","b":false}'
|
206
|
-
doc = p.parse(json)
|
207
|
-
assert_equal(Auto2, doc.class)
|
208
|
-
|
209
|
-
doc = p.parse(json)
|
210
|
-
assert_equal(Auto2, doc.class)
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_default_parser
|
214
|
-
doc = Oj::Parser.usual.parse('{"a":true,"b":null}')
|
215
|
-
assert_equal({'a'=>true, 'b'=>nil}, doc)
|
216
|
-
end
|
217
|
-
end
|
data/test/test_rails.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
$: << File.dirname(__FILE__)
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class RailsJuice < Minitest::Test
|
9
|
-
|
10
|
-
def test_bigdecimal_dump
|
11
|
-
orig = Oj.default_options
|
12
|
-
Oj.default_options = { mode: :rails, bigdecimal_as_decimal: true }
|
13
|
-
bd = BigDecimal('123')
|
14
|
-
json = Oj.dump(bd)
|
15
|
-
Oj.default_options = orig
|
16
|
-
|
17
|
-
assert_equal('0.123e3', json.downcase)
|
18
|
-
|
19
|
-
json = Oj.dump(bd, mode: :rails, bigdecimal_as_decimal: false)
|
20
|
-
assert_equal('"0.123e3"', json.downcase)
|
21
|
-
|
22
|
-
json = Oj.dump(bd, mode: :rails, bigdecimal_as_decimal: true)
|
23
|
-
assert_equal('0.123e3', json.downcase)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_invalid_encoding
|
27
|
-
assert_raises(EncodingError) {
|
28
|
-
Oj.dump("\"\xf3j", mode: :rails)
|
29
|
-
}
|
30
|
-
assert_raises(EncodingError) {
|
31
|
-
Oj.dump("\xf3j", mode: :rails)
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|