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.

@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.join(File.dirname(__FILE__), '..')
5
+
6
+ require 'helper'
7
+ require 'isolated/shared'
8
+
9
+ require 'json'
10
+ Oj.mimic_JSON
11
+
12
+ class MimicAfter < SharedMimicTest
13
+ end # MimicAfter
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.join(File.dirname(__FILE__), '..')
5
+
6
+ require 'helper'
7
+ require 'isolated/shared'
8
+
9
+ Oj.mimic_JSON
10
+
11
+ class MimicAlone < SharedMimicTest
12
+ end # MimicAlone
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.join(File.dirname(__FILE__), '..')
5
+
6
+ require 'helper'
7
+ require 'isolated/shared'
8
+
9
+ Oj.mimic_JSON
10
+ require 'json'
11
+
12
+ class MimicBefore < SharedMimicTest
13
+ end # MimicBefore
@@ -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
+
@@ -1,84 +1,70 @@
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 CompatJuice < Minitest::Test
12
9
 
13
- require 'test/unit'
14
- require 'stringio'
15
- require 'date'
16
- require 'bigdecimal'
17
- require 'oj'
10
+ class Jeez
11
+ attr_accessor :x, :y
18
12
 
19
- $ruby = RUBY_DESCRIPTION.split(' ')[0]
20
- $ruby = 'ree' if 'ruby' == $ruby && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
21
-
22
- class Jeez
23
- attr_accessor :x, :y
13
+ def initialize(x, y)
14
+ @x = x
15
+ @y = y
16
+ end
24
17
 
25
- def initialize(x, y)
26
- @x = x
27
- @y = y
28
- end
18
+ def eql?(o)
19
+ self.class == o.class && @x == o.x && @y == o.y
20
+ end
21
+ alias == eql?
29
22
 
30
- def eql?(o)
31
- self.class == o.class && @x == o.x && @y == o.y
32
- end
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
- def self.json_create(h)
40
- self.new(h['x'], h['y'])
41
- end
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
- module Two
46
- module Three
47
- class Deep
32
+ module One
33
+ module Two
34
+ module Three
35
+ class Deep
48
36
 
49
- def initialize()
50
- end
37
+ def initialize()
38
+ end
51
39
 
52
- def eql?(o)
53
- self.class == o.class
54
- end
55
- alias == eql?
40
+ def eql?(o)
41
+ self.class == o.class
42
+ end
43
+ alias == eql?
56
44
 
57
- def to_hash()
58
- {'json_class' => "#{self.class.name}"}
59
- end
45
+ def to_hash()
46
+ {'json_class' => "#{self.class.name}"}
47
+ end
60
48
 
61
- def to_json(*a)
62
- %{{"json_class":"#{self.class.name}"}}
63
- end
49
+ def to_json(*a)
50
+ %{{"json_class":"#{self.class.name}"}}
51
+ end
64
52
 
65
- def self.json_create(h)
66
- self.new()
67
- end
68
- end # Deep
69
- end # Three
70
- end # Two
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 hash_eql(h1, h2)
74
- return false if h1.size != h2.size
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
- class CompatJuice < ::Test::Unit::TestCase
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
@@ -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
@@ -1,17 +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'
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::Unit::TestCase
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)
@@ -1,75 +1,63 @@
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 FileJuice < Minitest::Test
9
+ class Jam
10
+ attr_accessor :x, :y
12
11
 
13
- require 'test/unit'
14
- require 'date'
15
- require 'bigdecimal'
16
- require 'oj'
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
- def initialize(x, y)
25
- @x = x
26
- @y = y
27
- end
17
+ def eql?(o)
18
+ self.class == o.class && @x == o.x && @y == o.y
19
+ end
20
+ alias == eql?
28
21
 
29
- def eql?(o)
30
- self.class == o.class && @x == o.x && @y == o.y
31
- end
32
- alias == eql?
22
+ end# Jam
33
23
 
34
- end# Jam
24
+ class Jeez < Jam
25
+ def initialize(x, y)
26
+ super
27
+ end
35
28
 
36
- class Jeez < Jam
37
- def initialize(x, y)
38
- super
39
- end
29
+ def to_json()
30
+ %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
31
+ end
40
32
 
41
- def to_json()
42
- %{{"json_class":"#{self.class}","x":#{@x},"y":#{@y}}}
43
- end
33
+ def self.json_create(h)
34
+ self.new(h['x'], h['y'])
35
+ end
36
+ end# Jeez
44
37
 
45
- def self.json_create(h)
46
- self.new(h['x'], h['y'])
47
- end
48
- end# Jeez
38
+ class Orange < Jam
39
+ def initialize(x, y)
40
+ super
41
+ end
49
42
 
50
- class Orange < Jam
51
- def initialize(x, y)
52
- super
53
- end
43
+ def as_json()
44
+ { :json_class => self.class,
45
+ :x => @x,
46
+ :y => @y }
47
+ end
54
48
 
55
- def as_json()
56
- { :json_class => self.class,
57
- :x => @x,
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 self.json_create(h)
62
- self.new(h['x'], h['y'])
54
+ def setup
55
+ @default_options = Oj.default_options
63
56
  end
64
- end
65
57
 
66
- class Range
67
- def to_hash()
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
  }