diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-09-26 20:58:11 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-09-26 20:58:11 +0400 |
commit | 4756424235c5222a832e1967d54c5ddb369f6fbf (patch) | |
tree | e5683c8d3cf0fbdb04cea29d38ead37aa97a2b8f /tests |
Initial commit
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Data/ByteString/Base32Spec.hs | 46 | ||||
-rw-r--r-- | tests/Spec.hs | 1 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/Data/ByteString/Base32Spec.hs b/tests/Data/ByteString/Base32Spec.hs new file mode 100644 index 0000000..3c646e2 --- /dev/null +++ b/tests/Data/ByteString/Base32Spec.hs | |||
@@ -0,0 +1,46 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | module Data.ByteString.Base32Spec (spec) where | ||
3 | |||
4 | import Control.Applicative | ||
5 | import Data.ByteString as BS | ||
6 | import Data.ByteString.Internal as BS | ||
7 | import Data.ByteString.Base32 as Base32 | ||
8 | import Test.Hspec | ||
9 | import Test.QuickCheck | ||
10 | |||
11 | |||
12 | instance Arbitrary ByteString where | ||
13 | arbitrary = BS.pack <$> arbitrary | ||
14 | |||
15 | spec :: Spec | ||
16 | spec = do | ||
17 | describe "encode" $ do | ||
18 | it "conform RFC examples" $ do | ||
19 | encode "" `shouldBe` "" | ||
20 | encode "f" `shouldBe` "MY======" | ||
21 | encode "fo" `shouldBe` "MZXQ====" | ||
22 | encode "foo" `shouldBe` "MZXW6===" | ||
23 | encode "foob" `shouldBe` "MZXW6YQ=" | ||
24 | encode "fooba" `shouldBe` "MZXW6YTB" | ||
25 | encode "foobar" `shouldBe` "MZXW6YTBOI======" | ||
26 | |||
27 | it "size always multiple of 8 bytes" $ property $ \bs -> | ||
28 | (BS.length (encode bs) `rem` 8) `shouldBe` 0 | ||
29 | |||
30 | it "padding less than" $ property $ \bs -> | ||
31 | count (c2w '=') bs `shouldSatisfy` (< 8) | ||
32 | |||
33 | describe "decode" $ do | ||
34 | it "conform RFC examples" $ do | ||
35 | decode "" `shouldBe` "" | ||
36 | decode "MY======" `shouldBe` "f" | ||
37 | decode "MZXQ====" `shouldBe` "fo" | ||
38 | decode "MZXW6===" `shouldBe` "foo" | ||
39 | decode "MZXW6YQ=" `shouldBe` "foob" | ||
40 | decode "MZXW6YTB" `shouldBe` "fooba" | ||
41 | decode "MZXW6YTBOI======" `shouldBe` "foobar" | ||
42 | |||
43 | it "inverse for encode" $ property $ \bs -> | ||
44 | decode (encode bs) == bs | ||
45 | |||
46 | -- describe "decodeLenient" $ do | ||
diff --git a/tests/Spec.hs b/tests/Spec.hs new file mode 100644 index 0000000..52ef578 --- /dev/null +++ b/tests/Spec.hs | |||
@@ -0,0 +1 @@ | |||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} \ No newline at end of file | |||