oj 3.13.11 → 3.15.0
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 +74 -0
- data/README.md +4 -2
- data/ext/oj/buf.h +11 -6
- data/ext/oj/cache.c +25 -24
- 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 +17 -24
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +17 -44
- data/ext/oj/custom.c +70 -141
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +128 -118
- data/ext/oj/dump.h +12 -8
- data/ext/oj/dump_compat.c +564 -641
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +70 -199
- data/ext/oj/dump_strict.c +22 -46
- 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 +14 -5
- data/ext/oj/fast.c +75 -103
- data/ext/oj/intern.c +52 -50
- data/ext/oj/intern.h +4 -8
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +75 -47
- data/ext/oj/object.c +49 -66
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +140 -99
- data/ext/oj/oj.h +80 -51
- data/ext/oj/parse.c +162 -184
- data/ext/oj/parse.h +7 -10
- data/ext/oj/parser.c +89 -34
- data/ext/oj/parser.h +18 -7
- data/ext/oj/rails.c +82 -146
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +11 -12
- 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 +20 -31
- data/ext/oj/saj2.c +329 -93
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +3 -14
- data/ext/oj/sparse.c +26 -70
- data/ext/oj/stream_writer.c +12 -22
- data/ext/oj/strict.c +20 -52
- data/ext/oj/string_writer.c +21 -21
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +105 -150
- data/ext/oj/usual.h +68 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +1 -1
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +21 -26
- data/ext/oj/wab.c +31 -68
- 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/saj.rb +20 -6
- data/lib/oj/state.rb +9 -6
- 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/Options.md +10 -0
- 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/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +20 -34
- 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 +9 -71
- 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 +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 +48 -36
- 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 +13 -12
- data/test/perf.rb +21 -26
- 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 +12 -11
- data/test/perf_parser.rb +42 -48
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +57 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +68 -70
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +3 -3
- 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 +76 -42
- data/test/test_custom.rb +72 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +86 -90
- 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 +4 -4
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +85 -96
- data/test/test_parser.rb +6 -22
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +115 -23
- data/test/test_parser_usual.rb +6 -6
- 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 +30 -32
- data/test/test_various.rb +147 -99
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -4
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +33 -144
- 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 -16
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/zoo.rb +0 -13
data/test/test_wab.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'
|
@@ -19,20 +19,22 @@ require 'oj'
|
|
19
19
|
module WAB
|
20
20
|
class UUID
|
21
21
|
attr_reader :id
|
22
|
+
|
22
23
|
def initialize(id)
|
23
24
|
@id = id.downcase
|
24
|
-
raise
|
25
|
+
raise StandardError.new('Invalid UUID format.') if /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.match(@id).nil?
|
25
26
|
end
|
27
|
+
|
26
28
|
def to_s
|
27
29
|
@id
|
28
30
|
end
|
31
|
+
|
29
32
|
def ==(other)
|
30
33
|
other.is_a?(self.class) && @id == other.id
|
31
34
|
end
|
32
35
|
end # UUID
|
33
36
|
end # WAB
|
34
37
|
|
35
|
-
|
36
38
|
class WabJuice < Minitest::Test
|
37
39
|
|
38
40
|
module TestModule
|
@@ -52,16 +54,16 @@ class WabJuice < Minitest::Test
|
|
52
54
|
|
53
55
|
def test_fixnum
|
54
56
|
dump_and_load(0, false)
|
55
|
-
dump_and_load(
|
56
|
-
dump_and_load(-
|
57
|
+
dump_and_load(12_345, false)
|
58
|
+
dump_and_load(-54_321, false)
|
57
59
|
dump_and_load(1, false)
|
58
60
|
end
|
59
61
|
|
60
62
|
def test_float
|
61
63
|
dump_and_load(0.0, false)
|
62
|
-
dump_and_load(
|
64
|
+
dump_and_load(12_345.6789, false)
|
63
65
|
dump_and_load(70.35, false)
|
64
|
-
dump_and_load(-
|
66
|
+
dump_and_load(-54_321.012, false)
|
65
67
|
dump_and_load(1.7775, false)
|
66
68
|
dump_and_load(2.5024, false)
|
67
69
|
dump_and_load(2.48e16, false)
|
@@ -89,7 +91,7 @@ class WabJuice < Minitest::Test
|
|
89
91
|
end
|
90
92
|
|
91
93
|
def test_encode
|
92
|
-
dump_and_load(
|
94
|
+
dump_and_load('ぴーたー', false)
|
93
95
|
end
|
94
96
|
|
95
97
|
def test_array
|
@@ -101,23 +103,25 @@ class WabJuice < Minitest::Test
|
|
101
103
|
end
|
102
104
|
|
103
105
|
def test_array_deep
|
104
|
-
dump_and_load([1,[2,[3,[4,[5,[6,[7,[8,[9,[10,[11,[12,[13,[14,[15,[16,[17,[18,[19,[20]]]]]]]]]]]]]]]]]]]], false)
|
106
|
+
dump_and_load([1, [2, [3, [4, [5, [6, [7, [8, [9, [10, [11, [12, [13, [14, [15, [16, [17, [18, [19, [20]]]]]]]]]]]]]]]]]]]], false)
|
105
107
|
end
|
106
108
|
|
107
109
|
def test_deep_nest
|
110
|
+
skip 'TruffleRuby causes SEGV' if RUBY_ENGINE == 'truffleruby'
|
111
|
+
|
108
112
|
begin
|
109
|
-
n =
|
110
|
-
Oj.wab_load('[' * n + ']' * n)
|
113
|
+
n = 10_000
|
114
|
+
Oj.wab_load(('[' * n) + (']' * n))
|
111
115
|
rescue Exception => e
|
112
|
-
|
116
|
+
refute(e.message)
|
113
117
|
end
|
114
118
|
end
|
115
119
|
|
116
120
|
# Hash
|
117
121
|
def test_hash
|
118
122
|
dump_and_load({}, false)
|
119
|
-
dump_and_load({
|
120
|
-
dump_and_load({
|
123
|
+
dump_and_load({ tru: true, fals: false}, false)
|
124
|
+
dump_and_load({ tru: true, array: [], hash: {}}, false)
|
121
125
|
end
|
122
126
|
|
123
127
|
def test_hash_non_sym_keys
|
@@ -126,25 +130,25 @@ class WabJuice < Minitest::Test
|
|
126
130
|
|
127
131
|
def test_hash_deep
|
128
132
|
dump_and_load({x1: {
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
133
|
+
x2: {
|
134
|
+
x3: {
|
135
|
+
x4: {
|
136
|
+
x5: {
|
137
|
+
x6: {
|
138
|
+
x7: {
|
139
|
+
x8: {
|
140
|
+
x9: {
|
141
|
+
x10: {
|
142
|
+
x11: {
|
143
|
+
x12: {
|
144
|
+
x13: {
|
145
|
+
x14: {
|
146
|
+
x15: {
|
147
|
+
x16: {
|
148
|
+
x17: {
|
149
|
+
x18: {
|
150
|
+
x19: {
|
151
|
+
x20: {}}}}}}}}}}}}}}}}}}}}}, false)
|
148
152
|
end
|
149
153
|
|
150
154
|
def test_non_str_hash
|
@@ -152,7 +156,7 @@ class WabJuice < Minitest::Test
|
|
152
156
|
end
|
153
157
|
|
154
158
|
def test_bignum_object
|
155
|
-
dump_and_load(7
|
159
|
+
dump_and_load(7**55, false)
|
156
160
|
end
|
157
161
|
|
158
162
|
# BigDecimal
|
@@ -186,13 +190,13 @@ class WabJuice < Minitest::Test
|
|
186
190
|
end
|
187
191
|
|
188
192
|
def test_io_file
|
189
|
-
filename = File.join(
|
190
|
-
File.
|
193
|
+
filename = File.join(__dir__, 'open_file_test.json')
|
194
|
+
File.write(filename, %{{
|
191
195
|
"x":true,
|
192
196
|
"y":58,
|
193
197
|
"z": [1,2,3]
|
194
198
|
}
|
195
|
-
})
|
199
|
+
})
|
196
200
|
f = File.new(filename)
|
197
201
|
obj = Oj.wab_load(f)
|
198
202
|
f.close()
|
@@ -205,13 +209,13 @@ class WabJuice < Minitest::Test
|
|
205
209
|
end
|
206
210
|
|
207
211
|
def test_time
|
208
|
-
t = Time.gm(2017, 1, 5, 23, 58, 7,
|
212
|
+
t = Time.gm(2017, 1, 5, 23, 58, 7, 123_456.789)
|
209
213
|
json = Oj.dump(t, mode: :wab)
|
210
214
|
assert_equal('"2017-01-05T23:58:07.123456789Z"', json)
|
211
215
|
# must load and convert to json as the Time#== does not match identical
|
212
216
|
# times due to the way it tracks fractional seconds.
|
213
|
-
loaded = Oj.wab_load(json)
|
214
|
-
assert_equal(json, Oj.dump(loaded, mode: :wab),
|
217
|
+
loaded = Oj.wab_load(json)
|
218
|
+
assert_equal(json, Oj.dump(loaded, mode: :wab), 'json mismatch after load')
|
215
219
|
end
|
216
220
|
|
217
221
|
def test_uuid
|
@@ -295,7 +299,7 @@ class WabJuice < Minitest::Test
|
|
295
299
|
def dump_and_load(obj, trace=false)
|
296
300
|
json = Oj.dump(obj, mode: :wab, indent: 2)
|
297
301
|
puts json if trace
|
298
|
-
loaded = Oj.wab_load(json)
|
302
|
+
loaded = Oj.wab_load(json)
|
299
303
|
if obj.nil?
|
300
304
|
assert_nil(loaded)
|
301
305
|
else
|
data/test/test_writer.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: false
|
3
3
|
|
4
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
5
|
|
6
6
|
require 'helper'
|
7
7
|
|
@@ -55,13 +55,13 @@ class OjWriter < Minitest::Test
|
|
55
55
|
def test_string_writer_nested_object
|
56
56
|
w = Oj::StringWriter.new(:indent => 0)
|
57
57
|
w.push_object()
|
58
|
-
w.push_object(
|
58
|
+
w.push_object('a1')
|
59
59
|
w.pop()
|
60
|
-
w.push_object(
|
61
|
-
w.push_object(
|
60
|
+
w.push_object('a2')
|
61
|
+
w.push_object('b')
|
62
62
|
w.pop()
|
63
63
|
w.pop()
|
64
|
-
w.push_object(
|
64
|
+
w.push_object('a3')
|
65
65
|
w.pop()
|
66
66
|
w.pop()
|
67
67
|
assert_equal(%|{"a1":{},"a2":{"b":{}},"a3":{}}\n|, w.to_s)
|
@@ -94,9 +94,9 @@ class OjWriter < Minitest::Test
|
|
94
94
|
w.push_value(7.3)
|
95
95
|
w.push_value(true)
|
96
96
|
w.push_value(nil)
|
97
|
-
w.push_value(
|
97
|
+
w.push_value('a string')
|
98
98
|
w.push_value({'a' => 65})
|
99
|
-
w.push_value([1,2])
|
99
|
+
w.push_value([1, 2])
|
100
100
|
w.pop()
|
101
101
|
assert_equal(%|[
|
102
102
|
7,
|
@@ -118,10 +118,10 @@ class OjWriter < Minitest::Test
|
|
118
118
|
def test_string_writer_block
|
119
119
|
w = Oj::StringWriter.new(:indent => 0)
|
120
120
|
w.push_object() {
|
121
|
-
w.push_object(
|
121
|
+
w.push_object('a1') {
|
122
122
|
w.push_value(7, 'a7')
|
123
123
|
}
|
124
|
-
w.push_array(
|
124
|
+
w.push_array('a2') {
|
125
125
|
w.push_value('x')
|
126
126
|
w.push_value(3)
|
127
127
|
}
|
@@ -152,7 +152,7 @@ class OjWriter < Minitest::Test
|
|
152
152
|
assert(true)
|
153
153
|
return
|
154
154
|
end
|
155
|
-
assert(false,
|
155
|
+
assert(false, '*** expected an exception')
|
156
156
|
end
|
157
157
|
|
158
158
|
def test_string_writer_array_key
|
@@ -166,7 +166,7 @@ class OjWriter < Minitest::Test
|
|
166
166
|
assert(true)
|
167
167
|
return
|
168
168
|
end
|
169
|
-
assert(false,
|
169
|
+
assert(false, '*** expected an exception')
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_string_writer_pop_with_key
|
@@ -177,7 +177,7 @@ class OjWriter < Minitest::Test
|
|
177
177
|
assert(true)
|
178
178
|
return
|
179
179
|
end
|
180
|
-
assert(false,
|
180
|
+
assert(false, '*** expected an exception')
|
181
181
|
end
|
182
182
|
|
183
183
|
def test_string_writer_obj_no_key
|
@@ -189,7 +189,7 @@ class OjWriter < Minitest::Test
|
|
189
189
|
assert(true)
|
190
190
|
return
|
191
191
|
end
|
192
|
-
assert(false,
|
192
|
+
assert(false, '*** expected an exception')
|
193
193
|
end
|
194
194
|
|
195
195
|
def test_string_writer_deep
|
@@ -208,9 +208,9 @@ class OjWriter < Minitest::Test
|
|
208
208
|
def test_string_writer_pop_all
|
209
209
|
w = Oj::StringWriter.new(:indent => 0)
|
210
210
|
w.push_object()
|
211
|
-
w.push_object(
|
211
|
+
w.push_object('a1')
|
212
212
|
w.pop()
|
213
|
-
w.push_array(
|
213
|
+
w.push_array('a2')
|
214
214
|
w.push_value(3)
|
215
215
|
w.push_array()
|
216
216
|
w.pop_all()
|
@@ -228,23 +228,23 @@ class OjWriter < Minitest::Test
|
|
228
228
|
# Stream Writer
|
229
229
|
|
230
230
|
class SString < ::String
|
231
|
-
alias
|
231
|
+
alias write concat
|
232
232
|
end
|
233
|
-
|
233
|
+
|
234
234
|
def test_stream_writer_encoding
|
235
235
|
output = SString.new.force_encoding(::Encoding::UTF_8)
|
236
236
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
237
237
|
# Oddly enough, when pushing ASCII characters with UTF-8 encoding or even
|
238
238
|
# ASCII-8BIT does not change the output encoding. Pushing any non-ASCII no
|
239
239
|
# matter what the encoding changes the output encoding to ASCII-8BIT.
|
240
|
-
x =
|
240
|
+
x = '香港' # Hong Kong
|
241
241
|
x = x.force_encoding('ASCII-8BIT')
|
242
242
|
w.push_value(x)
|
243
243
|
assert_equal(::Encoding::UTF_8, output.encoding)
|
244
244
|
end
|
245
245
|
|
246
246
|
def test_stream_writer_empty_array
|
247
|
-
output = StringIO.open(
|
247
|
+
output = StringIO.open('', 'w+')
|
248
248
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
249
249
|
w.push_array()
|
250
250
|
w.pop()
|
@@ -252,19 +252,19 @@ class OjWriter < Minitest::Test
|
|
252
252
|
end
|
253
253
|
|
254
254
|
def test_stream_writer_mixed_stringio
|
255
|
-
output = StringIO.open(
|
255
|
+
output = StringIO.open('', 'w+')
|
256
256
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
257
257
|
w.push_object()
|
258
|
-
w.push_object(
|
258
|
+
w.push_object('a1')
|
259
259
|
w.pop()
|
260
|
-
w.push_object(
|
261
|
-
w.push_array(
|
260
|
+
w.push_object('a2')
|
261
|
+
w.push_array('b')
|
262
262
|
w.push_value(7)
|
263
263
|
w.push_value(true)
|
264
|
-
w.push_value(
|
264
|
+
w.push_value('string')
|
265
265
|
w.pop()
|
266
266
|
w.pop()
|
267
|
-
w.push_object(
|
267
|
+
w.push_object('a3')
|
268
268
|
w.pop()
|
269
269
|
w.pop()
|
270
270
|
result = output.string()
|
@@ -272,20 +272,20 @@ class OjWriter < Minitest::Test
|
|
272
272
|
end
|
273
273
|
|
274
274
|
def test_stream_writer_mixed_file
|
275
|
-
filename = File.join(
|
276
|
-
File.open(filename,
|
275
|
+
filename = File.join(__dir__, 'open_file_test.json')
|
276
|
+
File.open(filename, 'w') do |f|
|
277
277
|
w = Oj::StreamWriter.new(f, :indent => 0)
|
278
278
|
w.push_object()
|
279
|
-
w.push_object(
|
279
|
+
w.push_object('a1')
|
280
280
|
w.pop()
|
281
|
-
w.push_object(
|
282
|
-
w.push_array(
|
281
|
+
w.push_object('a2')
|
282
|
+
w.push_array('b')
|
283
283
|
w.push_value(7)
|
284
284
|
w.push_value(true)
|
285
|
-
w.push_value(
|
285
|
+
w.push_value('string')
|
286
286
|
w.pop()
|
287
287
|
w.pop()
|
288
|
-
w.push_object(
|
288
|
+
w.push_object('a3')
|
289
289
|
w.pop()
|
290
290
|
w.pop()
|
291
291
|
end
|
@@ -294,7 +294,7 @@ class OjWriter < Minitest::Test
|
|
294
294
|
end
|
295
295
|
|
296
296
|
def test_stream_writer_nested_key_object
|
297
|
-
output = StringIO.open(
|
297
|
+
output = StringIO.open('', 'w+')
|
298
298
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
299
299
|
w.push_object()
|
300
300
|
w.push_key('a1')
|
@@ -316,16 +316,16 @@ class OjWriter < Minitest::Test
|
|
316
316
|
|
317
317
|
def push_stuff(w, pop_all=true)
|
318
318
|
w.push_object()
|
319
|
-
w.push_object(
|
319
|
+
w.push_object('a1')
|
320
320
|
w.pop()
|
321
|
-
w.push_object(
|
322
|
-
w.push_array(
|
321
|
+
w.push_object('a2')
|
322
|
+
w.push_array('b')
|
323
323
|
w.push_value(7)
|
324
324
|
w.push_value(true)
|
325
|
-
w.push_value(
|
325
|
+
w.push_value('string')
|
326
326
|
w.pop()
|
327
327
|
w.pop()
|
328
|
-
w.push_object(
|
328
|
+
w.push_object('a3')
|
329
329
|
if pop_all
|
330
330
|
w.pop_all()
|
331
331
|
else
|
@@ -335,31 +335,31 @@ class OjWriter < Minitest::Test
|
|
335
335
|
end
|
336
336
|
|
337
337
|
def test_stream_writer_buf_small
|
338
|
-
output = StringIO.open(
|
338
|
+
output = StringIO.open('', 'w+')
|
339
339
|
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 20)
|
340
340
|
push_stuff(w)
|
341
341
|
assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
|
342
342
|
end
|
343
343
|
|
344
344
|
def test_stream_writer_buf_large
|
345
|
-
output = StringIO.open(
|
346
|
-
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size =>
|
345
|
+
output = StringIO.open('', 'w+')
|
346
|
+
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 16_000)
|
347
347
|
push_stuff(w)
|
348
348
|
assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
|
349
349
|
end
|
350
350
|
|
351
351
|
def test_stream_writer_buf_flush
|
352
|
-
output = StringIO.open(
|
352
|
+
output = StringIO.open('', 'w+')
|
353
353
|
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 4096)
|
354
354
|
push_stuff(w, false)
|
355
355
|
# no flush so nothing should be in the output yet
|
356
|
-
assert_equal(
|
356
|
+
assert_equal('', output.string())
|
357
357
|
w.flush()
|
358
358
|
assert_equal(%|{"a1":{},"a2":{"b":[7,true,"string"]},"a3":{}}\n|, output.string())
|
359
359
|
end
|
360
|
-
|
360
|
+
|
361
361
|
def test_stream_writer_buf_flush_small
|
362
|
-
output = StringIO.open(
|
362
|
+
output = StringIO.open('', 'w+')
|
363
363
|
w = Oj::StreamWriter.new(output, :indent => 0, :buffer_size => 30)
|
364
364
|
push_stuff(w, false)
|
365
365
|
# flush should be called at 30 bytes but since the writes are chunky flush
|
@@ -370,7 +370,7 @@ class OjWriter < Minitest::Test
|
|
370
370
|
end
|
371
371
|
|
372
372
|
def test_stream_writer_push_null_value_with_key
|
373
|
-
output = StringIO.open(
|
373
|
+
output = StringIO.open('', 'w+')
|
374
374
|
w = Oj::StreamWriter.new(output, :indent => 0)
|
375
375
|
w.push_object()
|
376
376
|
w.push_value(nil, 'nothing')
|
data/test/tests.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 'test_compat'
|
@@ -22,3 +22,12 @@ require 'test_rails'
|
|
22
22
|
require 'test_wab'
|
23
23
|
require 'test_writer'
|
24
24
|
require 'test_integer_range'
|
25
|
+
|
26
|
+
at_exit do
|
27
|
+
require 'helper'
|
28
|
+
if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
|
29
|
+
# Oj::debug_odd("teardown before GC.verify_compaction_references")
|
30
|
+
verify_gc_compaction
|
31
|
+
# Oj::debug_odd("teardown after GC.verify_compaction_references")
|
32
|
+
end
|
33
|
+
end
|
data/test/tests_mimic.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
|
+
$LOAD_PATH << File.join(__dir__, 'json_gem')
|
6
6
|
|
7
7
|
require 'json_common_interface_test'
|
8
8
|
require 'json_encoding_test'
|
@@ -12,3 +12,12 @@ require 'json_generator_test'
|
|
12
12
|
require 'json_generic_object_test'
|
13
13
|
require 'json_parser_test'
|
14
14
|
require 'json_string_matching_test'
|
15
|
+
|
16
|
+
at_exit do
|
17
|
+
require 'helper'
|
18
|
+
if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
|
19
|
+
# Oj::debug_odd("teardown before GC.verify_compaction_references")
|
20
|
+
verify_gc_compaction
|
21
|
+
# Oj::debug_odd("teardown after GC.verify_compaction_references")
|
22
|
+
end
|
23
|
+
end
|
@@ -1,7 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << __dir__
|
5
|
+
$LOAD_PATH << File.join(__dir__, 'json_gem')
|
6
6
|
|
7
7
|
require 'json_addition_test'
|
8
|
+
|
9
|
+
at_exit do
|
10
|
+
require 'helper'
|
11
|
+
if '3.1.0' <= RUBY_VERSION && RbConfig::CONFIG['host_os'] !~ /(mingw|mswin)/
|
12
|
+
# Oj::debug_odd("teardown before GC.verify_compaction_references")
|
13
|
+
verify_gc_compaction
|
14
|
+
# Oj::debug_odd("teardown after GC.verify_compaction_references")
|
15
|
+
end
|
16
|
+
end
|