28 lines
1.1 KiB
Haskell
28 lines
1.1 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Data.HexStringSpec where
|
|
|
|
import Data.HexString (fromRawBytes, fromText, hexString, toBytes, toText)
|
|
|
|
import qualified Data.ByteString.Char8 as BS8
|
|
|
|
import Test.Hspec
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
describe "when constructing a hex string" $ do
|
|
it "should reject strings outside the range" $ do
|
|
print (hexString (BS8.pack "/")) `shouldThrow` anyErrorCall
|
|
print (hexString (BS8.pack ":")) `shouldThrow` anyErrorCall
|
|
print (hexString (BS8.pack "`")) `shouldThrow` anyErrorCall
|
|
print (hexString (BS8.pack "g")) `shouldThrow` anyErrorCall
|
|
describe "when interpreting a hex string" $ do
|
|
it "should convert the hex string properly when interpreting as bytes" $
|
|
toBytes (hexString "ffff") `shouldBe` BS8.pack "\255\255"
|
|
it "should convert bytes to the proper hex string" $
|
|
fromRawBytes (BS8.pack "\255\255") `shouldBe` hexString (BS8.pack "ffff")
|
|
it "should convert the hex string to text" $
|
|
toText (hexString "ffff") `shouldBe` "ffff"
|
|
it "should read text into the hex string" $
|
|
fromText "ffff" `shouldBe` hexString (BS8.pack "ffff")
|