Created
December 20, 2009 17:58
-
-
Save anonymous/260580 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BsonTest where | |
import Data.Binary.Put | |
import Data.Binary.Get | |
import qualified Data.ByteString.Lazy as L | |
import qualified Data.ByteString.Char8 as C8 | |
import qualified Data.ByteString.Internal as I | |
import Data.ByteString hiding (putStrLn,map,zip, filter) | |
import System.Directory | |
import Control.Monad | |
import Debug.Trace | |
import BSONValues | |
data TestResult = TestResult { filename :: String, bytes :: L.ByteString, obj :: BSONValue } | |
main = do loadDir "basic_types" >> loadDir "complex" >> loadDir "single_types" | |
loadDir n = do paths <- getDirectoryContents n | |
let files = filter ((isSuffixOf (C8.pack "bson")) . C8.pack) paths | |
globs <- sequence [ getFile $ mkFile n f | f <- files ] | |
let results = [ TestResult (mkFile n (fst fb)) (snd fb) (runObjects (snd fb)) | fb <- zip files globs] | |
mapM testPut results | |
runObjects b = (runGet getBSONObject) b | |
getFile f = L.readFile f | |
mkFile d f = d++"/"++f | |
putObj :: (FilePath, BSONValue) -> IO () | |
putObj (f, o) = do let str = runPut $ putBSONValue o in | |
L.writeFile (f ++ "2") str | |
testPut :: TestResult -> IO () | |
testPut (TestResult f b o) = let str = (runPut $ putBSONValue o) in | |
if (str == b) then putStrLn $ f ++ ":: SUCCEEDED" | |
else putStrLn $ f ++ ":: FAILED" | |
--rightseq = sequence . map (uncurry (fmap fmap (,))) | |
--rightseq (bs, io) = do { m <- io; return (bs, m) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment