|
| 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") |
0 commit comments