packages feed

AesonBson 0.2.0 → 0.2.1

raw patch · 3 files changed

+44/−6 lines, 3 filesdep +AesonBsondep +HUnitdep +hspecdep ~aesondep ~bson

Dependencies added: AesonBson, HUnit, hspec, text

Dependency ranges changed: aeson, bson

Files

AesonBson.cabal view
@@ -1,5 +1,5 @@ name:          AesonBson-version:       0.2.0+version:       0.2.1 license:       OtherLicense license-file:  LICENSE copyright:     CC0@@ -7,10 +7,9 @@ maintainer:    Niklas Hambüchen <mail@nh2.me> category:      Data build-type:    Simple-synopsis:      Python-to-Haskell function calls stability:     experimental tested-With:   GHC==7.4.2-cabal-version: >= 1.10+cabal-version: >= 1.8 homepage:      https://github.com/nh2/AesonBson bug-Reports:   https://github.com/nh2/AesonBson/issues synopsis:      Mapping between Aeson's JSON and Bson objects.@@ -34,5 +33,22 @@     unordered-containers >= 0.1.3.0,     vector >= 0.7.1   hs-source-dirs: .-  default-language: Haskell2010+  ghc-options: -Wall++++test-Suite tests+  type: exitcode-stdio-1.0+  hs-source-dirs:+    test+  main-is:+    Main.hs+  build-depends:+    base < 5,+    AesonBson,+    aeson,+    bson,+    hspec >= 1.7.2.1,+    HUnit >= 1.2.5.2,+    text >= 0.11.3.1   ghc-options: -Wall
Data/AesonBson.hs view
@@ -24,7 +24,6 @@ import           Data.Monoid import qualified Data.HashMap.Strict as HashMap (fromList, toList) import qualified Data.Vector as Vector (fromList, toList)-import           Numeric (showHex)   -- | Converts a JSON value to BSON.@@ -49,7 +48,9 @@ aesonifyValue (Uuid (UUID uuid)) = toJSON uuid aesonifyValue (Md5 (MD5 md5)) = toJSON md5 aesonifyValue (UserDef (UserDefined userdef)) = toJSON userdef-aesonifyValue (ObjId (Oid w32 w64)) = toJSON $ showHex w32 (showHex w64 "")+aesonifyValue (ObjId oid) = toJSON $ show oid -- Relies on bson to show the OID as 24 digit hex.+                                              -- It would be better if BSON exposed a non-show function for this,+                                              -- preferably a fast one. aesonifyValue (BSON.Bool bool) = toJSON bool aesonifyValue (UTC utc) = toJSON utc aesonifyValue (BSON.Null) = AESON.Null
+ test/Main.hs view
@@ -0,0 +1,21 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where++import           Test.Hspec+import           Data.Aeson.Types as AESON+import           Data.Bson as BSON+import qualified Data.Text as T++import Data.AesonBson++main :: IO ()+main = hspec $ do+  describe "BSON -> JSON" $ do++    it "converts an ObjId to 24 digits hex" $ do+      -- https://github.com/nh2/aesonbson/pull/2+      let objid = ObjId (read "000000010000000000000001" :: ObjectId)+          AESON.String str = aesonifyValue objid+      str `shouldBe` "000000010000000000000001"+      T.length str `shouldBe` 24