diff options
author | Sergei Trofimovich <slyfox@gentoo.org> | 2012-03-10 15:51:52 +0000 |
---|---|---|
committer | Sergei Trofimovich <slyfox@gentoo.org> | 2012-03-10 15:51:52 +0000 |
commit | 0cd1df0aae41f6e8e7fa5531f3b8c3862f8cc84e (patch) | |
tree | f3bbf868b8d78044747e09f5a0583082a8331b31 /dev-haskell | |
parent | Moving dev-php/php-codecoverage to dev-php/PHP_CodeCoverage (diff) | |
download | gentoo-2-0cd1df0aae41f6e8e7fa5531f3b8c3862f8cc84e.tar.gz gentoo-2-0cd1df0aae41f6e8e7fa5531f3b8c3862f8cc84e.tar.bz2 gentoo-2-0cd1df0aae41f6e8e7fa5531f3b8c3862f8cc84e.zip |
Initial version. Fast base64 encoding and deconding for ByteStrings for haskell. A depend for app-text/pandoc-1.9.
(Portage version: 2.2.0_alpha90_p1/cvs/Linux x86_64)
Diffstat (limited to 'dev-haskell')
-rw-r--r-- | dev-haskell/base64-bytestring/ChangeLog | 11 | ||||
-rw-r--r-- | dev-haskell/base64-bytestring/base64-bytestring-0.1.1.1.ebuild | 40 | ||||
-rw-r--r-- | dev-haskell/base64-bytestring/files/Tests.hs | 116 | ||||
-rw-r--r-- | dev-haskell/base64-bytestring/metadata.xml | 11 |
4 files changed, 178 insertions, 0 deletions
diff --git a/dev-haskell/base64-bytestring/ChangeLog b/dev-haskell/base64-bytestring/ChangeLog new file mode 100644 index 000000000000..80304c9dd83b --- /dev/null +++ b/dev-haskell/base64-bytestring/ChangeLog @@ -0,0 +1,11 @@ +# ChangeLog for dev-haskell/base64-bytestring +# Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2 +# $Header: /var/cvsroot/gentoo-x86/dev-haskell/base64-bytestring/ChangeLog,v 1.1 2012/03/10 15:51:52 slyfox Exp $ + +*base64-bytestring-0.1.1.1 (10 Mar 2012) + + 10 Mar 2012; Sergei Trofimovich <slyfox@gentoo.org> + +base64-bytestring-0.1.1.1.ebuild, +files/Tests.hs, +metadata.xml: + Initial version. Fast base64 encoding and deconding for ByteStrings for + haskell. A depend for app-text/pandoc-1.9. + diff --git a/dev-haskell/base64-bytestring/base64-bytestring-0.1.1.1.ebuild b/dev-haskell/base64-bytestring/base64-bytestring-0.1.1.1.ebuild new file mode 100644 index 000000000000..ec3d4ef02c61 --- /dev/null +++ b/dev-haskell/base64-bytestring/base64-bytestring-0.1.1.1.ebuild @@ -0,0 +1,40 @@ +# Copyright 1999-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/dev-haskell/base64-bytestring/base64-bytestring-0.1.1.1.ebuild,v 1.1 2012/03/10 15:51:52 slyfox Exp $ + +# ebuild generated by hackport 0.2.13 + +EAPI="3" + +CABAL_FEATURES="lib profile haddock hscolour hoogle" +inherit haskell-cabal + +DESCRIPTION="Fast base64 encoding and deconding for ByteStrings" +HOMEPAGE="https://github.com/bos/base64-bytestring" +SRC_URI="http://hackage.haskell.org/packages/archive/${PN}/${PV}/${P}.tar.gz" + +LICENSE="BSD" +SLOT="0" +KEYWORDS="~amd64 ~x86" +IUSE="test" + +RDEPEND=">=dev-lang/ghc-6.10.1" +DEPEND="${RDEPEND} + >=dev-haskell/cabal-1.8 + test? ( + dev-haskell/hunit + >=dev-haskell/quickcheck-2.4.0.1 + dev-haskell/test-framework + dev-haskell/test-framework-hunit + dev-haskell/test-framework-quickcheck2 + ) + " + +src_prepare() { + cp "${FILESDIR}/Tests.hs" tests \ + || die "Could not copy missing Tests.hs" +} + +src_configure() { + cabal_src_configure $(use test && use_enable test tests) #395351 +} diff --git a/dev-haskell/base64-bytestring/files/Tests.hs b/dev-haskell/base64-bytestring/files/Tests.hs new file mode 100644 index 000000000000..da661f52382f --- /dev/null +++ b/dev-haskell/base64-bytestring/files/Tests.hs @@ -0,0 +1,116 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Main (main) where + +import Test.Framework (Test, defaultMain, testGroup) +import Test.Framework.Providers.QuickCheck2 (testProperty) +import Test.Framework.Providers.HUnit (testCase) + +import Test.QuickCheck (Arbitrary(..)) + +import Control.Monad (liftM) +import qualified Data.ByteString.Base64 as Base64 +import qualified Data.ByteString.Base64.URL as Base64URL +import Data.ByteString (ByteString) +import Data.ByteString.Char8 () +import qualified Data.ByteString as B +import Test.HUnit hiding (Test) + + +main :: IO () +main = defaultMain tests + +tests :: [Test] +tests = [ + testGroup "Base64" [ + testProperty "decodeEncode" $ + genericDecodeEncode Base64.encode Base64.decode + , testProperty "decodeEncode Lenient" $ + genericDecodeEncode Base64.encode + (liftM Right Base64.decodeLenient) + , testGroup "base64-string tests" base64_string_tests + ] + , testGroup "Base64URL" [ + testProperty "decodeEncode" $ + genericDecodeEncode Base64URL.encode Base64URL.decode + , testProperty "decodeEncode Lenient" $ + genericDecodeEncode Base64URL.encode + (liftM Right Base64URL.decodeLenient) + , testGroup "base64-string tests" base64url_string_tests + ] + ] + +instance Arbitrary ByteString where + arbitrary = liftM B.pack arbitrary + +-- | Decoding an encoded sintrg should produce the original string. +genericDecodeEncode :: (ByteString -> ByteString) + -> (ByteString -> Either String ByteString) + -> ByteString -> Bool +genericDecodeEncode enc dec x = case dec (enc x) of + Left _ -> False + Right x' -> x == x' + +-- +-- Unit tests from base64-string +-- Copyright (c) Ian Lynagh, 2005, 2007. +-- + +base64_string_tests :: [Test] +base64_string_tests = + base64_string_test Base64.encode Base64.decode testData ++ + base64_string_test Base64.encode decodeURL testData + where decodeURL :: ByteString -> Either String ByteString + decodeURL = liftM Right Base64.decodeLenient + testData :: [(ByteString, ByteString)] + testData = [("", "") + ,("\0", "AA==") + ,("\255", "/w==") + ,("E", "RQ==") + ,("Ex", "RXg=") + ,("Exa", "RXhh") + ,("Exam", "RXhhbQ==") + ,("Examp", "RXhhbXA=") + ,("Exampl", "RXhhbXBs") + ,("Example", "RXhhbXBsZQ==") + ,("Ex\0am\254ple", "RXgAYW3+cGxl") + ,("Ex\0am\255ple", "RXgAYW3/cGxl") + ] + +-- | Same as the base64_string_tests but using the alternative alphabet +base64url_string_tests :: [Test] +base64url_string_tests = + base64_string_test Base64URL.encode Base64URL.decode testData ++ + base64_string_test Base64URL.encode decodeURL testData + where decodeURL :: ByteString -> Either String ByteString + decodeURL = liftM Right Base64URL.decodeLenient + testData :: [(ByteString, ByteString)] + testData = [("", "") + ,("\0", "AA==") + ,("\255", "_w==") + ,("E", "RQ==") + ,("Ex", "RXg=") + ,("Exa", "RXhh") + ,("Exam", "RXhhbQ==") + ,("Examp", "RXhhbXA=") + ,("Exampl", "RXhhbXBs") + ,("Example", "RXhhbXBsZQ==") + ,("Ex\0am\254ple", "RXgAYW3-cGxl") + ,("Ex\0am\255ple", "RXgAYW3_cGxl") + ] + +-- | Generic test given encod enad decode funstions and a +-- list of (plain, encoded) pairs +base64_string_test :: (ByteString -> ByteString) + -> (ByteString -> Either String ByteString) + -> [(ByteString, ByteString)] -> [Test] +base64_string_test enc dec testData = concat + [ [ testCase ("base64-string: Encode " ++ show plain) + (encoded_plain @?= encoded), + testCase ("base64-string: Decode " ++ show plain) + (decoded_encoded @?= Right plain) ] + | (plain, encoded) <- testData, + let encoded_plain = enc plain + decoded_encoded = dec encoded + ] diff --git a/dev-haskell/base64-bytestring/metadata.xml b/dev-haskell/base64-bytestring/metadata.xml new file mode 100644 index 000000000000..c07246e99cef --- /dev/null +++ b/dev-haskell/base64-bytestring/metadata.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> +<pkgmetadata> + <herd>haskell</herd> + <maintainer> + <email>haskell@gentoo.org</email> + </maintainer> + <longdescription> + Fast base64 encoding and deconding for ByteStrings + </longdescription> +</pkgmetadata> |