summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-12-19 21:45:38 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2013-12-19 21:45:38 -0800
commit207105a5432a7f613c65c1d390b18dd0b32de53f (patch)
tree8c8843edcb8f370e6ceac1a5a93e19ea71c1f7cf /spec
parent6f77ca8b1d0e4e055bd99444b504004a24608ad1 (diff)
downloadffi-yajl-207105a5432a7f613c65c1d390b18dd0b32de53f.tar.gz
add some floating point tests
Diffstat (limited to 'spec')
-rw-r--r--spec/ffi_yajl/parser_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/ffi_yajl/parser_spec.rb b/spec/ffi_yajl/parser_spec.rb
index 28a0f36..bb7c356 100644
--- a/spec/ffi_yajl/parser_spec.rb
+++ b/spec/ffi_yajl/parser_spec.rb
@@ -26,5 +26,47 @@ describe "FFI_Yajl::Parser" do
expect { parser.parse(json) }.to raise_error(FFI_Yajl::ParseError)
end
+ context "when parsing floats" do
+ it "parses simple floating point values" do
+ json = '{"foo": 3.14159265358979}'
+ expect(parser.parse(json)).to eql({"foo" => 3.14159265358979})
+ end
+
+ it "parses simple negative floating point values" do
+ json = '{"foo":-2.00231930436153}'
+ expect(parser.parse(json)).to eql({"foo" => -2.00231930436153})
+ end
+
+ it "parses floats with negative exponents and a large E" do
+ json = '{"foo": 1.602176565E-19}'
+ expect(parser.parse(json)).to eql({"foo" => 1.602176565e-19})
+ end
+
+ it "parses floats with negative exponents and a small e" do
+ json = '{"foo": 6.6260689633e-34 }'
+ expect(parser.parse(json)).to eql({"foo" => 6.6260689633e-34 })
+ end
+
+ it "parses floats with positive exponents and a large E" do
+ json = '{"foo": 6.0221413E+23}'
+ expect(parser.parse(json)).to eql({"foo" => 6.0221413e+23})
+ end
+
+ it "parses floats with positive exponents and a small e" do
+ json = '{"foo": 8.9875517873681764e+9 }'
+ expect(parser.parse(json)).to eql({"foo" => 8.9875517873681764e+9 })
+ end
+
+ it "parses floats with an exponent without a sign and a large E" do
+ json = '{"foo": 2.99792458E8 }'
+ expect(parser.parse(json)).to eql({"foo" => 2.99792458e+8 })
+ end
+
+ it "parses floats with an exponent without a sign and a small e" do
+ json = '{"foo": 1.0973731568539e7 }'
+ expect(parser.parse(json)).to eql({"foo" => 1.0973731568539e+7 })
+ end
+
+ end
end