oj 2.12.1 → 2.12.2

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,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #!/usr/bin/env ruby
4
+ # encoding: UTF-8
5
+
6
+ $: << File.dirname(__FILE__)
7
+
8
+ require 'helper'
9
+
10
+
@@ -0,0 +1,11 @@
1
+ %w(lib ext test).each do |dir|
2
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
3
+ end
4
+ require 'oj'
5
+ require 'json'
6
+
7
+ Oj::Doc.open([{:name => "T-Shirt"}].to_json) do |doc|
8
+ doc.each_child do |child|
9
+ p child.fetch("name")
10
+ end
11
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'helper'
7
+
8
+ class Handler
9
+ def initialize
10
+ @state = []
11
+ end
12
+
13
+ def hash_start
14
+ @state << {}
15
+ @state.last
16
+ end
17
+
18
+ def hash_end
19
+ @state.pop
20
+ end
21
+
22
+ def hash_set(h,k,v)
23
+ h.store(k,v)
24
+ end
25
+
26
+ def array_start
27
+ @state << []
28
+ @state.last
29
+ end
30
+
31
+
32
+ def array_end
33
+ @state.pop
34
+ end
35
+
36
+ def array_append(a,v)
37
+ a << v
38
+ end
39
+
40
+ def error(message, line, column); p "ERROR: #{message}" end
41
+ end
42
+
43
+ handler = Handler.new
44
+ def handler.add_value(v)
45
+ p v
46
+ end
47
+
48
+ Oj.sc_parse(handler, StringIO.new('{"a":"b","c":[1,2,{"d":"e"}]}[4,5,6]'))
@@ -1,19 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- $VERBOSE = true
5
-
6
4
  %w(lib ext test).each do |dir|
7
5
  $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
8
6
  end
9
7
 
10
- require 'rubygems' if RUBY_VERSION.start_with?('1.8.')
11
8
  require 'oj'
12
9
 
13
- Oj.mimic_JSON
14
-
15
- #puts Oj.default_options
16
-
17
- range = ("01".."12")
18
10
 
19
- puts Oj.dump(range)
11
+ Thread.new do
12
+ string_io = StringIO.new('{"foo":"bar"}')
13
+ Oj.load(string_io)
14
+ string_io.rewind
15
+ puts string_io.read
16
+ end.join
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
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
7
+
8
+ $VERBOSE = true
9
+
10
+ $: << File.join(File.dirname(__FILE__), "../lib")
11
+ $: << File.join(File.dirname(__FILE__), "../ext")
12
+
13
+ require 'oj'
14
+
15
+ A = Struct.new(:a,:b,:c,:d)
16
+ B = Struct.new(:e,:f)
17
+
18
+ obj = [A.new(55, B.new(1, 'X'), B.new(2, 'Y'), 3)]
19
+
20
+ s = Oj.dump(obj, :mode => :object)
21
+
22
+ 100000.times do
23
+ Oj.load(s, :mode => :object)
24
+ # ds = Oj.dump(o, :mode => :object)
25
+ # if ds != s
26
+ # puts ds
27
+ # raise "holy crap"
28
+ # end
29
+ end
@@ -5,7 +5,7 @@ $: << File.dirname(__FILE__)
5
5
 
6
6
  require 'helper'
7
7
 
