Skip to content

Reduce size in genJson to prevent excessively large structures #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"purescript-maps": "^3.0.0"
},
"devDependencies": {
"purescript-strongcheck": "^3.1.0"
"purescript-quickcheck": "^4.6.1"
}
}
4 changes: 2 additions & 2 deletions src/Data/Argonaut/Gen.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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
| size > 1 = Gen.resize (_ - 1) (Gen.choose genJArray genJObject)
| 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)
Expand Down
21 changes: 12 additions & 9 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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"] <?>
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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
Expand Down