ffi-yajl 2.2.0-universal-java → 2.2.1-universal-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,6 @@ require 'libyajl2'
29
29
 
30
30
  module FFI_Yajl
31
31
  module MapLibraryName
32
-
33
32
  private
34
33
 
35
34
  # Stub for tests to override the host_os
@@ -23,7 +23,8 @@
23
23
  module FFI_Yajl
24
24
  class ParseError < StandardError; end
25
25
  class Parser
26
- attr_accessor :stack, :key_stack, :key, :finished
26
+ attr_writer :stack, :key_stack
27
+ attr_accessor :key, :finished
27
28
 
28
29
  attr_accessor :opts
29
30
 
@@ -31,14 +32,14 @@ module FFI_Yajl
31
32
  # stack used to build up our complex object
32
33
  #
33
34
  def stack
34
- @stack ||= Array.new
35
+ @stack ||= []
35
36
  end
36
37
 
37
38
  #
38
39
  # stack to keep track of keys as we create nested hashes
39
40
  #
40
41
  def key_stack
41
- @key_stack ||= Array.new
42
+ @key_stack ||= []
42
43
  end
43
44
 
44
45
  def self.parse(obj, *args)
@@ -80,9 +81,7 @@ module FFI_Yajl
80
81
  # XXX: bug-compat with ruby-yajl
81
82
  return nil if str == ""
82
83
 
83
- if str.respond_to?(:read)
84
- str = str.read()
85
- end
84
+ str = str.read if str.respond_to?(:read)
86
85
 
87
86
  # call either the ext or ffi hook
88
87
  do_yajl_parse(str, yajl_opts)
@@ -21,5 +21,5 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
 
23
23
  module FFI_Yajl
24
- VERSION = "2.2.0"
24
+ VERSION = "2.2.1"
25
25
  end
@@ -25,18 +25,17 @@ require 'spec_helper'
25
25
  require 'date'
26
26
 
27
27
  describe "FFI_Yajl::Encoder" do
28
-
29
28
  let(:options) { {} }
30
29
 
31
30
  let(:encoder) { FFI_Yajl::Encoder.new(options) }
32
31
 
33
- it "encodes hashes in keys as strings", :ruby_gte_193 => true do
34
- ruby = { {'a' => 'b'} => 2 }
32
+ it "encodes hashes in keys as strings", ruby_gte_193: true do
33
+ ruby = { { 'a' => 'b' } => 2 }
35
34
  expect(encoder.encode(ruby)).to eq('{"{\"a\"=>\"b\"}":2}')
36
35
  end
37
36
 
38
- it "encodes arrays in keys as strings", :ruby_gte_193 => true do
39
- ruby = { [0,1] => 2 }
37
+ it "encodes arrays in keys as strings", ruby_gte_193: true do
38
+ ruby = { [0, 1] => 2 }
40
39
  expect(encoder.encode(ruby)).to eq('{"[0, 1]":2}')
41
40
  end
42
41
 
@@ -66,14 +65,14 @@ describe "FFI_Yajl::Encoder" do
66
65
  end
67
66
 
68
67
  it "encodes bignums in keys as strings" do
69
- ruby = { 12345678901234567890 => 2 }
68
+ ruby = { 12_345_678_901_234_567_890 => 2 }
70
69
  expect(encoder.encode(ruby)).to eq('{"12345678901234567890":2}')
71
70
  end
72
71
 
73
72
  it "encodes objects in keys as strings" do
74
73
  o = Object.new
75
74
  ruby = { o => 2 }
76
- expect(encoder.encode(ruby)).to eq(%Q{{"#{o.to_s}":2}})
75
+ expect(encoder.encode(ruby)).to eq(%{{"#{o}":2}})
77
76
  end
78
77
 
79
78
  it "encodes an object in a key which has a #to_json method as strings" do
@@ -84,7 +83,7 @@ describe "FFI_Yajl::Encoder" do
84
83
  end
85
84
  o = Thing.new
86
85
  ruby = { o => 2 }
87
- expect(encoder.encode(ruby)).to eq(%Q{{"#{o.to_s}":2}})
86
+ expect(encoder.encode(ruby)).to eq(%{{"#{o}":2}})
88
87
  end
89
88
 
90
89
  # XXX: 127 == YAJL_MAX_DEPTH hardcodedness, zero control for us, it isn't even a twiddleable #define
@@ -92,18 +91,18 @@ describe "FFI_Yajl::Encoder" do
92
91
  root = []
93
92
  a = root
94
93
  127.times { |_| a << []; a = a[0] }
