summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-09-26 20:58:11 +0400
committerSam T <pxqr.sta@gmail.com>2013-09-26 20:58:11 +0400
commit4756424235c5222a832e1967d54c5ddb369f6fbf (patch)
treee5683c8d3cf0fbdb04cea29d38ead37aa97a2b8f /tests
Initial commit
Diffstat (limited to 'tests')
-rw-r--r--tests/Data/ByteString/Base32Spec.hs46
-rw-r--r--tests/Spec.hs1
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 #-}
2module Data.ByteString.Base32Spec (spec) where
3
4import Control.Applicative
5import Data.ByteString as BS
6import Data.ByteString.Internal as BS
7import Data.ByteString.Base32 as Base32
8import Test.Hspec
9import Test.QuickCheck
10
11
12instance Arbitrary ByteString where
13 arbitrary = BS.pack <$> arbitrary
14
15spec :: Spec
16spec = 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