Skip to content

Commit 22801a1

Browse files
committed
Add tests
1 parent fe19db8 commit 22801a1

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

hw-json-simd.cabal

+9
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ flag sse42
4747

4848
common base { build-depends: base >= 4 && < 5 }
4949
common bytestring { build-depends: bytestring >= 0.10.6 && < 0.11 }
50+
common hedgehog { build-depends: hedgehog >= 0.5 && < 0.7 }
51+
common hspec { build-depends: hspec >= 2.4 && < 3 }
52+
common hw-bits { build-depends: hw-bits >= 0.7.0.5 && < 0.8 }
53+
common hw-hspec-hedgehog { build-depends: hw-hspec-hedgehog >= 0.1.0.4 && < 0.2 }
5054
common hw-prim { build-depends: hw-prim >= 0.6.2.21 && < 0.7 }
5155
common lens { build-depends: lens >= 4 && < 5 }
5256
common optparse-applicative { build-depends: optparse-applicative >= 0.14 && < 0.15 }
@@ -122,6 +126,10 @@ executable hw-json-simd
122126
test-suite hw-json-simd-test
123127
import: base, config
124128
, bytestring
129+
, hedgehog
130+
, hspec
131+
, hw-bits
132+
, hw-hspec-hedgehog
125133
, hw-prim
126134
, lens
127135
, semigroups
@@ -131,6 +139,7 @@ test-suite hw-json-simd-test
131139
main-is: Spec.hs
132140
autogen-modules: Paths_hw_json_simd
133141
other-modules: Paths_hw_json_simd
142+
HaskellWorks.Data.Json.Simd.Index.StandardSpec
134143
hs-source-dirs: test
135144
ghc-options: -threaded -rtsopts -with-rtsopts=-N
136145
build-depends: hw-json-simd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{-# LANGUAGE FlexibleContexts #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
4+
module HaskellWorks.Data.Json.Simd.Index.StandardSpec
5+
( spec
6+
) where
7+
8+
import Data.Semigroup ((<>))
9+
import HaskellWorks.Data.Bits.BitShow
10+
import HaskellWorks.Hspec.Hedgehog
11+
import Hedgehog
12+
import Test.Hspec
13+
14+
import qualified Data.ByteString as BS
15+
import qualified Data.ByteString.Lazy as LBS
16+
import qualified HaskellWorks.Data.ByteString.Lazy as LBS
17+
import qualified HaskellWorks.Data.Json.Simd.Index.Standard as SI
18+
19+
{-# ANN module ("HLint: ignore Redundant do" :: String) #-}
20+
21+
makeStandardJsonIbs :: LBS.ByteString -> BS.ByteString
22+
makeStandardJsonIbs bs = let Right chunks = fmap fst <$> SI.makeStandardJsonIbBps (LBS.resegmentPadded 512 bs) in mconcat chunks
23+
24+
makeStandardJsonBps :: LBS.ByteString -> BS.ByteString
25+
makeStandardJsonBps bs = let Right chunks = fmap snd <$> SI.makeStandardJsonIbBps (LBS.resegmentPadded 512 bs) in mconcat chunks
26+
27+
spec :: Spec
28+
spec = describe "HaskellWorks.Data.Json.Succinct.Cursor.InterestBitsSpec" $ do
29+
it "Evaluating interest bits" $ requireTest $ do
30+
bitShow (makeStandardJsonBps "" ) === ""
31+
bitShow (makeStandardJsonBps " \n \r \t ") === ""
32+
bitShow (makeStandardJsonBps "1234 " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
33+
bitShow (makeStandardJsonBps "1.1 " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
34+
bitShow (makeStandardJsonBps "-1.1e-1 " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
35+
bitShow (makeStandardJsonBps "false " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
36+
bitShow (makeStandardJsonBps "true " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
37+
bitShow (makeStandardJsonBps "\"hello\" " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
38+
bitShow (makeStandardJsonBps "\"\\\"\" " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
39+
bitShow (makeStandardJsonBps "{ " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
40+
bitShow (makeStandardJsonBps "} " ) === "00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
41+
bitShow (makeStandardJsonBps "[ " ) === "10000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
42+
bitShow (makeStandardJsonBps "] " ) === "00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
43+
bitShow (makeStandardJsonBps ": " ) === ""
44+
bitShow (makeStandardJsonBps ", " ) === ""
45+
bitShow (makeStandardJsonBps "{{}}" ) === "11000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
46+
bitShow (makeStandardJsonBps " { { } } " ) === "11000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
47+
it "Evaluating interest bits" $ requireTest $ do
48+
bitShow (makeStandardJsonIbs "" ) === ""
49+
bitShow (makeStandardJsonIbs " \n \r \t ") === "00000000" <> mconcat (replicate 63 " 00000000")
50+
bitShow (makeStandardJsonIbs "1234 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
51+
bitShow (makeStandardJsonIbs "1.1 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
52+
bitShow (makeStandardJsonIbs "-1.1e-2 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
53+
bitShow (makeStandardJsonIbs "false " ) === "10000000" <> mconcat (replicate 63 " 00000000")
54+
bitShow (makeStandardJsonIbs "true " ) === "10000000" <> mconcat (replicate 63 " 00000000")
55+
bitShow (makeStandardJsonIbs "\"hello\" " ) === "10000000" <> mconcat (replicate 63 " 00000000")
56+
bitShow (makeStandardJsonIbs "\"\\\"\" " ) === "10000000" <> mconcat (replicate 63 " 00000000")
57+
bitShow (makeStandardJsonIbs "{ " ) === "10000000" <> mconcat (replicate 63 " 00000000")
58+
bitShow (makeStandardJsonIbs "} " ) === "00000000" <> mconcat (replicate 63 " 00000000")
59+
bitShow (makeStandardJsonIbs "[ " ) === "10000000" <> mconcat (replicate 63 " 00000000")
60+
bitShow (makeStandardJsonIbs "] " ) === "00000000" <> mconcat (replicate 63 " 00000000")
61+
bitShow (makeStandardJsonIbs ": " ) === "00000000" <> mconcat (replicate 63 " 00000000")
62+
bitShow (makeStandardJsonIbs ", " ) === "00000000" <> mconcat (replicate 63 " 00000000")
63+
bitShow (makeStandardJsonIbs "{{}}" ) === "11000000" <> mconcat (replicate 63 " 00000000")
64+
bitShow (makeStandardJsonIbs " { { } } " ) === "01010000" <> mconcat (replicate 63 " 00000000")
65+
it "Evaluating interest bits 2" $ requireTest $ do
66+
bitShow (makeStandardJsonIbs "" ) === ""
67+
-- bitShow (makeStandardJsonIbs " \n \r \t ") === "00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
68+
bitShow (makeStandardJsonIbs "1234 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
69+
bitShow (makeStandardJsonIbs "1.1 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
70+
bitShow (makeStandardJsonIbs "-1.1 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
71+
bitShow (makeStandardJsonIbs "-1.1e-2 " ) === "10000000" <> mconcat (replicate 63 " 00000000")
72+
bitShow (makeStandardJsonIbs "false " ) === "10000000" <> mconcat (replicate 63 " 00000000")
73+
bitShow (makeStandardJsonIbs "true " ) === "10000000" <> mconcat (replicate 63 " 00000000")
74+
bitShow (makeStandardJsonIbs "\"hello\" " ) === "10000000" <> mconcat (replicate 63 " 00000000")
75+
bitShow (makeStandardJsonIbs "\"\\\"\" " ) === "10000000" <> mconcat (replicate 63 " 00000000")
76+
bitShow (makeStandardJsonIbs "{ " ) === "10000000" <> mconcat (replicate 63 " 00000000")
77+
bitShow (makeStandardJsonIbs "} " ) === "00000000" <> mconcat (replicate 63 " 00000000")
78+
bitShow (makeStandardJsonIbs "[ " ) === "10000000" <> mconcat (replicate 63 " 00000000")
79+
bitShow (makeStandardJsonIbs "] " ) === "00000000" <> mconcat (replicate 63 " 00000000")
80+
bitShow (makeStandardJsonIbs ": " ) === "00000000" <> mconcat (replicate 63 " 00000000")
81+
bitShow (makeStandardJsonIbs ", " ) === "00000000" <> mconcat (replicate 63 " 00000000")
82+
bitShow (makeStandardJsonIbs "{{}}" ) === "11000000" <> mconcat (replicate 63 " 00000000")
83+
bitShow (makeStandardJsonIbs " { { } } " ) === "01010000" <> mconcat (replicate 63 " 00000000")

test/Spec.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
main :: IO ()
2-
main = putStrLn "Test suite not yet implemented"
1+
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}

0 commit comments

Comments
 (0)