summaryrefslogtreecommitdiff
path: root/tests/Data/ByteString/Base32Spec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Data/ByteString/Base32Spec.hs')
-rw-r--r--tests/Data/ByteString/Base32Spec.hs41
1 files changed, 21 insertions, 20 deletions
diff --git a/tests/Data/ByteString/Base32Spec.hs b/tests/Data/ByteString/Base32Spec.hs
index 148539a..4cec8f9 100644
--- a/tests/Data/ByteString/Base32Spec.hs
+++ b/tests/Data/ByteString/Base32Spec.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# OPTIONS -fno-warn-orphans #-} 2{-# OPTIONS -fno-warn-orphans #-}
2module Data.ByteString.Base32Spec (spec) where 3module Data.ByteString.Base32Spec (spec) where
3 4
@@ -34,19 +35,19 @@ spec = do
34 35
35 describe "decode" $ do 36 describe "decode" $ do
36 it "conform RFC examples" $ do 37 it "conform RFC examples" $ do
37 decode "" `shouldBe` "" 38 decode "" `shouldBe` Right ""
38 decode "MY======" `shouldBe` "f" 39 decode "MY======" `shouldBe` Right "f"
39 decode "MZXQ====" `shouldBe` "fo" 40 decode "MZXQ====" `shouldBe` Right "fo"
40 decode "MZXW6===" `shouldBe` "foo" 41 decode "MZXW6===" `shouldBe` Right "foo"
41 decode "MZXW6YQ=" `shouldBe` "foob" 42 decode "MZXW6YQ=" `shouldBe` Right "foob"
42 decode "MZXW6YTB" `shouldBe` "fooba" 43 decode "MZXW6YTB" `shouldBe` Right "fooba"
43 decode "MZXW6YTBOI======" `shouldBe` "foobar" 44 decode "MZXW6YTBOI======" `shouldBe` Right "foobar"
44 45
45 it "inverse for encode" $ property $ \bs -> 46 it "inverse for encode" $ property $ \bs ->
46 decode (encode bs) == bs 47 decode (encode bs) == Right bs
47 48
48 it "case insensitive" $ property $ \bs -> 49 it "case insensitive" $ property $ \bs ->
49 decode (BC.map toLower (encode bs)) == bs 50 decode (BC.map toLower (encode bs)) == Right bs
50 51
51 it "fail gracefully if encoded data contains non alphabet chars" $ do 52 it "fail gracefully if encoded data contains non alphabet chars" $ do
52 evaluate (decode "0=======") `shouldThrow` anyErrorCall 53 evaluate (decode "0=======") `shouldThrow` anyErrorCall
@@ -54,20 +55,20 @@ spec = do
54 55
55 describe "decodeLenient" $ do 56 describe "decodeLenient" $ do
56 it "conform RFC examples" $ do 57 it "conform RFC examples" $ do
57 decodeLenient "" `shouldBe` "" 58 decodeLenient "" `shouldBe` Right ""
58 decodeLenient "MY======" `shouldBe` "f" 59 decodeLenient "MY======" `shouldBe` Right "f"
59 decodeLenient "MZXQ====" `shouldBe` "fo" 60 decodeLenient "MZXQ====" `shouldBe` Right "fo"
60 decodeLenient "MZXW6===" `shouldBe` "foo" 61 decodeLenient "MZXW6===" `shouldBe` Right "foo"
61 decodeLenient "MZXW6YQ=" `shouldBe` "foob" 62 decodeLenient "MZXW6YQ=" `shouldBe` Right "foob"
62 decodeLenient "MZXW6YTB" `shouldBe` "fooba" 63 decodeLenient "MZXW6YTB" `shouldBe` Right "fooba"
63 decodeLenient "MZXW6YTBOI======" `shouldBe` "foobar" 64 decodeLenient "MZXW6YTBOI======" `shouldBe` Right "foobar"
64 65
65 it "inverse for encode" $ property $ \bs -> 66 it "inverse for encode" $ property $ \bs ->
66 decodeLenient (encode bs) == bs 67 decodeLenient (encode bs) == Right bs
67 68
68 it "case insensitive" $ property $ \bs -> 69 it "case insensitive" $ property $ \bs ->
69 decodeLenient (BC.map toLower (encode bs)) == bs 70 decodeLenient (BC.map toLower (encode bs)) == Right bs
70 71
71 it "skip non alphabet chars" $ do 72 it "skip non alphabet chars" $ do
72 decodeLenient "|" `shouldBe` "" 73 decodeLenient "|" `shouldBe` Right ""
73 decodeLenient "M|Y" `shouldBe` "f" 74 decodeLenient "M|Y" `shouldBe` Right "f"