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_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'
|
@@ -18,8 +18,16 @@ require 'test_object'
|
|
18
18
|
require 'test_saj'
|
19
19
|
require 'test_scp'
|
20
20
|
require 'test_strict'
|
21
|
-
require 'test_various'
|
22
21
|
require 'test_rails'
|
23
22
|
require 'test_wab'
|
24
23
|
require 'test_writer'
|
25
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
|