diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-10-04 13:15:57 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-10-04 13:15:57 +0400 |
commit | 2534b8aff490a9e38e927ffc77d0a2e37c17db77 (patch) | |
tree | aa8246ab665c6b522ccd1832338bb535e77905a3 /tests | |
parent | 4a5926d07371144df8147e6bb71f878df327ac8a (diff) |
Add spec for lenient decoding
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Data/ByteString/Base32/HexSpec.hs | 20 | ||||
-rw-r--r-- | tests/Data/ByteString/Base32Spec.hs | 20 |
2 files changed, 39 insertions, 1 deletions
diff --git a/tests/Data/ByteString/Base32/HexSpec.hs b/tests/Data/ByteString/Base32/HexSpec.hs index 4e41d09..3a04b09 100644 --- a/tests/Data/ByteString/Base32/HexSpec.hs +++ b/tests/Data/ByteString/Base32/HexSpec.hs | |||
@@ -45,3 +45,23 @@ spec = do | |||
45 | it "fail gracefully if encoded data contains non alphabet chars" $ do | 45 | it "fail gracefully if encoded data contains non alphabet chars" $ do |
46 | evaluate (decode "#=======") `shouldThrow` anyErrorCall | 46 | evaluate (decode "#=======") `shouldThrow` anyErrorCall |
47 | evaluate (decode "AAAAAAAA#=======") `shouldThrow` anyErrorCall | 47 | evaluate (decode "AAAAAAAA#=======") `shouldThrow` anyErrorCall |
48 | |||
49 | describe "decodeLenient" $ do | ||
50 | it "conform RFC examples" $ do | ||
51 | decodeLenient "" `shouldBe` "" | ||
52 | decodeLenient "MY======" `shouldBe` "f" | ||
53 | decodeLenient "MZXQ====" `shouldBe` "fo" | ||
54 | decodeLenient "MZXW6===" `shouldBe` "foo" | ||
55 | decodeLenient "MZXW6YQ=" `shouldBe` "foob" | ||
56 | decodeLenient "MZXW6YTB" `shouldBe` "fooba" | ||
57 | decodeLenient "MZXW6YTBOI======" `shouldBe` "foobar" | ||
58 | |||
59 | it "inverse for encode" $ property $ \bs -> | ||
60 | decodeLenient (encode bs) == bs | ||
61 | |||
62 | it "case insensitive" $ property $ \bs -> | ||
63 | decodeLenient (BC.map toLower (encode bs)) == bs | ||
64 | |||
65 | it "skip non alphabet chars" $ do | ||
66 | decodeLenient "|" `shouldBe` "" | ||
67 | decodeLenient "M|Y" `shouldBe` "f" | ||
diff --git a/tests/Data/ByteString/Base32Spec.hs b/tests/Data/ByteString/Base32Spec.hs index 66df53a..148539a 100644 --- a/tests/Data/ByteString/Base32Spec.hs +++ b/tests/Data/ByteString/Base32Spec.hs | |||
@@ -52,4 +52,22 @@ spec = do | |||
52 | evaluate (decode "0=======") `shouldThrow` anyErrorCall | 52 | evaluate (decode "0=======") `shouldThrow` anyErrorCall |
53 | evaluate (decode "AAAAAAAA0=======") `shouldThrow` anyErrorCall | 53 | evaluate (decode "AAAAAAAA0=======") `shouldThrow` anyErrorCall |
54 | 54 | ||
55 | -- describe "decodeLenient" $ do | 55 | describe "decodeLenient" $ do |
56 | it "conform RFC examples" $ do | ||
57 | decodeLenient "" `shouldBe` "" | ||
58 | decodeLenient "MY======" `shouldBe` "f" | ||
59 | decodeLenient "MZXQ====" `shouldBe` "fo" | ||
60 | decodeLenient "MZXW6===" `shouldBe` "foo" | ||
61 | decodeLenient "MZXW6YQ=" `shouldBe` "foob" | ||
62 | decodeLenient "MZXW6YTB" `shouldBe` "fooba" | ||
63 | decodeLenient "MZXW6YTBOI======" `shouldBe` "foobar" | ||
64 | |||
65 | it "inverse for encode" $ property $ \bs -> | ||
66 | decodeLenient (encode bs) == bs | ||
67 | |||
68 | it "case insensitive" $ property $ \bs -> | ||
69 | decodeLenient (BC.map toLower (encode bs)) == bs | ||
70 | |||
71 | it "skip non alphabet chars" $ do | ||
72 | decodeLenient "|" `shouldBe` "" | ||
73 | decodeLenient "M|Y" `shouldBe` "f" | ||