1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 02:14:20 +03:00
semantic/test/Numeric/Spec.hs
Patrick Thomson f9f0dd5e79 Use a hand-written integer parser.
Rather than relying on the `Read` instance for `Integer`, let's make
our assumptions about the format explicit. This was mostly a matter of
extracting internal functions from the `Scientific` parser.
2018-06-25 11:55:32 -04:00

39 lines
910 B
Haskell

module Numeric.Spec
( spec
) where
import SpecHelpers
import Data.Either
import Numeric.Exts
spec :: Spec
spec = describe "Integer parsing" $ do
let go cases = forM_ cases $ \(s, v) -> parseInteger s `shouldBe` Right v
it "should handle Python integers" $
go [ ("-1", (negate 1))
, ("0xDEAD", 0xDEAD)
, ("0XDEAD", 0xDEAD)
, ("1j", 1)
, ("0o123", 83)
, ("0O123", 83)
, ("0b001", 1)
, ("0B001", 1)
, ("1_1", 11) -- underscore syntax is Python 3 only
, ("0B1_1", 3)
, ("0O1_1", 9)
, ("0L", 0)
]
it "should handle Ruby integers" $
go [ ("0xa_bcd_ef0_123_456_789", 0xabcdef0123456789)
, ("01234567", 342391)
]
it "should not accept floating-points" $ do
parseInteger "1.5" `shouldSatisfy` isLeft
it "should not accept the empty string" $ do
parseInteger "" `shouldSatisfy` isLeft