@@ -114,6 +114,9 @@ tests = testGroup "unit" [
114114 , testCase "SingleFieldCon" singleFieldCon
115115 , testGroup "Ordering of object keys" keyOrdering
116116 , testCase "Ratio with denominator 0" ratioDenominator0
117+ , testCase "Rational parses number" rationalNumber
118+ , testCase "Big rational" bigRationalDecoding
119+ , testCase "Small rational" smallRationalDecoding
117120 , testCase "Big scientific exponent" bigScientificExponent
118121 , testCase "Big integer decoding" bigIntegerDecoding
119122 , testCase "Big natural decading" bigNaturalDecoding
@@ -620,6 +623,25 @@ ratioDenominator0 =
620623 (Left "Error in $: Ratio denominator was 0")
621624 (eitherDecode "{ \"numerator\": 1, \"denominator\": 0 }" :: Either String Rational)
622625
626+rationalNumber :: Assertion
627+rationalNumber =
628+ assertEqual "Ratio with denominator 0"
629+ (Right 1.37)
630+ (eitherDecode "1.37" :: Either String Rational)
631+
632+bigRationalDecoding :: Assertion
633+bigRationalDecoding =
634+ assertEqual "Decoding an Integer with a large exponent should fail"
635+ (Left "Error in $: parsing Ratio failed, found a number with exponent 2000, but it must not be greater than 1024 or less than -1024")
636+ ((eitherDecode :: L.ByteString -> Either String Rational) "1e2000")
637+
638+smallRationalDecoding :: Assertion
639+smallRationalDecoding =
640+ assertEqual "Decoding an Integer with a large exponent should fail"
641+ (Left "Error in $: parsing Ratio failed, found a number with exponent -2000, but it must not be greater than 1024 or less than -1024")
642+ ((eitherDecode :: L.ByteString -> Either String Rational) "1e-2000")
643+
644+
623645bigScientificExponent :: Assertion
624646bigScientificExponent =
625647 assertEqual "Encoding an integral scientific with a large exponent should normalize it"