@@ -15,14 +15,14 @@ import Prelude
1515
1616import Control.Monad.Gen.Class (chooseBool )
1717import Control.Monad.Gen.Common as MGC
18- import Control.Monad.ST ( pureST )
18+ import Control.Monad.ST as ST
1919import Data.Array.NonEmpty (NonEmptyArray )
2020import Data.Array.NonEmpty as NEA
21- import Data.Array.ST (pushSTArray , unsafeFreeze , unsafeThaw )
22- import Data.Char (toCharCode , fromCharCode )
21+ import Data.Array.ST as STA
2322import Data.Either (Either (..))
23+ import Data.Enum (fromEnum , toEnumWithDefaults )
2424import Data.Foldable (foldl )
25- import Data.Generic.Rep (class Generic , to , from , NoArguments (..), Sum (..), Product (..), Constructor (..), Argument (..), Rec (..), Field (..) )
25+ import Data.Generic.Rep (class Generic , to , from , NoArguments (..), Sum (..), Product (..), Constructor (..), Argument (..))
2626import Data.Identity (Identity (..))
2727import Data.Int (toNumber )
2828import Data.Lazy (Lazy , defer , force )
@@ -31,16 +31,19 @@ import Data.List.NonEmpty (NonEmptyList(..))
3131import Data.Maybe (Maybe (..), fromJust )
3232import Data.Newtype (wrap )
3333import Data.NonEmpty (NonEmpty (..), (:|))
34- import Data.Record ( insert )
35- import Data.String ( charCodeAt , fromCharArray , split )
34+ import Data.String ( split )
35+ import Data.String.CodeUnits ( charAt , fromCharArray )
3636import Data.String.NonEmpty (NonEmptyString )
3737import Data.String.NonEmpty as NES
38+ import Data.String.NonEmpty.CodeUnits as NESCU
3839import Data.Symbol (class IsSymbol , SProxy (..))
3940import Data.Tuple (Tuple (..))
4041import Partial.Unsafe (unsafePartial )
42+ import Prim.Row as Row
43+ import Prim.RowList as RL
44+ import Record as Record
4145import Test.QuickCheck.Gen (Gen , arrayOf , chooseInt , elements , listOf , oneOf , perturbGen , repeatable , sized , uniform )
42- import Type.Prelude (class RowToList )
43- import Type.Row (kind RowList , class RowLacks , Nil , Cons , RLProxy (..))
46+ import Type.Data.RowList (RLProxy (..))
4447
4548-- | The `Arbitrary` class represents those types whose values can be
4649-- | _randomly-generated_.
@@ -85,19 +88,19 @@ instance arbString :: Arbitrary String where
8588 arbitrary = fromCharArray <$> arbitrary
8689
8790instance coarbString :: Coarbitrary String where
88- coarbitrary s = coarbitrary $ (charCodeAt zero <$> split (wrap " " ) s)
91+ coarbitrary s = coarbitrary $ (charAt zero <$> split (wrap " " ) s)
8992
9093instance arbNonEmptyString :: Arbitrary NonEmptyString where
91- arbitrary = NES .cons <$> arbitrary <*> arbitrary
94+ arbitrary = NESCU .cons <$> arbitrary <*> arbitrary
9295
9396instance coarbNonEmptyString :: Coarbitrary NonEmptyString where
9497 coarbitrary = coarbitrary <<< NES .toString
9598
9699instance arbChar :: Arbitrary Char where
97- arbitrary = fromCharCode <$> chooseInt 0 65536
100+ arbitrary = toEnumWithDefaults bottom top <$> chooseInt 0 65536
98101
99102instance coarbChar :: Coarbitrary Char where
100- coarbitrary c = coarbitrary $ toCharCode c
103+ coarbitrary c = coarbitrary $ fromEnum c
101104
102105instance arbUnit :: Arbitrary Unit where
103106 arbitrary = pure unit
@@ -117,16 +120,16 @@ instance arbArray :: Arbitrary a => Arbitrary (Array a) where
117120 arbitrary = arrayOf arbitrary
118121
119122instance coarbArray :: Coarbitrary a => Coarbitrary (Array a ) where
120- coarbitrary = foldl (\f x -> f <<< coarbitrary x) id
123+ coarbitrary = foldl (\f x -> f <<< coarbitrary x) identity
121124
122125instance arbNonEmptyArray :: Arbitrary a => Arbitrary (NonEmptyArray a ) where
123126 arbitrary = do
124127 x <- arbitrary
125128 xs <- arbitrary
126- pure $ unsafePartial fromJust $ NEA .fromArray $ pureST do
127- mxs <- unsafeThaw xs
128- _ <- pushSTArray mxs x
129- unsafeFreeze mxs
129+ pure $ unsafePartial fromJust $ NEA .fromArray $ ST .run do
130+ mxs <- STA . unsafeThaw xs
131+ _ <- STA .push x mxs
132+ STA . unsafeFreeze mxs
130133
131134instance coarbNonEmptyArray :: Coarbitrary a => Coarbitrary (NonEmptyArray a ) where
132135 coarbitrary = coarbitrary <<< NEA .toArray
@@ -163,7 +166,7 @@ instance arbitraryList :: Arbitrary a => Arbitrary (List a) where
163166 arbitrary = sized \n -> chooseInt zero n >>= flip listOf arbitrary
164167
165168instance coarbList :: Coarbitrary a => Coarbitrary (List a ) where
166- coarbitrary = foldl (\f x -> f <<< coarbitrary x) id
169+ coarbitrary = foldl (\f x -> f <<< coarbitrary x) identity
167170
168171instance arbitraryIdentity :: Arbitrary a => Arbitrary (Identity a ) where
169172 arbitrary = Identity <$> arbitrary
@@ -193,7 +196,7 @@ instance arbitraryNoArguments :: Arbitrary NoArguments where
193196 arbitrary = pure NoArguments
194197
195198instance coarbitraryNoArguments :: Coarbitrary NoArguments where
196- coarbitrary NoArguments = id
199+ coarbitrary NoArguments = identity
197200
198201-- | To be able to evenly distribute over chains of Sum types we build up
199202-- | a collection of generators and choose between. Each right component
@@ -232,18 +235,6 @@ instance arbitraryArgument :: Arbitrary a => Arbitrary (Argument a) where
232235instance coarbitraryArgument :: Coarbitrary a => Coarbitrary (Argument a ) where
233236 coarbitrary (Argument a) = coarbitrary a
234237
235- instance arbitraryRec :: Arbitrary a => Arbitrary (Rec a ) where
236- arbitrary = Rec <$> arbitrary
237-
238- instance coarbitraryRec :: Coarbitrary a => Coarbitrary (Rec a ) where
239- coarbitrary (Rec a) = coarbitrary a
240-
241- instance arbitraryField :: Arbitrary a => Arbitrary (Field s a ) where
242- arbitrary = Field <$> arbitrary
243-
244- instance coarbitraryField :: Coarbitrary a => Coarbitrary (Field s a ) where
245- coarbitrary (Field a) = coarbitrary a
246-
247238-- | A `Generic` implementation of the `arbitrary` member from the `Arbitrary` type class.
248239genericArbitrary :: forall a rep . Generic a rep => Arbitrary rep => Gen a
249240genericArbitrary = to <$> (arbitrary :: Gen rep )
@@ -253,30 +244,27 @@ genericCoarbitrary :: forall a rep. Generic a rep => Coarbitrary rep => a -> Gen
253244genericCoarbitrary x g = to <$> coarbitrary (from x) (from <$> g)
254245
255246-- | A helper typeclass to implement `Arbitrary` for records.
256- class ArbitraryRowList
257- (list :: RowList )
258- (row :: # Type )
259- | list -> row where
247+ class ArbitraryRowList list row | list -> row where
260248 arbitraryRecord :: RLProxy list -> Gen (Record row )
261249
262- instance arbitraryRowListNil :: ArbitraryRowList Nil () where
250+ instance arbitraryRowListNil :: ArbitraryRowList RL. Nil () where
263251 arbitraryRecord _ = pure {}
264252
265253instance arbitraryRowListCons ::
266254 ( Arbitrary a
267255 , ArbitraryRowList listRest rowRest
268- , RowLacks key rowRest
269- , RowCons key a rowRest rowFull
270- , RowToList rowFull (Cons key a listRest )
256+ , Row.Lacks key rowRest
257+ , Row.Cons key a rowRest rowFull
258+ , RL. RowToList rowFull (RL. Cons key a listRest )
271259 , IsSymbol key
272- ) => ArbitraryRowList (Cons key a listRest ) rowFull where
260+ ) => ArbitraryRowList (RL. Cons key a listRest ) rowFull where
273261 arbitraryRecord _ = do
274262 value <- arbitrary
275263 previous <- arbitraryRecord (RLProxy :: RLProxy listRest )
276- pure $ insert (SProxy :: SProxy key ) value previous
264+ pure $ Record . insert (SProxy :: SProxy key ) value previous
277265
278266instance arbitraryRecordInstance ::
279- ( RowToList row list
267+ ( RL. RowToList row list
280268 , ArbitraryRowList list row
281269 ) => Arbitrary (Record row ) where
282270 arbitrary = arbitraryRecord (RLProxy :: RLProxy list )
0 commit comments