8
- $json1 = %{{
8
+ $json1 = %|{
9
9
  "array": [
10
10
  {
11
11
  "num" : 3,
@@ -18,7 +18,7 @@ $json1 = %{{
18
18
  }
19
19
  ],
20
20
  "boolean" : true
21
- }}
21
+ }|
22
22
 
23
23
  class DocTest < Minitest::Test
24
24
  def setup
@@ -61,6 +61,22 @@ class DocTest < Minitest::Test
61
61
  end
62
62
  end
63
63
 
64
+ def test_encoding
65
+ json = %{"ぴーたー"}
66
+ Oj::Doc.open(json) do |doc|
67
+ assert_equal(String, doc.type)
68
+ assert_equal("ぴーたー", doc.fetch())
69
+ end
70
+ end
71
+
72
+ def test_encoding_escaped
73
+ json = %{"\\u3074\\u30fc\\u305f\\u30fc"}
74
+ Oj::Doc.open(json) do |doc|
75
+ assert_equal(String, doc.type)
76
+ assert_equal("ぴーたー", doc.fetch())
77
+ end
78
+ end
79
+
64
80
  def test_fixnum
65
81
  json = %{12345}
66
82
  Oj::Doc.open(json) do |doc|
@@ -243,6 +259,18 @@ class DocTest < Minitest::Test
243
259
  end
244
260
  end
245
261
 
262
+ def test_move_fetch_path
263
+ Oj::Doc.open($json1) do |doc|
264
+ [['/array/1', 'num', 3],
265
+ ['/array/1', 'string', 'message'],
266
+ ['/array/1/hash', 'h2/a', [1, 2, 3]],
267
+ ].each do |path,fetch_path,val|
268
+ doc.move(path)
269
+ assert_equal(val, doc.fetch(fetch_path))
270
+ end
271
+ end
272
+ end
273
+
246
274
  def test_home
247
275
  Oj::Doc.open($json1) do |doc|
248
276
  doc.move('/array/1/num')
@@ -351,13 +351,23 @@ class ScpTest < Minitest::Test
351
351
 
352
352
  def test_socket_close
353
353
  json = %{{"one":true,"two":false}}
354
- Thread.start(json) do |j|
354
+ begin
355
355
  server = TCPServer.new(8080)
356
+ rescue
357
+ # Not able to open a socket to run the test. Might be Travis.
358
+ return
359
+ end
360
+ Thread.start(json) do |j|
356
361
  c = server.accept()
357
362
  c.puts json
358
363
  c.close
359
364
  end
360
- sock = TCPSocket.new('localhost', 8080)
365
+ begin
366
+ sock = TCPSocket.new('localhost', 8080)
367
+ rescue
368
+ # Not able to open a socket to run the test. Might be Travis.
369
+ return
370
+ end
361
371
  handler = Closer.new(sock)
362
372
  err = nil
363
373
  begin
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ %w(lib ext test).each do |dir|
7
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
8
+ end
9
+
10
+ require 'minitest'
11
+ require 'minitest/autorun'
12
+ require 'oj'
13
+
14
+ Oj.mimic_JSON
15
+
16
+ require 'rails/all'
17
+ require 'active_model'
18
+ require 'active_model_serializers'
19
+ require 'active_support/json'
20
+
21
+ #Oj.mimic_JSON
22
+
23
+ class Category
24
+ include ActiveModel::Model
25
+ include ActiveModel::SerializerSupport
26
+
27
+ attr_accessor :id, :name
28
+
29
+ def initialize(id, name)
30
+ @id = id
31
+ @name = name
32
+ end
33
+ end
34
+
35
+ class CategorySerializer < ActiveModel::Serializer
36
+ attributes :id, :name
37
+ end
38
+
39
+ class MimicRails < Minitest::Test
40
+
41
+ def test_dump_object
42
+ Oj.default_options= {:indent => 0}
43
+ category = Category.new(1, 'test')
44
+ serializer = CategorySerializer.new(category)
45
+
46
+ json = serializer.to_json()
47
+ puts "*** serializer.to_json() #{serializer.to_json()}"
48
+ assert_equal(%|{"category":{"id":1,"name":"test"}}|, json)
49
+
50
+ json = serializer.as_json()
51
+ puts "*** serializer.as_json() #{serializer.as_json()}"
52
+ assert_equal({"category" => {:id => 1, :name => "test"}}, json)
53
+
54
+ json = JSON.dump(serializer)
55
+ puts "*** JSON.dump(serializer) #{JSON.dump(serializer)}"
56
+ assert_equal(%|{"category":{"id":1,"name":"test"}}|, json)
57
+ end
58
+
59
+ end # MimicRails
@@ -244,15 +244,12 @@ class Juice < Minitest::Test
244
244
  def test_encode
245
245
  opts = Oj.default_options
246
246
  Oj.default_options = { :ascii_only => false }
247
- unless 'jruby' == $ruby
248
- dump_and_load("ぴーたー", false)
249
- end
247
+ dump_and_load("ぴーたー", false)
248
+
250
249
  Oj.default_options = { :ascii_only => true }
251
250
  json = Oj.dump("ぴーたー")
252
251
  assert_equal(%{"\\u3074\\u30fc\\u305f\\u30fc"}, json)
253
- unless 'jruby' == $ruby
254
- dump_and_load("ぴーたー", false)
255
- end
252
+ dump_and_load("ぴーたー", false)
256
253
  Oj.default_options = opts
257
254
  end
258
255
 
@@ -873,8 +870,6 @@ class Juice < Minitest::Test
873
870
  json = Oj.dump(1..7, :mode => :object, :indent => 0)
874
871
  if 'rubinius' == $ruby
875
872
  assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
876
- elsif 'jruby' == $ruby
877
- assert(%{{"^O":"Range","begin":1,"end":7,"exclude_end?":false}} == json)
878
873
  else
879
874
  assert_equal(%{{"^u":["Range",1,7,false]}}, json)
880
875
  end
@@ -1106,7 +1101,6 @@ class Juice < Minitest::Test
1106
1101
 
1107
1102
  # Stream Deeply Nested
1108
1103
  def test_deep_nest
1109
- #unless 'jruby' == RUBY_DESCRIPTION.split(' ')[0]
1110
1104
  begin
1111
1105
  n = 10000
1112
1106
  Oj.strict_load('[' * n + ']' * n)
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ %w(lib ext).each do |dir|
5
+ $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
6
+ end
7
+
8
+ require 'stringio'
9
+ require 'oj'
10
+
11
+
12
+ filename = File.join(File.dirname(__FILE__), 'day.json')
13
+ File.open(filename, "w") do |f|
14
+ w = Oj::StreamWriter.new(f, :indent => -1)
15
+ 390.times do |i|
16
+ w.push_object()
17
+ w.push_value(12, 'msgType')
18
+ w.push_value(1, 'version')
19
+ w.push_value(1_400_074_200 + i * 60, 'bar')
20
+ w.push_value('TBC', 'source')
21
+ w.push_array('timebars')
22
+ w.push_object()
23
+ w.push_value('aapl_24', 'asset')
24
+ w.push_value(91.87, 'close')
25
+ w.pop()
26
+ w.pop()
27
+ w.pop()
28
+ end
29
+ f.write("\n")
30
+ end
31
+
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+
6
+ require 'helper'
7
+
8
+ require 'zlib'
9
+
10
+ File.open('test.json.gz', 'r') do |file|
11
+ Zlib::GzipReader.wrap(file) do |f2|
12
+ puts "*** f2: #{f2}"
13
+ Oj.load(f2) do |val|
14
+ puts val
15
+ end
16
+ end
17
+ end
18
+
19
+ =begin
20
+ And a json file with the following contents (then gzipped):
21
+
22
+ {"a":2}
23
+ {"b":2}
24
+ The output is:
25
+
26
+ {"a"=>2}
27
+ {"b"=>2}
28
+ bin/test:8:in `load': undefined method `new' for #<EOFError: end of file reached> (NoMethodError)
29
+ from bin/test:8:in `block (2 levels) in <main>'
30
+ from bin/test:7:in `wrap'
31
+ from bin/test:7:in `block in <main>'
32
+ from bin/test:6:in `open'
33
+ from bin/test:6:in `<main>'
34
+ =end
metadata CHANGED
@@ -1,65 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.1
5
- prerelease:
4
+ version: 2.12.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Ohler
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake-compiler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0.9'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0.9'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: minitest
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '5'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '5'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rails
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '4'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '4'
62
- description: ! 'The fastest JSON parser and object serializer. '
55
+ description: 'The fastest JSON parser and object serializer. '
63
56
  email: peter@ohler.com
64
57
  executables: []
65
58
  extensions:
@@ -67,52 +60,57 @@ extensions:
67
60
  extra_rdoc_files:
68
61
  - README.md
69
62
  files:
70
- - lib/oj/active_support_helper.rb
71
- - lib/oj/bag.rb
72
- - lib/oj/error.rb
73
- - lib/oj/mimic.rb
74
- - lib/oj/saj.rb
75
- - lib/oj/schandler.rb
76
- - lib/oj/version.rb
77
- - lib/oj.rb
78
- - ext/oj/extconf.rb
63
+ - LICENSE
64
+ - README.md
79
65
  - ext/oj/buf.h
80
- - ext/oj/cache8.h
81
- - ext/oj/circarray.h
82
- - ext/oj/encode.h
83
- - ext/oj/err.h
84
- - ext/oj/hash.h
85
- - ext/oj/odd.h
86
- - ext/oj/oj.h
87
- - ext/oj/parse.h
88
- - ext/oj/reader.h
89
- - ext/oj/resolve.h
90
- - ext/oj/val_stack.h
91
66
  - ext/oj/cache8.c
67
+ - ext/oj/cache8.h
92
68
  - ext/oj/circarray.c
69
+ - ext/oj/circarray.h
93
70
  - ext/oj/compat.c
94
71
  - ext/oj/dump.c
72
+ - ext/oj/encode.h
95
73
  - ext/oj/err.c
74
+ - ext/oj/err.h
75
+ - ext/oj/extconf.rb
96
76
  - ext/oj/fast.c
97
77
  - ext/oj/hash.c
78
+ - ext/oj/hash.h
98
79
  - ext/oj/hash_test.c
99
80
  - ext/oj/object.c
100
81
  - ext/oj/odd.c
82
+ - ext/oj/odd.h
101
83
  - ext/oj/oj.c
84
+ - ext/oj/oj.h
102
85
  - ext/oj/parse.c
86
+ - ext/oj/parse.h
103
87
  - ext/oj/reader.c
88
+ - ext/oj/reader.h
104
89
  - ext/oj/resolve.c
90
+ - ext/oj/resolve.h
105
91
  - ext/oj/saj.c
106
92
  - ext/oj/scp.c
107
93
  - ext/oj/sparse.c
108
94
  - ext/oj/strict.c
109
95
  - ext/oj/val_stack.c
96
+ - ext/oj/val_stack.h
97
+ - lib/oj.rb
98
+ - lib/oj/active_support_helper.rb
99
+ - lib/oj/bag.rb
100
+ - lib/oj/error.rb
101
+ - lib/oj/mimic.rb
102
+ - lib/oj/saj.rb
103
+ - lib/oj/schandler.rb
104
+ - lib/oj/version.rb
110
105
  - test/_test_active.rb
111
106
  - test/_test_active_mimic.rb
112
107
  - test/_test_mimic_rails.rb
113
108
  - test/bug.rb
109
+ - test/bug2.rb
110
+ - test/example.rb
114
111
  - test/files.rb
115
112
  - test/helper.rb
113
+ - test/io.rb
116
114
  - test/isolated/shared.rb
117
115
  - test/isolated/test_mimic_after.rb
118
116
  - test/isolated/test_mimic_alone.rb
@@ -120,18 +118,17 @@ files:
120
118
  - test/isolated/test_mimic_define.rb
121
119
  - test/isolated/test_mimic_rails_after.rb
122
120
  - test/isolated/test_mimic_rails_before.rb
121
+ - test/mod.rb
123
122
  - test/perf.rb
124
- - test/perf1.rb
125
- - test/perf2.rb
126
123
  - test/perf_compat.rb
127
124
  - test/perf_fast.rb
128
125
  - test/perf_file.rb
129
- - test/perf_obj_old.rb
130
126
  - test/perf_object.rb
131
127
  - test/perf_saj.rb
132
128
  - test/perf_scp.rb
133
129
  - test/perf_simple.rb
134
130
  - test/perf_strict.rb
131
+ - test/sample.rb
135
132
  - test/sample/change.rb
136
133
  - test/sample/dir.rb
137
134
  - test/sample/doc.rb
@@ -144,49 +141,48 @@ files:
144
141
  - test/sample/rect.rb
145
142
  - test/sample/shape.rb
146
143
  - test/sample/text.rb
147
- - test/sample.rb
148
144
  - test/sample_json.rb
149
- - test/test_bigd.rb
145
+ - test/struct.rb
150
146
  - test/test_compat.rb
151
147
  - test/test_debian.rb
152
148
  - test/test_fast.rb
153
149
  - test/test_file.rb
154
150
  - test/test_gc.rb
155
151
  - test/test_object.rb
156
- - test/test_range.rb
157
152
  - test/test_saj.rb
158
153
  - test/test_scp.rb
154
+ - test/test_serializer.rb
159
155
  - test/test_strict.rb
160
156
  - test/test_various.rb
161
157
  - test/test_writer.rb
162
- - LICENSE
163
- - README.md
158
+ - test/write_timebars.rb
159
+ - test/zip.rb
164
160
  homepage: http://www.ohler.com/oj
165
161
  licenses:
166
162
  - MIT
163
+ metadata: {}
167
164
  post_install_message:
168
165
  rdoc_options:
169
- - --main
166
+ - "--main"
170
167
  - README.md
171
168
  require_paths:
172
169
  - lib
173
170
  - ext
174
171
  required_ruby_version: !ruby/object:Gem::Requirement
175
- none: false
176
172
  requirements:
177
- - - ! '>='
173
+ - - ">="
178
174
  - !ruby/object:Gem::Version
179
175
  version: '0'
180
176
  required_rubygems_version: !ruby/object:Gem::Requirement
181
- none: false
182
177
  requirements:
183
- - - ! '>='
178
+ - - ">="
184
179
  - !ruby/object:Gem::Version
185
180
  version: '0'
186
181
  requirements: []
187
182
  rubyforge_project: oj
188
- rubygems_version: 1.8.23.2
183
+ rubygems_version: 2.4.5
189
184
  signing_key:
190
- specification_version: 3
185
+ specification_version: 4
191
186
  summary: A fast JSON parser and serializer.
192
187
  test_files: []
188
+ has_rdoc: true