Permalink
Browse files

Unit producer

Signed-off-by: Alexander Dorofeev <aka.spin@gmail.com>
  • Loading branch information...
1 parent e8e746f commit 9cc5ea97d00490726e9add9d65a1f877ff0c193e @akaspin committed Jun 18, 2012
View
@@ -1,5 +1,5 @@
name: couchdb-conduit
-version: 0.8.2
+version: 0.8.3
cabal-version: >= 1.8
build-type: Simple
stability: Testing
@@ -17,6 +17,7 @@ module Database.CouchDB.Conduit.View
-- * View query parameters
-- $view_query #view_query#
+ viewQpUnit,
viewQp,
viewQpBS,
viewQpInt,
@@ -60,6 +61,7 @@ import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Char8 as BS8
import qualified Data.HashMap.Lazy as M
+import qualified Data.HashMap.Strict as MS
import qualified Data.Aeson as A
import Data.Attoparsec
@@ -87,6 +89,11 @@ import Database.CouchDB.Conduit.LowLevel (couch, protect')
-- complex parameters can be very tedious. To simplify this, use following
-- functions.
+-- | Not query parameter. Returns empty 'MS.HashMap'. Aeson will convert
+-- this to @\{\}@ (JSON unit). This useful for @startkey@ and @endkey@.
+viewQpUnit :: MS.HashMap B.ByteString Bool
+viewQpUnit = MS.empty
+
-- | Make complex view query parameter.
--
-- > viewQP "key" (["a", "b"] :: [String])
@@ -12,8 +12,6 @@ import CouchDBAuth
import Control.Monad.IO.Class (liftIO)
import qualified Data.ByteString as B
-import Data.Conduit (($$))
-import qualified Data.Conduit.List as CL
import qualified Network.HTTP.Conduit as H
import qualified Network.HTTP.Types as HT
@@ -24,28 +22,9 @@ import Database.CouchDB.Conduit.LowLevel
tests :: Test
tests = mutuallyExclusive $ testGroup "Base" [
- testCase "Just HTTP" caseJustHttp,
- testCase "Just HTTP IO" caseJustHttpIO,
testCase "Just connect" caseJustConnect,
testCase "Put and delete DB" caseDbPut
]
--- testCase "Put DB" case_dbPut
-
-caseJustHttp :: Assertion
-caseJustHttp = do
- request <- H.parseUrl "http://google.com/"
- r <- H.withManager $ \manager -> do
- H.Response _ _ _ bsrc <- H.http request manager
- bsrc $$ CL.consume
- print r
-
-caseJustHttpIO :: Assertion
-caseJustHttpIO = do
- request <- H.parseUrl "http://google.com/"
- H.withManager $ \manager -> do
- H.Response _ _ _ bsrc <- H.http request manager
- r <- bsrc $$ CL.consume
- liftIO $ print r
-- | Just connect
caseJustConnect :: Assertion
@@ -17,6 +17,7 @@ import Control.Applicative ((<$>), (<*>), empty)
import qualified Data.ByteString as B
import Data.String.Conversions ((<>), cs)
import Data.Aeson ((.:), (.=))
+import qualified Data.HashMap.Strict as H
import qualified Data.Aeson as A
--import qualified Data.Aeson.Generic as AG
import Data.Generics (Data, Typeable)
@@ -56,11 +57,14 @@ caseMakeParams = do
let numP = viewQpInt "numP" 1
let bsP = viewQpBS "bsP" "a"
let arrP = viewQp "arrP" (["a", "b", "c"] :: [B.ByteString])
+ let tupleP = viewQp "tupleP" (1 :: Int, H.empty :: H.HashMap String Int)
liftIO $ (
("numP", Just "1"),
("bsP", Just "\"a\""),
- ("arrP", Just "[\"a\",\"b\",\"c\"]"))
- @=? (numP, bsP, arrP)
+ ("arrP", Just "[\"a\",\"b\",\"c\"]"),
+ ("tupleP", Just "[1,{}]")
+ )
+ @=? (numP, bsP, arrP, tupleP)
caseBigValues :: Assertion
caseBigValues = bracket_

0 comments on commit 9cc5ea9

Please sign in to comment.