Skip to content

Commit af9203c

Browse files
authored
Merge pull request #93 from purescript/compiler/0.12
Updates for 0.12
2 parents 2c840b8 + a5d47b5 commit af9203c

File tree

9 files changed

+113
-238
lines changed

9 files changed

+113
-238
lines changed

LICENSE

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
The MIT License (MIT)
1+
Copyright 2018 PureScript
22

3-
Copyright (c) 2014 PureScript
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
45

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
this software and associated documentation files (the "Software"), to deal in
7-
the Software without restriction, including without limitation the rights to
8-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
the Software, and to permit persons to whom the Software is furnished to do so,
10-
subject to the following conditions:
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
118

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation and/or
11+
other materials provided with the distribution.
1412

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
3. Neither the name of the copyright holder nor the names of its contributors
14+
may be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bower.json

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "purescript-quickcheck",
33
"homepage": "https://github.com/purescript/purescript-quickcheck",
4-
"license": "MIT",
4+
"license": "BSD-3-Clause",
55
"authors": [
66
"John A. De Goes <[email protected]> (http://degoes.net)",
77
"Phil Freeman <[email protected]>"
@@ -20,23 +20,36 @@
2020
"package.json"
2121
],
2222
"dependencies": {
23-
"purescript-arrays": "^4.3.0",
24-
"purescript-console": "^3.0.0",
25-
"purescript-either": "^3.0.0",
26-
"purescript-enums": "^3.0.0",
27-
"purescript-exceptions": "^3.0.0",
28-
"purescript-gen": "^1.0.0",
29-
"purescript-lists": "^4.0.0",
30-
"purescript-nonempty": "^4.0.0",
31-
"purescript-partial": "^1.2.0",
32-
"purescript-random": "^3.0.0",
33-
"purescript-strings": "^3.5.0",
34-
"purescript-transformers": "^3.0.0",
35-
"purescript-generics-rep": "^5.0.0",
36-
"purescript-typelevel-prelude": "^2.4.0",
37-
"purescript-record": "^0.2.0"
23+
"purescript-arrays": "^5.0.0",
24+
"purescript-console": "^4.0.0",
25+
"purescript-control": "^4.0.0",
26+
"purescript-effect": "^2.0.0",
27+
"purescript-either": "^4.0.0",
28+
"purescript-enums": "^4.0.0",
29+
"purescript-exceptions": "^4.0.0",
30+
"purescript-foldable-traversable": "^4.0.0",
31+
"purescript-gen": "^2.0.0",
32+
"purescript-generics-rep": "^6.0.0",
33+
"purescript-identity": "^4.0.0",
34+
"purescript-integers": "^4.0.0",
35+
"purescript-lazy": "^4.0.0",
36+
"purescript-lcg": "^2.0.0",
37+
"purescript-lists": "^5.0.0",
38+
"purescript-math": "^2.1.1",
39+
"purescript-maybe": "^4.0.0",
40+
"purescript-newtype": "^3.0.0",
41+
"purescript-nonempty": "^5.0.0",
42+
"purescript-partial": "^2.0.0",
43+
"purescript-prelude": "^4.0.0",
44+
"purescript-record": "^1.0.0",
45+
"purescript-st": "^4.0.0",
46+
"purescript-strings": "^4.0.0",
47+
"purescript-tailrec": "^4.0.0",
48+
"purescript-transformers": "^4.0.0",
49+
"purescript-tuples": "^5.0.0",
50+
"purescript-unfoldable": "^4.0.0"
3851
},
3952
"devDependencies": {
40-
"purescript-assert": "^3.0.0"
53+
"purescript-assert": "^4.0.0"
4154
}
4255
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"eslint": "^3.17.1",
10-
"pulp": "^11.0.0",
11-
"purescript-psa": "^0.5.1",
12-
"rimraf": "^2.6.1"
9+
"eslint": "^4.19.1",
10+
"pulp": "^12.2.0",
11+
"purescript-psa": "^0.6.0",
12+
"rimraf": "^2.6.2"
1313
}
1414
}

