Skip to content

Commit

Permalink
Add rechunked tests with hashWithSalt
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed May 22, 2024
1 parent 03f2c0f commit 0d2444d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ instance Arbitrary ChunkSize where

-- | Ensure that the rechunk function causes a rechunked string to
-- still match its original form.
pTextRechunk :: T.Text -> NonEmptyList ChunkSize -> Bool
pTextRechunk t cs = TL.fromStrict t == rechunkText t cs
pTextRechunk :: T.Text -> NonEmptyList ChunkSize -> Property
pTextRechunk t cs = TL.fromStrict t === rechunkText t cs

-- | Lazy strings must hash to the same value no matter how they are
-- chunked.
pTextLazyRechunked :: T.Text
-> NonEmptyList ChunkSize -> NonEmptyList ChunkSize -> Bool
pTextLazyRechunked t cs0 cs1 =
hash (rechunkText t cs0) == hash (rechunkText t cs1)
pTextLazyRechunked :: T.Text -> NonEmptyList ChunkSize -> NonEmptyList ChunkSize -> Property
pTextLazyRechunked t cs0 cs1 = hash (rechunkText t cs0) === hash (rechunkText t cs1)

pTextLazyRechunked' :: T.Text -> Int -> NonEmptyList ChunkSize -> NonEmptyList ChunkSize -> Property
pTextLazyRechunked' t salt cs0 cs1 = hashWithSalt salt (rechunkText t cs0) === hashWithSalt salt (rechunkText t cs1)

-- | Break up a string into chunks of different sizes.
rechunkText :: T.Text -> NonEmptyList ChunkSize -> TL.Text
Expand Down Expand Up @@ -133,9 +134,11 @@ pBSRechunk t cs = fromStrict t == rechunkBS t cs

-- | Lazy bytestrings must hash to the same value no matter how they
-- are chunked.
pBSLazyRechunked :: B.ByteString
-> NonEmptyList ChunkSize -> NonEmptyList ChunkSize -> Bool
pBSLazyRechunked t cs1 cs2 = hash (rechunkBS t cs1) == hash (rechunkBS t cs2)
pBSLazyRechunked :: B.ByteString -> NonEmptyList ChunkSize -> NonEmptyList ChunkSize -> Property
pBSLazyRechunked t cs1 cs2 = hash (rechunkBS t cs1) === hash (rechunkBS t cs2)

pBSLazyRechunked' :: B.ByteString -> Int -> NonEmptyList ChunkSize -> NonEmptyList ChunkSize -> Property
pBSLazyRechunked' t salt cs1 cs2 = hashWithSalt salt (rechunkBS t cs1) === hashWithSalt salt (rechunkBS t cs2)

-- This wrapper is required by 'runST'.
data ByteArray = BA { unBA :: ByteArray# }
Expand Down Expand Up @@ -230,13 +233,15 @@ properties =
, testProperty "text/lazy" pTextLazy
, testProperty "text/rechunk" pTextRechunk
, testProperty "text/rechunked" pTextLazyRechunked
, testProperty "text/rechunked-salt" pTextLazyRechunked'
]
, testGroup "bytestring"
[ testProperty "bytestring/strict" pBS
, testProperty "bytestring/lazy" pBSLazy
, testProperty "bytestring/short" pBSShort
, testProperty "bytestring/rechunk" pBSRechunk
, testProperty "bytestring/rechunked" pBSLazyRechunked
, testProperty "bytestring/rechunked-salt" pBSLazyRechunked'
]
, testGroup "generics"
[
Expand Down

0 comments on commit 0d2444d

Please sign in to comment.