packages feed

base32-bytestring 0.2.0.0 → 0.2.0.1

raw patch · 4 files changed

+149/−3 lines, 4 files

Files

ChangeLog view
@@ -1,5 +1,9 @@ 2013-11-29  Sam Truzjan  <pxqr.sta@gmail.com> +	* 0.2.0.1: Add tests to tarball.++2013-11-29  Sam Truzjan  <pxqr.sta@gmail.com>+ 	* 0.2.0.0: Allow to catch decoding errors in pure code.  2013-10-31  Sam Truzjan  <pxqr.sta@gmail.com>
base32-bytestring.cabal view
@@ -1,5 +1,5 @@ name:                base32-bytestring-version:             0.2.0.0+version:             0.2.0.1 license:             BSD3 license-file:        LICENSE author:              Sam Truzjan@@ -29,14 +29,14 @@   type:                git   location:            git://github.com/pxqr/base32-bytestring.git   branch:              master-  tag:                 v0.2.0.0+  tag:                 v0.2.0.1  library   default-language:    Haskell2010   default-extensions:   hs-source-dirs:      src   exposed-modules:     Data.ByteString.Base32-                     , Data.ByteString.Base32.Hex+                       Data.ByteString.Base32.Hex   other-modules:       Data.ByteString.Base32.Internal   build-depends:       base        == 4.*                      , bytestring  >= 0.9@@ -50,6 +50,8 @@   type:                exitcode-stdio-1.0   hs-source-dirs:      tests   main-is:             Spec.hs+  other-modules:       Data.ByteString.Base32Spec+                       Data.ByteString.Base32.HexSpec   build-depends:       base   == 4.*                      , base32-bytestring                      , bytestring
+ tests/Data/ByteString/Base32/HexSpec.hs view
@@ -0,0 +1,67 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS -fno-warn-orphans #-}+module Data.ByteString.Base32.HexSpec ( spec ) where++import Control.Applicative+import Data.ByteString as BS+import Data.ByteString.Char8 as BC+import Data.ByteString.Base32.Hex+import Data.Char+import Test.Hspec+import Test.QuickCheck+++instance Arbitrary ByteString where+  arbitrary = BS.pack <$> arbitrary++spec :: Spec+spec = do+  describe "encode" $ do+    it "conform rfc examples" $ do+      encode ""         `shouldBe` ""+      encode "f"        `shouldBe` "CO======"+      encode "fo"       `shouldBe` "CPNG===="+      encode "foo"      `shouldBe` "CPNMU==="+      encode "foob"     `shouldBe` "CPNMUOG="+      encode "fooba"    `shouldBe` "CPNMUOJ1"+      encode "foobar"   `shouldBe` "CPNMUOJ1E8======"++  describe "decode" $ do+    it "conform rfc examples" $ do+      decode ""         `shouldBe` Right ""+      decode "CO======" `shouldBe` Right "f"+      decode "CPNG====" `shouldBe` Right "fo"+      decode "CPNMU===" `shouldBe` Right "foo"+      decode "CPNMUOG=" `shouldBe` Right "foob"+      decode "CPNMUOJ1" `shouldBe` Right "fooba"+      decode "CPNMUOJ1E8======" `shouldBe` Right "foobar"++    it "inverse for encode" $ property $ \bs ->+      decode (encode bs) == Right bs++    it "case insensitive" $ property $ \bs ->+      decode (BC.map toLower (encode bs)) == Right bs++    it "fail gracefully if encoded data contains non alphabet chars" $ do+      decode "#======="         `shouldBe` Left "'#' is not base32 character"+      decode "AAAAAAAA#=======" `shouldBe` Left "'#' is not base32 character"++  describe "decodeLenient" $ do+    it "conform RFC examples" $ do+      decode ""         `shouldBe` Right ""+      decode "CO======" `shouldBe` Right "f"+      decode "CPNG====" `shouldBe` Right "fo"+      decode "CPNMU===" `shouldBe` Right "foo"+      decode "CPNMUOG=" `shouldBe` Right "foob"+      decode "CPNMUOJ1" `shouldBe` Right "fooba"+      decode "CPNMUOJ1E8======" `shouldBe` Right "foobar"++    it "inverse for encode" $ property $ \bs ->+      decodeLenient (encode bs) == Right bs++    it "case insensitive" $ property $ \bs ->+      decodeLenient (BC.map toLower (encode bs)) == Right bs++    it "skip non alphabet chars" $ do+      decodeLenient "|"   `shouldBe` Right ""+      decodeLenient "C|O" `shouldBe` Right "f"
+ tests/Data/ByteString/Base32Spec.hs view
@@ -0,0 +1,73 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS -fno-warn-orphans #-}+module Data.ByteString.Base32Spec (spec) where++import Control.Applicative+import Data.ByteString as BS+import Data.ByteString.Char8 as BC+import Data.ByteString.Base32 as Base32+import Data.Char+import Test.Hspec+import Test.QuickCheck+++instance Arbitrary ByteString where+  arbitrary = BS.pack <$> arbitrary++spec :: Spec+spec = do+  describe "encode" $ do+    it "conform RFC examples" $ do+      encode ""       `shouldBe` ""+      encode "f"      `shouldBe` "MY======"+      encode "fo"     `shouldBe` "MZXQ===="+      encode "foo"    `shouldBe` "MZXW6==="+      encode "foob"   `shouldBe` "MZXW6YQ="+      encode "fooba"  `shouldBe` "MZXW6YTB"+      encode "foobar" `shouldBe` "MZXW6YTBOI======"++    it "size always multiple of 8 bytes" $ property $ \bs ->+      (BS.length (encode bs) `rem` 8) `shouldBe` 0++    it "padding less than 8 bytes" $ property $ \bs ->+      BC.count '=' bs `shouldSatisfy` (< 8)++  describe "decode" $ do+    it "conform RFC examples" $ do+      decode ""                 `shouldBe` Right ""+      decode "MY======"         `shouldBe` Right "f"+      decode "MZXQ===="         `shouldBe` Right "fo"+      decode  "MZXW6==="        `shouldBe` Right "foo"+      decode "MZXW6YQ="         `shouldBe` Right "foob"+      decode "MZXW6YTB"         `shouldBe` Right "fooba"+      decode "MZXW6YTBOI======" `shouldBe` Right "foobar"++    it "inverse for encode" $ property $ \bs ->+      decode (encode bs) == Right bs++    it "case insensitive" $ property $ \bs ->+      decode (BC.map toLower (encode bs)) == Right bs++    it "fail gracefully if encoded data contains non alphabet chars" $ do+      decode "0======="         `shouldBe` Left "'0' is not base32 character"+      decode "AAAAAAAA0=======" `shouldBe` Left "'0' is not base32 character"++  describe "decodeLenient" $ do+    it "conform RFC examples" $ do+      decodeLenient ""                 `shouldBe` Right ""+      decodeLenient "MY======"         `shouldBe` Right "f"+      decodeLenient "MZXQ===="         `shouldBe` Right "fo"+      decodeLenient  "MZXW6==="        `shouldBe` Right "foo"+      decodeLenient "MZXW6YQ="         `shouldBe` Right "foob"+      decodeLenient "MZXW6YTB"         `shouldBe` Right "fooba"+      decodeLenient "MZXW6YTBOI======" `shouldBe` Right "foobar"++    it "inverse for encode" $ property $ \bs ->+      decodeLenient (encode bs) == Right bs++    it "case insensitive" $ property $ \bs ->+      decodeLenient (BC.map toLower (encode bs)) == Right bs++    it "skip non alphabet chars" $ do+      decodeLenient "|"   `shouldBe` Right ""+      decodeLenient "M|Y" `shouldBe` Right "f"