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.

@@ -1,38 +1,36 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- # Ubuntu does not accept arguments to ruby when called using env. To get
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
- $VERBOSE = true
6
+ require 'helper'
10
7
 
11
- $: << File.join(File.dirname(__FILE__), "../lib")
12
- $: << File.join(File.dirname(__FILE__), "../ext")
8
+ class GCTest < Minitest::Test
9
+ class Goo
10
+ attr_accessor :x, :child
13
11
 
14
- require 'test/unit'
15
- require 'oj'
12
+ def initialize(x, child)
13
+ @x = x
14
+ @child = child
15
+ end
16
16
 
17
- class Goo
18
- attr_accessor :x, :child
17
+ def to_hash()
18
+ { 'json_class' => "#{self.class}", 'x' => x, 'child' => child }
19
+ end
19
20
 
20
- def initialize(x, child)
21
- @x = x
22
- @child = child
23
- end
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 self.json_create(h)
30
- GC.start
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
- class GCTest < ::Test::Unit::TestCase
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
@@ -1,158 +1,143 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
- # required. That can be set in the RUBYOPT environment variable.
6
- # export RUBYOPT=-w
4
+ $: << File.dirname(__FILE__)
7
5
 
8
- $VERBOSE = true
6
+ require 'helper'
9
7
 
10
- $: << File.join(File.dirname(__FILE__), "../lib")
11
- $: << File.join(File.dirname(__FILE__), "../ext")
8
+ class ObjectJuice < Minitest::Test
9
+ class Jeez
10
+ attr_accessor :x, :y
12
11
 
13
- require 'test/unit'
14
- require 'stringio'
15
- require 'date'
16
- require 'bigdecimal'
17
- require 'oj'
12
+ def initialize(x, y)
13
+ @x = x
14
+ @y = y
15
+ end
18
16
 
19
- $ruby = RUBY_DESCRIPTION.split(' ')[0]
20
- $ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
17
+ def eql?(o)
18
+ self.class == o.class && @x == o.x && @y == o.y
19
+ end
20
+ alias == eql?
21
21
 
22
- class Jeez
23
- attr_accessor :x, :y
22
+ def to_json(*a)
23
+ %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
24
+ end
24
25
 
25
- def initialize(x, y)
26
- @x = x
27
- @y = y
28
- end
26
+ def self.json_create(h)
27
+ self.new(h['x'], h['y'])
28
+ end
29
+ end # Jeez
29
30
 
30
- def eql?(o)
31
- self.class == o.class && @x == o.x && @y == o.y
32
- end
33
- alias == eql?
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
- def self.json_create(h)
40
- self.new(h['x'], h['y'])
41
- end
42
- end # Jeez
36
+ def initialize()
37
+ end
43
38
 
44
- module One
45
- module Two
46
- module Three
47
- class Deep
39
+ def eql?(o)
40
+ self.class == o.class
41
+ end
42
+ alias == eql?
48
43
 
49
- def initialize()
50
- end
44
+ def to_hash()
45
+ {'json_class' => "#{self.class.name}"}
46
+ end
51
47
 
52
- def eql?(o)
53
- self.class == o.class
54
- end
55
- alias == eql?
48
+ def to_json(*a)
49
+ %{{"json_class":"#{self.class.name}"}}
50
+ end
56
51
 
57
- def to_hash()
58
- {'json_class' => "#{self.class.name}"}
59
- end
52
+ def self.json_create(h)
53
+ self.new()
54
+ end
55
+ end # Deep
56
+ end # Three
57
+ end # Two
60
58
 
61
- def to_json(*a)
62
- %{{"json_class":"#{self.class.name}"}}
63
- end
59
+ class Stuck2 < Struct.new(:a, :b)
60
+ end
64
61
 
65
- def self.json_create(h)
66
- self.new()
67
- end
68
- end # Deep
69
- end # Three
70
- end # Two
62
+ end # One
71
63
 
72
- class Stuck2 < Struct.new(:a, :b)
64
+ class Stuck < Struct.new(:a, :b)
73
65
  end
74
66
 
75
- end # One
67
+ class Strung < String
76
68
 
