packages feed

libasterix 0.11.0 → 0.11.1

raw patch · 3 files changed

+15/−3 lines, 3 files

Files

libasterix.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               libasterix-version:            0.11.0+version:            0.11.1 synopsis:           Asterix data processing library description:     This library provides features to process asterix data format, including
src/Asterix/Base.hs view
@@ -840,9 +840,10 @@ parseRawDatablock :: ByteString -> Either ParsingError (RawDatablock, ByteString) parseRawDatablock bs = do     let n = BS.length bs-    when (n < 3) $ Left "overflow"+    when (n < 3) $ Left "overflow datablock header"     let m = fromIntegral (BS.index bs 1) * 256 + fromIntegral (BS.index bs 2)-    when (m > n) $ Left "overflow"+    when (m < 3) $ Left "unexpected length"+    when (m > n) $ Left "overflow datablock records"     pure (RawDatablock $ BS.take m bs, BS.drop m bs)  -- | Parse many RawDatablocks.
test/TestRawDatablock.hs view
@@ -8,6 +8,7 @@ import           Data.Word import           Test.Tasty import           Test.Tasty.HUnit+import           Test.Tasty.QuickCheck  import           Asterix.Base import           Asterix.BitString@@ -33,6 +34,9 @@     , "02000402" -- cat2     ] +allZeros :: String+allZeros = "00000000000000000000"+ datagramIn :: ByteString datagramIn = fromJust $ unhexlify $ mconcat samples @@ -47,6 +51,13 @@     , testCase "reverse" $ assertEqual "sample"         (fromJust $ unhexlify $ mconcat $ reverse samples)         (builderToByteStringSlow $ reverseDatablocks datagramIn)+    , testCase "all zeros" $ assertEqual "sample"+        True (isLeft $ parseRawDatablocks $ fromJust $ unhexlify allZeros)+    , testProperty "random input" $ withMaxSuccess 10_000 $ \(lst :: [Word8]) ->+        let bs = BS.pack lst+            result = parseRawDatablocks bs+        -- this is always true, but we want the expression to terminate+        in (isLeft result || isRight result)     ]   where     cat1 = take 2 samples