From d7592b849c00c233d5ba633cf31bc032a575bf8e Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Wed, 24 Jan 2018 15:07:48 +0000 Subject: [PATCH] Reduce size in `genJson` to prevent excessively large structures Also switch to using QuickCheck, since fixing a bug in there revealed how the current size is a little silly. --- bower.json | 2 +- src/Data/Argonaut/Gen.purs | 4 ++-- test/Test/Main.purs | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/bower.json b/bower.json index 50cd413..685a627 100644 --- a/bower.json +++ b/bower.json @@ -33,6 +33,6 @@ "purescript-maps": "^3.0.0" }, "devDependencies": { - "purescript-strongcheck": "^3.1.0" + "purescript-quickcheck": "^4.6.1" } } diff --git a/src/Data/Argonaut/Gen.purs b/src/Data/Argonaut/Gen.purs index 9f047d9..eed825c 100644 --- a/src/Data/Argonaut/Gen.purs +++ b/src/Data/Argonaut/Gen.purs @@ -15,7 +15,7 @@ import Data.String as S import Data.StrMap as SM genJson :: forall m. MonadGen m => MonadRec m => Lazy (m J.Json) => m J.Json -genJson = Gen.resize (min 10) $ Gen.sized genJson' +genJson = Gen.resize (min 5) $ Gen.sized genJson' where genJson' :: Int -> m J.Json genJson' size @@ -23,7 +23,7 @@ genJson = Gen.resize (min 10) $ Gen.sized genJson' | otherwise = genLeaf genLeaf :: m J.Json - genLeaf = Gen.oneOf $ pure J.jsonNull :| [ genJBoolean, genJNumber, genJString] + genLeaf = Gen.oneOf $ pure J.jsonNull :| [genJBoolean, genJNumber, genJString] genJArray :: m J.Json genJArray = J.fromArray <$> Gen.unfoldable (defer \_ -> genJson) diff --git a/test/Test/Main.purs b/test/Test/Main.purs index e08bd6c..9f85346 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -17,8 +17,8 @@ import Control.Monad.Gen as Gen import Partial.Unsafe (unsafePartial) -import Test.StrongCheck (SC, (===), (), assert, quickCheck, quickCheck', Result) -import Test.StrongCheck.Gen (Gen) +import Test.QuickCheck (class Testable, QC, Result, quickCheck, quickCheck', (), (===)) +import Test.QuickCheck.Gen (Gen) foreign import thisIsNull :: Json foreign import thisIsBoolean :: Json @@ -28,7 +28,7 @@ foreign import thisIsArray :: Json foreign import thisIsObject :: Json foreign import nil :: JNull -isTest :: SC () Unit +isTest :: QC () Unit isTest = do assert (isNull thisIsNull "Error in null test") assert (isBoolean thisIsBoolean "Error in boolean test") @@ -37,7 +37,7 @@ isTest = do assert (isArray thisIsArray "Error in array test") assert (isObject thisIsObject "Error in object test") -foldTest :: SC () Unit +foldTest :: QC () Unit foldTest = do assert (foldFn thisIsNull == "null" "Error in foldJson null") assert (foldFn thisIsBoolean == "boolean" "Error in foldJson boolean") @@ -65,7 +65,7 @@ cases = , thisIsObject ] -foldXXX :: SC () Unit +foldXXX :: QC () Unit foldXXX = do assert ((foldJsonNull "not null" (const "null") <$> cases) == ["null", "not null", "not null", "not null", "not null", "not null"] @@ -89,7 +89,7 @@ foldXXX = do "Error in foldJsonObject") -fromTest :: SC () Unit +fromTest :: QC () Unit fromTest = do assert ((foldJsonNull false (const true) (fromNull nil)) "Error in fromNull") quickCheck (\bool -> foldJsonBoolean Nothing Just (fromBoolean bool) == Just bool "Error in fromBoolean") @@ -106,7 +106,7 @@ fromTest = do in (foldJsonObject Nothing Just (fromObject sm) == Just sm) "Error in fromObject") -toTest :: SC () Unit +toTest :: QC () Unit toTest = do assert (assertion toNull thisIsNull "Error in toNull") assert (assertion toBoolean thisIsBoolean "Error in toBoolean") @@ -122,7 +122,7 @@ toTest = do in forCases == exact msg -parserTest :: SC () Unit +parserTest :: QC () Unit parserTest = do assert ((isLeft (jsonParser "\\\ffff")) "Error in jsonParser") quickCheck' 10 roundtripTest @@ -132,7 +132,10 @@ parserTest = do json <- Gen.resize (const 5) genJson pure $ jsonParser (stringify json) === Right json -main :: SC () Unit +assert :: forall eff prop. Testable prop => prop -> QC eff Unit +assert = quickCheck' 1 + +main :: QC () Unit main = do log "isXxx tests" isTest