95
- expect{ encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
94
+ expect { encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
96
95
  end
97
96
 
98
97
  it "raises an exception for deeply nested hashes" do
99
98
  root = {}
100
99
  a = root
101
- 127.times {|_| a["a"] = {}; a = a["a"] }
102
- expect{ encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
100
+ 127.times { |_| a["a"] = {}; a = a["a"] }
101
+ expect { encoder.encode(root) }.to raise_error(FFI_Yajl::EncodeError)
103
102
  end
104
103
 
105
104
  it "encodes symbols in keys as strings" do
106
- ruby = { :thing => 1 }
105
+ ruby = { thing: 1 }
107
106
  expect(encoder.encode(ruby)).to eq('{"thing":1}')
108
107
  end
109
108
 
@@ -113,7 +112,7 @@ describe "FFI_Yajl::Encoder" do
113
112
  end
114
113
 
115
114
  it "can encode 32-bit unsigned ints" do
116
- ruby = { "gid"=>4294967294 }
115
+ ruby = { "gid" => 4_294_967_294 }
117
116
  expect(encoder.encode(ruby)).to eq('{"gid":4294967294}')
118
117
  end
119
118
 
@@ -128,7 +127,7 @@ describe "FFI_Yajl::Encoder" do
128
127
 
129
128
  it "can encode Date objects" do
130
129
  ruby = Date.parse('2001-02-03')
131
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-03"} )
130
+ expect(encoder.encode(ruby)).to eq( '"2001-02-03"' )
132
131
  end
133
132
 
134
133
  it "can encode StringIOs" do
@@ -148,13 +147,13 @@ describe "FFI_Yajl::Encoder" do
148
147
 
149
148
  it "encodes them correctly" do
150
149
  ruby = Time.local(2001, 02, 02, 21, 05, 06)
151
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-02 21:05:06 +0000"} )
150
+ expect(encoder.encode(ruby)).to eq( '"2001-02-02 21:05:06 +0000"' )
152
151
  end
153
152
  end
154
153
 
155
154
  it "can encode DateTime objects" do
156
155
  ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00')
157
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-03T04:05:06+07:00"} )
156
+ expect(encoder.encode(ruby)).to eq( '"2001-02-03T04:05:06+07:00"' )
158
157
  end
159
158
 
160
159
  describe "testing .to_json for Objects" do
@@ -176,25 +175,25 @@ describe "FFI_Yajl::Encoder" do
176
175
 
177
176
  context "when encoding invalid utf-8" do
178
177
  ruby = {
179
- "automatic"=>{
180
- "etc"=>{
181
- "passwd"=>{
182
- "root"=>{"dir"=>"/root", "gid"=>0, "uid"=>0, "shell"=>"/bin/sh", "gecos"=>"Elan Ruusam\xc3\xa4e"},
183
- "glen"=>{"dir"=>"/home/glen", "gid"=>500, "uid"=>500, "shell"=>"/bin/bash", "gecos"=>"Elan Ruusam\xE4e"},
184
- }
178
+ "automatic" => {
179
+ "etc" => {
180
+ "passwd" => {
181
+ "root" => { "dir" => "/root", "gid" => 0, "uid" => 0, "shell" => "/bin/sh", "gecos" => "Elan Ruusam\xc3\xa4e" },
182
+ "glen" => { "dir" => "/home/glen", "gid" => 500, "uid" => 500, "shell" => "/bin/bash", "gecos" => "Elan Ruusam\xE4e" },
183
+ },
185
184
  },
186
185
  },
187
186
  }
188
187
 
189
188
  it "raises an error on invalid json" do
190
- expect{ encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, /Invalid UTF-8 string 'Elan Ruusam.e': cannot encode to UTF-8/)
189
+ expect { encoder.encode(ruby) }.to raise_error(FFI_Yajl::EncodeError, /Invalid UTF-8 string 'Elan Ruusam.e': cannot encode to UTF-8/)
191
190
  end
192
191
 
193
192
  context "when validate_utf8 is off" do
194
- let(:options) { { :validate_utf8 => false } }
193
+ let(:options) { { validate_utf8: false } }
195
194
 
196
195
  it "does not raise an error" do
197
- expect{ encoder.encode(ruby) }.not_to raise_error
196
+ expect { encoder.encode(ruby) }.not_to raise_error
198
197
  end
199
198
 
200
199
  it "returns utf8" do
@@ -47,7 +47,6 @@ describe "FFI_Yajl::MapLibraryName" do
47
47
  end
48
48
 
49
49
  host_os_library_name_mapping.each do |host_os, library_names|
50
-
51
50
  context "#library_names" do
52
51
  it "maps #{host_os} correctly" do
53
52
  allow(Test).to receive(:host_os).and_return(host_os)
@@ -112,6 +111,5 @@ describe "FFI_Yajl::MapLibraryName" do
112
111
  Test.send(:ffi_open_yajl_library)
113
112
  end
114
113
  end
115
-
116
114
  end
117
115
  end
@@ -24,21 +24,20 @@
24
24
  require 'spec_helper'
25
25
 
26
26
  describe "FFI_Yajl::Parser" do
27
-
28
27
  shared_examples_for "correct json parsing" do
29
28
  context "when json has 23456789012E666" do
30
29
  let(:json) { '{"key": 23456789012E666}' }
31
30
 
32
31
  it "should return infinity" do
33
- infinity = (1.0/0)
34
- expect(parser).to eq({"key" => infinity})
32
+ infinity = (1.0 / 0)
33
+ expect(parser).to eq("key" => infinity)
35
34
  end
36
35
  end
37
36
 
38
37
  context "when parsing nil" do
39
38
  let(:json) { nil }
40
39
  it "should not coredump ruby" do
41
- expect{ parser }.to raise_error(FFI_Yajl::ParseError)
40
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
42
41
  end
43
42
  end
44
43
 
@@ -88,79 +87,79 @@ describe "FFI_Yajl::Parser" do
88
87
  let(:json) { '{"key": /* this is a comment */ "value"}' }
89
88
 
90
89
  context "when allow_comments is false" do
91
- let(:options) { { :allow_comments => false } }
90
+ let(:options) { { allow_comments: false } }
92
91
 
93
92
  it "should not parse" do
94
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
93
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
95
94
  end
96
95
  end
97
96
 
98
97
  context "when allow_comments is true" do
99
- let(:options) { { :allow_comments => true } }
98
+ let(:options) { { allow_comments: true } }
100
99
 
101
100
  it "should parse" do
102
- expect(parser).to eq({"key"=>"value"})
101
+ expect(parser).to eq("key" => "value")
103
102
  end
104
103
  end
105
104
 
106
105
  context "by default" do
107
- let(:options) { }
106
+ let(:options) {}
108
107
 
109
108
  it "should parse" do
110
- expect(parser).to eq({"key"=>"value"})
109
+ expect(parser).to eq("key" => "value")
111
110
  end
112
111
  end
113
112
  end
114
113
 
115
114
  context "when json has multiline comments" do
116
- let(:json) { %Q{{"key": \n/*\n this is a multiline comment \n*/\n "value"}} }
115
+ let(:json) { %{{"key": \n/*\n this is a multiline comment \n*/\n "value"}} }
117
116
 
118
117
  context "when allow_comments is false" do
119
- let(:options) { { :allow_comments => false } }
118
+ let(:options) { { allow_comments: false } }
120
119
 
121
120
  it "should not parse" do
122
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
121
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
123
122
  end
124
123
  end
125
124
 
126
125
  context "when allow_comments is true" do
127
- let(:options) { { :allow_comments => true } }
126
+ let(:options) { { allow_comments: true } }
128
127
 
129
128
  it "should parse" do
130
- expect(parser).to eq({"key"=>"value"})
129
+ expect(parser).to eq("key" => "value")
131
130
  end
132
131
  end
133
132
  end
134
133
 
135
134
  context "when json has inline comments" do
136
- let(:json) { %Q{{"key": \n// this is an inline comment\n "value"}} }
135
+ let(:json) { %{{"key": \n// this is an inline comment\n "value"}} }
137
136
 
138
137
  context "when allow_comments is false" do
139
- let(:options) { { :allow_comments => false } }
138
+ let(:options) { { allow_comments: false } }
140
139
 
141
140
  it "should not parse" do
142
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
141
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
143
142
  end
144
143
  end
145
144
 
146
145
  context "when allow_comments is true" do
147
- let(:options) { { :allow_comments => true } }
146
+ let(:options) { { allow_comments: true } }
148
147
 
149
148
  it "should parse" do
150
- expect(parser).to eq({"key"=>"value"})
149
+ expect(parser).to eq("key" => "value")
151
150
  end
152
151
  end
153
152
  end
154
153
 
155
154
  context "when json is invalid UTF8" do
156
- let(:json) { "[\"#{"\201\203"}\"]" }
155
+ let(:json) { "[\"\201\203\"]" }
157
156
 
158
157
  it "should not parse by default" do
159
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
158
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
160
159
  end
161
160
 
162
161
  context "when :dont_validate_strings is set to true" do
163
- let(:options) { { :dont_validate_strings => true } }
162
+ let(:options) { { dont_validate_strings: true } }
164
163
 
165
164
  it "should parse" do
166
165
  expect(parser).to eq(["\x81\x83"])
@@ -168,46 +167,46 @@ describe "FFI_Yajl::Parser" do
168
167
  end
169
168
 
170
169
  context "when :dont_validate_strings is set to false" do
171
- let(:options) { { :dont_validate_strings => false } }
170
+ let(:options) { { dont_validate_strings: false } }
172
171
 
173
172
  it "should not parse" do
174
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
173
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
175
174
  end
176
175
  end
177
176
 
178
177
  context "when :check_utf8 is set to true" do
179
- let(:options) { { :check_utf8 => true } }
178
+ let(:options) { { check_utf8: true } }
180
179
 
181
180
  it "should not parse" do
182
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
181
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
183
182
  end
184
183
 
185
184
  context "when :dont_validate_strings is set to true" do
186
- let(:options) { { :check_utf8 => true, :dont_validate_strings => true } }
185
+ let(:options) { { check_utf8: true, dont_validate_strings: true } }
187
186
 
188
187
  it "should raise an ArgumentError" do
189
- expect{parser}.to raise_error(ArgumentError)
188
+ expect { parser }.to raise_error(ArgumentError)
190
189
  end
191
190
  end
192
191
 
193
192
  context "when :dont_validate_strings is set to false" do
194
- let(:options) { { :check_utf8 => true, :dont_validate_strings => false } }
193
+ let(:options) { { check_utf8: true, dont_validate_strings: false } }
195
194
 
196
195
  it "should not parse" do
197
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
196
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
198
197
  end
199
198
  end
200
199
  end
201
200
 
202
201
  context "when :check_utf8 is set to false" do
203
- let(:options) { { :check_utf8 => false } }
202
+ let(:options) { { check_utf8: false } }
204
203
 
205
204
  it "should parse" do
206
205
  expect(parser).to eq(["\x81\x83"])
207
206
  end
208
207
 
209
208
  context "when :dont_validate_strings is set to true" do
210
- let(:options) { { :check_utf8 => false, :dont_validate_strings => true } }
209
+ let(:options) { { check_utf8: false, dont_validate_strings: true } }
211
210
 
212
211
  it "should parse" do
213
212
  expect(parser).to eq(["\x81\x83"])
@@ -215,10 +214,10 @@ describe "FFI_Yajl::Parser" do
215
214
  end
216
215
 
217
216
  context "when :dont_validate_strings is set to false" do
218
- let(:options) { { :check_utf8 => false, :dont_validate_strings => false } }
217
+ let(:options) { { check_utf8: false, dont_validate_strings: false } }
219
218
 
220
219
  it "should raise an ArgumentError" do
221
- expect{parser}.to raise_error(ArgumentError)
220
+ expect { parser }.to raise_error(ArgumentError)
222
221
  end
223
222
  end
224
223
  end
@@ -228,7 +227,7 @@ describe "FFI_Yajl::Parser" do
228
227
  let(:json) { StringIO.new('{"key": 1234}') }
229
228
 
230
229
  it "should parse" do
231
- expect(parser).to eq({"key" => 1234})
230
+ expect(parser).to eq("key" => 1234)
232
231
  end
233
232
  end
234
233
 
@@ -236,14 +235,14 @@ describe "FFI_Yajl::Parser" do
236
235
  let(:json) { '{"key": 1234}' }
237
236
 
238
237
  it "should parse correctly" do
239
- expect(parser).to eq({"key" => 1234})
238
+ expect(parser).to eq("key" => 1234)
240
239
  end
241
240
 
242
241
  context "when symbolize_keys is true" do
243
- let(:options) { { :symbolize_keys => true } }
242
+ let(:options) { { symbolize_keys: true } }
244
243
 
245
244
  it "should symbolize keys correctly" do
246
- expect(parser).to eq({:key => 1234})
245
+ expect(parser).to eq(key: 1234)
247
246
  end
248
247
  end
249
248
 
@@ -254,7 +253,7 @@ describe "FFI_Yajl::Parser" do
254
253
  parser do |obj|
255
254
  output = obj
256
255
  end
257
- expect(output).to eq({"key" => 1234})
256
+ expect(output).to eq("key" => 1234)
258
257
  end
259
258
  end
260
259
  end
@@ -305,14 +304,14 @@ describe "FFI_Yajl::Parser" do
305
304
  let(:json) { '{"日本語": 1234}' }
306
305
 
307
306
  it "should parse correctly" do
308
- expect(parser).to eq({"日本語" => 1234})
307
+ expect(parser).to eq("日本語" => 1234)
309
308
  end
310
309
 
311
310
  context "when symbolize_keys is true" do
312
- let(:options) { { :symbolize_keys => true } }
311
+ let(:options) { { symbolize_keys: true } }
313
312
 
314
313
  it "should symbolize keys correctly" do
315
- expect(parser).to eq({:"日本語" => 1234})
314
+ expect(parser).to eq(:"日本語" => 1234) # rubocop:disable Style/HashSyntax
316
315
  end
317
316
 
318
317
  if RUBY_VERSION.to_f >= 1.9
@@ -327,7 +326,7 @@ describe "FFI_Yajl::Parser" do
327
326
  let(:json) { "{\"id\": 2147483649}" }
328
327
 
329
328
  it "should parse corectly" do
330
- expect(parser).to eql({"id" => 2147483649})
329
+ expect(parser).to eql("id" => 2_147_483_649)
331
330
  end
332
331
  end
333
332
 
@@ -335,7 +334,7 @@ describe "FFI_Yajl::Parser" do
335
334
  let(:json) { "{\"id\": 5687389800}" }
336
335
 
337
336
  it "should parse corectly" do
338
- expect(parser).to eql({"id" => 5687389800})
337
+ expect(parser).to eql("id" => 5_687_389_800)
339
338
  end
340
339
  end
341
340
 
@@ -343,7 +342,7 @@ describe "FFI_Yajl::Parser" do
343
342
  let(:json) { "{\"id\": 1046289770033519442869495707521600000000}" }
344
343
 
345
344
  it "should parse corectly" do
346
- expect(parser).to eql({"id" => 1046289770033519442869495707521600000000})
345
+ expect(parser).to eql("id" => 1_046_289_770_033_519_442_869_495_707_521_600_000_000)
347
346
  end
348
347
  end
349
348
 
@@ -383,12 +382,11 @@ describe "FFI_Yajl::Parser" do
383
382
  end
384
383
 
385
384
  context "with allow_trailing_garbage" do
386
- let(:options) { { :allow_trailing_garbage => true } }
385
+ let(:options) { { allow_trailing_garbage: true } }
387
386
  it "parses" do
388
- expect(parser).to eq({"foo"=>{"foo"=>1234}})
387
+ expect(parser).to eq("foo" => { "foo" => 1234 })
389
388
  end
390
389
  end
391
-
392
390
  end
393
391
 
394
392
  context "when an extra bracket is present" do
@@ -476,20 +474,20 @@ describe "FFI_Yajl::Parser" do
476
474
 
477
475
  # NOTE: parsing floats with 8 million digits on windows has some kind of huge
478
476
  # perf issues likely in ruby and/or the underlying windows libs
479
- context "when parsing big floats", :ruby_gte_193 => true, :unix_only => true do
477
+ context "when parsing big floats", ruby_gte_193: true, unix_only: true do
480
478
  let(:json) { '[0.' + '1' * 2**23 + ']' }
481
479
 
482
480
  it "parses" do
483
- expect{ parser }.not_to raise_error
481
+ expect { parser }.not_to raise_error
484
482
  end
485
483
  end
486
484
 
487
- context "when parsing long hash keys with symbolize_keys option", :ruby_gte_193 => true do
485
+ context "when parsing long hash keys with symbolize_keys option", ruby_gte_193: true do
488
486
  let(:json) { '{"' + 'a' * 2**23 + '": 0}' }
489
- let(:options) { { :symbolize_keys => true } }
487
+ let(:options) { { symbolize_keys: true } }
490
488
 
491
489
  it "parses" do
492
- expect{ parser }.not_to raise_error
490
+ expect { parser }.not_to raise_error
493
491
  end
494
492
  end
495
493
 
@@ -502,9 +500,9 @@ describe "FFI_Yajl::Parser" do
502
500
 
503
501
  context "should raise an exception for repeated keys" do
504
502
  let(:json) { '{"foo":"bar","foo":"baz"}' }
505
- let(:options) { { :unique_key_checking => true } }
503
+ let(:options) { { unique_key_checking: true } }
506
504
  it "should raise" do
507
- expect{ parser }.to raise_error(FFI_Yajl::ParseError)
505
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
508
506
  end
509
507
  end
510
508
  end