Skip to content

Add tests #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2.1

orbs:
haskell: haskell-works/haskell-build@1.6.2
haskell: haskell-works/haskell-build@dev:jky
github: haskell-works/[email protected]
hackage: haskell-works/[email protected]
display: haskell-works/[email protected]
Expand Down
9 changes: 9 additions & 0 deletions hw-json-simd.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ flag sse42

common base { build-depends: base >= 4 && < 5 }
common bytestring { build-depends: bytestring >= 0.10.6 && < 0.11 }
common hedgehog { build-depends: hedgehog >= 0.5 && < 0.7 }
common hspec { build-depends: hspec >= 2.4 && < 3 }
common hw-bits { build-depends: hw-bits >= 0.7.0.5 && < 0.8 }
common hw-hspec-hedgehog { build-depends: hw-hspec-hedgehog >= 0.1.0.4 && < 0.2 }
common hw-prim { build-depends: hw-prim >= 0.6.2.21 && < 0.7 }
common lens { build-depends: lens >= 4 && < 5 }
common optparse-applicative { build-depends: optparse-applicative >= 0.14 && < 0.15 }
Expand Down Expand Up @@ -122,6 +126,10 @@ executable hw-json-simd
test-suite hw-json-simd-test
import: base, config
, bytestring
, hedgehog
, hspec
, hw-bits
, hw-hspec-hedgehog
, hw-prim
, lens
, semigroups
Expand All @@ -131,6 +139,7 @@ test-suite hw-json-simd-test
main-is: Spec.hs
autogen-modules: Paths_hw_json_simd
other-modules: Paths_hw_json_simd
HaskellWorks.Data.Json.Simd.Index.StandardSpec
hs-source-dirs: test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: hw-json-simd
83 changes: 83 additions & 0 deletions test/HaskellWorks/Data/Json/Simd/Index/StandardSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}

module HaskellWorks.Data.Json.Simd.Index.StandardSpec
( spec
) where

import Data.Semigroup ((<>))
import HaskellWorks.Data.Bits.BitShow
import HaskellWorks.Hspec.Hedgehog
import Hedgehog
import Test.Hspec

import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified HaskellWorks.Data.ByteString.Lazy as LBS
import qualified HaskellWorks.Data.Json.Simd.Index.Standard as SI

{-# ANN module ("HLint: ignore Redundant do" :: String) #-}

makeStandardJsonIbs :: LBS.ByteString -> BS.ByteString
makeStandardJsonIbs bs = let Right chunks = fmap fst <$> SI.makeStandardJsonIbBps (LBS.resegmentPadded 512 bs) in mconcat chunks

makeStandardJsonBps :: LBS.ByteString -> BS.ByteString
makeStandardJsonBps bs = let Right chunks = fmap snd <$> SI.makeStandardJsonIbBps (LBS.resegmentPadded 512 bs) in mconcat chunks

spec :: Spec
spec = describe "HaskellWorks.Data.Json.Succinct.Cursor.InterestBitsSpec" $ do
it "Evaluating interest bits" $ requireTest $ do
bitShow (makeStandardJsonBps "" ) === ""
bitShow (makeStandardJsonBps " \n \r \t ") === ""
bitShow (makeStandardJsonBps "1234 " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "1.1 " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "-1.1e-1 " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "false " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "true " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "\"hello\" " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "\"\\\"\" " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "{ " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "} " ) === "00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "[ " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps "] " ) === "00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps ": " ) === ""
bitShow (makeStandardJsonBps ", " ) === ""
bitShow (makeStandardJsonBps "{{}}" ) === "11000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonBps " { { } } " ) === "11000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
it "Evaluating interest bits" $ requireTest $ do
bitShow (makeStandardJsonIbs "" ) === ""
bitShow (makeStandardJsonIbs " \n \r \t ") === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "1234 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "1.1 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "-1.1e-2 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "false " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "true " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "\"hello\" " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "\"\\\"\" " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "{ " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "} " ) === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "[ " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "] " ) === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs ": " ) === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs ", " ) === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "{{}}" ) === "11000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs " { { } } " ) === "01010000" <> mconcat (replicate 63 " 00000000")
it "Evaluating interest bits 2" $ requireTest $ do
bitShow (makeStandardJsonIbs "" ) === ""
-- bitShow (makeStandardJsonIbs " \n \r \t ") === "00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
bitShow (makeStandardJsonIbs "1234 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "1.1 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "-1.1 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "-1.1e-2 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "false " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "true " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "\"hello\" " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "\"\\\"\" " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "{ " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "} " ) === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "[ " ) === "10000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "] " ) === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs ": " ) === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs ", " ) === "00000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs "{{}}" ) === "11000000" <> mconcat (replicate 63 " 00000000")
bitShow (makeStandardJsonIbs " { { } } " ) === "01010000" <> mconcat (replicate 63 " 00000000")
3 changes: 1 addition & 2 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}