ffi-yajl 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/Rakefile +11 -12
- data/bin/ffi-yajl-bench +4 -5
- data/ext/ffi_yajl/ext/dlopen/extconf.rb +1 -0
- data/ext/ffi_yajl/ext/encoder/encoder.c +9 -4
- data/ext/ffi_yajl/ext/encoder/extconf.rb +2 -1
- data/ext/ffi_yajl/ext/parser/extconf.rb +2 -1
- data/ext/ffi_yajl/ext/parser/parser.c +1 -0
- data/lib/ffi_yajl/benchmark/encode.rb +32 -90
- data/lib/ffi_yajl/benchmark/encode_json_and_marshal.rb +14 -14
- data/lib/ffi_yajl/benchmark/encode_json_and_yaml.rb +13 -19
- data/lib/ffi_yajl/benchmark/encode_profile.rb +11 -15
- data/lib/ffi_yajl/benchmark/http.rb +9 -13
- data/lib/ffi_yajl/benchmark/parse.rb +71 -124
- data/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +17 -17
- data/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +19 -19
- data/lib/ffi_yajl/benchmark/parse_profile.rb +10 -14
- data/lib/ffi_yajl/benchmark/parse_profile_ruby_prof.rb +11 -16
- data/lib/ffi_yajl/benchmark/parse_stream.rb +17 -17
- data/lib/ffi_yajl/benchmark.rb +0 -1
- data/lib/ffi_yajl/encoder.rb +3 -3
- data/lib/ffi_yajl/ffi/encoder.rb +29 -32
- data/lib/ffi_yajl/ffi/parser.rb +30 -37
- data/lib/ffi_yajl/ffi.rb +23 -24
- data/lib/ffi_yajl/map_library_name.rb +0 -1
- data/lib/ffi_yajl/parser.rb +5 -6
- data/lib/ffi_yajl/version.rb +1 -1
- data/spec/ffi_yajl/encoder_spec.rb +24 -25
- data/spec/ffi_yajl/map_library_name_spec.rb +0 -2
- data/spec/ffi_yajl/parser_spec.rb +54 -56
- data/spec/spec_helper.rb +8 -9
- metadata +2 -2
@@ -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(
|
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) { { :
|
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) { { :
|
98
|
+
let(:options) { { allow_comments: true } }
|
100
99
|
|
101
100
|
it "should parse" do
|
102
|
-
expect(parser).to eq(
|
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(
|
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) { %
|
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) { { :
|
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) { { :
|
126
|
+
let(:options) { { allow_comments: true } }
|
128
127
|
|
129
128
|
it "should parse" do
|
130
|
-
expect(parser).to eq(
|
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) { %
|
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) { { :
|
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) { { :
|
146
|
+
let(:options) { { allow_comments: true } }
|
148
147
|
|
149
148
|
it "should parse" do
|
150
|
-
expect(parser).to eq(
|
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) { "[\"
|
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) { { :
|
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) { { :
|
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) { { :
|
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) { { :
|
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) { { :
|
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) { { :
|
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) { { :
|
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) { { :
|
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(
|
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(
|
238
|
+
expect(parser).to eq("key" => 1234)
|
240
239
|
end
|
241
240
|
|
242
241
|
context "when symbolize_keys is true" do
|
243
|
-
let(:options) { { :
|
242
|
+
let(:options) { { symbolize_keys: true } }
|
244
243
|
|
245
244
|
it "should symbolize keys correctly" do
|
246
|
-
expect(parser).to eq(
|
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(
|
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(
|
307
|
+
expect(parser).to eq("日本語" => 1234)
|
309
308
|
end
|
310
309
|
|
311
310
|
context "when symbolize_keys is true" do
|
312
|
-
let(:options) { { :
|
311
|
+
let(:options) { { symbolize_keys: true } }
|
313
312
|
|
314
313
|
it "should symbolize keys correctly" do
|
315
|
-
expect(parser).to eq(
|
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(
|
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(
|
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(
|
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) { { :
|
385
|
+
let(:options) { { allow_trailing_garbage: true } }
|
387
386
|
it "parses" do
|
388
|
-
expect(parser).to eq(
|
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", :
|
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", :
|
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) { { :
|
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) { { :
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
|
23
|
-
|
23
|
+
$LOAD_PATH << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib"))
|
24
24
|
|
25
25
|
# load yajl-ruby into the same process (tests that both c-libs can be
|
26
26
|
# linked in the same process). this should work, see:
|
@@ -28,19 +28,18 @@ $: << File.expand_path(File.join(File.dirname( __FILE__ ), "../lib"))
|
|
28
28
|
begin
|
29
29
|
require 'yajl'
|
30
30
|
rescue LoadError
|
31
|
-
|
31
|
+
puts 'WARN: yajl cannot be loaded, expected if this is jruby'
|
32
32
|
end
|
33
33
|
|
34
34
|
require 'ffi_yajl'
|
35
35
|
|
36
|
-
RSpec.configure do |
|
37
|
-
|
38
|
-
|
36
|
+
RSpec.configure do |conf|
|
37
|
+
conf.filter_run_excluding unix_only: true unless RUBY_PLATFORM !~ /mswin|mingw|windows/
|
38
|
+
conf.filter_run_excluding ruby_gte_193: true unless RUBY_VERSION.to_f >= 2.0 || RUBY_VERSION =~ /^1\.9\.3/
|
39
39
|
|
40
|
-
|
40
|
+
conf.order = 'random'
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
conf.expect_with :rspec do |rspec|
|
43
|
+
rspec.syntax = :expect
|
44
44
|
end
|
45
|
-
|
46
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-yajl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lamont Granquist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|