Skip to content

Commit c7c0183

Browse files
committed
mismi-s3-core: Add fileNameSizePairs generator
1 parent c3c6997 commit c7c0183

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

mismi-s3-core/mismi-s3-core.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ test-suite test
4040
, ambiata-mismi-s3-core
4141
, ambiata-p
4242
, attoparsec
43+
, filepath >= 1.3 && < 1.5
4344
, text
4445
, QuickCheck >= 2.7 && < 2.10
4546
, quickcheck-instances == 0.3.*

mismi-s3-core/test/Test/Mismi/S3/Core/Arbitrary.hs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@
33
{-# OPTIONS_GHC -fno-warn-orphans #-}
44
module Test.Mismi.S3.Core.Arbitrary where
55

6-
import Data.Text as T
6+
import qualified Data.List as L
7+
import qualified Data.Text as T
78

8-
import Disorder.Corpus
9+
import Disorder.Corpus (simpsons, southpark)
910

1011
import Mismi.S3.Core.Data
1112

1213
import P
1314

14-
import Test.QuickCheck
15+
import Test.QuickCheck (Arbitrary (..), Gen)
16+
import qualified Test.QuickCheck as QC
1517
import Test.QuickCheck.Instances ()
1618

19+
import System.FilePath (FilePath)
1720

1821
instance Arbitrary WriteMode where
19-
arbitrary = elements [Fail, Overwrite]
22+
arbitrary = QC.elements [Fail, Overwrite]
2023

2124
instance Arbitrary Bucket where
22-
arbitrary = Bucket <$> elements southpark
25+
arbitrary = Bucket <$> QC.elements southpark
2326

2427
instance Arbitrary Address where
25-
arbitrary = frequency [
28+
arbitrary = QC.frequency [
2629
(9, Address <$> arbitrary <*> arbitrary)
2730
, (1, flip Address (Key "") <$> arbitrary)
2831
]
@@ -32,8 +35,17 @@ instance Arbitrary Key where
3235
-- Unfortunately unicode characters aren't supported in the Haskell AWS library
3336
-- https://github.com/ambiata/vee/issues/7
3437
arbitrary =
35-
let genPath = elements ["happy", "sad", ".", ":", "-"]
38+
let genPath = QC.elements ["happy", "sad", ".", ":", "-"]
3639
path = do
37-
sep <- elements ["-", "=", "#", ""]
38-
T.take 256 . T.intercalate "/" <$> listOf1 (T.intercalate sep <$> listOf1 genPath)
39-
in (Key . append "tests/") <$> path
40+
sep <- QC.elements ["-", "=", "#", ""]
41+
T.take 256 . T.intercalate "/" <$> QC.listOf1 (T.intercalate sep <$> QC.listOf1 genPath)
42+
in (Key . T.append "tests/") <$> path
43+
44+
45+
fileNameSizePairs :: Int -> Gen [(FilePath, Int64)]
46+
fileNameSizePairs len = do
47+
names <- QC.vectorOf len $ QC.elements simpsons
48+
lengths <- QC.vectorOf len $ QC.choose (1, 1000000000)
49+
pure $ L.zipWith3 zipper names [(0::Int) ..] lengths
50+
where
51+
zipper n i l = (n <> show i, l)

mismi-s3-core/test/mismi-s3-core-test.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ library
1111
, ambiata-mismi-s3-core
1212
, ambiata-p
1313
, attoparsec
14+
, filepath >= 1.3 && < 1.5
1415
, text
1516
, QuickCheck >= 2.7 && < 2.10
1617
, quickcheck-instances == 0.3.*

0 commit comments

Comments
 (0)