From 13dc0f086d3d8f217a2818a429ac117c97397e9b Mon Sep 17 00:00:00 2001 From: Sam T Date: Thu, 26 Sep 2013 22:39:29 +0400 Subject: Make decode case insensitive. > 6. Base 32 Encoding > > The Base 32 encoding is designed to represent arbitrary sequences of > octets in a form that _needs to be case insensitive_ but that need not > be human readable. --- tests/Data/ByteString/Base32Spec.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/Data/ByteString/Base32Spec.hs b/tests/Data/ByteString/Base32Spec.hs index ff3e13c..60e340c 100644 --- a/tests/Data/ByteString/Base32Spec.hs +++ b/tests/Data/ByteString/Base32Spec.hs @@ -4,8 +4,9 @@ module Data.ByteString.Base32Spec (spec) where import Control.Applicative import Control.Exception import Data.ByteString as BS -import Data.ByteString.Internal as BS +import Data.ByteString.Char8 as BC import Data.ByteString.Base32 as Base32 +import Data.Char import Test.Hspec import Test.QuickCheck @@ -29,7 +30,7 @@ spec = do (BS.length (encode bs) `rem` 8) `shouldBe` 0 it "padding less than" $ property $ \bs -> - count (c2w '=') bs `shouldSatisfy` (< 8) + BC.count '=' bs `shouldSatisfy` (< 8) describe "decode" $ do it "conform RFC examples" $ do @@ -44,6 +45,9 @@ spec = do it "inverse for encode" $ property $ \bs -> decode (encode bs) == bs + it "case insensitive" $ property $ \bs -> + decode (BC.map toLower (encode bs)) == bs + it "fail gracefully if encoded data contains non alphabet chars" $ do evaluate (decode "0=======") `shouldThrow` anyErrorCall evaluate (decode "AAAAAAAA0=======") `shouldThrow` anyErrorCall -- cgit v1.2.3