[flori/json] Skip BigDecimal tests when it's missing to load
https://github.com/flori/json/commit/3dd36c6077
This commit is contained in:
parent
9f51810f34
commit
56c8dab468
@ -2,7 +2,10 @@
|
|||||||
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
||||||
require 'json'
|
require 'json'
|
||||||
end
|
end
|
||||||
defined?(::BigDecimal) or require 'bigdecimal'
|
begin
|
||||||
|
require 'bigdecimal'
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
|
|
||||||
class BigDecimal
|
class BigDecimal
|
||||||
# Import a JSON Marshalled object.
|
# Import a JSON Marshalled object.
|
||||||
@ -26,4 +29,4 @@ class BigDecimal
|
|||||||
def to_json(*args)
|
def to_json(*args)
|
||||||
as_json.to_json(*args)
|
as_json.to_json(*args)
|
||||||
end
|
end
|
||||||
end
|
end if defined?(::BigDecimal)
|
||||||
|
@ -183,7 +183,7 @@ class JSONAdditionTest < Test::Unit::TestCase
|
|||||||
def test_bigdecimal
|
def test_bigdecimal
|
||||||
assert_equal BigDecimal('3.141', 23), JSON(JSON(BigDecimal('3.141', 23)), :create_additions => true)
|
assert_equal BigDecimal('3.141', 23), JSON(JSON(BigDecimal('3.141', 23)), :create_additions => true)
|
||||||
assert_equal BigDecimal('3.141', 666), JSON(JSON(BigDecimal('3.141', 666)), :create_additions => true)
|
assert_equal BigDecimal('3.141', 666), JSON(JSON(BigDecimal('3.141', 666)), :create_additions => true)
|
||||||
end
|
end if defined?(::BigDecimal)
|
||||||
|
|
||||||
def test_ostruct
|
def test_ostruct
|
||||||
o = OpenStruct.new
|
o = OpenStruct.new
|
||||||
|
@ -4,7 +4,10 @@ require 'test_helper'
|
|||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
require 'ostruct'
|
require 'ostruct'
|
||||||
require 'bigdecimal'
|
begin
|
||||||
|
require 'bigdecimal'
|
||||||
|
rescue LoadError
|
||||||
|
end
|
||||||
|
|
||||||
class JSONParserTest < Test::Unit::TestCase
|
class JSONParserTest < Test::Unit::TestCase
|
||||||
include JSON
|
include JSON
|
||||||
@ -113,7 +116,7 @@ class JSONParserTest < Test::Unit::TestCase
|
|||||||
def test_parse_bigdecimals
|
def test_parse_bigdecimals
|
||||||
assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class)
|
assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class)
|
||||||
assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
|
assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
|
||||||
end
|
end if defined?(::BigDecimal)
|
||||||
|
|
||||||
def test_parse_string_mixed_unicode
|
def test_parse_string_mixed_unicode
|
||||||
assert_equal(["éé"], JSON.parse("[\"\\u00e9é\"]"))
|
assert_equal(["éé"], JSON.parse("[\"\\u00e9é\"]"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user