oj 2.9.4 → 2.9.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of oj might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/ext/oj/dump.c +2 -1
- data/ext/oj/oj.c +54 -3
- data/ext/oj/parse.c +15 -8
- data/ext/oj/parse.h +1 -0
- data/ext/oj/reader.c +3 -2
- data/ext/oj/scp.c +5 -6
- data/lib/oj/mimic.rb +2 -2
- data/lib/oj/version.rb +1 -1
- data/test/_test_mimic_rails.rb +31 -0
- data/test/helper.rb +27 -0
- data/test/{test_mimic.rb → isolated/shared.rb} +69 -50
- data/test/isolated/test_mimic_after.rb +13 -0
- data/test/isolated/test_mimic_alone.rb +12 -0
- data/test/isolated/test_mimic_before.rb +13 -0
- data/test/isolated/test_mimic_define.rb +28 -0
- data/test/isolated/test_mimic_rails_after.rb +19 -0
- data/test/isolated/test_mimic_rails_before.rb +19 -0
- data/test/test_compat.rb +50 -64
- data/test/test_debian.rb +53 -0
- data/test/test_fast.rb +13 -13
- data/test/test_file.rb +45 -58
- data/test/test_gc.rb +22 -24
- data/test/test_object.rb +100 -114
- data/test/test_saj.rb +16 -14
- data/test/test_scp.rb +21 -14
- data/test/test_strict.rb +9 -23
- data/test/{tests.rb → test_various.rb} +96 -129
- data/test/test_writer.rb +10 -12
- data/test/zip.rb +34 -0
- metadata +57 -18
- data/test/a.rb +0 -38
- data/test/bug.rb +0 -17
- data/test/debian_test.rb +0 -90
- data/test/e.rb +0 -12
- data/test/foo.rb +0 -24
- data/test/lots.rb +0 -68
- data/test/mj.rb +0 -48
- data/test/perf_str.rb +0 -38
- data/test/perf_strictx.rb +0 -97
- data/test/test_mimic_after.rb +0 -35
- data/test/test_strictx.rb +0 -58
- data/test/write_fake_log.rb +0 -63
- data/test/x.rb +0 -59
data/test/test_gc.rb
CHANGED
@@ -1,38 +1,36 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
|
-
|
5
|
-
# warnings to show up the -w options is required. That can be set in the RUBYOPT
|
6
|
-
# environment variable.
|
7
|
-
# export RUBYOPT=-w
|
4
|
+
$: << File.dirname(__FILE__)
|
8
5
|
|
9
|
-
|
6
|
+
require 'helper'
|
10
7
|
|
11
|
-
|
12
|
-
|
8
|
+
class GCTest < Minitest::Test
|
9
|
+
class Goo
|
10
|
+
attr_accessor :x, :child
|
13
11
|
|
14
|
-
|
15
|
-
|
12
|
+
def initialize(x, child)
|
13
|
+
@x = x
|
14
|
+
@child = child
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
def to_hash()
|
18
|
+
{ 'json_class' => "#{self.class}", 'x' => x, 'child' => child }
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def to_hash()
|
26
|
-
{ 'json_class' => "#{self.class}", 'x' => x, 'child' => child }
|
27
|
-
end
|
21
|
+
def self.json_create(h)
|
22
|
+
GC.start
|
23
|
+
self.new(h['x'], h['child'])
|
24
|
+
end
|
25
|
+
end # Goo
|
28
26
|
|
29
|
-
def
|
30
|
-
|
31
|
-
self.new(h['x'], h['child'])
|
27
|
+
def setup
|
28
|
+
@default_options = Oj.default_options
|
32
29
|
end
|
33
|
-
end # Goo
|
34
30
|
|
35
|
-
|
31
|
+
def teardown
|
32
|
+
Oj.default_options = @default_options
|
33
|
+
end
|
36
34
|
|
37
35
|
# if no crash then the GC marking is working
|
38
36
|
def test_parse_compat_gc
|
data/test/test_object.rb
CHANGED
@@ -1,158 +1,143 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
|
-
|
5
|
-
# required. That can be set in the RUBYOPT environment variable.
|
6
|
-
# export RUBYOPT=-w
|
4
|
+
$: << File.dirname(__FILE__)
|
7
5
|
|
8
|
-
|
6
|
+
require 'helper'
|
9
7
|
|
10
|
-
|
11
|
-
|
8
|
+
class ObjectJuice < Minitest::Test
|
9
|
+
class Jeez
|
10
|
+
attr_accessor :x, :y
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
require 'oj'
|
12
|
+
def initialize(x, y)
|
13
|
+
@x = x
|
14
|
+
@y = y
|
15
|
+
end
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
def eql?(o)
|
18
|
+
self.class == o.class && @x == o.x && @y == o.y
|
19
|
+
end
|
20
|
+
alias == eql?
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
def to_json(*a)
|
23
|
+
%{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
26
|
+
def self.json_create(h)
|
27
|
+
self.new(h['x'], h['y'])
|
28
|
+
end
|
29
|
+
end # Jeez
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def to_json(*a)
|
36
|
-
%{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
|
37
|
-
end
|
31
|
+
module One
|
32
|
+
module Two
|
33
|
+
module Three
|
34
|
+
class Deep
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
end # Jeez
|
36
|
+
def initialize()
|
37
|
+
end
|
43
38
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
def eql?(o)
|
40
|
+
self.class == o.class
|
41
|
+
end
|
42
|
+
alias == eql?
|
48
43
|
|
49
|
-
|
50
|
-
|
44
|
+
def to_hash()
|
45
|
+
{'json_class' => "#{self.class.name}"}
|
46
|
+
end
|
51
47
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
alias == eql?
|
48
|
+
def to_json(*a)
|
49
|
+
%{{"json_class":"#{self.class.name}"}}
|
50
|
+
end
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
def self.json_create(h)
|
53
|
+
self.new()
|
54
|
+
end
|
55
|
+
end # Deep
|
56
|
+
end # Three
|
57
|
+
end # Two
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
end
|
59
|
+
class Stuck2 < Struct.new(:a, :b)
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
self.new()
|
67
|
-
end
|
68
|
-
end # Deep
|
69
|
-
end # Three
|
70
|
-
end # Two
|
62
|
+
end # One
|
71
63
|
|
72
|
-
class
|
64
|
+
class Stuck < Struct.new(:a, :b)
|
73
65
|
end
|
74
66
|
|
75
|
-
|
67
|
+
class Strung < String
|
76
68
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
def initialize(str, safe)
|
70
|
+
super(str)
|
71
|
+
@safe = safe
|
72
|
+
end
|
81
73
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
74
|
+
def safe?()
|
75
|
+
@safe
|
76
|
+
end
|
86
77
|
|
87
|
-
|
88
|
-
|
89
|
-
|
78
|
+
def self.create(str, safe)
|
79
|
+
new(str, safe)
|
80
|
+
end
|
90
81
|
|
91
|
-
|
92
|
-
|
93
|
-
|
82
|
+
def eql?(o)
|
83
|
+
super && self.class == o.class && @safe == o.safe?
|
84
|
+
end
|
85
|
+
alias == eql?
|
94
86
|
|
95
|
-
|
96
|
-
|
87
|
+
def inspect()
|
88
|
+
return super + '(' + @safe + ')'
|
89
|
+
end
|
97
90
|
end
|
98
|
-
alias == eql?
|
99
91
|
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|
92
|
+
class AutoStrung < String
|
93
|
+
attr_accessor :safe
|
104
94
|
|
105
|
-
|
106
|
-
|
95
|
+
def initialize(str, safe)
|
96
|
+
super(str)
|
97
|
+
@safe = safe
|
98
|
+
end
|
107
99
|
|
108
|
-
|
109
|
-
|
110
|
-
|
100
|
+
def eql?(o)
|
101
|
+
self.class == o.class && super(o) && @safe == o.safe
|
102
|
+
end
|
103
|
+
alias == eql?
|
111
104
|
end
|
112
105
|
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
alias == eql?
|
117
|
-
end
|
106
|
+
class AutoArray < Array
|
107
|
+
attr_accessor :safe
|
118
108
|
|
119
|
-
|
120
|
-
|
109
|
+
def initialize(a, safe)
|
110
|
+
super(a)
|
111
|
+
@safe = safe
|
112
|
+
end
|
121
113
|
|
122
|
-
|
123
|
-
|
124
|
-
|
114
|
+
def eql?(o)
|
115
|
+
self.class == o.class && super(o) && @safe == o.safe
|
116
|
+
end
|
117
|
+
alias == eql?
|
125
118
|
end
|
126
119
|
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
alias == eql?
|
131
|
-
end
|
120
|
+
class AutoHash < Hash
|
121
|
+
attr_accessor :safe
|
132
122
|
|
133
|
-
|
134
|
-
|
123
|
+
def initialize(h, safe)
|
124
|
+
super(h)
|
125
|
+
@safe = safe
|
126
|
+
end
|
135
127
|
|
136
|
-
|
137
|
-
|
138
|
-
|
128
|
+
def eql?(o)
|
129
|
+
self.class == o.class && super(o) && @safe == o.safe
|
130
|
+
end
|
131
|
+
alias == eql?
|
139
132
|
end
|
140
133
|
|
141
|
-
def
|
142
|
-
|
134
|
+
def setup
|
135
|
+
@default_options = Oj.default_options
|
143
136
|
end
|
144
|
-
alias == eql?
|
145
|
-
end
|
146
137
|
|
147
|
-
def
|
148
|
-
|
149
|
-
h1.keys.each do |k|
|
150
|
-
return false unless h1[k] == h2[k]
|
138
|
+
def teardown
|
139
|
+
Oj.default_options = @default_options
|
151
140
|
end
|
152
|
-
true
|
153
|
-
end
|
154
|
-
|
155
|
-
class ObjectJuice < ::Test::Unit::TestCase
|
156
141
|
|
157
142
|
def test_nil
|
158
143
|
dump_and_load(nil, false)
|
@@ -297,7 +282,7 @@ class ObjectJuice < ::Test::Unit::TestCase
|
|
297
282
|
end
|
298
283
|
|
299
284
|
def test_io_file
|
300
|
-
filename = 'open_file_test.json'
|
285
|
+
filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
|
301
286
|
File.open(filename, 'w') { |f| f.write(%{{
|
302
287
|
"x":true,
|
303
288
|
"y":58,
|
@@ -414,6 +399,7 @@ class ObjectJuice < ::Test::Unit::TestCase
|
|
414
399
|
end
|
415
400
|
|
416
401
|
def test_mixed_hash_object
|
402
|
+
Oj.default_options = { :mode => :object }
|
417
403
|
json = Oj.dump({ 1 => true, 'nil' => nil, :sim => 4 })
|
418
404
|
h = Oj.object_load(json)
|
419
405
|
assert_equal({ 1 => true, 'nil' => nil, :sim => 4 }, h)
|
data/test/test_saj.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
|
-
|
5
|
-
# required. That can be set in the RUBYOPT environment variable.
|
6
|
-
# export RUBYOPT=-w
|
4
|
+
$: << File.dirname(__FILE__)
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
$: << File.join(File.dirname(__FILE__), "../lib")
|
11
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
12
|
-
|
13
|
-
require 'test/unit'
|
14
|
-
require 'oj'
|
15
|
-
require 'pp'
|
6
|
+
require 'helper'
|
16
7
|
|
17
8
|
$json = %{{
|
18
9
|
"array": [
|
@@ -62,7 +53,16 @@ class AllSaj < Oj::Saj
|
|
62
53
|
|
63
54
|
end # AllSaj
|
64
55
|
|
65
|
-
class SajTest < ::Test
|
56
|
+
class SajTest < Minitest::Test
|
57
|
+
|
58
|
+
def setup
|
59
|
+
@default_options = Oj.default_options
|
60
|
+
end
|
61
|
+
|
62
|
+
def teardown
|
63
|
+
Oj.default_options = @default_options
|
64
|
+
end
|
65
|
+
|
66
66
|
def test_nil
|
67
67
|
handler = AllSaj.new()
|
68
68
|
json = %{null}
|
@@ -177,8 +177,10 @@ class SajTest < ::Test::Unit::TestCase
|
|
177
177
|
handler = AllSaj.new()
|
178
178
|
json = %{12345xyz}
|
179
179
|
Oj.saj_parse(handler, json)
|
180
|
-
assert_equal([
|
181
|
-
|
180
|
+
assert_equal([:add_value, 12345, nil], handler.calls.first)
|
181
|
+
type, message, line, column = handler.calls.last
|
182
|
+
assert_equal([:error, 1, 6], [type, line, column])
|
183
|
+
assert_match(%r{invalid format, extra characters at line 1, column 6 \[(?:[a-z\.]+/)*saj\.c:\d+\]}, message)
|
182
184
|
end
|
183
185
|
|
184
186
|
end
|
data/test/test_scp.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
|
-
|
5
|
-
# required. That can be set in the RUBYOPT environment variable.
|
6
|
-
# export RUBYOPT=-w
|
4
|
+
$: << File.dirname(__FILE__)
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
$: << File.join(File.dirname(__FILE__), "../lib")
|
11
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
12
|
-
|
13
|
-
require 'test/unit'
|
14
|
-
require 'oj'
|
15
|
-
require 'pp'
|
6
|
+
require 'helper'
|
16
7
|
|
17
8
|
$json = %{{
|
18
9
|
"array": [
|
@@ -66,14 +57,22 @@ class AllHandler < Oj::ScHandler
|
|
66
57
|
def hash_set(h, key, value)
|
67
58
|
@calls << [:hash_set, key, value]
|
68
59
|
end
|
69
|
-
|
60
|
+
|
70
61
|
def array_append(a, value)
|
71
62
|
@calls << [:array_append, value]
|
72
63
|
end
|
73
64
|
|
74
65
|
end # AllHandler
|
75
66
|
|
76
|
-
class ScpTest < ::Test
|
67
|
+
class ScpTest < Minitest::Test
|
68
|
+
|
69
|
+
def setup
|
70
|
+
@default_options = Oj.default_options
|
71
|
+
end
|
72
|
+
|
73
|
+
def teardown
|
74
|
+
Oj.default_options = @default_options
|
75
|
+
end
|
77
76
|
|
78
77
|
def test_nil
|
79
78
|
handler = AllHandler.new()
|
@@ -233,7 +232,15 @@ class ScpTest < ::Test::Unit::TestCase
|
|
233
232
|
begin
|
234
233
|
Oj.sc_parse(handler, json)
|
235
234
|
rescue Exception => e
|
236
|
-
|
235
|
+
assert_match(%r{unexpected character at line 1, column 6 \[(?:[a-z\.]+/)*parse\.c:\d+\]}, e.message)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_null_string
|
240
|
+
handler = AllHandler.new()
|
241
|
+
json = %{"\0"}
|
242
|
+
assert_raises Oj::ParseError do
|
243
|
+
Oj.sc_parse(handler, json)
|
237
244
|
end
|
238
245
|
end
|
239
246
|
|
data/test/test_strict.rb
CHANGED
@@ -1,33 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
|
-
|
5
|
-
# required. That can be set in the RUBYOPT environment variable.
|
6
|
-
# export RUBYOPT=-w
|
4
|
+
$: << File.dirname(__FILE__)
|
7
5
|
|
8
|
-
|
6
|
+
require 'helper'
|
9
7
|
|
10
|
-
|
11
|
-
$: << File.join(File.dirname(__FILE__), "../ext")
|
8
|
+
class StrictJuice < Minitest::Test
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
require 'date'
|
16
|
-
require 'bigdecimal'
|
17
|
-
require 'oj'
|
18
|
-
|
19
|
-
$ruby = RUBY_DESCRIPTION.split(' ')[0]
|
20
|
-
$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
|
21
|
-
|
22
|
-
def hash_eql(h1, h2)
|
23
|
-
return false if h1.size != h2.size
|
24
|
-
h1.keys.each do |k|
|
25
|
-
return false unless h1[k] == h2[k]
|
10
|
+
def setup
|
11
|
+
@default_options = Oj.default_options
|
26
12
|
end
|
27
|
-
true
|
28
|
-
end
|
29
13
|
|
30
|
-
|
14
|
+
def teardown
|
15
|
+
Oj.default_options = @default_options
|
16
|
+
end
|
31
17
|
|
32
18
|
def test_nil
|
33
19
|
dump_and_load(nil, false)
|
@@ -175,7 +161,7 @@ class StrictJuice < ::Test::Unit::TestCase
|
|
175
161
|
end
|
176
162
|
|
177
163
|
def test_io_file
|
178
|
-
filename = 'open_file_test.json'
|
164
|
+
filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
|
179
165
|
File.open(filename, 'w') { |f| f.write(%{{
|
180
166
|
"x":true,
|
181
167
|
"y":58,
|