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/Data/ByteString/Base32 | |
parent | 4a5926d07371144df8147e6bb71f878df327ac8a (diff) |
Add spec for lenient decoding
Diffstat (limited to 'tests/Data/ByteString/Base32')
-rw-r--r-- | tests/Data/ByteString/Base32/HexSpec.hs | 20 |
1 files changed, 20 insertions, 0 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" | ||