diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-09-27 01:18:30 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-09-27 01:18:30 +0400 |
commit | 623179f92f82761f5c783a3193f24713916b024f (patch) | |
tree | f12752e5166ed6e50768a78973161b346fa27f65 /tests/Data/ByteString/Base32/HexSpec.hs | |
parent | cc321b3ae254db365ab105f48305f9e427b1486d (diff) |
Added spec for base32hex
Diffstat (limited to 'tests/Data/ByteString/Base32/HexSpec.hs')
-rw-r--r-- | tests/Data/ByteString/Base32/HexSpec.hs | 47 |
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 #-} | ||
2 | module Data.ByteString.Base32.HexSpec ( spec ) where | ||
3 | |||
4 | import Control.Applicative | ||
5 | import Control.Exception | ||
6 | import Data.ByteString as BS | ||
7 | import Data.ByteString.Char8 as BC | ||
8 | import Data.ByteString.Base32.Hex | ||
9 | import Data.Char | ||
10 | import Test.Hspec | ||
11 | import Test.QuickCheck | ||
12 | |||
13 | |||
14 | instance Arbitrary ByteString where | ||
15 | arbitrary = BS.pack <$> arbitrary | ||
16 | |||
17 | spec :: Spec | ||
18 | spec = 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 | ||