From 623179f92f82761f5c783a3193f24713916b024f Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Fri, 27 Sep 2013 01:18:30 +0400 Subject: Added spec for base32hex --- tests/Data/ByteString/Base32/HexSpec.hs | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/Data/ByteString/Base32/HexSpec.hs diff --git a/tests/Data/ByteString/Base32/HexSpec.hs b/tests/Data/ByteString/Base32/HexSpec.hs new file mode 100644 index 0000000..4e41d09 --- /dev/null +++ b/tests/Data/ByteString/Base32/HexSpec.hs @@ -0,0 +1,47 @@ +{-# OPTIONS -fno-warn-orphans #-} +module Data.ByteString.Base32.HexSpec ( spec ) where + +import Control.Applicative +import Control.Exception +import Data.ByteString as BS +import Data.ByteString.Char8 as BC +import Data.ByteString.Base32.Hex +import Data.Char +import Test.Hspec +import Test.QuickCheck + + +instance Arbitrary ByteString where + arbitrary = BS.pack <$> arbitrary + +spec :: Spec +spec = do + describe "encode" $ do + it "conform rfc examples" $ do + encode "" `shouldBe` "" + encode "f" `shouldBe` "CO======" + encode "fo" `shouldBe` "CPNG====" + encode "foo" `shouldBe` "CPNMU===" + encode "foob" `shouldBe` "CPNMUOG=" + encode "fooba" `shouldBe` "CPNMUOJ1" + encode "foobar" `shouldBe` "CPNMUOJ1E8======" + + describe "decode" $ do + it "conform rfc examples" $ do + decode "" `shouldBe` "" + decode "CO======" `shouldBe` "f" + decode "CPNG====" `shouldBe` "fo" + decode "CPNMU===" `shouldBe` "foo" + decode "CPNMUOG=" `shouldBe` "foob" + decode "CPNMUOJ1" `shouldBe` "fooba" + decode "CPNMUOJ1E8======" `shouldBe` "foobar" + + it "inverse for encode" $ property $ \bs -> + decode (encode bs) == bs + + it "case insensitive" $ property $ \bs -> + decode (BC.map toLower (encode bs)) == bs + + it "fail gracefully if encoded data contains non alphabet chars" $ do + evaluate (decode "#=======") `shouldThrow` anyErrorCall + evaluate (decode "AAAAAAAA#=======") `shouldThrow` anyErrorCall -- cgit v1.2.3