@@ -15,14 +15,14 @@ import Prelude
15
15
16
16
import Control.Monad.Gen.Class (chooseBool )
17
17
import Control.Monad.Gen.Common as MGC
18
- import Control.Monad.ST ( pureST )
18
+ import Control.Monad.ST as ST
19
19
import Data.Array.NonEmpty (NonEmptyArray )
20
20
import 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
23
22
import Data.Either (Either (..))
23
+ import Data.Enum (fromEnum , toEnumWithDefaults )
24
24
import 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 (..))
26
26
import Data.Identity (Identity (..))
27
27
import Data.Int (toNumber )
28
28
import Data.Lazy (Lazy , defer , force )
@@ -31,16 +31,19 @@ import Data.List.NonEmpty (NonEmptyList(..))
31
31
import Data.Maybe (Maybe (..), fromJust )
32
32
import Data.Newtype (wrap )
33
33
import 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 )
36
36
import Data.String.NonEmpty (NonEmptyString )
37
37
import Data.String.NonEmpty as NES
38
+ import Data.String.NonEmpty.CodeUnits as NESCU
38
39
import Data.Symbol (class IsSymbol , SProxy (..))
39
40
import Data.Tuple (Tuple (..))
40
41
import Partial.Unsafe (unsafePartial )
42
+ import Prim.Row as Row
43
+ import Prim.RowList as RL
44
+ import Record as Record
41
45
import 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 (..))
44
47
45
48
-- | The `Arbitrary` class represents those types whose values can be
46
49
-- | _randomly-generated_.
@@ -85,19 +88,19 @@ instance arbString :: Arbitrary String where
85
88
arbitrary = fromCharArray <$> arbitrary
86
89
87
90
instance coarbString :: Coarbitrary String where
88
- coarbitrary s = coarbitrary $ (charCodeAt zero <$> split (wrap " " ) s)
91
+ coarbitrary s = coarbitrary $ (charAt zero <$> split (wrap " " ) s)
89
92
90
93
instance arbNonEmptyString :: Arbitrary NonEmptyString where
91
- arbitrary = NES .cons <$> arbitrary <*> arbitrary
94
+ arbitrary = NESCU .cons <$> arbitrary <*> arbitrary
92
95
93
96
instance coarbNonEmptyString :: Coarbitrary NonEmptyString where
94
97
coarbitrary = coarbitrary <<< NES .toString
95
98
96
99
instance arbChar :: Arbitrary Char where
97
- arbitrary = fromCharCode <$> chooseInt 0 65536
100
+ arbitrary = toEnumWithDefaults bottom top <$> chooseInt 0 65536
98
101
99
102
instance coarbChar :: Coarbitrary Char where
100
- coarbitrary c = coarbitrary $ toCharCode c
103
+ coarbitrary c = coarbitrary $ fromEnum c
101
104
102
105
instance arbUnit :: Arbitrary Unit where
103
106
arbitrary = pure unit
@@ -117,16 +120,16 @@ instance arbArray :: Arbitrary a => Arbitrary (Array a) where
117
120
arbitrary = arrayOf arbitrary
118
121
119
122
instance 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
121
124
122
125
instance arbNonEmptyArray :: Arbitrary a => Arbitrary (NonEmptyArray a ) where
123
126
arbitrary = do
124
127
x <- arbitrary
125
128
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
130
133
131
134
instance coarbNonEmptyArray :: Coarbitrary a => Coarbitrary (NonEmptyArray a ) where
132
135
coarbitrary = coarbitrary <<< NEA .toArray
@@ -163,7 +166,7 @@ instance arbitraryList :: Arbitrary a => Arbitrary (List a) where
163
166
arbitrary = sized \n -> chooseInt zero n >>= flip listOf arbitrary
164
167
165
168
instance 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
167
170
168
171
instance arbitraryIdentity :: Arbitrary a => Arbitrary (Identity a ) where
169
172
arbitrary = Identity <$> arbitrary
@@ -193,7 +196,7 @@ instance arbitraryNoArguments :: Arbitrary NoArguments where
193
196
arbitrary = pure NoArguments
194
197
195
198
instance coarbitraryNoArguments :: Coarbitrary NoArguments where
196
- coarbitrary NoArguments = id
199
+ coarbitrary NoArguments = identity
197
200
198
201
-- | To be able to evenly distribute over chains of Sum types we build up
199
202
-- | a collection of generators and choose between. Each right component
@@ -232,18 +235,6 @@ instance arbitraryArgument :: Arbitrary a => Arbitrary (Argument a) where
232
235
instance coarbitraryArgument :: Coarbitrary a => Coarbitrary (Argument a ) where
233
236
coarbitrary (Argument a) = coarbitrary a
234
237
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
-
247
238
-- | A `Generic` implementation of the `arbitrary` member from the `Arbitrary` type class.
248
239
genericArbitrary :: forall a rep . Generic a rep => Arbitrary rep => Gen a
249
240
genericArbitrary = to <$> (arbitrary :: Gen rep )
@@ -253,30 +244,27 @@ genericCoarbitrary :: forall a rep. Generic a rep => Coarbitrary rep => a -> Gen
253
244
genericCoarbitrary x g = to <$> coarbitrary (from x) (from <$> g)
254
245
255
246
-- | 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
260
248
arbitraryRecord :: RLProxy list -> Gen (Record row )
261
249
262
- instance arbitraryRowListNil :: ArbitraryRowList Nil () where
250
+ instance arbitraryRowListNil :: ArbitraryRowList RL. Nil () where
263
251
arbitraryRecord _ = pure {}
264
252
265
253
instance arbitraryRowListCons ::
266
254
( Arbitrary a
267
255
, 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 )
271
259
, IsSymbol key
272
- ) => ArbitraryRowList (Cons key a listRest ) rowFull where
260
+ ) => ArbitraryRowList (RL. Cons key a listRest ) rowFull where
273
261
arbitraryRecord _ = do
274
262
value <- arbitrary
275
263
previous <- arbitraryRecord (RLProxy :: RLProxy listRest )
276
- pure $ insert (SProxy :: SProxy key ) value previous
264
+ pure $ Record . insert (SProxy :: SProxy key ) value previous
277
265
278
266
instance arbitraryRecordInstance ::
279
- ( RowToList row list
267
+ ( RL. RowToList row list
280
268
, ArbitraryRowList list row
281
269
) => Arbitrary (Record row ) where
282
270
arbitrary = arbitraryRecord (RLProxy :: RLProxy list )
0 commit comments