summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/Data/ByteString/Base32/HexSpec.hs47
1 files changed, 47 insertions, 0 deletions
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 @@
1{-# OPTIONS -fno-warn-orphans #-}
2module Data.ByteString.Base32.HexSpec ( spec ) where
3
4import Control.Applicative
5import Control.Exception
6import Data.ByteString as BS
7import Data.ByteString.Char8 as BC
8import Data.ByteString.Base32.Hex
9import Data.Char
10import Test.Hspec
11import Test.QuickCheck
12
13
14instance Arbitrary ByteString where
15 arbitrary = BS.pack <$> arbitrary
16
17spec :: Spec
18spec = do
19 describe "encode" $ do
20 it "conform rfc examples" $ do
21 encode "" `shouldBe` ""
22 encode "f" `shouldBe` "CO======"
23 encode "fo" `shouldBe` "CPNG===="
24 encode "foo" `shouldBe` "CPNMU==="
25 encode "foob" `shouldBe` "CPNMUOG="
26 encode "fooba" `shouldBe` "CPNMUOJ1"
27 encode "foobar" `shouldBe` "CPNMUOJ1E8======"
28
29 describe "decode" $ do
30 it "conform rfc examples" $ do
31 decode "" `shouldBe` ""
32 decode "CO======" `shouldBe` "f"
33 decode "CPNG====" `shouldBe` "fo"
34 decode "CPNMU===" `shouldBe` "foo"
35 decode "CPNMUOG=" `shouldBe` "foob"
36 decode "CPNMUOJ1" `shouldBe` "fooba"
37 decode "CPNMUOJ1E8======" `shouldBe` "foobar"
38
39 it "inverse for encode" $ property $ \bs ->
40 decode (encode bs) == bs
41
42 it "case insensitive" $ property $ \bs ->
43 decode (BC.map toLower (encode bs)) == bs
44
45 it "fail gracefully if encoded data contains non alphabet chars" $ do
46 evaluate (decode "#=======") `shouldThrow` anyErrorCall
47 evaluate (decode "AAAAAAAA#=======") `shouldThrow` anyErrorCall