diff options
Diffstat (limited to 'tests/Data/ByteString')
-rw-r--r-- | tests/Data/ByteString/Base32/HexSpec.hs | 41 | ||||
-rw-r--r-- | tests/Data/ByteString/Base32Spec.hs | 41 |
2 files changed, 42 insertions, 40 deletions
diff --git a/tests/Data/ByteString/Base32/HexSpec.hs b/tests/Data/ByteString/Base32/HexSpec.hs index 2cdadef..7cddb69 100644 --- a/tests/Data/ByteString/Base32/HexSpec.hs +++ b/tests/Data/ByteString/Base32/HexSpec.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
1 | {-# OPTIONS -fno-warn-orphans #-} | 2 | {-# OPTIONS -fno-warn-orphans #-} |
2 | module Data.ByteString.Base32.HexSpec ( spec ) where | 3 | module Data.ByteString.Base32.HexSpec ( spec ) where |
3 | 4 | ||
@@ -28,19 +29,19 @@ spec = do | |||
28 | 29 | ||
29 | describe "decode" $ do | 30 | describe "decode" $ do |
30 | it "conform rfc examples" $ do | 31 | it "conform rfc examples" $ do |
31 | decode "" `shouldBe` "" | 32 | decode "" `shouldBe` Right "" |
32 | decode "CO======" `shouldBe` "f" | 33 | decode "CO======" `shouldBe` Right "f" |
33 | decode "CPNG====" `shouldBe` "fo" | 34 | decode "CPNG====" `shouldBe` Right "fo" |
34 | decode "CPNMU===" `shouldBe` "foo" | 35 | decode "CPNMU===" `shouldBe` Right "foo" |
35 | decode "CPNMUOG=" `shouldBe` "foob" | 36 | decode "CPNMUOG=" `shouldBe` Right "foob" |
36 | decode "CPNMUOJ1" `shouldBe` "fooba" | 37 | decode "CPNMUOJ1" `shouldBe` Right "fooba" |
37 | decode "CPNMUOJ1E8======" `shouldBe` "foobar" | 38 | decode "CPNMUOJ1E8======" `shouldBe` Right "foobar" |
38 | 39 | ||
39 | it "inverse for encode" $ property $ \bs -> | 40 | it "inverse for encode" $ property $ \bs -> |
40 | decode (encode bs) == bs | 41 | decode (encode bs) == Right bs |
41 | 42 | ||
42 | it "case insensitive" $ property $ \bs -> | 43 | it "case insensitive" $ property $ \bs -> |
43 | decode (BC.map toLower (encode bs)) == bs | 44 | decode (BC.map toLower (encode bs)) == Right bs |
44 | 45 | ||
45 | it "fail gracefully if encoded data contains non alphabet chars" $ do | 46 | it "fail gracefully if encoded data contains non alphabet chars" $ do |
46 | evaluate (decode "#=======") `shouldThrow` anyErrorCall | 47 | evaluate (decode "#=======") `shouldThrow` anyErrorCall |
@@ -48,20 +49,20 @@ spec = do | |||
48 | 49 | ||
49 | describe "decodeLenient" $ do | 50 | describe "decodeLenient" $ do |
50 | it "conform RFC examples" $ do | 51 | it "conform RFC examples" $ do |
51 | decode "" `shouldBe` "" | 52 | decode "" `shouldBe` Right "" |
52 | decode "CO======" `shouldBe` "f" | 53 | decode "CO======" `shouldBe` Right "f" |
53 | decode "CPNG====" `shouldBe` "fo" | 54 | decode "CPNG====" `shouldBe` Right "fo" |
54 | decode "CPNMU===" `shouldBe` "foo" | 55 | decode "CPNMU===" `shouldBe` Right "foo" |
55 | decode "CPNMUOG=" `shouldBe` "foob" | 56 | decode "CPNMUOG=" `shouldBe` Right "foob" |
56 | decode "CPNMUOJ1" `shouldBe` "fooba" | 57 | decode "CPNMUOJ1" `shouldBe` Right "fooba" |
57 | decode "CPNMUOJ1E8======" `shouldBe` "foobar" | 58 | decode "CPNMUOJ1E8======" `shouldBe` Right "foobar" |
58 | 59 | ||
59 | it "inverse for encode" $ property $ \bs -> | 60 | it "inverse for encode" $ property $ \bs -> |
60 | decodeLenient (encode bs) == bs | 61 | decodeLenient (encode bs) == Right bs |
61 | 62 | ||
62 | it "case insensitive" $ property $ \bs -> | 63 | it "case insensitive" $ property $ \bs -> |
63 | decodeLenient (BC.map toLower (encode bs)) == bs | 64 | decodeLenient (BC.map toLower (encode bs)) == Right bs |
64 | 65 | ||
65 | it "skip non alphabet chars" $ do | 66 | it "skip non alphabet chars" $ do |
66 | decodeLenient "|" `shouldBe` "" | 67 | decodeLenient "|" `shouldBe` Right "" |
67 | decodeLenient "C|O" `shouldBe` "f" | 68 | decodeLenient "C|O" `shouldBe` Right "f" |
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 #-} |
2 | module Data.ByteString.Base32Spec (spec) where | 3 | module 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" |