2015-04-20 02:39:58 +00:00
|
|
|
module Data.HexStringSpec where
|
|
|
|
|
2015-04-20 09:26:56 +00:00
|
|
|
import Data.HexString ( hexString
|
|
|
|
, toHex
|
|
|
|
, fromHex
|
|
|
|
, asText )
|
2015-04-20 02:39:58 +00:00
|
|
|
|
2015-04-20 09:26:56 +00:00
|
|
|
import qualified Data.ByteString as BS
|
|
|
|
import qualified Data.ByteString.Char8 as BS8
|
2015-04-20 02:39:58 +00:00
|
|
|
import qualified Data.Text as T
|
|
|
|
|
2015-04-20 06:25:01 +00:00
|
|
|
import qualified Data.Binary as B ( encode )
|
|
|
|
|
2015-04-20 02:39:58 +00:00
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
2015-04-20 09:26:56 +00:00
|
|
|
describe "when constructing a hex string" $ do
|
|
|
|
it "should accept strings that fall within a valid range" $
|
|
|
|
hexString (BS8.pack "0123456789abcdef") `shouldBe` hexString (BS8.pack "0123456789abcdef")
|
2015-04-20 02:39:58 +00:00
|
|
|
|
2015-04-20 09:26:56 +00:00
|
|
|
it "should reject strings outside the range" $ do
|
|
|
|
putStrLn (show (hexString (BS8.pack "/"))) `shouldThrow` anyErrorCall
|
|
|
|
putStrLn (show (hexString (BS8.pack ":"))) `shouldThrow` anyErrorCall
|
|
|
|
putStrLn (show (hexString (BS8.pack "`"))) `shouldThrow` anyErrorCall
|
|
|
|
putStrLn (show (hexString (BS8.pack "g"))) `shouldThrow` anyErrorCall
|