src/Test/QuickCheck.purs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
-- | main = quickCheck \n -> n + 1 > n
1717
-- | ```
1818
module Test.QuickCheck
19-
( QC
20-
, quickCheck
19+
( quickCheck
2120
, quickCheckGen
2221
, quickCheck'
2322
, quickCheckGen'
@@ -44,36 +43,31 @@ module Test.QuickCheck
4443
, (>?)
4544
, assertGreaterThanEq
4645
, (>=?)
47-
, module Test.QuickCheck.LCG
46+
, module Random.LCG
4847
, module Test.QuickCheck.Arbitrary
4948
) where
5049

5150
import Prelude
5251

53-
import Control.Monad.Eff (Eff)
54-
import Control.Monad.Eff.Console (CONSOLE, log)
55-
import Control.Monad.Eff.Exception (EXCEPTION, throwException, error)
56-
import Control.Monad.Eff.Random (RANDOM)
5752
import Control.Monad.Rec.Class (Step(..), tailRec)
5853
import Data.Foldable (for_)
5954
import Data.List (List)
6055
import Data.Maybe (Maybe(..))
6156
import Data.Maybe.First (First(..))
62-
import Data.Monoid (mempty)
6357
import Data.Tuple (Tuple(..))
6458
import Data.Unfoldable (replicateA)
59+
import Effect (Effect)
60+
import Effect.Console (log)
61+
import Effect.Exception (throwException, error)
62+
import Random.LCG (Seed, mkSeed, unSeed, randomSeed)
6563
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary, class Coarbitrary, coarbitrary)
6664
import Test.QuickCheck.Gen (Gen, evalGen, runGen)
67-
import Test.QuickCheck.LCG (Seed, runSeed, randomSeed)
68-
69-
-- | A type synonym which represents the effects used by the `quickCheck` function.
70-
type QC eff a = Eff (console :: CONSOLE, random :: RANDOM, exception :: EXCEPTION | eff) a
7165

7266
-- | Test a property.
7367
-- |
7468
-- | This function generates a new random seed, runs 100 tests and
7569
-- | prints the test results to the console.
76-
quickCheck :: forall eff prop. Testable prop => prop -> QC eff Unit
70+
quickCheck :: forall prop. Testable prop => prop -> Effect Unit
7771
quickCheck prop = quickCheck' 100 prop
7872

7973
-- | A version of `quickCheck` with the property specialized to `Gen`.
@@ -84,31 +78,31 @@ quickCheck prop = quickCheck' 100 prop
8478
-- | `MonadGen`-constrained properties as they will not infer correctly when
8579
-- | used with the `quickCheck` functions unless an explicit type annotation is
8680
-- | used.
87-
quickCheckGen :: forall eff prop. Testable prop => Gen prop -> QC eff Unit
81+
quickCheckGen :: forall prop. Testable prop => Gen prop -> Effect Unit
8882
quickCheckGen = quickCheck
8983

9084
-- | A variant of the `quickCheck` function which accepts an extra parameter
9185
-- | representing the number of tests which should be run.
92-
quickCheck' :: forall eff prop. Testable prop => Int -> prop -> QC eff Unit
86+
quickCheck' :: forall prop. Testable prop => Int -> prop -> Effect Unit
9387
quickCheck' n prop = do
9488
seed <- randomSeed
9589
quickCheckWithSeed seed n prop
9690

9791
-- | A version of `quickCheck'` with the property specialized to `Gen`.
98-
quickCheckGen' :: forall eff prop. Testable prop => Int -> Gen prop -> QC eff Unit
92+
quickCheckGen' :: forall prop. Testable prop => Int -> Gen prop -> Effect Unit
9993
quickCheckGen' = quickCheck'
10094

