1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00
semantic/test/Generators.hs
Rob Rix 7251c1c4b4
Generate empty source values 20% of the time.
Co-Authored-By: Patrick Thomson <patrickt@users.noreply.github.com>
2019-08-06 16:38:41 -04:00

15 lines
485 B
Haskell

{-# LANGUAGE TypeFamilies #-}
module Generators
( source
) where
import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Data.Source
import Data.Functor.Identity
source :: (GenBase m ~ Identity, MonadGen m) => Hedgehog.Range Int -> m Data.Source.Source
source r = Gen.frequency [ (1, empty), (20, nonEmpty) ]
where empty = pure mempty
nonEmpty = Data.Source.fromUTF8 <$> Gen.utf8 r (Gen.frequency [ (1, pure '\r'), (1, pure '\n'), (20, Gen.unicode) ])