Skip to content

Commit

Permalink
Added testing aeson/jsonstream parsing for benchmark files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrap committed Aug 31, 2015
1 parent f1cc73e commit 5d82c0d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions json-stream.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ test-suite spec
, unordered-containers
, hspec
, scientific
, directory


-- executable spdtest
-- main-is: spdtest.hs
Expand Down
23 changes: 19 additions & 4 deletions test/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Control.Monad (forM_)
import Data.Text.Encoding (encodeUtf8)
import qualified Data.Vector as Vec
import qualified Data.HashMap.Strict as HMap
import System.Directory (getDirectoryContents)

import Data.JsonStream.Parser
import Data.JsonStream.TokenParser
Expand Down Expand Up @@ -301,8 +302,6 @@ errTests = describe "Tests of previous errors" $ do
-- iter dta cont
-- iter _ TokFailed = print "tok failed"



aeCompare :: Spec
aeCompare = describe "Compare parsing of strings aeason vs json-stream" $ do
let values = [
Expand All @@ -326,11 +325,27 @@ aeCompare = describe "Compare parsing of strings aeason vs json-stream" $ do
, " { \"a\" : true } "
, "{ \"v\":1.7976931348623157E308} "
]

forM_ values $ \test -> it ("Parses " ++ show test ++ " the same as aeson") $ do
let resStream = head $ parseByteString value test :: AE.Value
let Just resAeson = AE.decode (BL.fromChunks [test])
resStream `shouldBe` resAeson

readBenchFiles dirname =
getDirectoryContents dirname >>= return . (filter isJson) >>= mapM readFile
where
readFile fname = BS.readFile (dirname ++ "/" ++ fname)
isJson fname = take 5 (reverse fname) == "nosj."

aeCompareBench :: Spec
aeCompareBench = describe "Compare benchmark jsons" $
it "JSONs from benchamark directory are the same" $ do
values <- readBenchFiles "benchmarks/json-data"
forM_ values $ \test -> do
let resStream = head $ parseByteString value test :: AE.Value
let Just resAeson = AE.decode (BL.fromChunks [test])
resStream `shouldBe` resAeson

spec :: Spec
spec = do
specBase
Expand All @@ -339,7 +354,7 @@ spec = do
specControl
errTests
aeCompare
aeCompareBench

main :: IO ()
main = do
hspec spec
main = hspec spec

0 comments on commit 5d82c0d

Please sign in to comment.