10195
-- | A variant of the `quickCheck'` function that accepts a specific seed as
10296
-- | well as the number tests that should be run.
10397
quickCheckWithSeed
104-
:: forall eff prop. Testable prop => Seed -> Int -> prop -> QC eff Unit
98+
:: forall prop. Testable prop => Seed -> Int -> prop -> Effect Unit
10599
quickCheckWithSeed initialSeed n prop = do
106100
let result = tailRec loop { seed: initialSeed, index: 0, successes: 0, firstFailure: mempty }
107101
log $ show result.successes <> "/" <> show n <> " test(s) passed."
108102
for_ result.firstFailure \{ index, message, seed: failureSeed } ->
109103
throwException $ error
110104
$ "Test " <> show (index + 1)
111-
<> " (seed " <> show (runSeed failureSeed) <> ") failed: \n"
105+
<> " (seed " <> show (unSeed failureSeed) <> ") failed: \n"
112106
<> message
113107
where
114108
loop :: LoopState -> Step LoopState LoopState
@@ -133,7 +127,7 @@ quickCheckWithSeed initialSeed n prop = do
133127
}
134128

135129
-- | A version of `quickCheckWithSeed` with the property specialized to `Gen`.
136-
quickCheckGenWithSeed :: forall eff prop. Testable prop => Seed -> Int -> Gen prop -> QC eff Unit
130+
quickCheckGenWithSeed :: forall prop. Testable prop => Seed -> Int -> Gen prop -> Effect Unit
137131
quickCheckGenWithSeed = quickCheckWithSeed
138132

139133
type LoopState =

src/Test/QuickCheck/Arbitrary.purs

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import Prelude
1515

1616
import Control.Monad.Gen.Class (chooseBool)
1717
import Control.Monad.Gen.Common as MGC
18-
import Control.Monad.ST (pureST)
18+
import Control.Monad.ST as ST
1919
import Data.Array.NonEmpty (NonEmptyArray)
2020
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
2322
import Data.Either (Either(..))
23+
import Data.Enum (fromEnum, toEnumWithDefaults)
2424
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(..))
2626
import Data.Identity (Identity(..))
2727
import Data.Int (toNumber)
2828
import Data.Lazy (Lazy, defer, force)
@@ -31,16 +31,19 @@ import Data.List.NonEmpty (NonEmptyList(..))
3131
import Data.Maybe (Maybe(..), fromJust)
3232
import Data.Newtype (wrap)
3333
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)
3636
import Data.String.NonEmpty (NonEmptyString)
3737
import Data.String.NonEmpty as NES
38+
import Data.String.NonEmpty.CodeUnits as NESCU
3839
import Data.Symbol (class IsSymbol, SProxy(..))
3940
import Data.Tuple (Tuple(..))
4041
import Partial.Unsafe (unsafePartial)
42+
import Prim.Row as Row
43+
import Prim.RowList as RL
44+
import Record as Record
4145
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(..))
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

8790
instance coarbString :: Coarbitrary String where
88-
coarbitrary s = coarbitrary $ (charCodeAt zero <$> split (wrap "") s)
91+
coarbitrary s = coarbitrary $ (charAt zero <$> split (wrap "") s)
8992

9093
instance arbNonEmptyString :: Arbitrary NonEmptyString where
91-
arbitrary = NES.cons <$> arbitrary <*> arbitrary
94+
arbitrary = NESCU.cons <$> arbitrary <*> arbitrary
9295

9396
instance coarbNonEmptyString :: Coarbitrary NonEmptyString where
9497
coarbitrary = coarbitrary <<< NES.toString
9598

9699
instance arbChar :: Arbitrary Char where
97-
arbitrary = fromCharCode <$> chooseInt 0 65536
100+
arbitrary = toEnumWithDefaults bottom top <$> chooseInt 0 65536
98101

99102
instance coarbChar :: Coarbitrary Char where
100-
coarbitrary c = coarbitrary $ toCharCode c
103+
coarbitrary c = coarbitrary $ fromEnum c
101104

102105
instance 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

119122
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
121124

122125
instance 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

131134
instance 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

165168
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
167170

168171
instance 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

195198
instance 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
232235
instance 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.
248239
genericArbitrary :: forall a rep. Generic a rep => Arbitrary rep => Gen a
249240
genericArbitrary = to <$> (arbitrary :: Gen rep)
@@ -253,30 +244,27 @@ genericCoarbitrary :: forall a rep. Generic a rep => Coarbitrary rep => a -> Gen
253244
genericCoarbitrary 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

265253
instance 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

278266
instance 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

Comments
 (0)