Skip to content

Commit 3d400a4

Browse files
committed
Vary the length of generated strings
1 parent e69a22c commit 3d400a4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Data/String/Gen.purs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ module Data.String.Gen where
22

33
import Prelude
44

5-
import Control.Monad.Gen (class MonadGen, unfoldable)
5+
import Control.Monad.Gen (class MonadGen, chooseInt, unfoldable, sized, resize)
66
import Control.Monad.Rec.Class (class MonadRec)
77
import Data.Char.Gen as CG
88
import Data.String as S
99

1010
-- | Generates a string using the specified character generator.
1111
genString :: forall m. MonadRec m => MonadGen m => m Char -> m String
12-
genString = map S.fromCharArray <<< unfoldable
12+
genString genChar = sized \size -> do
13+
newSize <- chooseInt 1 size
14+
resize (const newSize) $ S.fromCharArray <$> unfoldable genChar
1315

1416
-- | Generates a string using characters from the Unicode basic multilingual
1517
-- | plain.

0 commit comments

Comments
 (0)