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
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
class MimicDefine < Minitest::Test
|
9
|
+
def test_mimic_define
|
10
|
+
assert(defined?(JSON).nil?)
|
11
|
+
Oj.mimic_JSON
|
12
|
+
|
13
|
+
# Test constants
|
14
|
+
assert(!defined?(JSON).nil?)
|
15
|
+
assert(!defined?(JSON::ParserError).nil?)
|
16
|
+
assert(Object.respond_to?(:to_json))
|
17
|
+
|
18
|
+
# Test loaded features
|
19
|
+
assert(!require('json'))
|
20
|
+
|
21
|
+
begin
|
22
|
+
require('json_spec')
|
23
|
+
assert(false, '** should raise LoadError')
|
24
|
+
rescue LoadError
|
25
|
+
assert(true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end # MimicSingle
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'rails/all'
|
10
|
+
rescue Exception
|
11
|
+
Process.exit!(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
Oj.mimic_JSON
|
15
|
+
|
16
|
+
require 'isolated/shared'
|
17
|
+
|
18
|
+
class MimicRailsAfter < SharedMimicRailsTest
|
19
|
+
end # MimicRailsAfter
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.join(File.dirname(__FILE__), '..')
|
5
|
+
|
6
|
+
require 'helper'
|
7
|
+
|
8
|
+
Oj.mimic_JSON
|
9
|
+
begin
|
10
|
+
require 'rails/all'
|
11
|
+
rescue Exception
|
12
|
+
Process.exit!(true)
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'isolated/shared'
|
16
|
+
|
17
|
+
class MimicRailsBefore < SharedMimicRailsTest
|
18
|
+
end # MimicRailsBefore
|
19
|
+
|
data/test/test_compat.rb
CHANGED
@@ -1,84 +1,70 @@
|
|
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 CompatJuice < Minitest::Test
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
require 'date'
|
16
|
-
require 'bigdecimal'
|
17
|
-
require 'oj'
|
10
|
+
class Jeez
|
11
|
+
attr_accessor :x, :y
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
attr_accessor :x, :y
|
13
|
+
def initialize(x, y)
|
14
|
+
@x = x
|
15
|
+
@y = y
|
16
|
+
end
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
def eql?(o)
|
19
|
+
self.class == o.class && @x == o.x && @y == o.y
|
20
|
+
end
|
21
|
+
alias == eql?
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
alias == eql?
|
34
|
-
|
35
|
-
def as_json()
|
36
|
-
{"json_class" => self.class.to_s,"x" => @x,"y" => @y}
|
37
|
-
end
|
23
|
+
def as_json()
|
24
|
+
{"json_class" => self.class.to_s,"x" => @x,"y" => @y}
|
25
|
+
end
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end # Jeez
|
27
|
+
def self.json_create(h)
|
28
|
+
self.new(h['x'], h['y'])
|
29
|
+
end
|
30
|
+
end # Jeez
|
43
31
|
|
44
|
-
module One
|
45
|
-
|
46
|
-
|
47
|
-
|
32
|
+
module One
|
33
|
+
module Two
|
34
|
+
module Three
|
35
|
+
class Deep
|
48
36
|
|
49
|
-
|
50
|
-
|
37
|
+
def initialize()
|
38
|
+
end
|
51
39
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
40
|
+
def eql?(o)
|
41
|
+
self.class == o.class
|
42
|
+
end
|
43
|
+
alias == eql?
|
56
44
|
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
def to_hash()
|
46
|
+
{'json_class' => "#{self.class.name}"}
|
47
|
+
end
|
60
48
|
|
61
|
-
|
62
|
-
|
63
|
-
|
49
|
+
def to_json(*a)
|
50
|
+
%{{"json_class":"#{self.class.name}"}}
|
51
|
+
end
|
64
52
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end # One
|
53
|
+
def self.json_create(h)
|
54
|
+
self.new()
|
55
|
+
end
|
56
|
+
end # Deep
|
57
|
+
end # Three
|
58
|
+
end # Two
|
59
|
+
end # One
|
72
60
|
|
73
|
-
def
|
74
|
-
|
75
|
-
h1.keys.each do |k|
|
76
|
-
return false unless h1[k] == h2[k]
|
61
|
+
def setup
|
62
|
+
@default_options = Oj.default_options
|
77
63
|
end
|
78
|
-
true
|
79
|
-
end
|
80
64
|
|
81
|
-
|
65
|
+
def teardown
|
66
|
+
Oj.default_options = @default_options
|
67
|
+
end
|
82
68
|
|
83
69
|
def test_nil
|
84
70
|
dump_and_load(nil, false)
|
@@ -218,7 +204,7 @@ class CompatJuice < ::Test::Unit::TestCase
|
|
218
204
|
end
|
219
205
|
|
220
206
|
def test_io_file
|
221
|
-
filename = 'open_file_test.json'
|
207
|
+
filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
|
222
208
|
File.open(filename, 'w') { |f| f.write(%{{
|
223
209
|
"x":true,
|
224
210
|
"y":58,
|
@@ -297,7 +283,7 @@ class CompatJuice < ::Test::Unit::TestCase
|
|
297
283
|
end
|
298
284
|
|
299
285
|
def test_json_object_bad
|
300
|
-
json = %{{"json_class":"Junk","x":true}}
|
286
|
+
json = %{{"json_class":"CompatJuice::Junk","x":true}}
|
301
287
|
begin
|
302
288
|
Oj.compat_load(json)
|
303
289
|
rescue Exception => e
|
data/test/test_debian.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
|
5
|
+
class DebJuice < Minitest::Test
|
6
|
+
class Jam
|
7
|
+
attr_accessor :x, :y
|
8
|
+
|
9
|
+
def initialize(x, y)
|
10
|
+
@x = x
|
11
|
+
@y = y
|
12
|
+
end
|
13
|
+
|
14
|
+
def eql?(o)
|
15
|
+
self.class == o.class && @x == o.x && @y == o.y
|
16
|
+
end
|
17
|
+
alias == eql?
|
18
|
+
|
19
|
+
end# Jam
|
20
|
+
|
21
|
+
# contributed by sauliusg to fix as_json
|
22
|
+
class Orange < Jam
|
23
|
+
def initialize(x, y)
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def as_json()
|
28
|
+
{ :json_class => self.class,
|
29
|
+
:x => @x,
|
30
|
+
:y => @y }
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.json_create(h)
|
34
|
+
self.new(h['x'], h['y'])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_as_json_object_compat_hash_cached
|
39
|
+
Oj.default_options = { :mode => :compat, :class_cache => true }
|
40
|
+
obj = Orange.new(true, 58)
|
41
|
+
json = Oj.dump(obj, :indent => 2)
|
42
|
+
assert(!json.nil?)
|
43
|
+
dump_and_load(obj, true)
|
44
|
+
end
|
45
|
+
|
46
|
+
def dump_and_load(obj, trace=false)
|
47
|
+
json = Oj.dump(obj, :indent => 2)
|
48
|
+
loaded = Oj.load(json);
|
49
|
+
assert_equal(obj, loaded)
|
50
|
+
loaded
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/test/test_fast.rb
CHANGED
@@ -1,17 +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'
|
6
|
+
require 'helper'
|
15
7
|
|
16
8
|
$json1 = %{{
|
17
9
|
"array": [
|
@@ -28,7 +20,15 @@ $json1 = %{{
|
|
28
20
|
"boolean" : true
|
29
21
|
}}
|
30
22
|
|
31
|
-
class DocTest < ::Test
|
23
|
+
class DocTest < Minitest::Test
|
24
|
+
def setup
|
25
|
+
@default_options = Oj.default_options
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
Oj.default_options = @default_options
|
30
|
+
end
|
31
|
+
|
32
32
|
def test_nil
|
33
33
|
json = %{null}
|
34
34
|
Oj::Doc.open(json) do |doc|
|
@@ -310,7 +310,7 @@ class DocTest < ::Test::Unit::TestCase
|
|
310
310
|
end
|
311
311
|
|
312
312
|
def test_open_file
|
313
|
-
filename = 'open_file_test.json'
|
313
|
+
filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
|
314
314
|
File.open(filename, 'w') { |f| f.write('{"a":[1,2,3]}') }
|
315
315
|
Oj::Doc.open_file(filename) do |doc|
|
316
316
|
assert_equal(5, doc.size)
|
@@ -336,7 +336,7 @@ class DocTest < ::Test::Unit::TestCase
|
|
336
336
|
end
|
337
337
|
|
338
338
|
def test_file_open_close
|
339
|
-
filename = 'open_file_test.json'
|
339
|
+
filename = File.join(File.dirname(__FILE__), 'open_file_test.json')
|
340
340
|
File.open(filename, 'w') { |f| f.write('{"a":[1,2,3]}') }
|
341
341
|
doc = Oj::Doc.open_file(filename)
|
342
342
|
assert_equal(Oj::Doc, doc.class)
|
data/test/test_file.rb
CHANGED
@@ -1,75 +1,63 @@
|
|
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 FileJuice < Minitest::Test
|
9
|
+
class Jam
|
10
|
+
attr_accessor :x, :y
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
$ruby = RUBY_DESCRIPTION.split(' ')[0]
|
19
|
-
$ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
|
20
|
-
|
21
|
-
class Jam
|
22
|
-
attr_accessor :x, :y
|
12
|
+
def initialize(x, y)
|
13
|
+
@x = x
|
14
|
+
@y = y
|
15
|
+
end
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
def eql?(o)
|
18
|
+
self.class == o.class && @x == o.x && @y == o.y
|
19
|
+
end
|
20
|
+
alias == eql?
|
28
21
|
|
29
|
-
|
30
|
-
self.class == o.class && @x == o.x && @y == o.y
|
31
|
-
end
|
32
|
-
alias == eql?
|
22
|
+
end# Jam
|
33
23
|
|
34
|
-
|
24
|
+
class Jeez < Jam
|
25
|
+
def initialize(x, y)
|
26
|
+
super
|
27
|
+
end
|
35
28
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
29
|
+
def to_json()
|
30
|
+
%{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
|
31
|
+
end
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
def self.json_create(h)
|
34
|
+
self.new(h['x'], h['y'])
|
35
|
+
end
|
36
|
+
end# Jeez
|
44
37
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
38
|
+
class Orange < Jam
|
39
|
+
def initialize(x, y)
|
40
|
+
super
|
41
|
+
end
|
49
42
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
def as_json()
|
44
|
+
{ :json_class => self.class,
|
45
|
+
:x => @x,
|
46
|
+
:y => @y }
|
47
|
+
end
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
:y => @y }
|
49
|
+
def self.json_create(h)
|
50
|
+
self.new(h['x'], h['y'])
|
51
|
+
end
|
59
52
|
end
|
60
53
|
|
61
|
-
def
|
62
|
-
|
54
|
+
def setup
|
55
|
+
@default_options = Oj.default_options
|
63
56
|
end
|
64
|
-
end
|
65
57
|
|
66
|
-
|
67
|
-
|
68
|
-
{ 'begin' => self.begin, 'end' => self.end, 'exclude_end' => self.exclude_end? }
|
58
|
+
def teardown
|
59
|
+
Oj.default_options = @default_options
|
69
60
|
end
|
70
|
-
end # Range
|
71
|
-
|
72
|
-
class FileJuice < ::Test::Unit::TestCase
|
73
61
|
|
74
62
|
def test_nil
|
75
63
|
dump_and_load(nil, false)
|
@@ -100,7 +88,7 @@ class FileJuice < ::Test::Unit::TestCase
|
|
100
88
|
dump_and_load(-2.48e100 * 1.0e10, false)
|
101
89
|
dump_and_load(1/0.0, false)
|
102
90
|
end
|
103
|
-
|
91
|
+
|
104
92
|
def test_string
|
105
93
|
dump_and_load('', false)
|
106
94
|
dump_and_load('abc', false)
|
@@ -155,9 +143,9 @@ class FileJuice < ::Test::Unit::TestCase
|
|
155
143
|
Oj.default_options = { :mode => :compat, :use_to_json => true }
|
156
144
|
obj = Jeez.new(true, 58)
|
157
145
|
json = Oj.dump(obj, :indent => 2)
|
158
|
-
assert(%{{"json_class":"Jeez","x":true,"y":58}
|
146
|
+
assert(%{{"json_class":"FileJuice::Jeez","x":true,"y":58}
|
159
147
|
} == json ||
|
160
|
-
%{{"json_class":"Jeez","y":58,"x":true}
|
148
|
+
%{{"json_class":"FileJuice::Jeez","y":58,"x":true}
|
161
149
|
} == json)
|
162
150
|
dump_and_load(obj, false)
|
163
151
|
Oj.default_options = { :mode => :compat, :use_to_json => false }
|
@@ -211,7 +199,6 @@ class FileJuice < ::Test::Unit::TestCase
|
|
211
199
|
end
|
212
200
|
|
213
201
|
def test_bigdecimal_object
|
214
|
-
mode = Oj.default_options[:mode]
|
215
202
|
Oj.default_options = {:mode => :object}
|
216
203
|
dump_and_load(BigDecimal.new('3.14159265358979323846'), false)
|
217
204
|
end
|
@@ -229,7 +216,7 @@ class FileJuice < ::Test::Unit::TestCase
|
|
229
216
|
end
|
230
217
|
|
231
218
|
def dump_and_load(obj, trace=false)
|
232
|
-
filename = 'file_test.json'
|
219
|
+
filename = File.join(File.dirname(__FILE__), 'file_test.json')
|
233
220
|
File.open(filename, "w") { |f|
|
234
221
|
Oj.to_stream(f, obj, :indent => 2)
|
235
222
|
}
|