diff --git a/.circleci/config.yml b/.circleci/config.yml index 840c0d0..209b570 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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/github-release@1.2.1 hackage: haskell-works/hackage@1.0.0 display: haskell-works/display@1.0.1 diff --git a/hw-json-simd.cabal b/hw-json-simd.cabal index 5fd8fbe..438970c 100644 --- a/hw-json-simd.cabal +++ b/hw-json-simd.cabal @@ -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 } @@ -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 @@ -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 diff --git a/test/HaskellWorks/Data/Json/Simd/Index/StandardSpec.hs b/test/HaskellWorks/Data/Json/Simd/Index/StandardSpec.hs new file mode 100644 index 0000000..0b6763a --- /dev/null +++ b/test/HaskellWorks/Data/Json/Simd/Index/StandardSpec.hs @@ -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") diff --git a/test/Spec.hs b/test/Spec.hs index cd4753f..a824f8c 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,2 +1 @@ -main :: IO () -main = putStrLn "Test suite not yet implemented" +{-# OPTIONS_GHC -F -pgmF hspec-discover #-}