diff --git a/bower.json b/bower.json index 8a65280..579508e 100644 --- a/bower.json +++ b/bower.json @@ -11,12 +11,12 @@ }, "license": "MIT", "dependencies": { - "purescript-argonaut-codecs": "^3.0.0", - "purescript-argonaut-core": "^3.1.0", - "purescript-argonaut-traversals": "^3.0.0" + "purescript-argonaut-codecs": "^4.0.0", + "purescript-argonaut-core": "^4.0.0", + "purescript-argonaut-traversals": "^4.0.0" }, "devDependencies": { - "purescript-console": "^3.0.0", - "purescript-strongcheck": "^3.1.0" + "purescript-console": "^4.0.0", + "purescript-quickcheck": "^5.0.0" } } diff --git a/package.json b/package.json index c9ad9ff..85c3e1f 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,9 @@ "test": "pulp build --include examples -- --censor-lib --strict && pulp test" }, "devDependencies": { - "pulp": "^11.0.2", - "purescript-psa": "^0.5.1", - "purescript": "^0.11.6", + "pulp": "^12.0.0", + "purescript-psa": "^0.6.0", + "purescript": "^0.12.0", "rimraf": "^2.6.2" } } diff --git a/src/Data/Argonaut.purs b/src/Data/Argonaut.purs index ca9b26a..74981dd 100644 --- a/src/Data/Argonaut.purs +++ b/src/Data/Argonaut.purs @@ -8,7 +8,7 @@ module Data.Argonaut , module Data.Argonaut.Traversals ) where -import Data.Argonaut.Core (JArray, JAssoc, JBoolean, JNull, JNumber, JObject, JString, Json, foldJson, foldJsonArray, foldJsonBoolean, foldJsonNull, foldJsonNumber, foldJsonObject, foldJsonString, fromArray, fromBoolean, fromNull, fromNumber, fromObject, fromString, isArray, isBoolean, isNull, isNumber, isObject, isString, jNull, jsonEmptyArray, jsonEmptyObject, jsonEmptyString, jsonFalse, jsonNull, jsonSingletonArray, jsonSingletonObject, jsonTrue, jsonZero, stringify, toArray, toBoolean, toNull, toNumber, toObject, toString) +import Data.Argonaut.Core (Json, caseJson, caseJsonArray, caseJsonBoolean, caseJsonNull, caseJsonNumber, caseJsonObject, caseJsonString, fromArray, fromBoolean, fromNumber, fromObject, fromString, isArray, isBoolean, isNull, isNumber, isObject, isString, jsonEmptyArray, jsonEmptyObject, jsonEmptyString, jsonFalse, jsonNull, jsonSingletonArray, jsonSingletonObject, jsonTrue, jsonZero, stringify, toArray, toBoolean, toNull, toNumber, toObject, toString) import Data.Argonaut.Decode (class DecodeJson, decodeJson, defaultField, getField, getFieldOptional, (.?), (.?=), (.??)) import Data.Argonaut.Encode (class EncodeJson, assoc, encodeJson, extend, (:=), (~>)) import Data.Argonaut.JCursor (JCursor(..), JsonPrim(..), cursorGet, cursorSet, downField, downIndex, fail, fromPrims, inferEmpty, insideOut, primBool, primNull, primNum, primStr, primToJson, runJsonPrim, toPrims) diff --git a/test/Test/Main.purs b/test/Test/Main.purs index 45577ad..3435a44 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -2,68 +2,43 @@ module Test.Main where import Prelude -import Control.Monad.Eff.Console (log) - -import Data.Argonaut (Json, decodeJson, encodeJson, fromString, (.?)) -import Data.Argonaut.JCursor (JCursor(..), toPrims, fromPrims) +import Data.Argonaut (Json, decodeJson, encodeJson, stringify) import Data.Argonaut.Gen (genJson) +import Data.Argonaut.JCursor (JCursor(..), toPrims, fromPrims) import Data.Either (Either(..)) +import Data.Foldable (foldMap) import Data.Maybe (Maybe(..)) -import Data.StrMap as M - -import Test.StrongCheck (SC, Result, assert, quickCheck', ()) -import Test.StrongCheck.Arbitrary (class Arbitrary, arbitrary) -import Test.StrongCheck.Gen (chooseInt, resize) - -newtype TestJson = TestJson Json - -instance arbitraryJson :: Arbitrary TestJson where - arbitrary = TestJson <$> (resize 5 genJson) - -prop_encode_then_decode :: TestJson -> Boolean -prop_encode_then_decode (TestJson json) = - Right json == (decodeJson $ encodeJson $ json) - -prop_decode_then_encode :: TestJson -> Boolean -prop_decode_then_encode (TestJson json) = - let decoded = (decodeJson json) :: Either String Json in - Right json == (decoded >>= (encodeJson >>> pure)) - -prop_toPrims_fromPrims :: TestJson -> Result -prop_toPrims_fromPrims (TestJson j) = - Just j == fromPrims (toPrims j) "fromPrims.toPrims: " <> show (toPrims j) <> "\n\n" <> show (fromPrims (toPrims j)) - -newtype TestJCursor = TestJCursor JCursor - -runTestJCursor :: TestJCursor -> JCursor -runTestJCursor (TestJCursor j) = j - -instance arbJCursor :: Arbitrary TestJCursor where - arbitrary = do +import Data.String.Gen (genUnicodeString) +import Effect (Effect) +import Effect.Console (log) +import Test.QuickCheck (Result, quickCheck, ()) +import Test.QuickCheck.Gen (Gen, chooseInt, resize) + +genTestJson :: Gen Json +genTestJson = resize 5 genJson + +prop_toPrims_fromPrims :: Gen Result +prop_toPrims_fromPrims = do + j <- genTestJson + pure $ Just j == fromPrims (toPrims j) "fromPrims.toPrims: " <> show (toPrims j) <> "\n\n" <> foldMap stringify (fromPrims (toPrims j)) + +genTestJCursor :: Gen JCursor +genTestJCursor = do i <- chooseInt 0 2 r <- if i == 0 then pure JCursorTop - else if i == 1 then JField <$> arbitrary <*> (runTestJCursor <$> arbitrary) - else JIndex <$> arbitrary <*> (runTestJCursor <$> arbitrary) - pure $ TestJCursor r + else if i == 1 then JField <$> genUnicodeString <*> genTestJCursor + else JIndex <$> chooseInt bottom top <*> genTestJCursor + pure r -prop_jcursor_serialization :: TestJCursor -> Result -prop_jcursor_serialization (TestJCursor c) = - (decodeJson (encodeJson c) == Right c) "JCursor: " <> show c +prop_jcursor_serialization :: Gen Result +prop_jcursor_serialization = do + c <- genTestJCursor + pure $ (decodeJson (encodeJson c) == Right c) "JCursor: " <> show c -main :: SC () Unit +main :: Effect Unit main = do - log "Testing that any JSON can be encoded and then decoded" - quickCheck' 20 prop_encode_then_decode - - log "Testing that any JSON can be decoded and then encoded" - quickCheck' 20 prop_decode_then_encode - log "Testing that toPrims / fromPrims inverses" - quickCheck' 20 prop_toPrims_fromPrims + quickCheck prop_toPrims_fromPrims log "Testing that JCursor can be encoded / decoded from JSON" - quickCheck' 20 prop_jcursor_serialization - - log "Testing .? combinator" - assert $ let bar = fromString "bar" - in (M.singleton "foo" bar) .? "foo" == Right bar + quickCheck prop_jcursor_serialization