2015-04-20 02:39:58 +00:00
|
|
|
module Data.HexStringSpec where
|
|
|
|
|
|
|
|
import Data.HexString
|
|
|
|
|
2015-04-20 06:25:01 +00:00
|
|
|
import qualified Data.ByteString.Lazy.Char8 as BSL8
|
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
|
|
|
|
describe "when decoding hex data" $ do
|
|
|
|
it "should be able to parse basic hex data" $ do
|
2015-04-20 06:25:01 +00:00
|
|
|
(B.encode . decodeByteString) (BSL8.pack "ffff") `shouldBe` BSL8.pack "\255\255"
|
|
|
|
(B.encode . decodeString) "ffff" `shouldBe` BSL8.pack "\255\255"
|
|
|
|
(B.encode . decodeText) (T.pack "ffff") `shouldBe` BSL8.pack "\255\255"
|
2015-04-20 02:39:58 +00:00
|
|
|
|
|
|
|
it "should be able to recode basic hex data to different formats" $
|
2015-04-20 06:25:01 +00:00
|
|
|
let hex = BSL8.pack "ffff"
|
2015-04-20 02:39:58 +00:00
|
|
|
in do
|
|
|
|
(encodeText . decodeByteString) hex `shouldBe` T.pack "ffff"
|
|
|
|
(encodeString . decodeByteString) hex `shouldBe` "ffff"
|
2015-04-20 06:25:01 +00:00
|
|
|
(encodeByteString . decodeByteString) hex `shouldBe` BSL8.pack "ffff"
|