summaryrefslogtreecommitdiff
path: root/spec/ffi_yajl/parser_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ffi_yajl/parser_spec.rb')
-rw-r--r--spec/ffi_yajl/parser_spec.rb66
1 files changed, 32 insertions, 34 deletions
diff --git a/spec/ffi_yajl/parser_spec.rb b/spec/ffi_yajl/parser_spec.rb
index ed6ef2a..968e0ee 100644
--- a/spec/ffi_yajl/parser_spec.rb
+++ b/spec/ffi_yajl/parser_spec.rb
@@ -24,21 +24,20 @@
require 'spec_helper'
describe "FFI_Yajl::Parser" do
-
shared_examples_for "correct json parsing" do
context "when json has 23456789012E666" do
let(:json) { '{"key": 23456789012E666}' }
it "should return infinity" do
- infinity = (1.0/0)
- expect(parser).to eq({"key" => infinity})
+ infinity = (1.0 / 0)
+ expect(parser).to eq("key" => infinity)
end
end
context "when parsing nil" do
let(:json) { nil }
it "should not coredump ruby" do
- expect{ parser }.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -91,7 +90,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -99,27 +98,27 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
context "by default" do
- let(:options) { }
+ let(:options) {}
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
context "when json has multiline comments" do
- let(:json) { %Q{{"key": \n/*\n this is a multiline comment \n*/\n "value"}} }
+ let(:json) { %{{"key": \n/*\n this is a multiline comment \n*/\n "value"}} }
context "when allow_comments is false" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -127,19 +126,19 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
context "when json has inline comments" do
- let(:json) { %Q{{"key": \n// this is an inline comment\n "value"}} }
+ let(:json) { %{{"key": \n// this is an inline comment\n "value"}} }
context "when allow_comments is false" do
let(:options) { { :allow_comments => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -147,7 +146,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :allow_comments => true } }
it "should parse" do
- expect(parser).to eq({"key"=>"value"})
+ expect(parser).to eq("key" => "value")
end
end
end
@@ -156,7 +155,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "[\"#{"\201\203"}\"]" }
it "should not parse by default" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
context "when :dont_validate_strings is set to true" do
@@ -171,7 +170,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :dont_validate_strings => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
@@ -179,14 +178,14 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => true } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
context "when :dont_validate_strings is set to true" do
let(:options) { { :check_utf8 => true, :dont_validate_strings => true } }
it "should raise an ArgumentError" do
- expect{parser}.to raise_error(ArgumentError)
+ expect { parser }.to raise_error(ArgumentError)
end
end
@@ -194,7 +193,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => true, :dont_validate_strings => false } }
it "should not parse" do
- expect{parser}.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
end
@@ -218,7 +217,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :check_utf8 => false, :dont_validate_strings => false } }
it "should raise an ArgumentError" do
- expect{parser}.to raise_error(ArgumentError)
+ expect { parser }.to raise_error(ArgumentError)
end
end
end
@@ -228,7 +227,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { StringIO.new('{"key": 1234}') }
it "should parse" do
- expect(parser).to eq({"key" => 1234})
+ expect(parser).to eq("key" => 1234)
end
end
@@ -236,14 +235,14 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"key": 1234}' }
it "should parse correctly" do
- expect(parser).to eq({"key" => 1234})
+ expect(parser).to eq("key" => 1234)
end
context "when symbolize_keys is true" do
let(:options) { { :symbolize_keys => true } }
it "should symbolize keys correctly" do
- expect(parser).to eq({:key => 1234})
+ expect(parser).to eq(:key => 1234)
end
end
@@ -254,7 +253,7 @@ describe "FFI_Yajl::Parser" do
parser do |obj|
output = obj
end
- expect(output).to eq({"key" => 1234})
+ expect(output).to eq("key" => 1234)
end
end
end
@@ -305,14 +304,14 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"日本語": 1234}' }
it "should parse correctly" do
- expect(parser).to eq({"日本語" => 1234})
+ expect(parser).to eq("日本語" => 1234)
end
context "when symbolize_keys is true" do
let(:options) { { :symbolize_keys => true } }
it "should symbolize keys correctly" do
- expect(parser).to eq({:"日本語" => 1234})
+ expect(parser).to eq(:"日本語" => 1234)
end
if RUBY_VERSION.to_f >= 1.9
@@ -327,7 +326,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 2147483649}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 2147483649})
+ expect(parser).to eql("id" => 2_147_483_649)
end
end
@@ -335,7 +334,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 5687389800}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 5687389800})
+ expect(parser).to eql("id" => 5_687_389_800)
end
end
@@ -343,7 +342,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { "{\"id\": 1046289770033519442869495707521600000000}" }
it "should parse corectly" do
- expect(parser).to eql({"id" => 1046289770033519442869495707521600000000})
+ expect(parser).to eql("id" => 1_046_289_770_033_519_442_869_495_707_521_600_000_000)
end
end
@@ -385,10 +384,9 @@ describe "FFI_Yajl::Parser" do
context "with allow_trailing_garbage" do
let(:options) { { :allow_trailing_garbage => true } }
it "parses" do
- expect(parser).to eq({"foo"=>{"foo"=>1234}})
+ expect(parser).to eq("foo" => { "foo" => 1234 })
end
end
-
end
context "when an extra bracket is present" do
@@ -480,7 +478,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { '[0.' + '1' * 2**23 + ']' }
it "parses" do
- expect{ parser }.not_to raise_error
+ expect { parser }.not_to raise_error
end
end
@@ -489,7 +487,7 @@ describe "FFI_Yajl::Parser" do
let(:options) { { :symbolize_keys => true } }
it "parses" do
- expect{ parser }.not_to raise_error
+ expect { parser }.not_to raise_error
end
end
@@ -504,7 +502,7 @@ describe "FFI_Yajl::Parser" do
let(:json) { '{"foo":"bar","foo":"baz"}' }
let(:options) { { :unique_key_checking => true } }
it "should raise" do
- expect{ parser }.to raise_error(FFI_Yajl::ParseError)
+ expect { parser }.to raise_error(FFI_Yajl::ParseError)
end
end
end