77
- class Stuck < Struct.new(:a, :b)
78
- end
79
-
80
- class Strung < String
69
+ def initialize(str, safe)
70
+ super(str)
71
+ @safe = safe
72
+ end
81
73
 
82
- def initialize(str, safe)
83
- super(str)
84
- @safe = safe
85
- end
74
+ def safe?()
75
+ @safe
76
+ end
86
77
 
87
- def safe?()
88
- @safe
89
- end
78
+ def self.create(str, safe)
79
+ new(str, safe)
80
+ end
90
81
 
91
- def self.create(str, safe)
92
- new(str, safe)
93
- end
82
+ def eql?(o)
83
+ super && self.class == o.class && @safe == o.safe?
84
+ end
85
+ alias == eql?
94
86
 
95
- def eql?(o)
96
- super && self.class == o.class && @safe == o.safe?
87
+ def inspect()
88
+ return super + '(' + @safe + ')'
89
+ end
97
90
  end
98
- alias == eql?
99
91
 
100
- def inspect()
101
- return super + '(' + @safe + ')'
102
- end
103
- end
92
+ class AutoStrung < String
93
+ attr_accessor :safe
104
94
 
105
- class AutoStrung < String
106
- attr_accessor :safe
95
+ def initialize(str, safe)
96
+ super(str)
97
+ @safe = safe
98
+ end
107
99
 
108
- def initialize(str, safe)
109
- super(str)
110
- @safe = safe
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
- def eql?(o)
114
- self.class == o.class && super(o) && @safe == o.safe
115
- end
116
- alias == eql?
117
- end
106
+ class AutoArray < Array
107
+ attr_accessor :safe
118
108
 
119
- class AutoArray < Array
120
- attr_accessor :safe
109
+ def initialize(a, safe)
110
+ super(a)
111
+ @safe = safe
112
+ end
121
113
 
122
- def initialize(a, safe)
123
- super(a)
124
- @safe = safe
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
- def eql?(o)
128
- self.class == o.class && super(o) && @safe == o.safe
129
- end
130
- alias == eql?
131
- end
120
+ class AutoHash < Hash
121
+ attr_accessor :safe
132
122
 
133
- class AutoHash < Hash
134
- attr_accessor :safe
123
+ def initialize(h, safe)
124
+ super(h)
125
+ @safe = safe
126
+ end
135
127
 
136
- def initialize(h, safe)
137
- super(h)
138
- @safe = safe
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 eql?(o)
142
- self.class == o.class && super(o) && @safe == o.safe
134
+ def setup
135
+ @default_options = Oj.default_options
143
136
  end
144
- alias == eql?
145
- end
146
137
 
147
- def hash_eql(h1, h2)
148
- return false if h1.size != h2.size
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)
@@ -1,18 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
- # required. That can be set in the RUBYOPT environment variable.
6
- # export RUBYOPT=-w
4
+ $: << File.dirname(__FILE__)
7
5
 
8
- $VERBOSE = true
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::Unit::TestCase
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([[:add_value, 12345, nil],
181
- [:error, "invalid format, extra characters at line 1, column 6 [saj.c:688]", 1, 6]], handler.calls)
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
@@ -1,18 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
- # required. That can be set in the RUBYOPT environment variable.
6
- # export RUBYOPT=-w
4
+ $: << File.dirname(__FILE__)
7
5
 
8
- $VERBOSE = true
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::Unit::TestCase
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
- assert_equal("unexpected character at line 1, column 6 [parse.c:637]", e.message)
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
 
@@ -1,33 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- # Ubuntu does not accept arguments to ruby when called using env. To get warnings to show up the -w options is
5
- # required. That can be set in the RUBYOPT environment variable.
6
- # export RUBYOPT=-w
4
+ $: << File.dirname(__FILE__)
7
5
 
8
- $VERBOSE = true
6
+ require 'helper'
9
7
 
10
- $: << File.join(File.dirname(__FILE__), "../lib")
11
- $: << File.join(File.dirname(__FILE__), "../ext")
8
+ class StrictJuice < Minitest::Test
12
9
 
13
- require 'test/unit'
14
- require 'stringio'
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
- class StrictJuice < ::Test::Unit::TestCase
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,